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.



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

def initialize(pattern, options)
  @testing = options[:testing]
  @options = options
  @requested_pattern = pattern
  @no_comments = options[:no_comments]
end

Instance Attribute Details

#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

Instance Method Details

#no_comments?Boolean

Returns:

  • (Boolean)


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

def no_comments?
  @no_comments
end

#output_extensionObject



79
80
81
# File 'lib/origen/generator/job.rb', line 79

def output_extension
  '.' + Origen.tester.pat_extension
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



30
31
32
# File 'lib/origen/generator/job.rb', line 30

def output_pattern
  "#{output_pattern_directory}/#{output_pattern_filename}"
end

#output_pattern_directoryObject



61
62
63
# File 'lib/origen/generator/job.rb', line 61

def output_pattern_directory
  Origen.file_handler.output_directory
end

#output_pattern_filenameObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/origen/generator/job.rb', line 40

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 + output_extension
end

#output_pattern_filename=(val) ⇒ Object

This can be modified at runtime by the pattern generator in response to iterator substitutions



53
54
55
# File 'lib/origen/generator/job.rb', line 53

def output_pattern_filename=(val)
  @output_pattern_filename = val
end

#output_postfixObject



75
76
77
# File 'lib/origen/generator/job.rb', line 75

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

#output_prefixObject



69
70
71
72
73
# File 'lib/origen/generator/job.rb', line 69

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



35
36
37
# File 'lib/origen/generator/job.rb', line 35

def reference_pattern
  "#{reference_pattern_directory}/#{output_pattern_filename}"
end

#reference_pattern_directoryObject



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

def reference_pattern_directory
  Origen.file_handler.reference_directory
end

#requested_patternObject Also known as: requested_file



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

def requested_pattern
  @requested_pattern
end

#reset_output_pattern_filenameObject



57
58
59
# File 'lib/origen/generator/job.rb', line 57

def reset_output_pattern_filename
  @output_pattern_filename = nil
end

#runObject



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
# File 'lib/origen/generator/job.rb', line 83

def run
  Origen.app.current_job = 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
      Origen::Tester::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.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
      puts e.message
      puts e.backtrace
      exit 1
    end
  end
end

#test?Boolean

Returns true if the job is a test job, will only be true in a test scenario

Returns:

  • (Boolean)


15
16
17
# File 'lib/origen/generator/job.rb', line 15

def test?
  @testing
end