• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Origen-SDK / origen / 13040180576

13 Jan 2025 06:06PM UTC coverage: 73.961% (-0.02%) from 73.984%
13040180576

push

github

Cody Horton
Updated app version and history

6587 of 8906 relevant lines covered (73.96%)

7365.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.8
/lib/origen/application/configuration.rb
1
module Origen
8✔
2
  class Application
8✔
3
    class Configuration
8✔
4
      require 'pathname'
8✔
5

6
      # Returns the configuration's application instance
7
      attr_reader :app
8✔
8

9
      attr_accessor :name, :initials, :instructions,
8✔
10
                    :history_file, :release_directory, :release_email_subject,
11
                    :production_targets,
12
                    :vault, :output_directory, :reference_directory,
13
                    :semantically_version, :log_directory,
14
                    :pattern_directory, :pattern_output_directory, :pattern_prefix, :pattern_postfix,
15
                    :pattern_header, :default_lsf_action, :release_instructions,
16
                    :test_program_output_directory, :erb_trim_mode, :test_program_source_directory,
17
                    :test_program_template_directory, :referenced_pattern_list, :program_prefix,
18
                    :copy_command, :diff_command, :compile_only_dot_erb_files, :web_directory,
19
                    :web_domain,
20
                    :strict_errors, :unmanaged_dirs, :unmanaged_files, :remotes,
21
                    :external_app_dirs, :lint_test, :shared, :yammer_group, :rc_url, :rc_workflow,
22
                    :user_aliases, :release_externally, :gem_name, :disqus_shortname,
23
                    :default_plugin, :rc_tag_prepend_v
24

25
      attr_writer :pattern_name_translator, :proceed_with_pattern
8✔
26

27
      # Mark any attributes that are likely to depend on properties of the target here,
28
      # this will raise an error if they are ever accessed before the target has been
29
      # instantiated (a concern for Origen core developers only).
30
      #
31
      # These attributes will also receive an enhanced accessor that accepts a block, see
32
      # below for more details on this.
33
      ATTRS_THAT_DEPEND_ON_TARGET = [
8✔
34
        :output_directory, :reference_directory, :pattern_postfix, :pattern_prefix,
35
        :pattern_header, :current_plugin_pattern_header, :application_pattern_header, :shared_pattern_header,
36
        :release_directory, :pattern_name_translator, :pattern_directory, :pattern_output_directory,
37
        :proceed_with_pattern, :test_program_output_directory, :test_program_source_directory,
38
        :test_program_template_directory, :referenced_pattern_list, :program_prefix, :web_directory,
39
        :web_domain
40
      ]
41

42
      # Any attributes that want to accept a block, but not necessarily require the target
43
      # can be added here
44
      ATTRS_THAT_DONT_DEPEND_ON_TARGET = [
8✔
45
        :release_instructions, :history_file, :log_directory, :copy_command,
46
        :diff_command, :remotes,
47
        :external_app_dirs
48
      ]
49

50
      # If a current plugin is present then its value for these attributes will be
51
      # used instead of that from the current application
52
      ATTRS_THAT_CURRENT_PLUGIN_CAN_OVERRIDE = [
8✔
53
        :pattern_prefix, :pattern_postfix, :program_prefix, :pattern_header, :pattern_output_directory,
54
        :output_directory, :reference_directory, :test_program_output_directory,
55
        :test_program_template_directory, :referenced_pattern_list
56
      ]
57

58
      ATTRS_THAT_ARE_SET_TO_A_BLOCK = [
8✔
59
        :current_plugin_pattern_header, :application_pattern_header, :shared_pattern_header # :pattern_footer
60
      ]
61

62
      def log_deprecations
8✔
63
        # unless imports.empty?
64
        #  Origen.deprecate "App #{app.name} uses config.imports this will be removed in Origen V3 and a Gemfile/.gemspec should be used instead"
65
        # end
66
      end
67

68
      def initialize(app)
8✔
69
        @app = app
64✔
70
        @name = 'Unknown'
64✔
71
        @initials = 'NA'
64✔
72
        @semantically_version = false
64✔
73
        @compile_only_dot_erb_files = true
64✔
74
        # Functions used here since Origen.root is not available when this is first instantiated
75
        @output_directory = -> { "#{Origen.root}/output" }
152✔
76
        @reference_directory = lambda do
64✔
77
          if Origen.config.output_directory.to_s =~ /(\\|\/)output(\\|\/)/
×
78
            Origen.config.output_directory.to_s.sub(/(\\|\/)output(\\|\/)/, '\1.ref\2')
×
79
          else
80
            "#{Origen.root}/.ref"
×
81
          end
82
        end
83
        @release_directory = -> { Origen.root }
64✔
84
        @release_email_subject = false
64✔
85
        @log_directory = -> { "#{Origen.root}/log" }
400✔
86
        @pattern_name_translator = ->(name) { name }
64✔
87
        @pattern_directory = -> { "#{Origen.root}/pattern" }
288✔
88
        @pattern_output_directory = -> { Origen.app.config.output_directory }
328✔
89
        @history_file = -> { "#{Origen.root}/doc/history" }
64✔
90
        @default_lsf_action = :clear
64✔
91
        @proceed_with_pattern = ->(_name) { true }
536✔
92
        @erb_trim_mode = '%'
64✔
93
        @referenced_pattern_list = -> { "#{Origen.root}/list/referenced.list" }
80✔
94
        @copy_command = -> { Origen.running_on_windows? ? 'copy' : 'cp' }
112✔
95
        @diff_command = -> { Origen.running_on_windows? ? 'start winmerge' : 'tkdiff' }
64✔
96
        @imports = []
64✔
97
        @imports_dev = []
64✔
98
        @external_app_dirs = []
64✔
99
        @unmanaged_dirs = []
64✔
100
        @unmanaged_files = []
64✔
101
        @remotes = []
64✔
102
        @lint_test = {}
64✔
103
        @user_aliases = {}
64✔
104
        @rc_tag_prepend_v = true
64✔
105
      end
106

107
      # This defines an enhanced accessor for these attributes that allows them to be assigned
108
      # to an anonymous function to calculate the value based on some property of the target
109
      # objects.
110
      #
111
      # Without this the objects from the target could not be referenced in config/application.rb
112
      # because they don't exist yet, for example this will not work because $dut has not yet
113
      # been instantiated:
114
      #   # config/application.rb
115
      #
116
      #   config.output_directory = "#{Origen.root}/output/#{$dut.class}"
117
      #
118
      # However this accessor provides a way to do that via the following syntax:
119
      #   # config/application.rb
120
      #
121
      #   config.output_directory do
122
      #     "#{Origen.root}/output/#{$dut.class}"
123
      #   end
124
      #
125
      # Or on one line:
126
      #   # config/application.rb
127
      #
128
      #   config.output_directory { "#{Origen.root}/output/#{$dut.class}" }
129
      #
130
      # Or if you prefer the more explicit:
131
      #   # config/application.rb
132
      #
133
      #   config.output_directory = ->{ "#{Origen.root}/output/#{$dut.class}" }
134
      def self.add_attribute(name, options = {})
8✔
135
        options = {
162✔
136
          depend_on_target: true
54✔
137
        }.merge(options)
138
        attr_writer name
216✔
139

140
        define_method name do |override = true, &block|
216✔
141
          if block # _given?
34,072✔
142
            instance_variable_set("@#{name}".to_sym, block)
40✔
143
          else
144
            if override && ATTRS_THAT_CURRENT_PLUGIN_CAN_OVERRIDE.include?(name) &&
34,032✔
145
               app.current? && Origen.app.plugins.current
146
              var = Origen.app.plugins.current.config.send(name, override: false)
7,408✔
147
            end
148
            var ||= instance_variable_get("@#{name}".to_sym) || options[:default]
34,032✔
149
            if var.respond_to?('call')
34,032✔
150
              if options[:depend_on_target]
6,056✔
151
                # If an attempt has been made to access this attribute before the target has
152
                # been instantiated raise an error
153
                # Note Origen.app here instead of just app to ensure we are talking to the top level application,
154
                # that is the only one that has a target
155
                unless Origen.app.target_instantiated?
5,672✔
156
                  fail "You have attempted to access Origen.config.#{name} before instantiating the target"
×
157
                end
158
              end
159

160
              # Some config variables should be left as a block/proc object. If this is one of those, just return the var.
161
              ATTRS_THAT_ARE_SET_TO_A_BLOCK.include?(name) ? var : var.call
6,056✔
162
            else
163
              var
27,976✔
164
            end
165
          end
166
        end
167
      end
168

169
      ATTRS_THAT_DEPEND_ON_TARGET.each { |n| add_attribute(n) }
168✔
170

171
      ATTRS_THAT_DONT_DEPEND_ON_TARGET.each { |n| add_attribute(n, depend_on_target: false) }
64✔
172

173
      (ATTRS_THAT_CURRENT_PLUGIN_CAN_OVERRIDE - ATTRS_THAT_DEPEND_ON_TARGET - ATTRS_THAT_DONT_DEPEND_ON_TARGET).each do |name|
8✔
174
        if override && ATTRS_THAT_CURRENT_PLUGIN_CAN_OVERRIDE.include?(name) &&
×
175
           app.current? && Origen.app.plugins.current
176
          var = Origen.app.plugins.current.config.send(name, override: false)
×
177
        end
178
        var || instance_variable_get("@#{name}".to_sym)
×
179
      end
180

181
      def pattern_name_translator(name = nil, &block)
8✔
182
        if block
24✔
183
          @pattern_name_translator = block
16✔
184
        else
185
          @pattern_name_translator.call(name)
8✔
186
        end
187
      end
188

189
      def proceed_with_pattern(name = nil, &block)
8✔
190
        if block
472✔
191
          @proceed_with_pattern = block
×
192
        else
193
          @proceed_with_pattern.call(name)
472✔
194
        end
195
      end
196

197
      # Add a new pattern iterator
198
      def pattern_iterator
8✔
199
        yield Origen.generator.create_iterator
24✔
200
      end
201

202
      def lsf
8✔
203
        app.lsf.configuration
24✔
204
      end
205

206
      # Prevent a new attribute from a future version of Origen from dying before the
207
      # user can be prompted to upgrade
208
      def method_missing(method, *_args, &_block)
8✔
209
        method = method.to_s.sub('=', '')
×
210
        Origen.log.warning "WARNING - unknown configuration attribute in #{app.name}: #{method}"
×
211
      end
212
    end
213
  end
214
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc