Class: Origen::Generator::Job
Overview
A job is responsible for executing a single pattern source
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output_file_body ⇒ Object
:nodoc: all.
-
#pattern ⇒ Object
:nodoc: all.
-
#split_counter ⇒ Object
readonly
Returns the value of attribute split_counter.
Instance Method Summary collapse
- #inc_split_counter ⇒ Object
-
#initialize(pattern, options) ⇒ Job
constructor
A new instance of Job.
- #no_comments? ⇒ Boolean
- #output_extension ⇒ Object
- #output_override ⇒ Object
-
#output_pattern ⇒ Object
(also: #output_file)
Returns a full path to the output pattern, note that this is not available until the job has been run.
- #output_pattern_directory ⇒ Object
- #output_pattern_filename ⇒ Object
-
#output_pattern_filename=(val) ⇒ Object
This can be modified at runtime by the pattern generator in response to iterator substitutions.
- #output_postfix ⇒ Object
- #output_prefix ⇒ Object
- #reference_pattern ⇒ Object (also: #reference_file)
- #reference_pattern_directory ⇒ Object
- #requested_pattern ⇒ Object (also: #requested_file)
- #reset_output_pattern_filename ⇒ Object
- #run ⇒ Object
- #split_number ⇒ Object
-
#test? ⇒ Boolean
Returns true if the job is a test job, will only be true in a test scenario.
Constructor Details
#initialize(pattern, options) ⇒ Job
Returns a new instance of Job.
9 10 11 12 13 14 15 |
# File 'lib/origen/generator/job.rb', line 9 def initialize(pattern, ) @testing = [:testing] @options = @requested_pattern = pattern @no_comments = [:no_comments] @output_opt = [:output] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/origen/generator/job.rb', line 7 def @options end |
#output_file_body ⇒ Object
:nodoc: all
5 6 7 |
# File 'lib/origen/generator/job.rb', line 5 def output_file_body @output_file_body end |
#pattern ⇒ Object
:nodoc: all
5 6 7 |
# File 'lib/origen/generator/job.rb', line 5 def pattern @pattern end |
#split_counter ⇒ Object (readonly)
Returns the value of attribute split_counter.
6 7 8 |
# File 'lib/origen/generator/job.rb', line 6 def split_counter @split_counter end |
Instance Method Details
#inc_split_counter ⇒ Object
26 27 28 29 |
# File 'lib/origen/generator/job.rb', line 26 def inc_split_counter @split_counter ||= 0 @split_counter += 1 end |
#no_comments? ⇒ Boolean
22 23 24 |
# File 'lib/origen/generator/job.rb', line 22 def no_comments? @no_comments end |
#output_extension ⇒ Object
101 102 103 |
# File 'lib/origen/generator/job.rb', line 101 def output_extension '.' + Origen.tester.pat_extension end |
#output_override ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/origen/generator/job.rb', line 105 def output_override if @output_opt if @output_opt =~ /#{Origen.root}/ return @output_opt else return "#{Origen.root}/#{@output_opt}" end end nil end |
#output_pattern ⇒ Object Also known as: output_file
Returns a full path to the output pattern, note that this is not available until the job has been run
38 39 40 |
# File 'lib/origen/generator/job.rb', line 38 def output_pattern "#{output_pattern_directory}/#{output_pattern_filename}" end |
#output_pattern_directory ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/origen/generator/job.rb', line 69 def output_pattern_directory @output_pattern_directory ||= begin dir = output_override || Origen.app.config.pattern_output_directory if tester.respond_to?(:subdirectory) dir = File.join(dir, tester.subdirectory) end FileUtils.mkdir_p(dir) unless File.exist?(dir) dir end end |
#output_pattern_filename ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/origen/generator/job.rb', line 48 def output_pattern_filename return '' if @testing # If the pattern name has been overridden by an interator use that return @output_pattern_filename if @output_pattern_filename if !@pattern && !@output_file_body fail 'Sorry the output_pattern is not available until the job has been run' end body = @output_file_body ? @output_file_body : File.basename(@pattern, '.rb') output_prefix + body + output_postfix + split_number + output_extension end |
#output_pattern_filename=(val) ⇒ Object
This can be modified at runtime by the pattern generator in response to iterator substitutions
61 62 63 |
# File 'lib/origen/generator/job.rb', line 61 def output_pattern_filename=(val) @output_pattern_filename = val end |
#output_postfix ⇒ Object
97 98 99 |
# File 'lib/origen/generator/job.rb', line 97 def output_postfix Origen.config.pattern_postfix ? '_' + Origen.config.pattern_postfix : '' end |
#output_prefix ⇒ Object
91 92 93 94 95 |
# File 'lib/origen/generator/job.rb', line 91 def output_prefix p = Origen.config.pattern_prefix ? Origen.config.pattern_prefix + '_' : '' p = "_#{p}" if Origen.tester.doc? p end |
#reference_pattern ⇒ Object Also known as: reference_file
43 44 45 |
# File 'lib/origen/generator/job.rb', line 43 def reference_pattern "#{reference_pattern_directory}/#{output_pattern_filename}" end |
#reference_pattern_directory ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/origen/generator/job.rb', line 80 def reference_pattern_directory @reference_pattern_directory ||= begin dir = Origen.file_handler.reference_directory if tester.respond_to?(:subdirectory) dir = File.join(dir, tester.subdirectory) end FileUtils.mkdir_p(dir) unless File.exist?(dir) dir end end |
#requested_pattern ⇒ Object Also known as: requested_file
31 32 33 |
# File 'lib/origen/generator/job.rb', line 31 def requested_pattern @requested_pattern end |
#reset_output_pattern_filename ⇒ Object
65 66 67 |
# File 'lib/origen/generator/job.rb', line 65 def reset_output_pattern_filename @output_pattern_filename = nil end |
#run ⇒ Object
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 |
# File 'lib/origen/generator/job.rb', line 124 def run Origen.app.current_jobs << self begin if @options[:compile] Origen.generator.compiler.compile(@requested_pattern, @options) elsif @options[:job_type] == :merge Origen.generator.compiler.merge(@requested_pattern) elsif @options[:action] == :program Origen.flow.reset Origen.resources.reset OrigenTesters::Generator.execute_source(@pattern) else Origen.generator.pattern.reset # Resets the pattern controller ready for a new pattern # Give the app a chance to handle pattern dispatch skip = false Origen.app.listeners_for(:before_pattern_lookup).each do |listener| skip ||= !listener.before_pattern_lookup(@requested_pattern) end unless skip @pattern = Origen.generator.pattern_finder.find(@requested_pattern, @options) if @pattern.is_a?(Hash) @output_file_body = @pattern[:output] @pattern = @pattern[:pattern] end load @pattern unless @pattern == :skip # Run the pattern end end rescue Exception => e if @options[:continue] || Origen.running_remotely? Origen.log.error "FAILED - #{@requested_pattern} (for target #{Origen.target.name})" Origen.log.error e. e.backtrace.each do |l| Origen.log.error l end if @options[:compile] Origen.app.stats.failed_files += 1 else Origen.app.stats.failed_patterns += 1 end else raise end end Origen.app.current_jobs.pop end |
#split_number ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/origen/generator/job.rb', line 116 def split_number if split_counter "_part#{split_counter}" else '' end end |
#test? ⇒ Boolean
Returns true if the job is a test job, will only be true in a test scenario
18 19 20 |
# File 'lib/origen/generator/job.rb', line 18 def test? @testing end |