Class: Makit::Rake::TraceController

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/rake/trace_controller.rb

Overview

Enhanced trace controller for Rake with Makit-specific debugging information

This class provides enhanced tracing capabilities when –trace is passed to rake, adding makit-specific debugging information to help with troubleshooting and understanding command execution flow.

Examples:

Basic usage

# In Rakefile
require "makit"
Makit::Rake::TraceController.setup

With environment variable

MAKIT_TRACE=true rake --trace

Class Method Summary collapse

Class Method Details

.setupvoid

This method returns an undefined value.

Set up enhanced tracing for Rake tasks

This method should be called early in the Rakefile to enable enhanced tracing when –trace is passed to rake.



25
26
27
28
29
30
31
# File 'lib/makit/rake/trace_controller.rb', line 25

def self.setup
  return unless should_enhance_trace?

  # Set up enhanced tracing
  setup_enhanced_tracing
  Makit::Logging.debug("Enhanced trace controller activated") if defined?(Makit::Logging)
end

.setup_enhanced_tracingvoid

This method returns an undefined value.

Set up enhanced tracing by monkey patching Rake’s trace methods



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/makit/rake/trace_controller.rb', line 59

def self.setup_enhanced_tracing
  # Store the original trace method if not already stored
  unless ::Rake::Task.method_defined?(:makit_original_trace)
    ::Rake::Task.class_eval do
      alias_method :makit_original_trace, :trace

      def trace(mode, message)
        # Call original trace
        makit_original_trace(mode, message)

        # Add makit-specific trace info
        add_makit_trace_info(mode, message)
      end

      private

      # Add makit-specific trace information
      #
      # @param mode [Symbol] trace mode (:execute, :invoke, :prereq, etc.)
      # @param message [String] trace message
      # @return [void]
      def add_makit_trace_info(mode, message)
        case mode
        when :execute
          trace_makit_execution(message)
        when :invoke
          trace_makit_invocation(message)
        when :prereq
          trace_makit_prerequisite(message)
        when :syntax
          trace_makit_syntax(message)
        end
      end

      # Trace makit execution with detailed information
      #
      # @param message [String] execution message
      # @return [void]
      def trace_makit_execution(message)
        if makit_related?(message)
          puts "  [MAKIT] Executing: #{message}"
          puts "  [MAKIT] Strategy: #{get_makit_strategy_info}"
          puts "  [MAKIT] Environment: #{ENV["MAKIT_STRATEGY"] || "auto"}"
          puts "  [MAKIT] Working Directory: #{Dir.pwd}"
          puts "  [MAKIT] Timestamp: #{Time.now.iso8601}"
          puts "  [MAKIT] Task: #{name}"
        end
      end

      # Trace makit invocation
      #
      # @param message [String] invocation message
      # @return [void]
      def trace_makit_invocation(message)
        if makit_related?(message)
          puts "  [MAKIT] Invoking: #{message}"
          puts "  [MAKIT] Task: #{name}"
        end
      end

      # Trace makit prerequisite
      #
      # @param message [String] prerequisite message
      # @return [void]
      def trace_makit_prerequisite(message)
        if makit_related?(message)
          puts "  [MAKIT] Prerequisite: #{message}"
          puts "  [MAKIT] Task: #{name}"
        end
      end

      # Trace makit syntax
      #
      # @param message [String] syntax message
      # @return [void]
      def trace_makit_syntax(message)
        if makit_related?(message)
          puts "  [MAKIT] Syntax: #{message}"
        end
      end

      # Check if message is makit-related
      #
      # @param message [String] message to check
      # @return [Boolean] true if message is makit-related
      def makit_related?(message)
        message.downcase.include?("makit") ||
        message.include?("bundle") ||
        message.include?("gem") ||
        message.include?("dotnet") ||
        message.include?("protoc") ||
        message.include?("git")
      end

      # Get makit strategy information safely
      #
      # @return [String] strategy information
      def get_makit_strategy_info
        begin
          if defined?(Makit::Commands::Runner)
            runner = Makit::Commands::Runner.default
            info = runner.strategy_info
            "#{info[:type]} (#{info[:class]})"
          else
            "not available"
          end
        rescue => e
          "error: #{e.message}"
        end
      end
    end
  end
end

.should_enhance_trace?Boolean

Check if trace enhancement should be enabled

Returns:

  • (Boolean)

    true if trace enhancement should be enabled



36
37
38
39
40
# File 'lib/makit/rake/trace_controller.rb', line 36

def self.should_enhance_trace?
  ENV["RAKE_TRACE"] ||
  ARGV.include?("--trace") ||
  ENV["MAKIT_TRACE"] == "true"
end

.trace_statusHash

Get current trace status

Returns:

  • (Hash)

    trace status information



45
46
47
48
49
50
51
52
# File 'lib/makit/rake/trace_controller.rb', line 45

def self.trace_status
  {
    rake_trace: ENV["RAKE_TRACE"],
    trace_flag: ARGV.include?("--trace"),
    makit_trace: ENV["MAKIT_TRACE"],
    enhanced: should_enhance_trace?,
  }
end