origen 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (336) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ctags +0 -0
  3. data/bin/origen +165 -1
  4. data/bin/rgen +2 -0
  5. data/config/application.rb +141 -0
  6. data/config/commands.rb +72 -0
  7. data/config/development.rb +7 -0
  8. data/config/environment.rb +0 -0
  9. data/config/rgen.policy +7 -0
  10. data/config/rubocop/easy.yml +620 -0
  11. data/config/rubocop/easy_disabled.yml +271 -0
  12. data/config/rubocop/easy_enabled.yml +731 -0
  13. data/config/rubocop/strict.yml +620 -0
  14. data/config/rubocop/strict_disabled.yml +247 -0
  15. data/config/rubocop/strict_enabled.yml +755 -0
  16. data/config/users.rb +20 -0
  17. data/config/version.rb +1 -1
  18. data/helpers/url.rb +68 -0
  19. data/lib/c99/doc_interface.rb +56 -0
  20. data/lib/c99/j750_interface.rb +85 -0
  21. data/lib/c99/nvm.rb +89 -0
  22. data/lib/c99/target/mock2.rb +1 -0
  23. data/lib/c99/target/subdir/mock3.rb +1 -0
  24. data/lib/option_parser/optparse.rb +12 -0
  25. data/lib/origen/acronyms.rb +60 -0
  26. data/lib/origen/application/command_dispatcher.rb +12 -0
  27. data/lib/origen/application/configuration.rb +206 -0
  28. data/lib/origen/application/configuration_manager.rb +78 -0
  29. data/lib/origen/application/deployer.rb +367 -0
  30. data/lib/origen/application/environment.rb +186 -0
  31. data/lib/origen/application/lsf.rb +145 -0
  32. data/lib/origen/application/lsf_manager.rb +657 -0
  33. data/lib/origen/application/plugins_manager.rb +280 -0
  34. data/lib/origen/application/release.rb +359 -0
  35. data/lib/origen/application/runner.rb +246 -0
  36. data/lib/origen/application/statistics.rb +191 -0
  37. data/lib/origen/application/target.rb +374 -0
  38. data/lib/origen/application/version_tracker.rb +59 -0
  39. data/lib/origen/application/workspace_manager.rb +151 -0
  40. data/lib/origen/application.rb +746 -0
  41. data/lib/origen/bugs/bug.rb +36 -0
  42. data/lib/origen/bugs.rb +45 -0
  43. data/lib/origen/callbacks.rb +35 -0
  44. data/lib/origen/chip_mode.rb +118 -0
  45. data/lib/origen/chip_package.rb +461 -0
  46. data/lib/origen/client.rb +87 -0
  47. data/lib/origen/code_generators/actions.rb +258 -0
  48. data/lib/origen/code_generators/base.rb +57 -0
  49. data/lib/origen/code_generators/bundler.rb +17 -0
  50. data/lib/origen/code_generators/gem_setup.rb +49 -0
  51. data/lib/origen/code_generators/rake.rb +13 -0
  52. data/lib/origen/code_generators/rspec.rb +12 -0
  53. data/lib/origen/code_generators/semver.rb +39 -0
  54. data/lib/origen/code_generators/timever.rb +37 -0
  55. data/lib/origen/code_generators.rb +111 -0
  56. data/lib/origen/commands/add.rb +12 -0
  57. data/lib/origen/commands/compile.rb +62 -0
  58. data/lib/origen/commands/ctags.rb +9 -0
  59. data/lib/origen/commands/dispatch.rb +22 -0
  60. data/lib/origen/commands/environment.rb +11 -0
  61. data/lib/origen/commands/fetch.rb +63 -0
  62. data/lib/origen/commands/generate.rb +130 -0
  63. data/lib/origen/commands/interactive.rb +73 -0
  64. data/lib/origen/commands/lint.rb +82 -0
  65. data/lib/origen/commands/lsf.rb +93 -0
  66. data/lib/origen/commands/merge.rb +55 -0
  67. data/lib/origen/commands/modifications.rb +12 -0
  68. data/lib/origen/commands/new.rb +113 -0
  69. data/lib/origen/commands/plugin.rb +105 -0
  70. data/lib/origen/commands/program.rb +70 -0
  71. data/lib/origen/commands/rc.rb +442 -0
  72. data/lib/origen/commands/save.rb +56 -0
  73. data/lib/origen/commands/target.rb +27 -0
  74. data/lib/origen/commands/time.rb +127 -0
  75. data/lib/origen/commands/version.rb +17 -0
  76. data/lib/origen/commands/web.rb +221 -0
  77. data/lib/origen/commands.rb +272 -0
  78. data/lib/origen/commands_global.rb +76 -0
  79. data/lib/origen/controller.rb +94 -0
  80. data/lib/origen/core_ext/array.rb +23 -0
  81. data/lib/origen/core_ext/bignum.rb +36 -0
  82. data/lib/origen/core_ext/enumerable.rb +76 -0
  83. data/lib/origen/core_ext/fixnum.rb +46 -0
  84. data/lib/origen/core_ext/hash.rb +52 -0
  85. data/lib/origen/core_ext/module.rb +14 -0
  86. data/lib/origen/core_ext/numeric.rb +126 -0
  87. data/lib/origen/core_ext/object.rb +13 -0
  88. data/lib/origen/core_ext/range.rb +7 -0
  89. data/lib/origen/core_ext/string.rb +124 -0
  90. data/lib/origen/core_ext.rb +10 -0
  91. data/lib/origen/database/key_value_store.rb +111 -0
  92. data/lib/origen/database/key_value_stores.rb +108 -0
  93. data/lib/origen/database.rb +6 -0
  94. data/lib/origen/encodings.rb +102 -0
  95. data/lib/origen/features/feature.rb +22 -0
  96. data/lib/origen/features.rb +104 -0
  97. data/lib/origen/file_handler.rb +429 -0
  98. data/lib/origen/generator/comparator.rb +56 -0
  99. data/lib/origen/generator/compiler.rb +277 -0
  100. data/lib/origen/generator/flow.rb +49 -0
  101. data/lib/origen/generator/job.rb +131 -0
  102. data/lib/origen/generator/pattern.rb +356 -0
  103. data/lib/origen/generator/pattern_finder.rb +155 -0
  104. data/lib/origen/generator/pattern_iterator.rb +55 -0
  105. data/lib/origen/generator/renderer.rb +113 -0
  106. data/lib/origen/generator/resources.rb +40 -0
  107. data/lib/origen/generator/stage.rb +89 -0
  108. data/lib/origen/generator.rb +85 -0
  109. data/lib/origen/global_methods.rb +205 -0
  110. data/lib/origen/import_manager.rb +596 -0
  111. data/lib/origen/location/base.rb +116 -0
  112. data/lib/origen/location/map.rb +83 -0
  113. data/lib/origen/location.rb +6 -0
  114. data/lib/origen/log.rb +217 -0
  115. data/lib/origen/logger_methods.rb +56 -0
  116. data/lib/origen/mode.rb +61 -0
  117. data/lib/origen/model.rb +267 -0
  118. data/lib/origen/model_initializer.rb +45 -0
  119. data/lib/origen/nvm/block_array.rb +72 -0
  120. data/lib/origen/nvm.rb +6 -0
  121. data/lib/origen/parameters/live.rb +22 -0
  122. data/lib/origen/parameters/missing.rb +28 -0
  123. data/lib/origen/parameters/set.rb +144 -0
  124. data/lib/origen/parameters.rb +107 -0
  125. data/lib/origen/pdm.rb +218 -0
  126. data/lib/origen/pins/function_proxy.rb +36 -0
  127. data/lib/origen/pins/ground_pin.rb +6 -0
  128. data/lib/origen/pins/pin.rb +860 -0
  129. data/lib/origen/pins/pin_bank.rb +349 -0
  130. data/lib/origen/pins/pin_clock.rb +124 -0
  131. data/lib/origen/pins/pin_collection.rb +492 -0
  132. data/lib/origen/pins/pin_common.rb +206 -0
  133. data/lib/origen/pins/port.rb +268 -0
  134. data/lib/origen/pins/power_pin.rb +30 -0
  135. data/lib/origen/pins.rb +696 -0
  136. data/lib/origen/registers/bit.rb +562 -0
  137. data/lib/origen/registers/bit_collection.rb +787 -0
  138. data/lib/origen/registers/container.rb +288 -0
  139. data/lib/origen/registers/domain.rb +16 -0
  140. data/lib/origen/registers/reg.rb +1406 -0
  141. data/lib/origen/registers/reg_collection.rb +24 -0
  142. data/lib/origen/registers.rb +652 -0
  143. data/lib/origen/regression_manager.rb +251 -0
  144. data/lib/origen/remote_manager.rb +340 -0
  145. data/lib/origen/revision_control/base.rb +257 -0
  146. data/lib/origen/revision_control/design_sync.rb +276 -0
  147. data/lib/origen/revision_control/git.rb +243 -0
  148. data/lib/origen/revision_control/subversion.rb +6 -0
  149. data/lib/origen/revision_control.rb +44 -0
  150. data/lib/origen/ruby_version_check.rb +131 -0
  151. data/lib/origen/site_config.rb +61 -0
  152. data/lib/origen/specs/checkers.rb +103 -0
  153. data/lib/origen/specs/creation_info.rb +17 -0
  154. data/lib/origen/specs/doc_resource.rb +91 -0
  155. data/lib/origen/specs/exhibit.rb +17 -0
  156. data/lib/origen/specs/mode_select.rb +16 -0
  157. data/lib/origen/specs/note.rb +17 -0
  158. data/lib/origen/specs/override.rb +21 -0
  159. data/lib/origen/specs/power_supply.rb +13 -0
  160. data/lib/origen/specs/spec.rb +226 -0
  161. data/lib/origen/specs/version_history.rb +14 -0
  162. data/lib/origen/specs.rb +552 -0
  163. data/lib/origen/sub_blocks.rb +298 -0
  164. data/lib/origen/tester/api.rb +277 -0
  165. data/lib/origen/tester/bdm/bdm.rb +25 -0
  166. data/lib/origen/tester/command_based_tester.rb +46 -0
  167. data/lib/origen/tester/doc/doc.rb +226 -0
  168. data/lib/origen/tester/doc/generator/flow.rb +71 -0
  169. data/lib/origen/tester/doc/generator/flow_line.rb +203 -0
  170. data/lib/origen/tester/doc/generator/test.rb +68 -0
  171. data/lib/origen/tester/doc/generator/test_group.rb +66 -0
  172. data/lib/origen/tester/doc/generator/tests.rb +47 -0
  173. data/lib/origen/tester/doc/generator.rb +126 -0
  174. data/lib/origen/tester/doc/model.rb +162 -0
  175. data/lib/origen/tester/generator/flow_control_api.rb +606 -0
  176. data/lib/origen/tester/generator/identity_map.rb +25 -0
  177. data/lib/origen/tester/generator/placeholder.rb +13 -0
  178. data/lib/origen/tester/generator/test_numberer.rb +25 -0
  179. data/lib/origen/tester/generator.rb +271 -0
  180. data/lib/origen/tester/interface.rb +154 -0
  181. data/lib/origen/tester/j750/files.rb +45 -0
  182. data/lib/origen/tester/j750/generator/flow.rb +123 -0
  183. data/lib/origen/tester/j750/generator/flow_line.rb +288 -0
  184. data/lib/origen/tester/j750/generator/patgroup.rb +111 -0
  185. data/lib/origen/tester/j750/generator/patgroups.rb +41 -0
  186. data/lib/origen/tester/j750/generator/patset.rb +111 -0
  187. data/lib/origen/tester/j750/generator/patsets.rb +41 -0
  188. data/lib/origen/tester/j750/generator/templates/flow.txt.erb +9 -0
  189. data/lib/origen/tester/j750/generator/templates/instances.txt.erb +16 -0
  190. data/lib/origen/tester/j750/generator/templates/patgroups.txt.erb +8 -0
  191. data/lib/origen/tester/j750/generator/templates/patsets.txt.erb +10 -0
  192. data/lib/origen/tester/j750/generator/test_instance.rb +846 -0
  193. data/lib/origen/tester/j750/generator/test_instance_group.rb +60 -0
  194. data/lib/origen/tester/j750/generator/test_instances.rb +182 -0
  195. data/lib/origen/tester/j750/generator.rb +203 -0
  196. data/lib/origen/tester/j750/j750.rb +845 -0
  197. data/lib/origen/tester/j750/j750_hpt.rb +35 -0
  198. data/lib/origen/tester/j750/parser/ac_spec.rb +11 -0
  199. data/lib/origen/tester/j750/parser/ac_specs.rb +0 -0
  200. data/lib/origen/tester/j750/parser/dc_spec.rb +36 -0
  201. data/lib/origen/tester/j750/parser/dc_specs.rb +50 -0
  202. data/lib/origen/tester/j750/parser/descriptions.rb +340 -0
  203. data/lib/origen/tester/j750/parser/flow.rb +111 -0
  204. data/lib/origen/tester/j750/parser/flow_line.rb +207 -0
  205. data/lib/origen/tester/j750/parser/flows.rb +23 -0
  206. data/lib/origen/tester/j750/parser/pattern_set.rb +94 -0
  207. data/lib/origen/tester/j750/parser/pattern_sets.rb +33 -0
  208. data/lib/origen/tester/j750/parser/test_instance.rb +322 -0
  209. data/lib/origen/tester/j750/parser/test_instances.rb +26 -0
  210. data/lib/origen/tester/j750/parser/timeset.rb +15 -0
  211. data/lib/origen/tester/j750/parser/timesets.rb +0 -0
  212. data/lib/origen/tester/j750/parser.rb +104 -0
  213. data/lib/origen/tester/jlink/jlink.rb +33 -0
  214. data/lib/origen/tester/parser/description_lookup.rb +64 -0
  215. data/lib/origen/tester/parser/searchable_array.rb +32 -0
  216. data/lib/origen/tester/parser/searchable_hash.rb +32 -0
  217. data/lib/origen/tester/parser.rb +24 -0
  218. data/lib/origen/tester/time.rb +338 -0
  219. data/lib/origen/tester/timing.rb +253 -0
  220. data/lib/origen/tester/ultraflex/files.rb +45 -0
  221. data/lib/origen/tester/ultraflex/generator/flow.rb +119 -0
  222. data/lib/origen/tester/ultraflex/generator/flow_line.rb +269 -0
  223. data/lib/origen/tester/ultraflex/generator/patgroup.rb +111 -0
  224. data/lib/origen/tester/ultraflex/generator/patgroups.rb +41 -0
  225. data/lib/origen/tester/ultraflex/generator/patset.rb +111 -0
  226. data/lib/origen/tester/ultraflex/generator/patsets.rb +41 -0
  227. data/lib/origen/tester/ultraflex/generator/templates/flow.txt.erb +9 -0
  228. data/lib/origen/tester/ultraflex/generator/templates/instances.txt.erb +16 -0
  229. data/lib/origen/tester/ultraflex/generator/templates/patgroups.txt.erb +8 -0
  230. data/lib/origen/tester/ultraflex/generator/templates/patsets.txt.erb +10 -0
  231. data/lib/origen/tester/ultraflex/generator/test_instance.rb +622 -0
  232. data/lib/origen/tester/ultraflex/generator/test_instance_group.rb +60 -0
  233. data/lib/origen/tester/ultraflex/generator/test_instances.rb +174 -0
  234. data/lib/origen/tester/ultraflex/generator.rb +200 -0
  235. data/lib/origen/tester/ultraflex/parser/ac_spec.rb +11 -0
  236. data/lib/origen/tester/ultraflex/parser/ac_specs.rb +0 -0
  237. data/lib/origen/tester/ultraflex/parser/dc_spec.rb +36 -0
  238. data/lib/origen/tester/ultraflex/parser/dc_specs.rb +50 -0
  239. data/lib/origen/tester/ultraflex/parser/descriptions.rb +342 -0
  240. data/lib/origen/tester/ultraflex/parser/flow.rb +111 -0
  241. data/lib/origen/tester/ultraflex/parser/flow_line.rb +207 -0
  242. data/lib/origen/tester/ultraflex/parser/flows.rb +23 -0
  243. data/lib/origen/tester/ultraflex/parser/pattern_set.rb +94 -0
  244. data/lib/origen/tester/ultraflex/parser/pattern_sets.rb +33 -0
  245. data/lib/origen/tester/ultraflex/parser/test_instance.rb +262 -0
  246. data/lib/origen/tester/ultraflex/parser/test_instances.rb +26 -0
  247. data/lib/origen/tester/ultraflex/parser/timeset.rb +15 -0
  248. data/lib/origen/tester/ultraflex/parser/timesets.rb +0 -0
  249. data/lib/origen/tester/ultraflex/parser.rb +104 -0
  250. data/lib/origen/tester/ultraflex/ultraflex.rb +759 -0
  251. data/lib/origen/tester/v93k/generator/flow.rb +63 -0
  252. data/lib/origen/tester/v93k/generator/flow_node/print.rb +10 -0
  253. data/lib/origen/tester/v93k/generator/flow_node.rb +17 -0
  254. data/lib/origen/tester/v93k/generator/pattern.rb +16 -0
  255. data/lib/origen/tester/v93k/generator/pattern_master.rb +54 -0
  256. data/lib/origen/tester/v93k/generator/templates/_test_method.txt.erb +6 -0
  257. data/lib/origen/tester/v93k/generator/templates/_test_suite.txt.erb +11 -0
  258. data/lib/origen/tester/v93k/generator/templates/template.flow.erb +121 -0
  259. data/lib/origen/tester/v93k/generator/templates/template.pmfl.erb +9 -0
  260. data/lib/origen/tester/v93k/generator/test_function.rb +103 -0
  261. data/lib/origen/tester/v93k/generator/test_functions.rb +79 -0
  262. data/lib/origen/tester/v93k/generator/test_method.rb +46 -0
  263. data/lib/origen/tester/v93k/generator/test_methods.rb +75 -0
  264. data/lib/origen/tester/v93k/generator/test_suite.rb +54 -0
  265. data/lib/origen/tester/v93k/generator/test_suites.rb +65 -0
  266. data/lib/origen/tester/v93k/generator.rb +80 -0
  267. data/lib/origen/tester/v93k/v93k.rb +420 -0
  268. data/lib/origen/tester/vector.rb +86 -0
  269. data/lib/origen/tester/vector_generator.rb +633 -0
  270. data/lib/origen/tester/vector_pipeline.rb +150 -0
  271. data/lib/origen/tester.rb +56 -0
  272. data/lib/origen/top_level.rb +134 -0
  273. data/lib/origen/users/ldap.rb +65 -0
  274. data/lib/origen/users/user.rb +149 -0
  275. data/lib/origen/users.rb +30 -0
  276. data/lib/origen/utility/block_args.rb +93 -0
  277. data/lib/origen/utility/csv_data.rb +110 -0
  278. data/lib/origen/utility/design_sync.rb +494 -0
  279. data/lib/origen/utility/diff.rb +158 -0
  280. data/lib/origen/utility/input_capture.rb +121 -0
  281. data/lib/origen/utility/mailer.rb +143 -0
  282. data/lib/origen/utility/s_record.rb +205 -0
  283. data/lib/origen/utility/time_and_date.rb +30 -0
  284. data/lib/origen/utility.rb +12 -0
  285. data/lib/origen/version_checker.rb +117 -0
  286. data/lib/origen/version_string.rb +356 -0
  287. data/lib/origen.rb +648 -0
  288. data/lib/tasks/gem.rake +27 -22
  289. data/origen_site_config.yml +36 -0
  290. data/source_setup +17 -0
  291. data/spec/format/rgen_formatter.rb +14 -0
  292. data/templates/api_doc/README.txt.erb +24 -0
  293. data/templates/code_generators/gemfile_app.rb +4 -0
  294. data/templates/code_generators/gemfile_plugin.rb +6 -0
  295. data/templates/code_generators/gemspec.rb +33 -0
  296. data/templates/code_generators/rakefile.rb +10 -0
  297. data/templates/code_generators/spec_helper.rb +49 -0
  298. data/templates/code_generators/version.rb +8 -0
  299. data/templates/code_generators/version_time.rb +3 -0
  300. data/templates/git/gitignore.erb +33 -0
  301. data/templates/j750/_vt_flow.txt.erb +8 -0
  302. data/templates/j750/_vt_instances.txt.erb +4 -0
  303. data/templates/j750/program_sheet.txt.erb +9 -0
  304. data/templates/nanoc/Rules +74 -0
  305. data/templates/nanoc/config.yaml +77 -0
  306. data/templates/nanoc/content/favicon.ico +0 -0
  307. data/templates/nanoc/layouts/bootstrap.html.erb +63 -0
  308. data/templates/nanoc/layouts/bootstrap3.html.erb +71 -0
  309. data/templates/nanoc/layouts/freescale.html.erb +79 -0
  310. data/templates/nanoc/lib/bootstrap_filter.rb +49 -0
  311. data/templates/nanoc/lib/codeblocks_filter.rb +41 -0
  312. data/templates/nanoc/lib/default.rb +2 -0
  313. data/templates/nanoc/lib/gzip_filter.rb +16 -0
  314. data/templates/nanoc/lib/haml_code_filter.rb +41 -0
  315. data/templates/nanoc/lib/helpers.rb +1 -0
  316. data/templates/nanoc/lib/search_filter.rb +62 -0
  317. data/templates/nanoc_dynamic/content/search.js.erb +92 -0
  318. data/templates/shared/web/_logo.html +10 -0
  319. data/templates/test/_inline_sub.txt.erb +2 -0
  320. data/templates/test/environment.txt.erb +1 -0
  321. data/templates/test/inline.txt.erb +11 -0
  322. data/templates/test/inspections.txt.erb +19 -0
  323. data/templates/test/set1/_sub1.txt.erb +12 -0
  324. data/templates/test/set1/_sub4.txt.erb +1 -0
  325. data/templates/test/set1/_sub5.txt.erb +1 -0
  326. data/templates/test/set1/main.txt.erb +53 -0
  327. data/templates/test/set1/sub_dir/_sub2.txt.erb +20 -0
  328. data/templates/test/set1/sub_dir/_sub3.txt.erb +12 -0
  329. data/templates/test/set1/sub_dir/main2.txt.erb +4 -0
  330. data/templates/test/set2/template_with_no_erb_1.txt +9 -0
  331. data/templates/test/set2/template_with_no_erb_2.txt +9 -0
  332. data/templates/test/set3/_layout.html.erb +4 -0
  333. data/templates/test/set3/content.html.erb +6 -0
  334. data/templates/time/filter.rb.erb +15 -0
  335. data/templates/time/rules.rb.erb +45 -0
  336. metadata +639 -5
@@ -0,0 +1,277 @@
1
+ module Origen
2
+ class Generator
3
+ class Compiler # :nodoc: all
4
+ require 'fileutils'
5
+ require 'erb'
6
+ require 'pathname'
7
+ require "#{Origen.top}/helpers/url"
8
+
9
+ include Helpers
10
+ include Comparator
11
+ include Renderer
12
+
13
+ # During a compile this will return the current top-level file being compiled
14
+ #
15
+ # @example
16
+ # Origen.generator.compiler.current_file # => Pathname
17
+ attr_reader :current_file
18
+
19
+ # Where compile will place the compiled content in an output file, this method will return
20
+ # it as a string to the caller (i.e. without creating an output file)
21
+ #
22
+ # It expects an absolute path to a single template file as the file argument.
23
+ def compile_inline(file, options = {})
24
+ initial_options = options.merge({})
25
+ options = {
26
+ check_for_changes: false,
27
+ sub_template: false,
28
+ collect_stats: false,
29
+ initial_options: initial_options
30
+ }.merge(options)
31
+ run_erb(Pathname.new(file), options).strip
32
+ end
33
+
34
+ # Compile all files found under the source directory, non-erb files will be copied
35
+ # to the destination un-altered
36
+ def compile(file_or_dir, options = {})
37
+ options = {
38
+ check_for_changes: true,
39
+ sub_template: false,
40
+ collect_stats: true
41
+ }.merge(options)
42
+ # Doing here so the output_directory (requiring target load) doesn't get hit if
43
+ # it is already defined
44
+ options[:output_directory] ||= output_directory
45
+ @check_for_changes = options[:check_for_changes]
46
+ @options = options
47
+ if options[:sub_template]
48
+ block = options.delete(:block)
49
+ if is_erb?(file_or_dir)
50
+ run_erb(file_or_dir, options, &block)
51
+ else
52
+ f = File.open(file_or_dir)
53
+ content = f.read
54
+ f.close
55
+ insert(content)
56
+ end
57
+ else
58
+ Origen.file_handler.resolve_files(file_or_dir, ignore_with_prefix: '_', import: :template) do |file|
59
+ compile_file(file, options)
60
+ end
61
+ end
62
+ end
63
+
64
+ def merge(file_or_dir, options = {})
65
+ # Compile an up to date reference
66
+ compile(file_or_dir_path, check_for_changes: false, output_directory: merge_reference_directory)
67
+ diffs = []
68
+ Origen.file_handler.resolve_files(file_or_dir, ignore_with_prefix: '_') do |file|
69
+ diffs << merge_file(file, options)
70
+ end
71
+ diffs.compact!
72
+ puts ''
73
+ if diffs.size > 0
74
+ puts 'The following differences are present in the compiled files and must be resolved manually:'
75
+ puts ''
76
+ diffs.each do |diff|
77
+ puts diff
78
+ end
79
+ puts ''
80
+ else
81
+ puts 'Merged successfully!'
82
+ end
83
+ end
84
+
85
+ def stats
86
+ Origen.app.stats
87
+ end
88
+
89
+ # Compile the supplied file if it is an erb template writing the compiled
90
+ # version to the destination directory.
91
+ # If the file is not an erb template it is simply copied un-altered to the
92
+ # destination directory.
93
+ # File must be an absolute path to the file.
94
+ def compile_file(file, options = {})
95
+ @current_file = Pathname.new(file)
96
+ # This is used when templates are compiled through a test program, but can
97
+ # be problematic when used to compile files standalone. In practice this may
98
+ # not be an issue except when testing Origen and generating and compiling within
99
+ # the same thread, but clearing this here doesn't seem to do any harm.
100
+ Origen.file_handler.default_extension = nil
101
+ Origen.log.info "Compiling... #{relative_path_to(file)}" unless options[:quiet]
102
+ Origen.log.info " Created... #{relative_path_to(output_file(file, options))}" unless options[:quiet]
103
+ stats.completed_files += 1 if options[:collect_stats]
104
+ if is_erb?(file)
105
+ output = run_erb(file, options)
106
+ f = output_file(file, options).to_s
107
+ if output.is_a?(Pathname)
108
+ FileUtils.mv output.to_s, f
109
+ else
110
+ File.open(f, 'w') { |out| out.puts output }
111
+ end
112
+ else # Just copy it across
113
+ out = output_file(file, options)
114
+ # Delete the target if it already exists, this prevents permission denied errors when copying
115
+ FileUtils.rm_f(out.to_s) if File.exist?(out.to_s)
116
+ FileUtils.cp(file.to_s, out.dirname.to_s)
117
+ end
118
+ if options[:zip]
119
+ `gzip -f -9 #{output_file(file, options)}`
120
+ else
121
+ if @check_for_changes
122
+ check_for_changes(output_file(file, options), reference_file(file, options),
123
+ comment_char: Origen.app.tester ? Origen.app.tester.program_comment_char : nil,
124
+ compile_job: true)
125
+ end
126
+ end
127
+ end
128
+
129
+ def run_erb(file, opts = {}, &block)
130
+ # Refresh the target to start all settings from scratch each time
131
+ # This is an easy way to reset all registered values
132
+ Origen.app.reload_target! unless options[:preserve_target]
133
+ # Record the current file, this can be used to resolve any relative path
134
+ # references in the file about to be compiled
135
+ Origen.file_handler.current_file = file
136
+ # Make the file and options available to the template
137
+ if opts[:initial_options] || opts[:options]
138
+ options.merge!(opts.delete(:initial_options) || opts.delete(:options))
139
+ end
140
+ options[:file] = file
141
+ options[:top_level_file] = current_file
142
+ b = _get_binding(opts, &block)
143
+ if block_given?
144
+ content = ERB.new(File.read(file.to_s), 0, '%<>', buffer_name_for(file)).result(b)
145
+ else
146
+ content = ERB.new(File.read(file.to_s), 0, Origen.config.erb_trim_mode, buffer_name_for(file)).result(b)
147
+ end
148
+ insert(content)
149
+ end
150
+
151
+ # @api private
152
+ def _get_binding(opts, &block)
153
+ # Important, don't declare any local variable called options here,
154
+ # the scope of this method will be the default for any templates and
155
+ # we want options to refer to the global options method
156
+ b = opts[:binding] || opts[:scope] || binding
157
+ # If an object has been supplied as the scope, then do some tricks
158
+ # to get a hold of its internal scope
159
+ unless b.is_a?(Binding)
160
+ b.define_singleton_method :_get_binding do |local_opts, &_block|
161
+ # rubocop:disable Lint/UselessAssignment
162
+ options = local_opts
163
+ # rubocop:enable Lint/UselessAssignment
164
+ binding
165
+ end
166
+ # Here the global options, the ones visible right now, are passed to into the method defined above,
167
+ # they will get assigned to the local variable called option and that is what the template will
168
+ # be able to see
169
+ b = b._get_binding(options, &block)
170
+ end
171
+ b
172
+ end
173
+
174
+ def current_buffer
175
+ instance_variable_get(@current_buffer || '@_anonymous')
176
+ end
177
+
178
+ def current_buffer=(text)
179
+ instance_variable_set(@current_buffer || '@_anonymous', text)
180
+ end
181
+
182
+ # Returns the ERB buffer name for the given file, something like "@my_file_name"
183
+ def buffer_name_for(file)
184
+ # Not sure why the final gsub is needed but seems to fail to parse correctly otherwise.
185
+ @current_buffer = "@#{file.basename('.*').basename('.*').to_s.gsub('-', '_')}"
186
+ end
187
+
188
+ def merge_file(file, _options = {})
189
+ file = Pathname.new(file)
190
+ Origen.log.info "Merging... #{file.basename}"
191
+ if is_erb?(file) && File.exist?(output_file(file))
192
+ check_for_differences(output_file(file), merge_ref_file(file), file)
193
+ elsif File.exist?(output_file(file))
194
+ if check_for_differences(output_file(file), merge_ref_file(file), file)
195
+ FileUtils.cp(output_file(file), file.dirname.to_s)
196
+ end
197
+ end
198
+ end
199
+
200
+ def display_path_to(file)
201
+ p = relative_path_to(file).to_s
202
+ p.gsub!('/', '\\') if Origen.running_on_windows?
203
+ p
204
+ end
205
+
206
+ def check_for_differences(a, b, file)
207
+ if check_for_changes(a, b, comment_char: ["'", 'logprint'], quiet: true, compile_job: true)
208
+ puts "*** CHANGE DETECTED *** To rollback: #{Origen.config.copy_command} #{display_path_to(b)} #{display_path_to(a)}"
209
+ "#{Origen.config.diff_command} #{display_path_to(a)} #{display_path_to(b)} & #{ENV['EDITOR']} #{file.cleanpath} &"
210
+ end
211
+ end
212
+
213
+ # Returns true if the supplied file name has a .erb extension
214
+ def is_erb?(file)
215
+ !!(file.to_s =~ /.erb$/) || !Origen.config.compile_only_dot_erb_files
216
+ end
217
+
218
+ def output_directory
219
+ Origen.file_handler.output_directory
220
+ end
221
+
222
+ def reference_directory
223
+ Origen.file_handler.reference_directory
224
+ end
225
+
226
+ def merge_reference_directory
227
+ "#{Origen.root}/.merge_ref"
228
+ end
229
+
230
+ # Returns the output file corresponding to the given source file, the destination
231
+ # directory will be created if it doesn't exist.
232
+ def output_file(file, options = {})
233
+ options = {
234
+ output_directory: output_directory
235
+ }.merge(options)
236
+ # return @output_file if @output_file
237
+ sub_dir = options[:output_sub_dir] || Origen.file_handler.sub_dir_of(file).to_s
238
+ sub_dir = nil if sub_dir == '.'
239
+ filename = options[:output_file_name] || file.basename.to_s.gsub('.erb', '')
240
+ # filename.gsub!('target', $target.id) if filename =~ /target/ && $target.id
241
+ output = Pathname.new("#{options[:output_directory]}#{sub_dir ? '/' + sub_dir : ''}/#{filename}")
242
+ FileUtils.mkdir_p(output.dirname.to_s) unless File.exist?(output.dirname.to_s)
243
+ # @output_file = output
244
+ output
245
+ end
246
+
247
+ # Returns the reference file corresponding to the given source file, the destination
248
+ # directory will be created if it doesn't exist.
249
+ def reference_file(file, options = {})
250
+ # return @reference_file if @reference_file
251
+ sub_dir = Origen.file_handler.sub_dir_of(file).to_s
252
+ sub_dir = nil if sub_dir == '.'
253
+ filename = options[:output_file_name] || file.basename.to_s.gsub('.erb', '')
254
+ # filename.gsub!('target', $target.id) if filename =~ /target/ && $target.id
255
+ reference = Pathname.new("#{reference_directory}#{sub_dir ? '/' + sub_dir : ''}/#{filename}")
256
+ FileUtils.mkdir_p(reference.dirname.to_s) unless File.exist?(reference.dirname.to_s)
257
+ # @reference_file = reference
258
+ reference
259
+ end
260
+
261
+ def merge_ref_file(file, options = {})
262
+ options = {
263
+ directory: merge_reference_directory
264
+ }.merge(options)
265
+ # return @merge_ref_file if @merge_ref_file
266
+ sub_dir = Origen.file_handler.sub_dir_of(file).to_s
267
+ sub_dir = nil if sub_dir == '.'
268
+ filename = file.basename.to_s.gsub('.erb', '')
269
+ # filename.gsub!('target', $target.id) if filename =~ /target/ && $target.id
270
+ output = Pathname.new("#{options[:directory]}#{sub_dir ? '/' + sub_dir : ''}/#{filename}")
271
+ FileUtils.mkdir_p(output.dirname.to_s) unless File.exist?(output.dirname.to_s)
272
+ # @merge_ref_file = output
273
+ output
274
+ end
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,49 @@
1
+ module Origen
2
+ class Generator
3
+ class Flow
4
+ attr_accessor :top_level
5
+
6
+ def create(options = {}, &block)
7
+ # Refresh the target to start all settings from scratch each time
8
+ # This is an easy way to reset all registered values
9
+ Origen.app.reload_target!
10
+ Origen.tester.generating = :program
11
+ # Make the top level flow globally available, this helps to assign test descriptions
12
+ # to the correct flow whenever tests are instantiated from sub-flows
13
+ if Origen.interface_loaded? && Origen.interface.top_level_flow
14
+ sub_flow = true
15
+ if Origen.tester.doc?
16
+ Origen.interface.flow.start_section
17
+ end
18
+ else
19
+ sub_flow = false
20
+ end
21
+ job.output_file_body = options.delete(:name).to_s if options[:name]
22
+ if sub_flow
23
+ interface = Origen.interface
24
+ opts = Origen.generator.option_pipeline.pop || {}
25
+ interface.instance_exec(opts, &block)
26
+ if Origen.tester.doc?
27
+ Origen.interface.flow.stop_section
28
+ end
29
+ interface.close(flow: true, sub_flow: true)
30
+ else
31
+ Origen.log.info "Generating... #{Origen.file_handler.current_file.basename}"
32
+ interface = Origen.reset_interface(options)
33
+ Origen.interface.set_top_level_flow
34
+ Origen.interface.flow_generator.set_flow_description(Origen.interface.consume_comments)
35
+ interface.instance_eval(&block)
36
+ interface.close(flow: true)
37
+ end
38
+ end
39
+
40
+ def reset
41
+ Origen.interface.clear_top_level_flow if Origen.interface_loaded?
42
+ end
43
+
44
+ def job
45
+ Origen.app.current_job
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,131 @@
1
+ module Origen
2
+ class Generator
3
+ # A job is responsible for executing a single pattern source
4
+ class Job # :nodoc: all
5
+ attr_accessor :output_file_body, :pattern
6
+
7
+ def initialize(pattern, options)
8
+ @testing = options[:testing]
9
+ @options = options
10
+ @requested_pattern = pattern
11
+ @no_comments = options[:no_comments]
12
+ end
13
+
14
+ # Returns true if the job is a test job, will only be true in a test scenario
15
+ def test?
16
+ @testing
17
+ end
18
+
19
+ def no_comments?
20
+ @no_comments
21
+ end
22
+
23
+ def requested_pattern
24
+ @requested_pattern
25
+ end
26
+ alias_method :requested_file, :requested_pattern
27
+
28
+ # Returns a full path to the output pattern, note that this is not available
29
+ # until the job has been run
30
+ def output_pattern
31
+ "#{output_pattern_directory}/#{output_pattern_filename}"
32
+ end
33
+ alias_method :output_file, :output_pattern
34
+
35
+ def reference_pattern
36
+ "#{reference_pattern_directory}/#{output_pattern_filename}"
37
+ end
38
+ alias_method :reference_file, :reference_pattern
39
+
40
+ def output_pattern_filename
41
+ return '' if @testing
42
+ # If the pattern name has been overridden by an interator use that
43
+ return @output_pattern_filename if @output_pattern_filename
44
+ if !@pattern && !@output_file_body
45
+ fail 'Sorry the output_pattern is not available until the job has been run'
46
+ end
47
+ body = @output_file_body ? @output_file_body : File.basename(@pattern, '.rb')
48
+ output_prefix + body + output_postfix + output_extension
49
+ end
50
+
51
+ # This can be modified at runtime by the pattern generator in response to
52
+ # iterator substitutions
53
+ def output_pattern_filename=(val)
54
+ @output_pattern_filename = val
55
+ end
56
+
57
+ def reset_output_pattern_filename
58
+ @output_pattern_filename = nil
59
+ end
60
+
61
+ def output_pattern_directory
62
+ Origen.file_handler.output_directory
63
+ end
64
+
65
+ def reference_pattern_directory
66
+ Origen.file_handler.reference_directory
67
+ end
68
+
69
+ def output_prefix
70
+ p = Origen.config.pattern_prefix ? Origen.config.pattern_prefix + '_' : ''
71
+ p = "_#{p}" if Origen.tester.doc?
72
+ p
73
+ end
74
+
75
+ def output_postfix
76
+ Origen.config.pattern_postfix ? '_' + Origen.config.pattern_postfix : ''
77
+ end
78
+
79
+ def output_extension
80
+ '.' + Origen.tester.pat_extension
81
+ end
82
+
83
+ def run
84
+ Origen.app.current_job = self
85
+ begin
86
+ if @options[:compile]
87
+ Origen.generator.compiler.compile(@requested_pattern, @options)
88
+ elsif @options[:job_type] == :merge
89
+ Origen.generator.compiler.merge(@requested_pattern)
90
+ elsif @options[:action] == :program
91
+ Origen.flow.reset
92
+ Origen.resources.reset
93
+ Origen::Tester::Generator.execute_source(@pattern)
94
+ else
95
+ Origen.generator.pattern.reset # Resets the pattern controller ready for a new pattern
96
+ # Give the app a chance to handle pattern dispatch
97
+ skip = false
98
+ Origen.app.listeners_for(:before_pattern_lookup).each do |listener|
99
+ skip ||= !listener.before_pattern_lookup(@requested_pattern)
100
+ end
101
+ unless skip
102
+ @pattern = Origen.generator.pattern_finder.find(@requested_pattern, @options)
103
+ if @pattern.is_a?(Hash)
104
+ @output_file_body = @pattern[:output]
105
+ @pattern = @pattern[:pattern]
106
+ end
107
+ load @pattern unless @pattern == :skip # Run the pattern
108
+ end
109
+ end
110
+ rescue Exception => e
111
+ if @options[:continue] || Origen.running_remotely?
112
+ Origen.log.error "FAILED - #{@requested_pattern} (for target #{Origen.target.name})"
113
+ Origen.log.error e.message
114
+ e.backtrace.each do |l|
115
+ Origen.log.error l
116
+ end
117
+ if @options[:compile]
118
+ Origen.app.stats.failed_files += 1
119
+ else
120
+ Origen.app.stats.failed_patterns += 1
121
+ end
122
+ else
123
+ puts e.message
124
+ puts e.backtrace
125
+ exit 1
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end