Class: Origen::Generator::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/generator/job.rb

Overview

A job is responsible for executing a single pattern source

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @testing = options[:testing]
  @options = options
  @requested_pattern = pattern
  @no_comments = options[:no_comments]
  @output_opt = options[:output]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/origen/generator/job.rb', line 7

def options
  @options
end

#output_file_bodyObject

:nodoc: all



5
6
7
# File 'lib/origen/generator/job.rb', line 5

def output_file_body
  @output_file_body
end

#patternObject

:nodoc: all



5
6
7
# File 'lib/origen/generator/job.rb', line 5

def pattern
  @pattern
end

#split_counterObject (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_counterObject



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

Returns:

  • (Boolean)


22
23
24
# File 'lib/origen/generator/job.rb', line 22

def no_comments?
  @no_comments
end

#output_extensionObject



101
102
103
# File 'lib/origen/generator/job.rb', line 101

def output_extension
  '.' + Origen.tester.pat_extension
end

#output_overrideObject



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_patternObject 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_directoryObject



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_filenameObject



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_postfixObject



97
98
99
# File 'lib/origen/generator/job.rb', line 97

def output_postfix
  Origen.config.pattern_postfix ? '_' + Origen.config.pattern_postfix : ''
end

#output_prefixObject



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_patternObject 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_directoryObject



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_patternObject 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_filenameObject



65
66
67
# File 'lib/origen/generator/job.rb', line 65

def reset_output_pattern_filename
  @output_pattern_filename = nil
end

#runObject



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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/origen/generator/job.rb', line 128

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
        @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.message
      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.log.stop_job
  Origen.app.current_jobs.pop
end

#split_numberObject



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

#strip_dir_and_ext(name) ⇒ Object



124
125
126
# File 'lib/origen/generator/job.rb', line 124

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/origen/generator/job.rb', line 18

def test?
  @testing
end