origen 0.38.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/bin/origen +1 -236
  3. data/config/application.rb +10 -1
  4. data/config/version.rb +1 -1
  5. data/lib/origen/{boot_api.rb → boot/api.rb} +2 -2
  6. data/lib/origen/boot/app.rb +324 -0
  7. data/lib/origen/boot.rb +287 -0
  8. data/lib/origen/commands/archive.rb +175 -0
  9. data/lib/origen/commands/extract.rb +43 -0
  10. data/lib/origen/commands/new.rb +33 -23
  11. data/lib/origen/commands.rb +4 -1
  12. data/lib/origen/commands_global.rb +3 -2
  13. data/lib/origen/operating_systems.rb +4 -0
  14. data/lib/origen/revision_control.rb +1 -1
  15. data/lib/origen/site_config.rb +4 -1
  16. data/lib/origen.rb +3 -2
  17. data/origen_app_generators/Gemfile +16 -0
  18. data/origen_app_generators/Gemfile.lock +147 -0
  19. data/origen_app_generators/LICENSE +21 -0
  20. data/origen_app_generators/README.md +368 -0
  21. data/origen_app_generators/Rakefile +10 -0
  22. data/origen_app_generators/bin/boot.rb +37 -0
  23. data/{bin → origen_app_generators/bin}/fix_my_workspace +0 -0
  24. data/origen_app_generators/config/application.rb +153 -0
  25. data/origen_app_generators/config/boot.rb +1 -0
  26. data/origen_app_generators/config/commands.rb +63 -0
  27. data/origen_app_generators/config/shared_commands.rb +172 -0
  28. data/origen_app_generators/config/version.rb +8 -0
  29. data/origen_app_generators/doc/history +213 -0
  30. data/origen_app_generators/lib/origen_app_generators/application.rb +62 -0
  31. data/origen_app_generators/lib/origen_app_generators/base.rb +231 -0
  32. data/origen_app_generators/lib/origen_app_generators/empty_application.rb +15 -0
  33. data/origen_app_generators/lib/origen_app_generators/empty_plugin.rb +15 -0
  34. data/origen_app_generators/lib/origen_app_generators/new.rb +162 -0
  35. data/origen_app_generators/lib/origen_app_generators/origen_infrastructure/app_generator_plugin.rb +109 -0
  36. data/origen_app_generators/lib/origen_app_generators/plugin.rb +58 -0
  37. data/origen_app_generators/lib/origen_app_generators/sub_block_parser.rb +81 -0
  38. data/origen_app_generators/lib/origen_app_generators/test_engineering/stand_alone_application.rb +236 -0
  39. data/origen_app_generators/lib/origen_app_generators/test_engineering/test_block.rb +162 -0
  40. data/origen_app_generators/lib/origen_app_generators.rb +123 -0
  41. data/origen_app_generators/lib/tasks/app_generators.rake +6 -0
  42. data/origen_app_generators/lib/tasks/new_app_tests.rake +8 -0
  43. data/origen_app_generators/origen_app_generators.gemspec +33 -0
  44. data/origen_app_generators/spec/spec_helper.rb +49 -0
  45. data/origen_app_generators/spec/sub_block_spec.rb +36 -0
  46. data/origen_app_generators/target/debug.rb +8 -0
  47. data/origen_app_generators/target/default.rb +8 -0
  48. data/origen_app_generators/target/production.rb +0 -0
  49. data/origen_app_generators/templates/app_generators/application/Gemfile +19 -0
  50. data/origen_app_generators/templates/app_generators/application/Rakefile +7 -0
  51. data/origen_app_generators/templates/app_generators/application/config/application.rb +125 -0
  52. data/origen_app_generators/templates/app_generators/application/config/boot.rb +4 -0
  53. data/origen_app_generators/templates/app_generators/application/config/commands.rb +79 -0
  54. data/origen_app_generators/templates/app_generators/application/config/maillist_dev.txt +4 -0
  55. data/origen_app_generators/templates/app_generators/application/config/maillist_prod.txt +3 -0
  56. data/origen_app_generators/templates/app_generators/application/config/version.rb +8 -0
  57. data/origen_app_generators/templates/app_generators/application/doc/history +0 -0
  58. data/origen_app_generators/templates/app_generators/application/dot_keep +0 -0
  59. data/origen_app_generators/templates/app_generators/application/lib/app.rake +6 -0
  60. data/origen_app_generators/templates/app_generators/application/lib/module.rb +22 -0
  61. data/origen_app_generators/templates/app_generators/application/lib/top_level.rb +12 -0
  62. data/origen_app_generators/templates/app_generators/application/origen_core_session +2 -0
  63. data/origen_app_generators/templates/app_generators/application/spec/spec_helper.rb +44 -0
  64. data/origen_app_generators/templates/app_generators/application/target/debug.rb +8 -0
  65. data/origen_app_generators/templates/app_generators/application/target/default.rb +1 -0
  66. data/origen_app_generators/templates/app_generators/application/target/production.rb +4 -0
  67. data/origen_app_generators/templates/app_generators/application/templates/web/index.md.erb +19 -0
  68. data/origen_app_generators/templates/app_generators/application/templates/web/layouts/_basic.html.erb +13 -0
  69. data/origen_app_generators/templates/app_generators/application/templates/web/partials/_navbar.html.erb +20 -0
  70. data/origen_app_generators/templates/app_generators/application/templates/web/release_notes.md.erb +5 -0
  71. data/origen_app_generators/templates/app_generators/new/generator.rb +102 -0
  72. data/origen_app_generators/templates/app_generators/new/info.md.erb +9 -0
  73. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/config/load_generators.rb +6 -0
  74. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/application.rb +54 -0
  75. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/base.rb +55 -0
  76. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/module.rb +28 -0
  77. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/plugin.rb +64 -0
  78. data/origen_app_generators/templates/app_generators/plugin/Gemfile +26 -0
  79. data/origen_app_generators/templates/app_generators/plugin/Rakefile +10 -0
  80. data/origen_app_generators/templates/app_generators/plugin/config/boot.rb +24 -0
  81. data/origen_app_generators/templates/app_generators/plugin/gemspec.rb +42 -0
  82. data/origen_app_generators/templates/app_generators/plugin/lib/README +4 -0
  83. data/origen_app_generators/templates/app_generators/plugin/lib_dev/README +5 -0
  84. data/origen_app_generators/templates/app_generators/plugin/templates/web/index.md.erb +37 -0
  85. data/origen_app_generators/templates/app_generators/plugin/templates/web/partials/_navbar_external.html.erb +20 -0
  86. data/origen_app_generators/templates/app_generators/plugin/templates/web/partials/_navbar_internal.html.erb +20 -0
  87. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/Gemfile +23 -0
  88. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/j750.rb +1 -0
  89. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/jlink.rb +1 -0
  90. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/uflex.rb +1 -0
  91. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/v93k.rb +1 -0
  92. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/ip_block.rb +23 -0
  93. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/ip_block_controller.rb +5 -0
  94. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/top_level.rb +33 -0
  95. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/top_level_controller.rb +21 -0
  96. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/pattern/example.rb +4 -0
  97. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/target/top_level.rb +4 -0
  98. data/origen_app_generators/templates/app_generators/test_engineering/test_block/environment/j750.rb +2 -0
  99. data/origen_app_generators/templates/app_generators/test_engineering/test_block/environment/ultraflex.rb +2 -0
  100. data/origen_app_generators/templates/app_generators/test_engineering/test_block/environment/v93k.rb +2 -0
  101. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib/controller.rb +12 -0
  102. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib/interface.rb +21 -0
  103. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib/model.rb +18 -0
  104. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib_dev/dut.rb +27 -0
  105. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib_dev/dut_controller.rb +26 -0
  106. data/origen_app_generators/templates/app_generators/test_engineering/test_block/pattern/example.rb +5 -0
  107. data/origen_app_generators/templates/app_generators/test_engineering/test_block/program/prb1.rb +11 -0
  108. data/origen_app_generators/templates/app_generators/test_engineering/test_block/target/default.rb +2 -0
  109. data/origen_site_config.yml +13 -2
  110. data/templates/git/gitignore.erb +0 -1
  111. metadata +99 -4
@@ -0,0 +1,287 @@
1
+ $VERBOSE = nil # Don't care about world writable dir warnings and the like
2
+
3
+ require 'pathname'
4
+ require 'fileutils'
5
+
6
+ class OrigenBootError < StandardError
7
+ end
8
+
9
+ # Keep a note of the pwd at the time when Origen was first loaded, this is initially used
10
+ # by the site_config lookup.
11
+ $_origen_invocation_pwd ||= Pathname.pwd
12
+
13
+ load File.expand_path('../operating_systems.rb', __FILE__)
14
+ load File.expand_path('../site_config.rb', __FILE__)
15
+
16
+ # This will be referenced later in ruby_version_check, the origen used to launch
17
+ # the process is different than the one that actually runs under bundler
18
+ $origen_launch_root = Pathname.new(File.dirname(__FILE__)).parent
19
+
20
+ # Override any influence from $LANG in the users environment
21
+ Encoding.default_external = Encoding::UTF_8
22
+ Encoding.default_internal = Encoding::UTF_8
23
+ ENV['LC_ALL'] = nil
24
+ ENV['LANG'] = nil
25
+ ENV['LANG'] = 'en_US.UTF-8'
26
+
27
+ # Are we inside an Origen application workspace?
28
+ if defined?(ORIGEN_ROOT)
29
+ origen_root = ORIGEN_ROOT
30
+ else
31
+ app_config = File.join('config', 'application.rb')
32
+ if File.exist?(app_config)
33
+ origen_root = Dir.pwd
34
+ else
35
+ path = Pathname.new(Dir.pwd)
36
+ until path.root? || origen_root
37
+ if File.exist?(File.join(path, app_config))
38
+ origen_root = path.to_s
39
+ else
40
+ path = path.parent
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ warnings = nil
47
+
48
+ ########################################################################################################################
49
+ ########################################################################################################################
50
+ ## If running inside an application workspace
51
+ ########################################################################################################################
52
+ ########################################################################################################################
53
+ if origen_root
54
+ require_relative 'boot/app'
55
+
56
+ if ARGV.first == 'setup'
57
+ Origen::Boot.setup(origen_root)
58
+ puts
59
+ puts 'Your application has been setup successfully'
60
+ exit 0
61
+ else
62
+ warnings = Origen::Boot.app!(origen_root)
63
+ boot_app = true
64
+ end
65
+
66
+ ########################################################################################################################
67
+ ########################################################################################################################
68
+ ## If running outside an application and a user or central tool Origen bundle is to be used
69
+ ##
70
+ ## Note that there is a lot of duplication of the above code, however this is a copy of the original code
71
+ ## to boot up outside an app when a tool Origen bundle is present. It has been maintained separately to
72
+ ## ensure that the changes to how an application boots up do not affect the global tool installation functionality.
73
+ ########################################################################################################################
74
+ ########################################################################################################################
75
+ elsif Origen.site_config.gem_manage_bundler && (Origen.site_config.user_install_enable || Origen.site_config.tool_repo_install_dir)
76
+ # Force everyone to have a consistent way of installing gems with bundler.
77
+ # In this case, we aren't running from an Origen application, so build everything at Origen.home instead
78
+ # Have two options here: if user_install_enable is true, use user_install_dir. Otherwise, use the tool_repo_install_dir
79
+ install_dir = Origen.site_config.user_install_enable ? File.expand_path(Origen.site_config.user_install_dir) : File.expand_path(Origen.site_config.tool_repo_install_dir)
80
+ unless Dir.exist?(install_dir)
81
+ load File.expand_path('../../lib/origen/utility/input_capture.rb', __FILE__)
82
+ include Origen::Utility::InputCapture
83
+
84
+ puts "Root directory '#{install_dir}' does not exist. Would you like to create it?"
85
+ if get_text(confirm: :return_boolean)
86
+ FileUtils.mkdir(install_dir)
87
+ else
88
+ puts 'Exiting with creating Origen install'
89
+ exit!
90
+ end
91
+ end
92
+
93
+ gemfile = File.join(install_dir, 'Gemfile')
94
+ unless File.exist?(gemfile)
95
+ # Create a default Gemfile that can be further customized by the user.
96
+ # Initial Gemfile only requires Origen. Nothing else. Essentially a blank installation.
97
+ Dir.chdir(install_dir) do
98
+ `bundle init`
99
+ end
100
+ # The above will give a general Gemfile from Bundler. We'll just append "gem 'origen' to the end.
101
+ File.open(gemfile, 'a') do |f|
102
+ f << "gem 'origen'\n"
103
+ end
104
+ end
105
+ ENV['BUNDLE_GEMFILE'] = gemfile
106
+ ENV['BUNDLE_PATH'] = File.expand_path(Origen.site_config.gem_install_dir)
107
+ ENV['BUNDLE_BIN'] = File.join(install_dir, 'lbin')
108
+
109
+ origen_exec = File.join(ENV['BUNDLE_BIN'], 'origen')
110
+
111
+ # If the user/tool bundle already exists but we have not been invoked through that, abort this thread
112
+ # and re-launch under the required bundler environment
113
+ if File.exist?(origen_exec) && !ENV['BUNDLE_BIN_PATH'] && File.exist?(ENV['BUNDLE_PATH'])
114
+ exec Gem.ruby, origen_exec, *ARGV
115
+ exit 0
116
+ else
117
+ boot_app = false
118
+ end
119
+
120
+ if File.exist?(ENV['BUNDLE_GEMFILE'])
121
+ # Overriding bundler here so that bundle install can be automated as required
122
+ require 'bundler/shared_helpers'
123
+ if Bundler::SharedHelpers.in_bundle?
124
+ require 'bundler'
125
+ if STDOUT.tty?
126
+ begin
127
+ fail OrigenBootError unless File.exist?(ENV['BUNDLE_BIN'])
128
+ Bundler.setup
129
+ fail OrigenBootError unless File.exist?(ENV['BUNDLE_BIN'])
130
+ rescue Gem::LoadError, Bundler::BundlerError, OrigenBootError => e
131
+ cmd = "bundle install --gemfile #{ENV['BUNDLE_GEMFILE']} --binstubs #{ENV['BUNDLE_BIN']} --path #{ENV['BUNDLE_PATH']}"
132
+ # puts cmd
133
+ puts 'Installing required gems...'
134
+ puts
135
+ `chmod o-w #{install_dir}` # Stops some annoying world writable warnings during install
136
+ `chmod o-w #{install_dir}/bin` if File.exist?("#{install_dir}/bin")
137
+ `chmod o-w #{install_dir}/.bin` if File.exist?("#{install_dir}/.bin")
138
+ result = false
139
+
140
+ Bundler.with_clean_env do
141
+ if Origen.os.unix?
142
+ if Origen.site_config.gem_build_switches
143
+ Origen.site_config.gem_build_switches.each do |switches|
144
+ `bundle config build.#{switches}`
145
+ end
146
+ end
147
+ end
148
+ result = system(cmd)
149
+ end
150
+ `chmod o-w #{ENV['BUNDLE_BIN']}`
151
+ # Make .bat versions of all executables, Bundler should really be doing this when running
152
+ # on windows
153
+ if Origen.os.windows?
154
+ bat_present = File.exist? "#{install_dir}/lbin/origen.bat"
155
+ Dir.glob("#{install_dir}/lbin/*").each do |bin|
156
+ unless bin =~ /.bat$/
157
+ bat = "#{bin}.bat"
158
+ unless File.exist?(bat)
159
+ File.open(bat, 'w') { |f| f.write('@"ruby.exe" "%~dpn0" %*') }
160
+ end
161
+ end
162
+ end
163
+ if !bat_present && !result
164
+ puts 'Some Windows specific updates to your workspace were required, please re-run the last command'
165
+ exit 0
166
+ end
167
+ end
168
+ if result
169
+ exec "origen #{ARGV.join(' ')}"
170
+ exit 0
171
+ else
172
+ puts
173
+ puts "If you have just updated a gem version and are now getting an error that Bundler cannot find compatible versions for it then first try running 'bundle update <gemname>'."
174
+ puts "For example if you have just changed the version of origen_core run 'bundle update origen_core'."
175
+ exit 1
176
+ end
177
+ end
178
+ else
179
+ Bundler.setup
180
+ end
181
+ end
182
+ require 'bundler/setup'
183
+ require 'origen'
184
+ else
185
+ $LOAD_PATH.unshift "#{File.expand_path(File.dirname(__FILE__))}/../lib"
186
+ require 'origen'
187
+ end
188
+
189
+ ########################################################################################################################
190
+ ########################################################################################################################
191
+ ## We are running outside of an app and no-special global Origen tool setup is present
192
+ ########################################################################################################################
193
+ ########################################################################################################################
194
+ else
195
+ $LOAD_PATH.unshift "#{File.expand_path(File.dirname(__FILE__))}/../lib"
196
+ require 'origen'
197
+ end
198
+
199
+ ########################################################################################################################
200
+ ########################################################################################################################
201
+
202
+ begin
203
+ # Now that the runtime Origen version is loaded, we need to re-load the site config.
204
+ # This is because the version of the site_config that was originally loaded above has instantiated
205
+ # a site_config object, whereas earlier versions of Origen (which could now be loaded), instantiated
206
+ # a simple hash instead.
207
+ # Reloading now will ensure consistency between the site config object and the version of
208
+ # Origen that is now live.
209
+ Origen.instance_variable_set(:@site_config, nil)
210
+ load 'origen/site_config.rb'
211
+ require 'colored'
212
+ # Emit all broadcast messages before executing all commands
213
+ if Origen.site_config.broadcast_info
214
+ puts
215
+ Array(Origen.site_config.broadcast_info).each { |line| puts line }
216
+ puts
217
+ end
218
+ if Origen.site_config.broadcast_warning
219
+ puts
220
+ Array(Origen.site_config.broadcast_warning).each { |line| puts line.yellow }
221
+ puts
222
+ end
223
+ if Origen.site_config.broadcast_danger
224
+ puts
225
+ Array(Origen.site_config.broadcast_danger).each { |line| puts line.red }
226
+ puts
227
+ end
228
+ if Origen.site_config.broadcast_success
229
+ puts
230
+ Array(Origen.site_config.broadcast_success).each { |line| puts line.green }
231
+ puts
232
+ end
233
+
234
+ # If this script has been invoked from within an Origen application then open
235
+ # up all commands, if not then only allow the command to create a new Origen
236
+ # application.
237
+ if origen_root && boot_app
238
+ puts warnings if warnings && Origen.version >= '0.40.0'
239
+ require 'origen/commands'
240
+ else
241
+ require 'origen/commands_global'
242
+ end
243
+ rescue Exception => e
244
+ # A formatted stack dump will not be printed if the application ends via 'exit 0' or 'exit 1'. In that
245
+ # case the application code is responsible for printing a helpful error message.
246
+ # This will intercept all other exits, e.g. via 'fail "Something has done wrong"', and split the stack
247
+ # dump to separate all in-application references from Origen core/plugin references.
248
+ if e.is_a?(SystemExit)
249
+ exit e.status
250
+ else
251
+ puts
252
+ if Origen.app_loaded?
253
+ puts 'COMPLETE CALL STACK'
254
+ puts '-------------------'
255
+ puts e.message unless e.is_a?(SystemExit)
256
+ puts e.backtrace
257
+
258
+ puts
259
+ puts 'APPLICATION CALL STACK'
260
+ puts '----------------------'
261
+ puts e.message unless e.is_a?(SystemExit)
262
+ # Only print out the application stack trace by default, if verbose logging is
263
+ # enabled then output the full thing
264
+ e.backtrace.each do |line|
265
+ path = Pathname.new(line)
266
+ if path.absolute?
267
+ if line =~ /^#{Origen.root}/ && line !~ /^#{Origen.root}\/lbin/
268
+ puts line
269
+ end
270
+ else
271
+ puts line unless line =~ /^.\/lbin/
272
+ end
273
+ end
274
+ else
275
+ puts 'COMPLETE CALL STACK'
276
+ puts '-------------------'
277
+ puts e.message unless e.is_a?(SystemExit)
278
+ puts e.backtrace
279
+ end
280
+ exit 1
281
+ end
282
+ ensure
283
+ if Origen.app_loaded?
284
+ Origen.app.listeners_for(:on_origen_shutdown).each(&:on_origen_shutdown)
285
+ Origen.app.runner.shutdown
286
+ end
287
+ end
@@ -0,0 +1,175 @@
1
+ require 'optparse'
2
+ require 'fileutils'
3
+ require 'find'
4
+ require 'bundler'
5
+
6
+ options = {}
7
+ options[:exclude] = []
8
+
9
+ opt_parser = OptionParser.new do |opts|
10
+ opts.banner = 'Usage: origen archive [options]'
11
+ opts.on('--local', 'Install gems within your app so that it can run completely standalone, no archive is created') { options[:local] = true }
12
+ opts.on('--no-local', "Reverses a previously executed 'origen archive --local' operation, returning the app to use a conventional gem installation") { options[:no_local] = true }
13
+ opts.on('-e', '--exclude DIR', 'Exclude the given directory from the archive, e.g. --exclude simulation') { |dir| options[:exclude] << dir }
14
+ end
15
+ opt_parser.parse! ARGV
16
+
17
+ origen_binstub = File.join(Origen.root, 'lbin', 'origen')
18
+
19
+ unless File.exist?(origen_binstub) && File.read(origen_binstub) =~ /This file was generated by Origen/
20
+ puts 'An archive can only be created after your application is running the latest Origen boot system,'
21
+ puts 'run the following command to update your application and then try again:'
22
+ puts
23
+ puts ' origen setup'
24
+ puts
25
+ exit 1
26
+ end
27
+
28
+ if options[:no_local]
29
+ Dir.chdir Origen.root do
30
+ dir = File.join('vendor', 'gems')
31
+ FileUtils.rm_rf(dir) if File.exist?(dir)
32
+ end
33
+ passed = true
34
+ Bundler.with_clean_env do
35
+ passed = system('origen -v')
36
+ end
37
+ if passed
38
+ Origen.log.success 'Local gems have been removed and your application has been restored to use a conventional gem installation.'
39
+ exit 0
40
+ else
41
+ Origen.log.error 'A problem was encountered when trying to boot your application after removing local gems!'
42
+ exit 1
43
+ end
44
+ end
45
+
46
+ Origen.log.info 'Preparing the workspace' unless options[:local]
47
+ tmp1 = File.join(Origen.root, '..', "#{Origen.app.name}_copy")
48
+ name = "#{Origen.app.name}-#{Origen.app.version}"
49
+ tmpdir = File.join(Origen.root, 'tmp')
50
+ tmp = File.join(tmpdir, name)
51
+ archive = File.join(Origen.root, 'tmp', "#{name}.origen")
52
+ unless options[:local]
53
+ FileUtils.rm_rf(tmp1) if File.exist?(tmp1)
54
+ FileUtils.rm_rf(tmp) if File.exist?(tmp)
55
+ FileUtils.rm_rf(archive) if File.exist?(archive)
56
+ end
57
+
58
+ exclude_dirs = ['.bundle', 'output', 'tmp', 'web', 'waves', '.git', '.ref', 'dist', 'log', '.lsf', '.session'] + options[:exclude]
59
+
60
+ unless options[:local]
61
+ begin
62
+ Origen.log.info 'Creating a copy of the application'
63
+ if Origen.os.linux?
64
+ Dir.chdir Origen.root do
65
+ cmd = "rsync -av --progress . tmp/#{name} --exclude tmp"
66
+ exclude_dirs.each do |dir|
67
+ cmd += " --exclude #{dir}"
68
+ end
69
+ passed = system cmd
70
+ unless passed
71
+ Origen.log.error 'A problem was encountered when creating a copy of your application, archive aborted!'
72
+ exit 1
73
+ end
74
+ end
75
+ else
76
+ FileUtils.mkdir_p(tmp1)
77
+ FileUtils.cp_r "#{Origen.root}/.", tmp1
78
+ FileUtils.mv tmp1, tmp
79
+ end
80
+ # Remove all .svn or .SYNC directories
81
+ Find.find(tmp) do |path|
82
+ n = File.basename(path)
83
+ if FileTest.directory?(path) && (n == '.svn' || n == '.SYNC')
84
+ puts "Removing: #{path}"
85
+ FileUtils.remove_dir(path)
86
+ end
87
+ end
88
+ ensure
89
+ FileUtils.rm_rf(tmp1) if File.exist?(tmp1)
90
+ end
91
+ end
92
+
93
+ Origen.log.info 'Fetching all required gems' unless options[:local]
94
+ dir = options[:local] ? Origen.root : tmp
95
+ Dir.chdir dir do
96
+ # When archiving, also include copies of all gem packages for other platforms, this will help if the
97
+ # archive needs to run on a different platform to the one used to create it in the future
98
+ unless options[:local]
99
+ Bundler.with_clean_env do
100
+ FileUtils.rm_rf('.bundle') if File.exist?('.bundle')
101
+ system 'hash -r' # Ignore fail if not on bash
102
+
103
+ passed = system "GEM_HOME=#{File.expand_path(Origen.site_config.gem_install_dir)} bundle package --all --all-platforms --no-install"
104
+ unless passed
105
+ Origen.log.error 'A problem was encountered when packaging the gems, archive aborted!'
106
+ exit 1
107
+ end
108
+ FileUtils.rm_rf('.bundle') if File.exist?('.bundle')
109
+ end
110
+ end
111
+
112
+ Origen.log.info 'Installing gems into the application (this could take a while)'
113
+ FileUtils.mkdir_p(File.join('vendor', 'gems'))
114
+ require 'origen/boot/app'
115
+ begin
116
+ Origen::Boot.setup(dir)
117
+ Origen::Boot.setup_bundler(dir)
118
+ rescue Exception => e
119
+ Origen.log.error e.to_s
120
+ Origen.log.error 'A problem was encountered setting up the workspace, archive aborted!'
121
+ exit 1
122
+ end
123
+ FileUtils.touch('.origen_archive') unless options[:local]
124
+
125
+ Bundler.with_clean_env do
126
+ passed = system('bundle') && system('origen -v')
127
+ unless passed
128
+ Origen.log.error 'A problem was encountered installing the gem bundle, archive aborted!'
129
+ exit 1
130
+ end
131
+ end
132
+
133
+ unless options[:local]
134
+ Origen.log.info 'Removing all temporary and output files'
135
+ exclude_dirs.each do |dir|
136
+ if File.exist?(dir)
137
+ if File.symlink?(dir)
138
+ FileUtils.rm(dir)
139
+ else
140
+ FileUtils.rm_rf(dir)
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ if options[:local]
148
+ Origen.log.success 'Gems have been successfully installed to your application'
149
+ Origen.log.success ''
150
+ Origen.log.success 'If you ran this in error or otherwise want to undo it, run the following command:'
151
+ Origen.log.success ' origen archive --no-local'
152
+ Origen.log.success ''
153
+ else
154
+ Origen.log.info 'Creating archive'
155
+ Dir.chdir tmpdir do
156
+ FileUtils.rm_rf('.bundle') if File.exist?('.bundle')
157
+ passed = system "tar -cvzf #{name}.origen ./#{name}"
158
+ unless passed
159
+ Origen.log.error 'A problem was encountered creating the tarball, archive aborted!'
160
+ exit 1
161
+ end
162
+
163
+ Origen.log.info 'Cleaning up'
164
+ FileUtils.rm_rf(name)
165
+ end
166
+
167
+ puts
168
+ begin
169
+ size = `du -sh tmp/#{name}.origen`.split(/\s+/).first
170
+ Origen.log.success "Your application archive is complete and is #{size}B in size"
171
+ rescue
172
+ Origen.log.success 'Your application archive is complete'
173
+ end
174
+ Origen.log.success archive
175
+ end
@@ -0,0 +1,43 @@
1
+ require 'optparse'
2
+ require 'fileutils'
3
+ require 'bundler'
4
+
5
+ options = {}
6
+
7
+ opt_parser = OptionParser.new do |opts|
8
+ opts.banner = 'Usage: origen extract FILE [options]'
9
+ end
10
+ opt_parser.parse! ARGV
11
+
12
+ archive = ARGV.first
13
+
14
+ unless File.exist?(archive)
15
+ Origen.log.error "File not found: #{archive}"
16
+ exit 1
17
+ end
18
+
19
+ dirname = Pathname.new(archive).basename('.origen').to_s
20
+
21
+ if File.exist?(dirname)
22
+ Origen.log.error "The application directory already exists (#{dirname}), delete it and then try again if you want to overwrite it"
23
+ exit 1
24
+ end
25
+
26
+ passed = system "tar -xvzf #{archive}"
27
+ unless passed
28
+ Origen.log.error 'A problem was encountered extracting the tarball, extraction aborted!'
29
+ exit 1
30
+ end
31
+
32
+ Dir.chdir dirname do
33
+ Bundler.with_clean_env do
34
+ Origen.log.info 'Trying to boot the application...'
35
+
36
+ passed = system "#{File.join('lbin', 'origen')} -v"
37
+ if passed
38
+ Origen.log.success 'Your application has been extracted and can boot up'
39
+ else
40
+ Origen.log.error 'Something went wrong at the final hurdle, your application has been extracted but cannot boot'
41
+ end
42
+ end
43
+ end
@@ -62,7 +62,12 @@ else
62
62
  end
63
63
  end
64
64
 
65
- generators = [['http://rubygems.org', 'origen_app_generators']] + Array(Origen.site_config.app_generators)
65
+ generators = [['https://rubygems.org', 'origen_app_generators']] + Array(Origen.site_config.app_generators)
66
+
67
+ def use_packaged_generators
68
+ FileUtils.cp_r Origen.top.join('origen_app_generators').to_s, '.'
69
+ FileUtils.mv 'origen_app_generators', '0'
70
+ end
66
71
 
67
72
  if update_required
68
73
  puts 'Fetching the latest app generators...'
@@ -73,41 +78,46 @@ if update_required
73
78
  generators.each_with_index do |gen, i|
74
79
  # If a reference to a gem from a gem server
75
80
  if gen.is_a?(Array)
76
- response = HTTParty.get("#{gen[0]}/api/v1/dependencies.json?gems=#{gen[1]}")
81
+ begin
82
+ response = HTTParty.get("#{gen[0]}/api/v1/dependencies.json?gems=#{gen[1]}", timeout: 2)
77
83
 
78
- if response.success?
79
- latest_version = JSON.parse(response.body).map { |v| v['number'] }.max
80
-
81
- response = HTTParty.get("#{gen[0]}/gems/#{gen[1]}-#{latest_version}.gem")
82
84
  if response.success?
83
- File.open("#{gen[1]}-#{latest_version}.gem", 'wb') do |f|
84
- f.write response.parsed_response
85
+ latest_version = JSON.parse(response.body).map { |v| v['number'] }.max
86
+
87
+ response = HTTParty.get("#{gen[0]}/gems/#{gen[1]}-#{latest_version}.gem", timeout: 5)
88
+ if response.success?
89
+ File.open("#{gen[1]}-#{latest_version}.gem", 'wb') do |f|
90
+ f.write response.parsed_response
91
+ end
92
+
93
+ `gem unpack #{gen[1]}-#{latest_version}.gem`
94
+ FileUtils.rm_rf("#{gen[1]}-#{latest_version}.gem")
95
+ FileUtils.mv("#{gen[1]}-#{latest_version}", i.to_s)
96
+ else
97
+ use_packaged_generators if i == 0
85
98
  end
86
99
  else
87
- puts "Sorry, could not find generator #{gen[1]} version #{latest_version}"
100
+ use_packaged_generators if i == 0
88
101
  end
89
-
90
- `gem unpack #{gen[1]}-#{latest_version}.gem`
91
- FileUtils.rm_rf("#{gen[1]}-#{latest_version}.gem")
92
- FileUtils.mv("#{gen[1]}-#{latest_version}", i.to_s)
93
-
94
- else
95
- puts "Failed to get generator #{gen[1]}, the response from the server was:"
96
- puts response.body
102
+ rescue
103
+ use_packaged_generators if i == 0
97
104
  end
98
105
 
99
106
  # If a reference to a git repo
100
107
  elsif gen.to_s =~ /\.git$/
101
- Origen::RevisionControl.new(remote: gen, local: i.to_s).checkout(version: 'master', force: true)
108
+ begin
109
+ Origen::RevisionControl.new(remote: gen, local: i.to_s).checkout(version: 'master', force: true)
110
+ rescue
111
+ # Better for the user not to crash here, not much we can do otherwise
112
+ end
102
113
 
103
114
  # Assume a reference to a folder
104
115
  else
105
- if File.exist?(gen)
106
- FileUtils.cp_r(gen, i.to_s)
107
- else
108
- puts "Failed to find generator at #{gen}"
116
+ begin
117
+ FileUtils.cp_r(gen, i.to_s) if File.exist?(gen)
118
+ rescue
119
+ # Better for the user not to crash here, not much we can do otherwise
109
120
  end
110
-
111
121
  end
112
122
  end
113
123
 
@@ -230,7 +230,8 @@ end.compact
230
230
 
231
231
  case @command
232
232
  when 'generate', 'program', 'compile', 'merge', 'interactive', 'target', 'environment',
233
- 'save', 'lsf', 'web', 'time', 'dispatch', 'rc', 'lint', 'plugin', 'fetch', 'mode', 'gem' # , 'add'
233
+ 'save', 'lsf', 'web', 'time', 'dispatch', 'rc', 'lint', 'plugin', 'fetch', 'mode', 'gem',
234
+ 'archive'
234
235
 
235
236
  require "origen/commands/#{@command}"
236
237
  exit 0 unless @command == 'interactive'
@@ -271,12 +272,14 @@ The core origen commands are:
271
272
  compile Compile a template file or directory (short-cut alias: "c")
272
273
  exec Execute any Ruby file with access to your app environment
273
274
 
275
+ setup Setup an app workspace for the first time, or fix if it can't boot
274
276
  rc Revision control commands, see -h for details
275
277
  save Save the new or changed files from the last run or a given log file
276
278
  lsf Monitor and manage LSF jobs (short-cut alias: "l")
277
279
  web Web page tools, see -h for details
278
280
  time Tools for test time analysis and forecasting
279
281
  lint Lint and style check (and correct) your application code
282
+ archive Create an archive of your current application state
280
283
  site Monitor and manage the Origen site configuration
281
284
  EOT
282
285
  cmds.split(/\n/).each do |line|
@@ -88,8 +88,8 @@ end
88
88
 
89
89
  case @command
90
90
 
91
- when 'new'
92
- require 'origen/commands/new'
91
+ when 'new', 'extract'
92
+ require "origen/commands/#{@command}"
93
93
  exit 0
94
94
 
95
95
  when '--version', '-v'
@@ -119,6 +119,7 @@ The following commands are available:
119
119
  new origen application workspace in "./my_app"
120
120
  interactive Start an interactive Origen console (short-cut alias: "i"), this is just
121
121
  IRB with the 'origen' lib loaded automatically
122
+ extract Extract an Origen application archive (.origen file created with the archive command)
122
123
  site Monitor and manage the Origen site configuration
123
124
  EOT
124
125
  cmds.split(/\n/).each do |line|
@@ -22,6 +22,10 @@ module Origen
22
22
  !windows?
23
23
  end
24
24
  end
25
+
26
+ # Blow this cache whenever this file is re-loaded
27
+ @operating_systems = nil
28
+
25
29
  def self.os
26
30
  @operating_systems ||= OperatingSystems.new
27
31
  end
@@ -8,7 +8,7 @@ module Origen
8
8
 
9
9
  IGNORE_DIRS = %w(
10
10
  .ws .lsf log output web coverage .ref .yardoc .collection .bin
11
- .session .bundle .tpc pkg tmp lbin .git
11
+ .session .bundle .tpc pkg tmp .git
12
12
  )
13
13
 
14
14
  IGNORE_FILES = %w(
@@ -8,7 +8,7 @@ module Origen
8
8
  require_relative 'site_config/config'
9
9
 
10
10
  # Require some useful methods from Origen without requiring the entire module
11
- require_relative './boot_api'
11
+ require_relative 'boot/api'
12
12
 
13
13
  TRUE_VALUES = ['true', 'TRUE', '1', 1]
14
14
  FALSE_VALUES = ['false', 'FALSE', '0', 0]
@@ -428,6 +428,9 @@ module Origen
428
428
  end
429
429
  end
430
430
 
431
+ # Blow this cache whenever this file is re-loaded
432
+ @site_config = nil
433
+
431
434
  def self.site_config
432
435
  @site_config ||= SiteConfig.new
433
436
  end