origen 0.34.3 → 0.52.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/origen +1 -231
- data/config/application.rb +12 -3
- data/config/boot.rb +2 -7
- data/config/commands.rb +3 -74
- data/config/rubocop/easy_disabled.yml +4 -0
- data/config/rubocop/easy_enabled.yml +0 -4
- data/config/rubocop/strict_disabled.yml +4 -0
- data/config/rubocop/strict_enabled.yml +0 -4
- data/config/version.rb +2 -3
- data/lib/origen.rb +27 -14
- data/lib/origen/application.rb +88 -2
- data/lib/origen/application/deployer.rb +3 -1
- data/lib/origen/application/release.rb +2 -2
- data/lib/origen/application/runner.rb +35 -20
- data/lib/origen/boot.rb +302 -0
- data/lib/origen/boot/api.rb +13 -0
- data/lib/origen/boot/app.rb +284 -0
- data/lib/origen/code_generators.rb +30 -10
- data/lib/origen/code_generators/actions.rb +244 -34
- data/lib/origen/code_generators/base.rb +9 -2
- data/lib/origen/code_generators/block.rb +203 -0
- data/lib/origen/code_generators/block_common.rb +100 -0
- data/lib/origen/code_generators/dut.rb +62 -0
- data/lib/origen/code_generators/feature.rb +50 -0
- data/lib/origen/code_generators/klass.rb +41 -0
- data/lib/origen/code_generators/model.rb +60 -0
- data/lib/origen/code_generators/module.rb +92 -0
- data/lib/origen/commands.rb +30 -13
- data/lib/origen/commands/archive.rb +175 -0
- data/lib/origen/commands/extract.rb +43 -0
- data/lib/origen/commands/generate.rb +1 -0
- data/lib/origen/commands/lint.rb +6 -1
- data/lib/origen/commands/new.rb +48 -24
- data/lib/origen/commands/new_resource.rb +41 -0
- data/lib/origen/commands/site.rb +52 -0
- data/lib/origen/commands/web.rb +11 -6
- data/lib/origen/commands_global.rb +9 -7
- data/lib/origen/core_ext/numeric.rb +20 -0
- data/lib/{option_parser → origen/core_ext/option_parser}/optparse.rb +0 -0
- data/lib/origen/dependencies.rb +0 -0
- data/lib/origen/file_handler.rb +18 -6
- data/lib/origen/generator.rb +19 -10
- data/lib/origen/generator/comparator.rb +2 -1
- data/lib/origen/generator/flow.rb +3 -1
- data/lib/origen/generator/job.rb +60 -16
- data/lib/origen/generator/pattern.rb +132 -72
- data/lib/origen/generator/pattern_finder.rb +3 -3
- data/lib/origen/generator/pattern_sequence.rb +201 -0
- data/lib/origen/generator/pattern_sequencer.rb +99 -0
- data/lib/origen/generator/pattern_thread.rb +175 -0
- data/lib/origen/loader.rb +381 -0
- data/lib/origen/log.rb +250 -108
- data/lib/origen/model.rb +22 -1
- data/lib/origen/model/exporter.rb +50 -10
- data/lib/origen/model_initializer.rb +5 -1
- data/lib/origen/operating_systems.rb +4 -0
- data/lib/origen/parameters.rb +96 -4
- data/lib/origen/parameters/set.rb +4 -3
- data/lib/origen/pins.rb +10 -8
- data/lib/origen/pins/pin.rb +61 -46
- data/lib/origen/ports/port.rb +5 -0
- data/lib/origen/registers.rb +5 -0
- data/lib/origen/registers/bit.rb +57 -53
- data/lib/origen/registers/bit_collection.rb +100 -43
- data/lib/origen/registers/msb0_delegator.rb +47 -0
- data/lib/origen/registers/reg.rb +114 -99
- data/lib/origen/revision_control.rb +1 -1
- data/lib/origen/revision_control/git.rb +23 -3
- data/lib/origen/site_config.rb +251 -60
- data/lib/origen/site_config/config.rb +217 -0
- data/lib/origen/sub_blocks.rb +106 -31
- data/lib/origen/top_level.rb +11 -0
- data/lib/origen/users/user.rb +3 -2
- data/lib/origen/utility/mailer.rb +42 -9
- data/lib/origen/value/bin_str_val.rb +1 -1
- data/lib/origen/value/hex_str_val.rb +1 -1
- data/lib/origen/version_string.rb +6 -1
- data/lib/tasks/gem.rake +6 -1
- data/origen_app_generators/Gemfile +19 -0
- data/origen_app_generators/Gemfile.lock +152 -0
- data/origen_app_generators/LICENSE +21 -0
- data/origen_app_generators/README.md +368 -0
- data/{templates/code_generators/rakefile.rb → origen_app_generators/Rakefile} +0 -0
- data/origen_app_generators/bin/boot.rb +39 -0
- data/origen_app_generators/config/application.rb +153 -0
- data/origen_app_generators/config/boot.rb +1 -0
- data/origen_app_generators/config/commands.rb +63 -0
- data/origen_app_generators/config/shared_commands.rb +177 -0
- data/origen_app_generators/config/version.rb +8 -0
- data/origen_app_generators/doc/history +223 -0
- data/origen_app_generators/lbin/bundle +105 -0
- data/origen_app_generators/lbin/byebug +29 -0
- data/origen_app_generators/lbin/coderay +29 -0
- data/origen_app_generators/lbin/htmldiff +29 -0
- data/origen_app_generators/lbin/httparty +29 -0
- data/origen_app_generators/lbin/httpclient +29 -0
- data/origen_app_generators/lbin/kramdown +29 -0
- data/origen_app_generators/lbin/ldiff +29 -0
- data/origen_app_generators/lbin/nanoc +29 -0
- data/origen_app_generators/lbin/nokogiri +29 -0
- data/origen_app_generators/lbin/origen +62 -0
- data/origen_app_generators/lbin/pry +29 -0
- data/origen_app_generators/lbin/rackup +29 -0
- data/origen_app_generators/lbin/rake +29 -0
- data/origen_app_generators/lbin/rspec +29 -0
- data/origen_app_generators/lbin/rubocop +29 -0
- data/origen_app_generators/lbin/ruby-parse +29 -0
- data/origen_app_generators/lbin/ruby-rewrite +29 -0
- data/origen_app_generators/lbin/thor +29 -0
- data/origen_app_generators/lbin/tilt +29 -0
- data/origen_app_generators/lbin/yard +29 -0
- data/origen_app_generators/lbin/yardoc +29 -0
- data/origen_app_generators/lbin/yri +29 -0
- data/origen_app_generators/lib/origen_app_generators.rb +125 -0
- data/origen_app_generators/lib/origen_app_generators/application.rb +62 -0
- data/origen_app_generators/lib/origen_app_generators/base.rb +257 -0
- data/origen_app_generators/lib/origen_app_generators/empty_application.rb +15 -0
- data/origen_app_generators/lib/origen_app_generators/empty_plugin.rb +15 -0
- data/origen_app_generators/lib/origen_app_generators/new.rb +170 -0
- data/origen_app_generators/lib/origen_app_generators/new_app_tests.rb +4 -0
- data/origen_app_generators/lib/origen_app_generators/origen_infrastructure/app_generator_plugin.rb +107 -0
- data/origen_app_generators/lib/origen_app_generators/plugin.rb +55 -0
- data/origen_app_generators/lib/origen_app_generators/test_engineering/common.rb +29 -0
- data/origen_app_generators/lib/origen_app_generators/test_engineering/stand_alone_application.rb +64 -0
- data/origen_app_generators/lib/origen_app_generators/test_engineering/test_block.rb +61 -0
- data/origen_app_generators/origen_app_generators.gemspec +33 -0
- data/{templates/code_generators → origen_app_generators/spec}/spec_helper.rb +0 -0
- data/origen_app_generators/target/debug.rb +8 -0
- data/origen_app_generators/target/default.rb +8 -0
- data/origen_app_generators/target/production.rb +0 -0
- data/origen_app_generators/templates/app_generators/application/.gitignore +37 -0
- data/origen_app_generators/templates/app_generators/application/.irbrc +9 -0
- data/origen_app_generators/templates/app_generators/application/.rspec +1 -0
- data/origen_app_generators/templates/app_generators/application/.travis.yml +11 -0
- data/origen_app_generators/templates/app_generators/application/Gemfile +34 -0
- data/origen_app_generators/templates/app_generators/application/Rakefile +7 -0
- data/origen_app_generators/templates/app_generators/application/app/blocks/top_level.rb +12 -0
- data/origen_app_generators/templates/app_generators/application/app/lib/module.rb +6 -0
- data/origen_app_generators/templates/app_generators/application/app/templates/web/index.md.erb +19 -0
- data/origen_app_generators/templates/app_generators/application/app/templates/web/layouts/_basic.html.erb +13 -0
- data/origen_app_generators/templates/app_generators/application/app/templates/web/partials/_navbar.html.erb +20 -0
- data/origen_app_generators/templates/app_generators/application/app/templates/web/release_notes.md.erb +5 -0
- data/origen_app_generators/templates/app_generators/application/config/application.rb +121 -0
- data/origen_app_generators/templates/app_generators/application/config/boot.rb +4 -0
- data/origen_app_generators/templates/app_generators/application/config/commands.rb +79 -0
- data/origen_app_generators/templates/app_generators/application/config/maillist_dev.txt +4 -0
- data/origen_app_generators/templates/app_generators/application/config/maillist_prod.txt +3 -0
- data/origen_app_generators/templates/app_generators/application/config/version.rb +8 -0
- data/origen_app_generators/templates/app_generators/application/doc/history +0 -0
- data/origen_app_generators/templates/app_generators/application/dot_keep +0 -0
- data/origen_app_generators/templates/app_generators/application/origen_core_session +2 -0
- data/origen_app_generators/templates/app_generators/application/spec/spec_helper.rb +44 -0
- data/origen_app_generators/templates/app_generators/application/target/debug.rb +8 -0
- data/origen_app_generators/templates/app_generators/application/target/default.rb +1 -0
- data/origen_app_generators/templates/app_generators/application/target/production.rb +4 -0
- data/origen_app_generators/templates/app_generators/new/generator.rb +102 -0
- data/origen_app_generators/templates/app_generators/new/info.md.erb +9 -0
- data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/application.rb +54 -0
- data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/base.rb +55 -0
- data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/module.rb +28 -0
- data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/plugin.rb +64 -0
- data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/config/load_generators.rb +6 -0
- data/origen_app_generators/templates/app_generators/plugin/Gemfile +32 -0
- data/origen_app_generators/templates/app_generators/plugin/Rakefile +10 -0
- data/origen_app_generators/templates/app_generators/plugin/app/templates/web/index.md.erb +37 -0
- data/origen_app_generators/templates/app_generators/plugin/app/templates/web/partials/_navbar_external.html.erb +20 -0
- data/origen_app_generators/templates/app_generators/plugin/app/templates/web/partials/_navbar_internal.html.erb +20 -0
- data/origen_app_generators/templates/app_generators/plugin/config/boot.rb +24 -0
- data/origen_app_generators/templates/app_generators/plugin/gemspec.rb +43 -0
- data/origen_app_generators/templates/app_generators/test_engineering/environment/j750.rb +1 -0
- data/origen_app_generators/templates/app_generators/test_engineering/environment/uflex.rb +1 -0
- data/origen_app_generators/templates/app_generators/test_engineering/environment/v93k.rb +1 -0
- data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/.keep +0 -0
- data/origen_app_generators/templates/app_generators/test_engineering/test_block/.keep +0 -0
- data/origen_site_config.yml +55 -5
- data/templates/code_generators/attributes.rb +20 -0
- data/templates/code_generators/class.rb +9 -0
- data/templates/code_generators/controller.rb +87 -0
- data/templates/code_generators/model.rb +21 -0
- data/templates/code_generators/module.rb +4 -0
- data/templates/code_generators/parameters.rb +19 -0
- data/templates/code_generators/pins.rb +28 -0
- data/templates/code_generators/registers.rb +20 -0
- data/templates/code_generators/sub_blocks.rb +24 -0
- data/templates/code_generators/timesets.rb +24 -0
- data/templates/code_generators/version.rb +0 -1
- data/templates/git/gitignore.erb +0 -1
- data/vendor/lib/models/origen/export1.rb +77 -0
- data/vendor/lib/models/origen/export1/block1.rb +13 -0
- data/vendor/lib/models/origen/export1/block1/x.rb +36 -0
- data/vendor/lib/models/origen/non_origen_meta_data.md +1 -0
- metadata +149 -68
- data/bin/fix_my_workspace +0 -100
- data/lib/c99/ate_interface.rb +0 -77
- data/lib/c99/nvm.rb +0 -110
- data/lib/c99/target/mock2.rb +0 -1
- data/lib/c99/target/subdir/mock3.rb +0 -1
- data/lib/origen/code_generators/bundler.rb +0 -17
- data/lib/origen/code_generators/gem_setup.rb +0 -49
- data/lib/origen/code_generators/rake.rb +0 -13
- data/lib/origen/code_generators/rspec.rb +0 -12
- data/lib/origen/commands/add.rb +0 -12
- data/lib/tasks/private/build.rake +0 -8
- data/templates/code_generators/gemfile_app.rb +0 -4
- data/templates/code_generators/gemfile_plugin.rb +0 -6
- data/templates/code_generators/gemspec.rb +0 -33
data/lib/origen/site_config.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
module Origen
|
2
2
|
class SiteConfig
|
3
|
+
# NOTE: Gems are not allowed to be required here, only Ruby stlibs
|
3
4
|
require 'pathname'
|
4
5
|
require 'yaml'
|
5
6
|
require 'etc'
|
7
|
+
require 'erb'
|
8
|
+
require_relative 'site_config/config'
|
9
|
+
|
10
|
+
# Require some useful methods from Origen without requiring the entire module
|
11
|
+
require_relative 'boot/api'
|
6
12
|
|
7
13
|
TRUE_VALUES = ['true', 'TRUE', '1', 1]
|
8
14
|
FALSE_VALUES = ['false', 'FALSE', '0', 0]
|
9
15
|
|
10
|
-
#
|
16
|
+
# Adding parameters to this array will prevent them from being converted to booleans if
|
17
|
+
# they are assigned one of the values in the TRUE_VALUES/FALSE_VALUES arrays
|
18
|
+
NON_BOOLEAN_PARAMETERS = [:lsf_cores, :centralized_site_config_refresh]
|
11
19
|
|
12
20
|
# Gets the gem_intall_dir. This is either site_config.home_dir/gems or the site configs gem_install_dir
|
13
21
|
def gem_install_dir
|
@@ -72,11 +80,15 @@ module Origen
|
|
72
80
|
path
|
73
81
|
end
|
74
82
|
|
83
|
+
def centralized_site_config_cache_dir
|
84
|
+
File.expand_path(find_val('centralized_site_config_cache_dir'))
|
85
|
+
end
|
86
|
+
|
75
87
|
# Dynamically remove the highest instance of :var
|
76
88
|
def remove_highest(var)
|
77
|
-
|
78
|
-
if c.
|
79
|
-
return c.
|
89
|
+
configs.each do |c|
|
90
|
+
if c.has_var?(var)
|
91
|
+
return c.remove_var(var)
|
80
92
|
end
|
81
93
|
end
|
82
94
|
|
@@ -91,9 +103,9 @@ module Origen
|
|
91
103
|
# from lowest priority to highest.
|
92
104
|
# If [] is returned, it implies that there was no instancs of :var to be removed.
|
93
105
|
ret = []
|
94
|
-
|
95
|
-
if c.
|
96
|
-
ret << c.
|
106
|
+
configs.each do |c|
|
107
|
+
if c.has_var?(var)
|
108
|
+
ret << c.remove_var(var)
|
97
109
|
end
|
98
110
|
end
|
99
111
|
ret
|
@@ -104,7 +116,8 @@ module Origen
|
|
104
116
|
def add_as_highest(var, value)
|
105
117
|
# Don't want to override anything, so just shift in a dummy site config instance at the highest level and
|
106
118
|
# set the value there.
|
107
|
-
|
119
|
+
c = Config.new(path: :runtime, parent: self, values: { var.to_s => value })
|
120
|
+
configs.prepend(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
|
108
121
|
end
|
109
122
|
alias_method :[]=, :add_as_highest
|
110
123
|
|
@@ -113,17 +126,19 @@ module Origen
|
|
113
126
|
def add_as_lowest(var, value)
|
114
127
|
# Don't want to override anything, so just shift in a dummy site config at the lowest level and
|
115
128
|
# set the value there.
|
116
|
-
configs.append(var.to_s => value)
|
129
|
+
configs.append(Config.new(path: :runtime, parent: self, values: { var.to_s => value }))
|
117
130
|
end
|
118
131
|
|
119
132
|
# Adds a new site config file as the highest priority
|
120
133
|
def add_site_config_as_highest(site_config_file)
|
121
|
-
configs.prepend YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
|
134
|
+
# configs.prepend YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
|
135
|
+
configs.prepend(Config.new(path: site_config_file, parent: self))
|
122
136
|
end
|
123
137
|
|
124
138
|
# Adds a new site config file as the highest priority
|
125
139
|
def add_site_config_as_lowest(site_config_file)
|
126
|
-
configs.append YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
|
140
|
+
# configs.append YAML.load_file(File.expand_path('../../../origen_site_config.yml', __FILE__))
|
141
|
+
configs.append(Config.new(path: site_config_file, parent: self))
|
127
142
|
end
|
128
143
|
|
129
144
|
def method_missing(method, *args, &block)
|
@@ -144,15 +159,10 @@ module Origen
|
|
144
159
|
val
|
145
160
|
end
|
146
161
|
|
147
|
-
def get(val)
|
148
|
-
find_val(val)
|
149
|
-
end
|
150
|
-
alias_method :[], :get
|
151
|
-
|
152
162
|
def get_all(val)
|
153
163
|
ret = []
|
154
|
-
|
155
|
-
if c.
|
164
|
+
configs.each do |c|
|
165
|
+
if c.has_var?(val)
|
156
166
|
ret << c[val]
|
157
167
|
end
|
158
168
|
end
|
@@ -160,86 +170,267 @@ module Origen
|
|
160
170
|
end
|
161
171
|
|
162
172
|
def clear
|
163
|
-
|
173
|
+
configs.clear
|
164
174
|
end
|
165
175
|
|
166
176
|
def rebuild!
|
167
177
|
configs!
|
168
178
|
end
|
169
179
|
|
170
|
-
|
180
|
+
def refresh
|
181
|
+
configs.each(&:refresh)
|
182
|
+
end
|
183
|
+
|
184
|
+
def pretty_print_configs
|
185
|
+
puts 'The following config files are ordered from last-encountered (highest priority) first-encountered (lowest priority)'
|
186
|
+
puts
|
187
|
+
configs.each_with_index do |config, i|
|
188
|
+
puts "#{i}: #{config.path} (#{config.type})"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
alias_method :pp_configs, :pretty_print_configs
|
192
|
+
|
193
|
+
def all_vars
|
194
|
+
vars = {}
|
195
|
+
configs.each do |c|
|
196
|
+
vars = c.values.merge(vars)
|
197
|
+
end
|
198
|
+
vars
|
199
|
+
end
|
200
|
+
alias_method :env, :all_vars
|
201
|
+
|
202
|
+
# Gets all config variables as a hash, but the hash's values are the Config instances which defines the highest
|
203
|
+
# priority of each var, instead of the var's value itself.
|
204
|
+
def vars_by_configs
|
205
|
+
vars = {}
|
206
|
+
configs.each do |c|
|
207
|
+
vars = c.values.map { |k, v| [k, c] }.to_h.merge(vars)
|
208
|
+
end
|
209
|
+
vars
|
210
|
+
end
|
211
|
+
alias_method :vars_by_config, :vars_by_configs
|
212
|
+
|
213
|
+
def pretty_print_env(*vars)
|
214
|
+
puts
|
215
|
+
spacing = ' ' * 2
|
216
|
+
r = vars.empty? ? nil : Regexp.union(vars.map { |v| Regexp.new(v) })
|
217
|
+
all_vars.each do |var, val|
|
218
|
+
if !r.nil? && !(var.match r)
|
219
|
+
next
|
220
|
+
end
|
221
|
+
|
222
|
+
if val.is_a?(Array)
|
223
|
+
puts "#{var}: ["
|
224
|
+
val.each { |v| puts "#{spacing} #{v}" }
|
225
|
+
puts ']'
|
226
|
+
elsif val.is_a?(Hash)
|
227
|
+
puts "#{var}: {"
|
228
|
+
val.each { |v| puts "#{spacing} #{v}" }
|
229
|
+
puts '}'
|
230
|
+
else
|
231
|
+
puts "#{var}: #{val}"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
puts
|
235
|
+
end
|
236
|
+
alias_method :pp_env, :pretty_print_env
|
237
|
+
|
238
|
+
def to_env(val)
|
239
|
+
"ORIGEN_#{val.upcase}"
|
240
|
+
end
|
241
|
+
|
242
|
+
def env_contains?(val)
|
243
|
+
ENV.key?(val)
|
244
|
+
end
|
245
|
+
|
246
|
+
def env(val)
|
247
|
+
if env_contains?(val)
|
248
|
+
ENV[val]
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def inspect_variable(*vars)
|
253
|
+
vars.each do |var|
|
254
|
+
puts "Inspecting Variable: #{var}"
|
255
|
+
if env_contains?(to_env(var))
|
256
|
+
puts "Environment Variable (#{to_env(var)}): #{env(to_env(var))}"
|
257
|
+
else
|
258
|
+
puts "(No enviornment variable #{to_env(var)} defined)"
|
259
|
+
end
|
260
|
+
configs.each do |c|
|
261
|
+
if c.has_var?(var)
|
262
|
+
puts "#{c.path} (#{c.type}): #{c[var]}"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
puts
|
266
|
+
end
|
267
|
+
end
|
268
|
+
alias_method :inspect_var, :inspect_variable
|
269
|
+
alias_method :inspect_variables, :inspect_variable
|
270
|
+
alias_method :inspect_vars, :inspect_variable
|
271
|
+
|
272
|
+
# Inspects the config(s) at the incex given.
|
273
|
+
def inspect_configs(*config_indexes)
|
274
|
+
config_indexes.each do |i|
|
275
|
+
if i.to_i > configs.size
|
276
|
+
puts red("Origen::SiteConfig: index #{i} is out of range of the available configs! Total configs: #{configs.size}.")
|
277
|
+
elsif i.to_i < 0
|
278
|
+
puts red("Origen::SiteConfig: index #{i} is less than 0. This index is ignored.")
|
279
|
+
else
|
280
|
+
c = configs[i.to_i]
|
281
|
+
puts "Inspecting config \##{i}"
|
282
|
+
puts "Type: #{c.type}"
|
283
|
+
puts "Path: #{c.path}"
|
284
|
+
if c.centralized?
|
285
|
+
# Add a safeguard in case something happened being bootup and now and the cache is no longer present
|
286
|
+
puts "Cached At: #{c.cache_file}" if c.cache_file
|
287
|
+
puts "Cached On: #{c.cache_file.ctime}" if c.cache_file
|
288
|
+
end
|
289
|
+
|
290
|
+
puts
|
291
|
+
puts 'Values from this config:'
|
292
|
+
spacing = ' ' * 2
|
293
|
+
c.values.each do |var, val|
|
294
|
+
if val.is_a?(Array)
|
295
|
+
puts "#{var}: ["
|
296
|
+
val.each { |v| puts "#{spacing} #{v}" }
|
297
|
+
puts ']'
|
298
|
+
elsif val.is_a?(Hash)
|
299
|
+
puts "#{var}: {"
|
300
|
+
val.each { |v| puts "#{spacing} #{v}" }
|
301
|
+
puts '}'
|
302
|
+
else
|
303
|
+
puts "#{var}: #{val}"
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
puts
|
308
|
+
puts 'Active (highest-level) values from this config:'
|
309
|
+
spacing = ' ' * 2
|
310
|
+
vars_by_config.select { |k, v| v == c }.map { |k, v| [k, v[k]] }.to_h.each do |var, val|
|
311
|
+
if val.is_a?(Array)
|
312
|
+
puts "#{var}: ["
|
313
|
+
val.each { |v| puts "#{spacing} #{v}" }
|
314
|
+
puts ']'
|
315
|
+
elsif val.is_a?(Hash)
|
316
|
+
puts "#{var}: {"
|
317
|
+
val.each { |v| puts "#{spacing} #{v}" }
|
318
|
+
puts '}'
|
319
|
+
else
|
320
|
+
puts "#{var}: #{val}"
|
321
|
+
end
|
322
|
+
end
|
323
|
+
puts
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
alias_method :inspect_config, :inspect_configs
|
171
328
|
|
172
329
|
def find_val(val, options = {})
|
173
330
|
env = "ORIGEN_#{val.upcase}"
|
174
331
|
if ENV.key?(env)
|
175
332
|
value = ENV[env]
|
176
|
-
value
|
177
333
|
else
|
178
|
-
config = configs.find { |c| c.
|
179
|
-
value = config ? config
|
334
|
+
config = configs.find { |c| c.has_var?(val) }
|
335
|
+
value = config ? config.find_val(val) : nil
|
180
336
|
end
|
181
337
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
338
|
+
unless NON_BOOLEAN_PARAMETERS.include?(val.to_s.downcase.to_sym)
|
339
|
+
if TRUE_VALUES.include?(value)
|
340
|
+
return true
|
341
|
+
elsif FALSE_VALUES.include?(value)
|
342
|
+
return false
|
343
|
+
end
|
186
344
|
end
|
187
345
|
value
|
188
346
|
end
|
347
|
+
alias_method :get, :find_val
|
348
|
+
alias_method :[], :find_val
|
349
|
+
|
350
|
+
private
|
351
|
+
|
352
|
+
def red(message)
|
353
|
+
"\e[0;31;49m#{message}\e[0m"
|
354
|
+
end
|
189
355
|
|
190
356
|
def configs
|
191
357
|
@configs ||= configs!
|
192
358
|
end
|
193
359
|
|
360
|
+
# Searches a directory and returns an array of config objects (from lowest to highest priority) that were found
|
361
|
+
# @note This includes searching for <code>./config/</code> in <code>dir</code>. In other words, this searches both
|
362
|
+
# <code>dir</code> and <code>dir/config</code>.
|
363
|
+
def load_directory(dir, prepend: false)
|
364
|
+
[
|
365
|
+
File.join(dir, 'config', 'origen_site_config.yml'),
|
366
|
+
File.join(dir, 'config', 'origen_site_config.yml.erb'),
|
367
|
+
File.join(dir, 'origen_site_config.yml'),
|
368
|
+
File.join(dir, 'origen_site_config.yml.erb')
|
369
|
+
].each do |f|
|
370
|
+
if File.exist?(f)
|
371
|
+
if prepend
|
372
|
+
configs.unshift(Config.new(path: f, parent: self))
|
373
|
+
else
|
374
|
+
configs << Config.new(path: f, parent: self)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
194
380
|
# Forces a reparse of the site configs.
|
195
|
-
# This will set the
|
381
|
+
# This will set the configs along the current path first,
|
196
382
|
# then, using those values, will add a site config at the home directory.
|
197
383
|
def configs!
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
configs << YAML.load_file(file) if File.exist?(file) && YAML.load_file(file)
|
213
|
-
path = path.parent
|
214
|
-
end
|
215
|
-
|
216
|
-
# Add and any site_configs from the directory hierarchy where Ruby is installed
|
217
|
-
path = Pathname.new($LOAD_PATH.last)
|
218
|
-
until path.root?
|
219
|
-
file = File.join(path, 'origen_site_config.yml')
|
220
|
-
configs << YAML.load_file(file) if File.exist?(file) && YAML.load_file(file)
|
221
|
-
path = path.parent
|
222
|
-
end
|
384
|
+
# This global is set when Origen is first required, it generally means that what is considered
|
385
|
+
# to be the pwd for the purposes of looking for a site_config file is the place from where the
|
386
|
+
# user invoked Origen. Otherwise if the running app switches the PWD it can lead to confusing
|
387
|
+
# behavior - this was a particular problem when testing the new app generator which switches the
|
388
|
+
# pwd to /tmp to build the new app
|
389
|
+
path = $_origen_invocation_pwd
|
390
|
+
@configs = []
|
391
|
+
|
392
|
+
# Add any site_configs from where we are currently running from, i.e. the application
|
393
|
+
# directory area
|
394
|
+
until path.root?
|
395
|
+
load_directory(path)
|
396
|
+
path = path.parent
|
397
|
+
end
|
223
398
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
399
|
+
# Add and any site_configs from the directory hierarchy where Ruby is installed
|
400
|
+
path = Pathname.new($LOAD_PATH.last)
|
401
|
+
until path.root?
|
402
|
+
load_directory(path)
|
403
|
+
path = path.parent
|
228
404
|
end
|
229
405
|
|
406
|
+
# Add the one from the Origen core as the lowest priority, this one defines
|
407
|
+
# the default values
|
408
|
+
load_directory(File.expand_path('../../../', __FILE__))
|
409
|
+
|
230
410
|
# Add the site_config from the user's home directory as highest priority, if it exists
|
231
411
|
# But, make sure we take the site installation's setup into account.
|
232
412
|
# That is, if user's home directories are somewhere else, make sure we use that directory to the find
|
233
413
|
# the user's overwrite file. The user can then override that if they want."
|
234
|
-
|
235
|
-
|
236
|
-
|
414
|
+
load_directory(File.expand_path(user_install_dir), prepend: true)
|
415
|
+
|
416
|
+
# Load any centralized site configs now.
|
417
|
+
centralized_site_config = find_val('centralized_site_config')
|
418
|
+
if centralized_site_config
|
419
|
+
# We know the last two site configs will exists (they are in Origen core) and that they contain the default
|
420
|
+
# values. We want the centralized config to load right after those.
|
421
|
+
@configs.insert(-3, Config.new(path: centralized_site_config, parent: self))
|
237
422
|
end
|
238
423
|
|
424
|
+
# After all configs have been populated, see if the centralized needs refreshing
|
425
|
+
@configs.each { |c| c.refresh if c.needs_refresh? }
|
426
|
+
|
239
427
|
@configs
|
240
428
|
end
|
241
429
|
end
|
242
430
|
|
431
|
+
# Blow this cache whenever this file is re-loaded
|
432
|
+
@site_config = nil
|
433
|
+
|
243
434
|
def self.site_config
|
244
435
|
@site_config ||= SiteConfig.new
|
245
436
|
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
module Origen
|
2
|
+
class SiteConfig
|
3
|
+
class Config
|
4
|
+
attr_reader :path
|
5
|
+
attr_reader :parent
|
6
|
+
attr_reader :type
|
7
|
+
attr_reader :values
|
8
|
+
|
9
|
+
RESTRICTED_FROM_CENTRALIZED_VARIABLES = %w(centralized_site_config centralized_site_config_cache_dir centralized_site_config_verify_ssl)
|
10
|
+
|
11
|
+
def initialize(path:, parent:, values: nil)
|
12
|
+
@parent = parent
|
13
|
+
if path == :runtime
|
14
|
+
path = "runtime_#{object_id}"
|
15
|
+
@type = :runtime
|
16
|
+
elsif path.start_with?('http')
|
17
|
+
@path = path
|
18
|
+
@type = :centralized
|
19
|
+
else
|
20
|
+
@path = path
|
21
|
+
@type = :local
|
22
|
+
end
|
23
|
+
@contains_centralized = false
|
24
|
+
@loaded = false
|
25
|
+
|
26
|
+
if values
|
27
|
+
@values = values
|
28
|
+
@loaded = true
|
29
|
+
else
|
30
|
+
@values = nil
|
31
|
+
load
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def needs_refresh?
|
36
|
+
if centralized?
|
37
|
+
if refresh_time < 0
|
38
|
+
false
|
39
|
+
elsif cached?
|
40
|
+
# If the refresh time is 0, this will always be true
|
41
|
+
# Note the difference of time objects below will give the difference in seconds.
|
42
|
+
(Time.now - cached_file.ctime) / 3600.0 > refresh_time
|
43
|
+
else
|
44
|
+
# If the cached file cannot be found, force a new fetch
|
45
|
+
true
|
46
|
+
end
|
47
|
+
else
|
48
|
+
false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def refresh_time
|
53
|
+
parent.find_val('centralized_site_config_refresh')
|
54
|
+
end
|
55
|
+
|
56
|
+
def cached_file
|
57
|
+
@cached_file ||= Pathname(parent.centralized_site_config_cache_dir).join('cached_config')
|
58
|
+
end
|
59
|
+
|
60
|
+
def cached?
|
61
|
+
File.exist?(cached_file)
|
62
|
+
end
|
63
|
+
|
64
|
+
def fetch
|
65
|
+
def inform_user_of_cached_file
|
66
|
+
if cached?
|
67
|
+
puts yellow('Origen: Site Config: Found previously cached site config. Using the older site config.')
|
68
|
+
else
|
69
|
+
puts yellow('Origen: Site Config: No cached file found. An empty site config will be used in its place.')
|
70
|
+
end
|
71
|
+
puts
|
72
|
+
end
|
73
|
+
|
74
|
+
if centralized?
|
75
|
+
puts "Pulling centralized site config from: #{path}"
|
76
|
+
|
77
|
+
begin
|
78
|
+
# TODO: needs to be replaced with a net/http equivalent, can't use gems here. The reference
|
79
|
+
# to HTTParty will raise an error until that is done, but it will be handled gracefully below.
|
80
|
+
text = HTTParty.get(path, verify: parent.find_val('centralized_site_config_verify_ssl'))
|
81
|
+
puts "Caching centralized site config to: #{cached_file}"
|
82
|
+
|
83
|
+
unless Dir.exist?(cached_file.dirname)
|
84
|
+
FileUtils.mkdir_p(cached_file.dirname)
|
85
|
+
end
|
86
|
+
File.open(cached_file, 'w+') do |f|
|
87
|
+
f.write(text)
|
88
|
+
end
|
89
|
+
|
90
|
+
rescue SocketError => e
|
91
|
+
puts red("Origen: Site Config: Unable to connect to #{path}")
|
92
|
+
puts red('Origen: Site Config: Failed to retrieve centralized site config!')
|
93
|
+
puts red("Error from exception: #{e.message}")
|
94
|
+
|
95
|
+
inform_user_of_cached_file
|
96
|
+
rescue OpenSSL::SSL::SSLError => e
|
97
|
+
puts red("Origen: Site Config: Unable to connect to #{path}")
|
98
|
+
puts red('Origen: Site Config: Failed to retrieve centralized site config!')
|
99
|
+
puts red("Error from exception: #{e.message}")
|
100
|
+
puts red('It looks like the error is related to SSL certification. If this is a trusted server, you can use')
|
101
|
+
puts red("the site config setting 'centralized_site_config_verify_ssl' to disable verifying the SSL certificate.")
|
102
|
+
|
103
|
+
inform_user_of_cached_file
|
104
|
+
rescue Exception => e
|
105
|
+
# Rescue anything else to avoid any un-caught exceptions causing Origen not to boot.
|
106
|
+
# Print lots of red so that the users are aware that there's a problem, but don't ultimately want this
|
107
|
+
# to render Origen un-bootable
|
108
|
+
puts red("Origen: Site Config: Unexpected exception ocurred trying to either retrieve or cache the site config at #{path}")
|
109
|
+
puts red('Origen: Site Config: Failed to retrieve centralized site config!')
|
110
|
+
puts red("Class of exception: #{e.class}")
|
111
|
+
puts red("Error from exception: #{e.message}")
|
112
|
+
|
113
|
+
inform_user_of_cached_file
|
114
|
+
end
|
115
|
+
text
|
116
|
+
end
|
117
|
+
end
|
118
|
+
alias_method :refresh, :fetch
|
119
|
+
|
120
|
+
# Loads the site config into memory.
|
121
|
+
# Process the site config as an ERB, if indicated to do so (.erb file extension)
|
122
|
+
# After the initial load, any centralized site configs will be retreived (if needed), cached, and loaded.
|
123
|
+
def load
|
124
|
+
def read_erb(erb)
|
125
|
+
ERB.new(File.read(erb), 0, '%<>')
|
126
|
+
end
|
127
|
+
|
128
|
+
if centralized?
|
129
|
+
if !cached?
|
130
|
+
if fetch
|
131
|
+
erb = read_erb(cached_file)
|
132
|
+
else
|
133
|
+
# There was a problem fetching the config. Just use an empty string.
|
134
|
+
# Warning message will come from #fetch
|
135
|
+
erb = ERB.new('')
|
136
|
+
end
|
137
|
+
else
|
138
|
+
erb = read_erb(cached_file)
|
139
|
+
end
|
140
|
+
|
141
|
+
@values = (YAML.load(erb.result) || {})
|
142
|
+
else
|
143
|
+
if File.extname(path) == '.erb'
|
144
|
+
erb = read_erb(path)
|
145
|
+
@values = (YAML.load(erb.result) || {})
|
146
|
+
else
|
147
|
+
@values = (YAML.load_file(path) || {})
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
unless @values.is_a?(Hash)
|
152
|
+
puts red("Origen: Site Config: The config at #{path} was not parsed as a Hash, but as a #{@values.class}")
|
153
|
+
puts red(' Please review the format of the this file.')
|
154
|
+
puts red(' Alternatively, an error condition may have been received from the server.')
|
155
|
+
puts red(" This site config is available at: #{cached_file}")
|
156
|
+
puts red(' This config will not be loaded and will be replaced with an empty config.')
|
157
|
+
puts
|
158
|
+
@values = {}
|
159
|
+
end
|
160
|
+
|
161
|
+
if centralized?
|
162
|
+
# check for restricted centralized config values
|
163
|
+
RESTRICTED_FROM_CENTRALIZED_VARIABLES.each do |var|
|
164
|
+
if @values.key?(var)
|
165
|
+
val = @values.delete(var)
|
166
|
+
puts red("Origen: Site Config: config variable #{var} is not allowed in the centralized site config and will be removed.")
|
167
|
+
puts red(" Value #{val} will not be applied!")
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
@loaded = true
|
173
|
+
@values
|
174
|
+
end
|
175
|
+
|
176
|
+
def remove_var(var)
|
177
|
+
@values.delete(var)
|
178
|
+
end
|
179
|
+
|
180
|
+
def has_var?(var)
|
181
|
+
@values.key?(var)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Finds the value from this config, or from one of its centralized configs (if applicable)
|
185
|
+
def find_val(val)
|
186
|
+
@values[val]
|
187
|
+
end
|
188
|
+
alias_method :[], :find_val
|
189
|
+
|
190
|
+
def loaded?
|
191
|
+
@loaded
|
192
|
+
end
|
193
|
+
|
194
|
+
def local?
|
195
|
+
type == :local
|
196
|
+
end
|
197
|
+
|
198
|
+
def centralized?
|
199
|
+
type == :centralized
|
200
|
+
end
|
201
|
+
|
202
|
+
def runtime?
|
203
|
+
type == :runtime
|
204
|
+
end
|
205
|
+
|
206
|
+
private
|
207
|
+
|
208
|
+
def red(message)
|
209
|
+
"\e[0;31;49m#{message}\e[0m"
|
210
|
+
end
|
211
|
+
|
212
|
+
def yellow(message)
|
213
|
+
"\e[0;33;49m#{message}\e[0m"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|