origen 0.34.3 → 0.52.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +5 -5
  2. data/bin/origen +1 -231
  3. data/config/application.rb +12 -3
  4. data/config/boot.rb +2 -7
  5. data/config/commands.rb +3 -74
  6. data/config/rubocop/easy_disabled.yml +4 -0
  7. data/config/rubocop/easy_enabled.yml +0 -4
  8. data/config/rubocop/strict_disabled.yml +4 -0
  9. data/config/rubocop/strict_enabled.yml +0 -4
  10. data/config/version.rb +2 -3
  11. data/lib/origen.rb +27 -14
  12. data/lib/origen/application.rb +88 -2
  13. data/lib/origen/application/deployer.rb +3 -1
  14. data/lib/origen/application/release.rb +2 -2
  15. data/lib/origen/application/runner.rb +35 -20
  16. data/lib/origen/boot.rb +302 -0
  17. data/lib/origen/boot/api.rb +13 -0
  18. data/lib/origen/boot/app.rb +284 -0
  19. data/lib/origen/code_generators.rb +30 -10
  20. data/lib/origen/code_generators/actions.rb +244 -34
  21. data/lib/origen/code_generators/base.rb +9 -2
  22. data/lib/origen/code_generators/block.rb +203 -0
  23. data/lib/origen/code_generators/block_common.rb +100 -0
  24. data/lib/origen/code_generators/dut.rb +62 -0
  25. data/lib/origen/code_generators/feature.rb +50 -0
  26. data/lib/origen/code_generators/klass.rb +41 -0
  27. data/lib/origen/code_generators/model.rb +60 -0
  28. data/lib/origen/code_generators/module.rb +92 -0
  29. data/lib/origen/commands.rb +30 -13
  30. data/lib/origen/commands/archive.rb +175 -0
  31. data/lib/origen/commands/extract.rb +43 -0
  32. data/lib/origen/commands/generate.rb +1 -0
  33. data/lib/origen/commands/lint.rb +6 -1
  34. data/lib/origen/commands/new.rb +48 -24
  35. data/lib/origen/commands/new_resource.rb +41 -0
  36. data/lib/origen/commands/site.rb +52 -0
  37. data/lib/origen/commands/web.rb +11 -6
  38. data/lib/origen/commands_global.rb +9 -7
  39. data/lib/origen/core_ext/numeric.rb +20 -0
  40. data/lib/{option_parser → origen/core_ext/option_parser}/optparse.rb +0 -0
  41. data/lib/origen/dependencies.rb +0 -0
  42. data/lib/origen/file_handler.rb +18 -6
  43. data/lib/origen/generator.rb +19 -10
  44. data/lib/origen/generator/comparator.rb +2 -1
  45. data/lib/origen/generator/flow.rb +3 -1
  46. data/lib/origen/generator/job.rb +60 -16
  47. data/lib/origen/generator/pattern.rb +132 -72
  48. data/lib/origen/generator/pattern_finder.rb +3 -3
  49. data/lib/origen/generator/pattern_sequence.rb +201 -0
  50. data/lib/origen/generator/pattern_sequencer.rb +99 -0
  51. data/lib/origen/generator/pattern_thread.rb +175 -0
  52. data/lib/origen/loader.rb +381 -0
  53. data/lib/origen/log.rb +250 -108
  54. data/lib/origen/model.rb +22 -1
  55. data/lib/origen/model/exporter.rb +50 -10
  56. data/lib/origen/model_initializer.rb +5 -1
  57. data/lib/origen/operating_systems.rb +4 -0
  58. data/lib/origen/parameters.rb +96 -4
  59. data/lib/origen/parameters/set.rb +4 -3
  60. data/lib/origen/pins.rb +10 -8
  61. data/lib/origen/pins/pin.rb +61 -46
  62. data/lib/origen/ports/port.rb +5 -0
  63. data/lib/origen/registers.rb +5 -0
  64. data/lib/origen/registers/bit.rb +57 -53
  65. data/lib/origen/registers/bit_collection.rb +100 -43
  66. data/lib/origen/registers/msb0_delegator.rb +47 -0
  67. data/lib/origen/registers/reg.rb +114 -99
  68. data/lib/origen/revision_control.rb +1 -1
  69. data/lib/origen/revision_control/git.rb +23 -3
  70. data/lib/origen/site_config.rb +251 -60
  71. data/lib/origen/site_config/config.rb +217 -0
  72. data/lib/origen/sub_blocks.rb +106 -31
  73. data/lib/origen/top_level.rb +11 -0
  74. data/lib/origen/users/user.rb +3 -2
  75. data/lib/origen/utility/mailer.rb +42 -9
  76. data/lib/origen/value/bin_str_val.rb +1 -1
  77. data/lib/origen/value/hex_str_val.rb +1 -1
  78. data/lib/origen/version_string.rb +6 -1
  79. data/lib/tasks/gem.rake +6 -1
  80. data/origen_app_generators/Gemfile +19 -0
  81. data/origen_app_generators/Gemfile.lock +152 -0
  82. data/origen_app_generators/LICENSE +21 -0
  83. data/origen_app_generators/README.md +368 -0
  84. data/{templates/code_generators/rakefile.rb → origen_app_generators/Rakefile} +0 -0
  85. data/origen_app_generators/bin/boot.rb +39 -0
  86. data/origen_app_generators/config/application.rb +153 -0
  87. data/origen_app_generators/config/boot.rb +1 -0
  88. data/origen_app_generators/config/commands.rb +63 -0
  89. data/origen_app_generators/config/shared_commands.rb +177 -0
  90. data/origen_app_generators/config/version.rb +8 -0
  91. data/origen_app_generators/doc/history +223 -0
  92. data/origen_app_generators/lbin/bundle +105 -0
  93. data/origen_app_generators/lbin/byebug +29 -0
  94. data/origen_app_generators/lbin/coderay +29 -0
  95. data/origen_app_generators/lbin/htmldiff +29 -0
  96. data/origen_app_generators/lbin/httparty +29 -0
  97. data/origen_app_generators/lbin/httpclient +29 -0
  98. data/origen_app_generators/lbin/kramdown +29 -0
  99. data/origen_app_generators/lbin/ldiff +29 -0
  100. data/origen_app_generators/lbin/nanoc +29 -0
  101. data/origen_app_generators/lbin/nokogiri +29 -0
  102. data/origen_app_generators/lbin/origen +62 -0
  103. data/origen_app_generators/lbin/pry +29 -0
  104. data/origen_app_generators/lbin/rackup +29 -0
  105. data/origen_app_generators/lbin/rake +29 -0
  106. data/origen_app_generators/lbin/rspec +29 -0
  107. data/origen_app_generators/lbin/rubocop +29 -0
  108. data/origen_app_generators/lbin/ruby-parse +29 -0
  109. data/origen_app_generators/lbin/ruby-rewrite +29 -0
  110. data/origen_app_generators/lbin/thor +29 -0
  111. data/origen_app_generators/lbin/tilt +29 -0
  112. data/origen_app_generators/lbin/yard +29 -0
  113. data/origen_app_generators/lbin/yardoc +29 -0
  114. data/origen_app_generators/lbin/yri +29 -0
  115. data/origen_app_generators/lib/origen_app_generators.rb +125 -0
  116. data/origen_app_generators/lib/origen_app_generators/application.rb +62 -0
  117. data/origen_app_generators/lib/origen_app_generators/base.rb +257 -0
  118. data/origen_app_generators/lib/origen_app_generators/empty_application.rb +15 -0
  119. data/origen_app_generators/lib/origen_app_generators/empty_plugin.rb +15 -0
  120. data/origen_app_generators/lib/origen_app_generators/new.rb +170 -0
  121. data/origen_app_generators/lib/origen_app_generators/new_app_tests.rb +4 -0
  122. data/origen_app_generators/lib/origen_app_generators/origen_infrastructure/app_generator_plugin.rb +107 -0
  123. data/origen_app_generators/lib/origen_app_generators/plugin.rb +55 -0
  124. data/origen_app_generators/lib/origen_app_generators/test_engineering/common.rb +29 -0
  125. data/origen_app_generators/lib/origen_app_generators/test_engineering/stand_alone_application.rb +64 -0
  126. data/origen_app_generators/lib/origen_app_generators/test_engineering/test_block.rb +61 -0
  127. data/origen_app_generators/origen_app_generators.gemspec +33 -0
  128. data/{templates/code_generators → origen_app_generators/spec}/spec_helper.rb +0 -0
  129. data/origen_app_generators/target/debug.rb +8 -0
  130. data/origen_app_generators/target/default.rb +8 -0
  131. data/origen_app_generators/target/production.rb +0 -0
  132. data/origen_app_generators/templates/app_generators/application/.gitignore +37 -0
  133. data/origen_app_generators/templates/app_generators/application/.irbrc +9 -0
  134. data/origen_app_generators/templates/app_generators/application/.rspec +1 -0
  135. data/origen_app_generators/templates/app_generators/application/.travis.yml +11 -0
  136. data/origen_app_generators/templates/app_generators/application/Gemfile +34 -0
  137. data/origen_app_generators/templates/app_generators/application/Rakefile +7 -0
  138. data/origen_app_generators/templates/app_generators/application/app/blocks/top_level.rb +12 -0
  139. data/origen_app_generators/templates/app_generators/application/app/lib/module.rb +6 -0
  140. data/origen_app_generators/templates/app_generators/application/app/templates/web/index.md.erb +19 -0
  141. data/origen_app_generators/templates/app_generators/application/app/templates/web/layouts/_basic.html.erb +13 -0
  142. data/origen_app_generators/templates/app_generators/application/app/templates/web/partials/_navbar.html.erb +20 -0
  143. data/origen_app_generators/templates/app_generators/application/app/templates/web/release_notes.md.erb +5 -0
  144. data/origen_app_generators/templates/app_generators/application/config/application.rb +121 -0
  145. data/origen_app_generators/templates/app_generators/application/config/boot.rb +4 -0
  146. data/origen_app_generators/templates/app_generators/application/config/commands.rb +79 -0
  147. data/origen_app_generators/templates/app_generators/application/config/maillist_dev.txt +4 -0
  148. data/origen_app_generators/templates/app_generators/application/config/maillist_prod.txt +3 -0
  149. data/origen_app_generators/templates/app_generators/application/config/version.rb +8 -0
  150. data/origen_app_generators/templates/app_generators/application/doc/history +0 -0
  151. data/origen_app_generators/templates/app_generators/application/dot_keep +0 -0
  152. data/origen_app_generators/templates/app_generators/application/origen_core_session +2 -0
  153. data/origen_app_generators/templates/app_generators/application/spec/spec_helper.rb +44 -0
  154. data/origen_app_generators/templates/app_generators/application/target/debug.rb +8 -0
  155. data/origen_app_generators/templates/app_generators/application/target/default.rb +1 -0
  156. data/origen_app_generators/templates/app_generators/application/target/production.rb +4 -0
  157. data/origen_app_generators/templates/app_generators/new/generator.rb +102 -0
  158. data/origen_app_generators/templates/app_generators/new/info.md.erb +9 -0
  159. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/application.rb +54 -0
  160. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/base.rb +55 -0
  161. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/module.rb +28 -0
  162. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/app/lib/plugin.rb +64 -0
  163. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/config/load_generators.rb +6 -0
  164. data/origen_app_generators/templates/app_generators/plugin/Gemfile +32 -0
  165. data/origen_app_generators/templates/app_generators/plugin/Rakefile +10 -0
  166. data/origen_app_generators/templates/app_generators/plugin/app/templates/web/index.md.erb +37 -0
  167. data/origen_app_generators/templates/app_generators/plugin/app/templates/web/partials/_navbar_external.html.erb +20 -0
  168. data/origen_app_generators/templates/app_generators/plugin/app/templates/web/partials/_navbar_internal.html.erb +20 -0
  169. data/origen_app_generators/templates/app_generators/plugin/config/boot.rb +24 -0
  170. data/origen_app_generators/templates/app_generators/plugin/gemspec.rb +43 -0
  171. data/origen_app_generators/templates/app_generators/test_engineering/environment/j750.rb +1 -0
  172. data/origen_app_generators/templates/app_generators/test_engineering/environment/uflex.rb +1 -0
  173. data/origen_app_generators/templates/app_generators/test_engineering/environment/v93k.rb +1 -0
  174. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/.keep +0 -0
  175. data/origen_app_generators/templates/app_generators/test_engineering/test_block/.keep +0 -0
  176. data/origen_site_config.yml +55 -5
  177. data/templates/code_generators/attributes.rb +20 -0
  178. data/templates/code_generators/class.rb +9 -0
  179. data/templates/code_generators/controller.rb +87 -0
  180. data/templates/code_generators/model.rb +21 -0
  181. data/templates/code_generators/module.rb +4 -0
  182. data/templates/code_generators/parameters.rb +19 -0
  183. data/templates/code_generators/pins.rb +28 -0
  184. data/templates/code_generators/registers.rb +20 -0
  185. data/templates/code_generators/sub_blocks.rb +24 -0
  186. data/templates/code_generators/timesets.rb +24 -0
  187. data/templates/code_generators/version.rb +0 -1
  188. data/templates/git/gitignore.erb +0 -1
  189. data/vendor/lib/models/origen/export1.rb +77 -0
  190. data/vendor/lib/models/origen/export1/block1.rb +13 -0
  191. data/vendor/lib/models/origen/export1/block1/x.rb +36 -0
  192. data/vendor/lib/models/origen/non_origen_meta_data.md +1 -0
  193. metadata +149 -68
  194. data/bin/fix_my_workspace +0 -100
  195. data/lib/c99/ate_interface.rb +0 -77
  196. data/lib/c99/nvm.rb +0 -110
  197. data/lib/c99/target/mock2.rb +0 -1
  198. data/lib/c99/target/subdir/mock3.rb +0 -1
  199. data/lib/origen/code_generators/bundler.rb +0 -17
  200. data/lib/origen/code_generators/gem_setup.rb +0 -49
  201. data/lib/origen/code_generators/rake.rb +0 -13
  202. data/lib/origen/code_generators/rspec.rb +0 -12
  203. data/lib/origen/commands/add.rb +0 -12
  204. data/lib/tasks/private/build.rake +0 -8
  205. data/templates/code_generators/gemfile_app.rb +0 -4
  206. data/templates/code_generators/gemfile_plugin.rb +0 -6
  207. data/templates/code_generators/gemspec.rb +0 -33
@@ -0,0 +1,62 @@
1
+ module OrigenAppGenerators
2
+ # The base generator class that should be used by all application generators
3
+ class Application < Base
4
+ # Any methods that are not protected will get invoked in the order they are
5
+ # defined when the generator is run
6
+
7
+ protected
8
+
9
+ def type
10
+ :application
11
+ end
12
+
13
+ # This is the default list of files that will get generated for a new application
14
+ # when you call the compile_filelist method.
15
+ # To customize this for a domain specific application generator you can either
16
+ # delete an entry:
17
+ #
18
+ # filelist.delete(:config_application)
19
+ # compile_filelist
20
+ #
21
+ # Or point it to a different template, the supplied path is relative to templates/app_generators
22
+ #
23
+ # filelist[:config_application][:source] = "dng_test_app/config/application.rb"
24
+ # compile_filelist
25
+ def filelist
26
+ fail '@name must be defined before calling filelist for the first time' unless @name
27
+ @filelist ||= {
28
+ config_application: { source: 'config/application.rb' },
29
+ config_version: { source: 'config/version.rb' },
30
+ config_boot: { source: 'config/boot.rb' },
31
+ config_commands: { source: 'config/commands.rb' },
32
+ config_dev: { source: 'config/maillist_dev.txt' },
33
+ config_prod: { source: 'config/maillist_prod.txt' },
34
+ doc_history: { source: 'doc/history' },
35
+ target_default: { source: 'target/default.rb' },
36
+ # target_default: { source: 'debug.rb', # Relative to the file being linked to
37
+ # dest: 'target/default.rb', # Relative to destination_root
38
+ # type: :symlink },
39
+ environment_dir: { dest: 'environment', type: :directory },
40
+ lib_module: { source: 'app/lib/module.rb',
41
+ dest: "app/lib/#{@name}.rb" },
42
+ lib_module_dir: { dest: "app/lib/#{@name}", type: :directory },
43
+ app_blocks_dir: { dest: 'app/blocks', type: :directory },
44
+ spec_helper: { source: 'spec/spec_helper.rb' },
45
+ web_index: { source: 'app/templates/web/index.md.erb' },
46
+ web_basic_layout: { source: 'app/templates/web/layouts/_basic.html.erb' },
47
+ web_navbar: { source: 'app/templates/web/partials/_navbar.html.erb' },
48
+ web_release_notes: { source: 'app/templates/web/release_notes.md.erb' },
49
+ rakefile: { source: 'Rakefile' },
50
+ gemfile: { source: 'Gemfile' },
51
+ gitignore: { source: '.gitignore' },
52
+ irbrc: { source: '.irbrc' },
53
+ rspec: { source: '.rspec' },
54
+ # This sets the initial mode of the new workspace to 'debug'
55
+ session: { source: 'origen_core_session',
56
+ dest: '.session/origen_core',
57
+ copy: true
58
+ }
59
+ }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,257 @@
1
+ module OrigenAppGenerators
2
+ # This is the base generator used by all generators in this application
3
+ class Base < Origen::CodeGenerators::Base
4
+ include Origen::Utility::InputCapture
5
+
6
+ require 'gems'
7
+
8
+ def validate_application_name
9
+ @name = args.first.to_s.strip
10
+ if @name == ''
11
+ puts
12
+ puts "You must supply a name for what you want to call your application: 'origen new my_name'"
13
+ puts
14
+ exit 1
15
+ elsif @name != @name.symbolize.to_s
16
+ puts
17
+ puts 'The name of your new app must be lowercased and underscored and contain no special characters'
18
+ puts
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ def set_source_paths
24
+ # The base Origen generator puts the Origen core directory on the source path, in retrospect this
25
+ # was a bad idea and makes for hard to debug errors if an app generator resolves a template from
26
+ # outside of this app.
27
+ # So to keep things sane remove any inherited source paths.
28
+ self.class.source_paths.pop until self.class.source_paths.empty?
29
+ klass = self.class
30
+
31
+ until klass == OrigenAppGenerators::Base
32
+ if template_dir = OrigenAppGenerators.template_dirs[klass]
33
+ dir = []
34
+ last_class = nil
35
+ until klass.to_s =~ /^OrigenAppGenerators/
36
+ dir << "#{template_dir}/#{class_dir(klass)}"
37
+ last_class = klass
38
+ klass = klass.superclass
39
+ end
40
+ dir << "#{template_dir}/base"
41
+ klass = last_class
42
+ else
43
+ dir = []
44
+ class_dirs(klass).each do |class_dir|
45
+ dir << "#{Origen.root!}/templates/app_generators/#{class_dir}"
46
+ dir << "#{Origen.root!}/app/templates/app_generators/#{class_dir}"
47
+ end
48
+ end
49
+ Array(dir).each do |dir|
50
+ self.class.source_paths << dir if File.exist?(dir) && !self.class.source_paths.include?(dir)
51
+ end
52
+ klass = klass.superclass
53
+ end
54
+ end
55
+
56
+ # Just makes the type (:plugin or :application) available to all templates
57
+ def set_type
58
+ @type = type
59
+ end
60
+
61
+ def get_common_user_input
62
+ # Don't bother asking the user for this, their life will be easier if they just go with
63
+ # Origen's default namespace based on their app's name
64
+ @namespace = @name.to_s.camelize
65
+ end
66
+
67
+ def get_lastest_origen_version
68
+ @latest_origen_version ||= begin
69
+ (Gems.info 'origen')['version']
70
+ rescue
71
+ # If the above fails, e.g. due to an SSL error in the runtime environment, try to fetch the
72
+ # latest Origen version from the Origen website, before finally falling back to the version
73
+ # we are currently running if all else fails
74
+ begin
75
+ require 'httparty'
76
+ response = HTTParty.get('http://origen-sdk.org/origen/release_notes/')
77
+ version = Origen::VersionString.new(response.body.match(/Tag: v(\d+\.\d+.\d+)</).to_a.last)
78
+ if version.valid?
79
+ version
80
+ else
81
+ fail "Can't get the latest version!"
82
+ end
83
+ rescue
84
+ Origen.version
85
+ end
86
+ end
87
+ end
88
+
89
+ protected
90
+
91
+ def class_dir(klass)
92
+ names = klass.to_s.split('::')
93
+ names.shift
94
+ names.map(&:underscore).join('/')
95
+ end
96
+
97
+ def class_dirs(klass)
98
+ names = klass.to_s.split('::')
99
+ names.shift
100
+ dirs = []
101
+ until names.empty?
102
+ dirs << names.map(&:underscore).join('/')
103
+ names.pop
104
+ end
105
+ dirs
106
+ end
107
+
108
+ # def application_class?(klass)
109
+ # until klass == OrigenAppGenerators::Base
110
+ # end
111
+
112
+ def debugger
113
+ require 'byebug'
114
+ byebug # rubocop:disable Lint/Debugger
115
+ end
116
+
117
+ def plugin?
118
+ type == :plugin
119
+ end
120
+
121
+ def application?
122
+ !plugin?
123
+ end
124
+
125
+ def self.title
126
+ desc.sub(/^An? /, '').titleize
127
+ end
128
+
129
+ # Calling this will compile all files in filelist against the current instance
130
+ # variable values
131
+ def build_filelist
132
+ symlink_cmds = []
133
+ self.destination_root = args.first
134
+ filelist.each do |_name, file|
135
+ if file[:type] == :symlink
136
+ if Origen.running_on_windows?
137
+ dest = Pathname.new("#{destination_root}/#{file[:dest]}")
138
+ source = dest.dirname.to_s + "/#{file[:source]}"
139
+ symlink_cmds << "call mklink /h #{dest.to_s.gsub('/', '\\')} #{source.to_s.gsub('/', '\\')}"
140
+ else
141
+ create_link file[:dest], file[:source]
142
+ end
143
+ elsif file[:type] == :dir || file[:type] == :directory
144
+ if file[:copy]
145
+ if (file.key? :dest) && (file.key? :source)
146
+ directory(file[:source], file[:dest])
147
+ else
148
+ directory(file[:dest] || file[:source])
149
+ end
150
+ elsif file[:nokeep]
151
+ empty_directory(file[:dest] || file[:source])
152
+ else
153
+ copy_file('dot_keep', "#{file[:dest]}/.keep")
154
+ end
155
+ else
156
+ dest = file[:dest] || file[:source]
157
+ if file[:copy] || dest =~ /.erb$/
158
+ copy_file(file[:source], dest)
159
+ else
160
+ @options = file[:options] || {}
161
+ template(file[:source], dest)
162
+ end
163
+ end
164
+ end
165
+ symlink_cmds.each { |cmd| system(cmd) }
166
+ end
167
+
168
+ # Prompts the user to confirm or enter the Ruby namespace to be used in the app.
169
+ #
170
+ # If @name is already defined a proposal will be generated from that, alternatively a proposal
171
+ # can be supplied. If not proposal is resolved the user will be prompted to input from scratch.
172
+ def get_namespace(proposal = nil)
173
+ puts
174
+ puts "SELECT YOUR #{type.to_s.upcase}'S NAMESPACE"
175
+ puts
176
+ puts "All #{type} code needs to reside in a unique namespace, this prevents naming collisions with 3rd party plugins."
177
+ puts 'By Ruby conventions, this must start with a capital letter and should ideally be CamelCased and not use underscores.'
178
+ # puts 'Some examples:: C40TFSNVMTester, CAPIOrigen, LS2080, ApacheOrigen'
179
+ [@namespace_advice].each { |l| puts l } if @namespace_advice
180
+ puts
181
+ if !proposal && @name
182
+ proposal = @name.to_s.camelize
183
+ end
184
+ proposal = nil if proposal.length < 3
185
+
186
+ valid = false
187
+ until valid
188
+ @namespace = get_text(single: true, default: proposal)
189
+ proposal = nil
190
+ unless @namespace.empty?
191
+ if @namespace.length >= 3
192
+ valid = valid_constant?(@namespace)
193
+ end
194
+ unless valid
195
+ puts 'That namespace is not valid :-('
196
+ puts
197
+ end
198
+ end
199
+ end
200
+ @namespace
201
+ end
202
+
203
+ # Returns true if the given string can be converted to a valid Ruby constant and one that
204
+ # does not already exist within the scope of this application and Origen Core
205
+ def valid_constant?(string)
206
+ valid = false
207
+ # Try and convert this to a constant to test for validity, this will also screen things
208
+ # like Origen since that will not trigger an error
209
+ begin
210
+ string.constantize
211
+ rescue NameError => e
212
+ if e.message =~ /^uninitialized constant/
213
+ valid = true
214
+ end
215
+ else
216
+ # Something else is wrong with it
217
+ end
218
+ valid
219
+ end
220
+
221
+ # Prompts the user to input a name for the new application, this will be screened to ensure
222
+ # that it can cleanly cast to a symbol for use in Origen.
223
+ #
224
+ # This should be unique within the whole Origen ecosystem, in future this method will be enhanced
225
+ # to check with the Origen server which will in future maintain a database of known app names.
226
+ #
227
+ # The final name is returned at the end and assigned to variable @name for use in templates.
228
+ def get_name
229
+ proposal = args.first.symbolize.to_s
230
+ proposal = nil if proposal.length < 3
231
+ puts
232
+ puts "WHAT DO YOU WANT TO CALL YOUR NEW #{type.to_s.upcase}?"
233
+ puts
234
+ puts "This should be lowercased and underscored and will be used to uniquely identify your #{type} within the Origen ecosystem."
235
+ [@name_advice].each { |l| puts l } if @name_advice
236
+ puts
237
+ valid = false
238
+ until valid
239
+ name = get_text(single: true, default: proposal)
240
+ proposal = nil
241
+ unless name.empty?
242
+ if name == name.symbolize.to_s
243
+ if name.symbolize.to_s.length >= 3
244
+ valid = true
245
+ @name = name
246
+ end
247
+ else
248
+ puts
249
+ puts 'That name is not valid, how about this?'
250
+ proposal = name.symbolize.to_s
251
+ end
252
+ end
253
+ end
254
+ @name
255
+ end
256
+ end
257
+ end
@@ -0,0 +1,15 @@
1
+ module OrigenAppGenerators
2
+ # Generates a generic application shell
3
+ class EmptyApplication < Application
4
+ # Any methods that are not protected will get invoked in the order they are
5
+ # defined when the generator is run
6
+
7
+ def generate_files
8
+ build_filelist
9
+ end
10
+
11
+ def conclude
12
+ puts "New app created at: #{destination_root}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module OrigenAppGenerators
2
+ # Generates a generic plugin shell
3
+ class EmptyPlugin < Plugin
4
+ # Any methods that are not protected will get invoked in the order they are
5
+ # defined when the generator is run
6
+
7
+ def generate_files
8
+ build_filelist
9
+ end
10
+
11
+ def conclude
12
+ puts "New app created at: #{destination_root}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,170 @@
1
+ module OrigenAppGenerators
2
+ class New < Base
3
+ include Origen::Utility::InputCapture
4
+
5
+ desc 'Creates a new application generator within this application'
6
+
7
+ # Naming of this method is important here to override the default user input which
8
+ # does not apply to this generator
9
+ def get_common_user_input
10
+ get_domain
11
+ get_name
12
+ get_type
13
+ get_summary
14
+ @namespace = Origen.app.namespace
15
+ end
16
+
17
+ def set_type
18
+ # Type not applicable in for this generator
19
+ end
20
+
21
+ def generate_files
22
+ build_filelist
23
+ end
24
+
25
+ def enable
26
+ available = Origen.app.namespace.constantize::AVAILABLE
27
+ test_inputs = Origen.app.namespace.constantize::TEST_INPUTS
28
+
29
+ # **** Add require line ****
30
+ module_declaration = /\nmodule #{Origen.app.namespace}/
31
+ inject_into_file "#{app_dir}lib/#{Origen.app.name}.rb", "require '#{Origen.app.name}/#{@domain_namespace.underscore}/#{@classname.underscore}'\n",
32
+ before: module_declaration
33
+
34
+ # **** Add to the AVAILABLE hash ****
35
+ if available[@domain_summary]
36
+ existing_domain = /\s*('|")#{@domain_summary}('|") => \[\s*\n/
37
+ inject_into_file "#{app_dir}lib/#{Origen.app.name}.rb", " #{Origen.app.namespace}::#{@domain_namespace}::#{@classname},\n",
38
+ after: existing_domain
39
+ else
40
+ new_domain = <<-END
41
+ '#{@domain_summary}' => [
42
+ #{Origen.app.namespace}::#{@domain_namespace}::#{@classname},
43
+ ],
44
+ END
45
+ available_hash = /AVAILABLE = {\s*\n/
46
+ inject_into_file "#{app_dir}lib/#{Origen.app.name}.rb", new_domain, after: available_hash
47
+ end
48
+
49
+ # **** Add a starter set of test inputs ****
50
+ # First work out what the selection numbers will be for the new generator
51
+ if available[@domain_summary]
52
+ first = available.size - available.find_index { |k, _| k == @domain_summary }
53
+ second = available[@domain_summary].size
54
+ else
55
+ first = available.size + 1
56
+ second = 0
57
+ end
58
+ inputs = "\n # #{test_inputs.size} - #{@domain_namespace}::#{@classname}\n"
59
+ if @parentclass == 'Plugin'
60
+ inputs += " ['#{first}', '#{second}', :default, :default, 'A cool plugin', 'yes', :default]"
61
+ else
62
+ inputs += " ['#{first}', '#{second}', :default]"
63
+ end
64
+ inputs = ",#{inputs}" unless test_inputs.empty?
65
+ end_of_test_inputs = /\n\s*\]\s*#\s*END_OF_TEST_INPUTS/
66
+ inject_into_file "#{app_dir}lib/#{Origen.app.name}.rb", inputs, before: end_of_test_inputs
67
+ end
68
+
69
+ # Can't compile this as contains some final ERB, so substitute instead
70
+ # def customize_doc_page
71
+ # file = filelist[:doc_info][:dest]
72
+ # gsub_file file, 'TITLE_GOES_HERE', @title
73
+ # if @type == :plugin
74
+ # gsub_file file, 'INTRO_GOES_HERE', "This generates a customized version of the [Generic Plugin](<%= path 'origen_app_generators/plugin' %>)."
75
+ # else
76
+ # gsub_file file, 'INTRO_GOES_HERE', "This generates a customized version of the [Generic Application](<%= path 'origen_app_generators/application' %>)."
77
+ # end
78
+ # end
79
+
80
+ def conclude
81
+ system "origen lint #{Origen.root}/#{app_dir}lib/#{Origen.app.name}.rb"
82
+ puts
83
+ puts "New generator created at: #{filelist[:generator][:dest]}"
84
+ puts
85
+ puts "Create any template files you need for this generator in: #{filelist[:templates_dir][:dest]}"
86
+ puts
87
+ # puts "Before you go add some documentation about what this generates to: templates/web/origen_app_generators/origen_app_generators/#{@domain_namespace.underscore}/#{@classname.underscore}.md.erb"
88
+ # puts
89
+ end
90
+
91
+ protected
92
+
93
+ def app_dir
94
+ if File.exist?("#{Origen.root}/app/lib")
95
+ 'app/'
96
+ else
97
+ ''
98
+ end
99
+ end
100
+
101
+ def get_summary
102
+ puts
103
+ puts 'DESCRIBE YOUR NEW GENERATOR IN A FEW WORDS'
104
+ puts
105
+ @summary = get_text(single: true)
106
+ @title = @summary.sub(/^An? /, '').titleize
107
+ end
108
+
109
+ def get_type
110
+ puts
111
+ puts 'WILL YOUR TEMPLATE GENERATE A PLUGIN OR A TOP-LEVEL APPLICATION?'
112
+ puts
113
+ type = get_text(single: true, accept: %w(application plugin)).downcase
114
+ @parentclass = type.capitalize
115
+ end
116
+
117
+ def get_name
118
+ puts
119
+ puts 'GIVE YOUR NEW GENERATOR CLASS A NAME'
120
+ puts
121
+ puts 'Your new generator needs a class name, this should be reasonably descriptive although it will not be displayed to end users'
122
+ puts 'Some examples: GenericTestBlock, IPBlock, MPGBOMApp'
123
+ puts
124
+ valid = false
125
+ until valid
126
+ @classname = get_text(single: true).split('::').last
127
+ unless @classname.empty?
128
+ if @classname.length >= 3
129
+ valid = valid_constant?("#{Origen.app.namespace}::#{@domain_namespace}::#{@classname}")
130
+ end
131
+ unless valid
132
+ puts 'That class name is not valid :-('
133
+ puts
134
+ end
135
+ end
136
+ end
137
+ @classname
138
+ end
139
+
140
+ def get_domain
141
+ puts
142
+ puts 'WHAT APPLICATION DOMAIN WILL YOUR NEW APP TEMPLATE APPLY TO?'
143
+ puts
144
+ puts "Enter something like 'Test Engineering', 'Design', etc."
145
+ puts
146
+ domain = get_text(single: true)
147
+ domain = domain.split(' ').map do |word|
148
+ # Ensure all first letters capitalized, but make sure something like
149
+ # 'NVM' remains 'NVM' and not 'Nvm'
150
+ letters = word.split('')
151
+ letters.first.upcase!
152
+ letters.join
153
+ end.join(' ')
154
+
155
+ @domain_summary = domain
156
+ @domain_namespace = @domain_summary.gsub(' ', '')
157
+ end
158
+
159
+ def filelist
160
+ @filelist ||= {
161
+ generator: { source: 'generator.rb',
162
+ dest: "#{app_dir}lib/#{Origen.app.name}/#{@domain_namespace.underscore}/#{@classname.underscore}.rb" },
163
+ templates_dir: { dest: "#{app_dir}templates/app_generators/#{@domain_namespace.underscore}/#{@classname.underscore}",
164
+ type: :directory },
165
+ # doc_info: { source: 'info.md.erb',
166
+ # dest: "#{app_dir}templates/web/#{Origen.app.name}/#{@domain_namespace.underscore}/#{@classname.underscore}.md.erb" }
167
+ }
168
+ end
169
+ end
170
+ end