Class: Rubycc::Rmake::Plan

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycc/rmake/model.rb

Overview

The result of Makefile#plan: the steps in the order make would run them (prerequisites before dependents). It carries no execution logic — the recipe runner is B2.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps) ⇒ Plan

Returns a new instance of Plan.



111
112
113
# File 'lib/rubycc/rmake/model.rb', line 111

def initialize(steps)
  @steps = steps
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



109
110
111
# File 'lib/rubycc/rmake/model.rb', line 109

def steps
  @steps
end

Instance Method Details

#command_linesObject

The command texts in execution order, one per line — the shape a make -n transcript takes, used by the golden tests.



117
118
119
# File 'lib/rubycc/rmake/model.rb', line 117

def command_lines
  @steps.flat_map { |step| step.commands.map(&:text) }
end

#dumpObject

A human-readable dump that, unlike #command_lines, keeps the target boundaries and the +@+/+-+/+++ prefix attributes visible.



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/rubycc/rmake/model.rb', line 123

def dump
  @steps.map do |step|
    lines = step.commands.map do |cmd|
      flags = +""
      flags << "@" if cmd.silent?
      flags << "-" if cmd.ignore_error?
      flags << "+" if cmd.force?
      "    #{flags.empty? ? '' : "#{flags} "}#{cmd.text}"
    end
    (["#{step.target}:"] + lines).join("\n")
  end.join("\n")
end