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.
-
#split_names ⇒ Object
readonly
Returns the value of attribute split_names.
Instance Method Summary collapse
- #inc_split_counter(name = '') ⇒ 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
- #strip_dir_and_ext(name) ⇒ 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 |
#split_names ⇒ Object (readonly)
Returns the value of attribute split_names.
6 7 8 |
# File 'lib/origen/generator/job.rb', line 6 def split_names @split_names end |
Instance Method Details
#inc_split_counter(name = '') ⇒ Object
26 27 28 29 30 31 |
# File 'lib/origen/generator/job.rb', line 26 def inc_split_counter(name = '') @split_counter ||= 0 @split_names ||= [''] @split_counter += 1 @split_names << name end |
#no_comments? ⇒ Boolean
22 23 24 |
# File 'lib/origen/generator/job.rb', line 22 def no_comments? @no_comments end |
#output_extension ⇒ Object
104 105 106 |
# File 'lib/origen/generator/job.rb', line 104 def output_extension '.' + Origen.tester.pat_extension end |
#output_override ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/origen/generator/job.rb', line 108 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
40 41 42 |
# File 'lib/origen/generator/job.rb', line 40 def output_pattern "#{output_pattern_directory}/#{output_pattern_filename}" end |
#output_pattern_directory ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/origen/generator/job.rb', line 72 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
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/origen/generator/job.rb', line 50 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
64 65 66 |
# File 'lib/origen/generator/job.rb', line 64 def output_pattern_filename=(val) @output_pattern_filename = val end |
#output_postfix ⇒ Object
100 101 102 |
# File 'lib/origen/generator/job.rb', line 100 def output_postfix Origen.config.pattern_postfix ? '_' + Origen.config.pattern_postfix : '' end |
#output_prefix ⇒ Object
94 95 96 97 98 |
# File 'lib/origen/generator/job.rb', line 94 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
45 46 47 |
# File 'lib/origen/generator/job.rb', line 45 def reference_pattern "#{reference_pattern_directory}/#{output_pattern_filename}" end |
#reference_pattern_directory ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/origen/generator/job.rb', line 83 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
33 34 35 |
# File 'lib/origen/generator/job.rb', line 33 def requested_pattern @requested_pattern end |
#reset_output_pattern_filename ⇒ Object
68 69 70 |
# File 'lib/origen/generator/job.rb', line 68 def reset_output_pattern_filename @output_pattern_filename = nil end |
#run ⇒ Object
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/origen/generator/job.rb', line 135 def run Origen.app.current_jobs << self begin if @options[:compile] Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :compiler) Origen.generator.compiler.compile(@requested_pattern, @options) elsif @options[:job_type] == :merge Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :merger) Origen.generator.compiler.merge(@requested_pattern) elsif @options[:action] == :program if Origen.running_simulation? Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :simulator) else Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :program_generator) end Origen.flow.reset Origen.resources.reset OrigenTesters::Generator.execute_source(@pattern) else if Origen.running_simulation? Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :simulator) else Origen.log.start_job(strip_dir_and_ext(@requested_pattern), :pattern_generator) end 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 if @options[:sequence] @pattern = @requested_pattern Origen.pattern.sequence do |seq| # This splits the pattern name by "_" then removes all values that are common to all patterns # and then rejoins what is left. # The goal is to keep the thread ID concise for the log and rather than using the whole pattern # name only focussing on what is different. # e.g. if you combined patterns flash_read_ckbd_ip1_max.rb and flash_read_ckbd_ip2_max.rb into # a concurrent sequence then the two threads would be called 'ip1' and 'ip2'. ids = @options[:patterns].map do |pat| Pathname.new(pat).basename('.*').to_s.split('_') end ids = ids.map { |id| id.reject { |i| ids.all? { |id| id.include?(i) } }.join('_') } @options[:patterns].each_with_index do |pat, i| id = ids[i] id = i.to_s if id.empty? seq.in_parallel id do seq.run pat end end end else @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 end rescue Exception => e # Whoever has aborted the job is responsible for cleaning it up unless e.is_a?(Origen::Generator::AbortError) 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 end Origen.log.stop_job Origen.app.current_jobs.pop end |
#split_number ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/origen/generator/job.rb', line 119 def split_number if split_counter if split_names[split_counter] != '' "_#{split_names[split_counter]}" else "_part#{split_counter}" end else '' end end |
#strip_dir_and_ext(name) ⇒ Object
131 132 133 |
# File 'lib/origen/generator/job.rb', line 131 def strip_dir_and_ext(name) Pathname.new(name).basename('.*').basename('.*').to_s 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 |