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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 NXP Semiconductors and individual contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,368 @@
1
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Origen-SDK/users?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
+ [![Build Status](https://travis-ci.org/Origen-SDK/origen_app_generators.svg)](https://travis-ci.org/Origen-SDK/origen_app_generators)
3
+
4
+ # Origen App Generators
5
+
6
+ This plugin implements all of the starter applications that can be generated from the `origen new` command.
7
+ It is maintained separately from Origen core so that improvements and new
8
+ application templates can be released independently of the base platform.
9
+
10
+ Additionally, it provides infrastructure and APIs to allow companies to create their own version
11
+ of this plugin, allowing them to create their own customized starter application templates and then
12
+ make them available to their users via `origen new`.
13
+
14
+ To extend `origen new` with your own custom application generators,
15
+ run `origen new` and create your own version of this plugin by selecting the following options:
16
+
17
+ * 1 - Origen Infrastructure
18
+ * 0 - A plugin to make your own application templates available through the 'origen new' command
19
+
20
+ To hook your plugin into the `origen new` command, either release it to your private gem server, check it into your
21
+ Git server, or copy it to a central location that is accessible to all of your users.
22
+ Then update the [app_generators](https://github.com/Origen-SDK/origen/blob/master/origen_site_config.yml#L7) attribute within your
23
+ [site_config file](http://origen-sdk.org/origen/guides/starting/company/) to point to wherever you have put it.
24
+
25
+ If you don't see it straight away, run `origen new` with the `--fetch` option to force it to
26
+ fetch the latest versions of the generators.
27
+
28
+ The notes that follow apply to both the origen_app_generators plugin and any company-specific
29
+ generator plugins.
30
+
31
+ ## Quickstart
32
+
33
+ To create a new application generator run the following command:
34
+
35
+ ~~~text
36
+ origen app_gen:new
37
+ ~~~
38
+
39
+ This will create a new generator within the `lib` directory and then update the top-level file in the `lib` directory
40
+ to properly hook it into the `origen new` system.
41
+ By default, this new generator will create the same empty application or plugin starter that you would get from
42
+ selecting option 0 in the `origen new` command.
43
+
44
+ You can test run your new generator by running the following command:
45
+
46
+ ~~~text
47
+ origen app_gen:test
48
+ ~~~
49
+
50
+ This will build a new app in the application's `tmp` directory, and when complete you can cd into that directory
51
+ and run `origen -v` to verify that it can boot. At this point you can further interact with the application in the
52
+ normal way to test out anything else.
53
+
54
+ During the creation of a new generator, you will likely repeat this many times as you go through the process of modifying the
55
+ generator and then observing the new output. To make this easier, a system is built in that allows you to automate the
56
+ answers to the questions that are given to the user when creating a new application.
57
+
58
+ Within the top-level lib file you will see a set of test inputs something like this:
59
+
60
+ ~~~ruby
61
+ TEST_INPUTS = [
62
+ # 0 - TestEngineering::MicroTestBlock
63
+ ['1', '0', :default, :default, 'A cool plugin', 'yes', :default]
64
+ ] # END_OF_TEST_INPUTS Don't remove this comment, it is used by the app_gen:new command!
65
+ ~~~
66
+
67
+ The last item in the array will be a starter set of inputs that has been created for the new genrator that was just added.
68
+ To test the new generator with these inputs supply the `-i` option and supply the index number of the set of inputs you
69
+ wish to apply:
70
+
71
+ ~~~text
72
+ origen app_gen:test -i 0
73
+ ~~~
74
+ Modify the inputs as required as you further develop the generator, making sure to add a value for any additional questions
75
+ that you add. The `:default` keyword can be used for any questions which have a default option that you wish to select, this
76
+ is equivalent to just pressing return in response to the given question.
77
+
78
+ In all cases an additional argument must be supplied at the end, this tells the test command about any commands that you want
79
+ to run within the generated application to test it.
80
+ Supplying the `:default` keyword for this argument will execute the following tests:
81
+
82
+ * origen -v
83
+ * origen lint --no-correct
84
+ * Test that the default target loads cleanly
85
+ * origen web compile --no-serve
86
+
87
+ If you want to run no tests, set this final argument to `nil`.
88
+
89
+ Alternatively you can specify your own set of operations by supplying an array of commands:
90
+
91
+ ~~~ruby
92
+ ['1', '0', :default, :default, 'A cool plugin', 'yes', ['origen -v', 'origen g my_pattern']]
93
+ ~~~
94
+
95
+ Within the array of custom commands you can also supply the `:default` and `:load_target` keywords to execute the default
96
+ set of tests or the load target test respectively, for example:
97
+
98
+ ~~~ruby
99
+ ['1', '0', :default, :default, 'A cool plugin', 'yes', [:default, 'origen g my_pattern']]
100
+ ~~~
101
+
102
+ To run a regression test which will execute all sets of test inputs, run:
103
+
104
+ ~~~text
105
+ origen app_gen:test -r
106
+ ~~~
107
+
108
+ You should find the generator file itself (the one created for you in a sub-folder of the `lib` directory) well commented
109
+ and with pointers towards examples from existing generators.
110
+
111
+ Once you are happy with your new generator release your application generators plugin in the normal way. The version of the
112
+ generators picked up by the `origen new` command is automatically refreshed on a per-user basis every 24 hours, or if you
113
+ need access to it immediately run `origen new` with the `--fetch` option to force it.
114
+
115
+ There now follows a more detailed guide on how to create the generator itself.
116
+
117
+ ## Notes on Creating Generators
118
+
119
+ The application generators use a code generator API from Origen core which itself leans heavily on a 3rd party gem library called
120
+ Thor. This gem is used quite widely in the Ruby community for this kind of thing, not least by the code generators
121
+ provided by the Ruby on Rails web application platform.
122
+
123
+ The code generator API allows the user to do things like:
124
+
125
+ * Run code to collect user input
126
+ * Compile templates to produce dynamic output based on the user's responses
127
+ * Copy files verbatim
128
+ * Create directories and symlinks
129
+ * Delete and inject lines into existing files
130
+
131
+ Each application type that can be generated by this plugin is an example of a code generator.
132
+
133
+ The new application generators are organized into the following hierarchy:
134
+
135
+ ~~~text
136
+ OrigenAppGenerators::Application
137
+ |
138
+ -> MyAppGenerators::Application (Mixes in MyAppGenerators::Base)
139
+ |
140
+ -> OrigenAppGenerators::Plugin
141
+ |
142
+ -> MyAppGenerators::Plugin (Mixes in MyAppGenerators::Base)
143
+ ~~~
144
+
145
+ **All generators must be a subclass of either `OrigenAppGenerators::Application`
146
+ or `OrigenAppGenerators::Plugin` depending on whether the end application is intended to be a plugin or not.**
147
+
148
+ The new application generators should all perform the following functions:
149
+
150
+ * Prompt the user with some questions to get the new application name and so on
151
+ * Create the new application files by either copying or compiling source files and creating
152
+ symlinks or directories as required
153
+ * Make any final modifications to the resulting files
154
+ * Display any information that the user should know about their new application
155
+
156
+ ### Generator Execution
157
+
158
+ When a generator is executed any methods defined in it will be called in the order that they are
159
+ defined.
160
+ Any methods that are marked as `protected` will not be called.
161
+
162
+ For example when the following generator is executed:
163
+
164
+ ~~~ruby
165
+ module MyAppGenerators
166
+ class MyGenerator < Application
167
+ def say_hello
168
+ puts "Hello"
169
+ end
170
+
171
+ def call_a_helper
172
+ puts "About to call"
173
+ a_helper_method
174
+ puts "Returned from call"
175
+ end
176
+
177
+ protected
178
+
179
+ def a_helper_method
180
+ puts "Helper method called!"
181
+ end
182
+
183
+ def this_does_nothing
184
+ puts "Another method called!"
185
+ end
186
+ end
187
+ end
188
+ ~~~
189
+
190
+ Then you would see this:
191
+
192
+ ~~~text
193
+ Hello
194
+ About to call
195
+ Helper method called!
196
+ Returned from call
197
+ ~~~
198
+
199
+ Note that any methods defined by the parent classes will get called first. The
200
+ parent `OrigenAppGenerators::Application` and `OrigenAppGenerators::Plugin` classes implement methods to get the user
201
+ input that will be common to all applications.
202
+
203
+ You can disable this behavior if required by re-defining the relevant methods within the child generator class.
204
+
205
+ ### Source Files
206
+
207
+ All template or static source files for the generators live in `templates/app_generators` and from
208
+ there in sub folders based on the name of the particular generator.
209
+
210
+ All path references to source files made in your generator should be relative to its source file folder, and in
211
+ practice what this means is that if you want to refer to the source file of what will become
212
+ `Origen.root/config/application.rb` then you just refer to `config/application.rb`.
213
+
214
+ When looking for a particular source file the generator will search in the various source directories
215
+ belonging to your generator's parent classes.
216
+ For example let's say you make a test engineering generator that has the following class hierarchy:
217
+
218
+ ~~~text
219
+ OrigenAppGenerators::Application
220
+ |
221
+ -> OrigenAppGenerators::Plugin
222
+ |
223
+ -> MyAppGenerators::Plugin (Mixes in MyAppGenerators::Base)
224
+ |
225
+ -> TestEngineering::TestBlock
226
+ ~~~
227
+
228
+ Then the following source paths will be searched in this order:
229
+
230
+ ~~~text
231
+ <my_app_generators>/templates/app_generators/test_engineering/test_block
232
+ <my_app_generators>/templates/app_generators/plugin
233
+ <my_app_generators>/templates/app_generators/base
234
+ <origen_app_generators>/templates/app_generators/plugin
235
+ <origen_app_generators>/templates/app_generators/application
236
+ ~~~
237
+
238
+ This means that if you create a file called `config/application.rb` within
239
+ `<my_app_generators>/templates/app_generators/test_engineering/test_block` then this will override the corresponding
240
+ file from origen_app_generators.
241
+
242
+ However see the warning in *The Filelist* section below before doing this!
243
+
244
+ ### Lean Environment
245
+
246
+ When the generator is run by a user to generate a new application, it will not run within the scope of an
247
+ Origen application.
248
+ This means that any references to `Origen.app` within the generator code are meaningless and will
249
+ result in an error.
250
+
251
+ Furthermore, because there is no application there is also no associated gem bundle, so the generator must
252
+ be able to run within the lean Ruby environment that is used to boot Origen. In practice what this means is
253
+ that you can use any gems that Origen itself relies on (these will be installed in the base Ruby installation),
254
+ but you cannot use any others.
255
+
256
+ The `origen app_gen:test` command that is provided for testing the generators will run them within the lean environment, so if it
257
+ works there you can be confident that it will also run in production.
258
+
259
+ ### The Filelist
260
+
261
+ Each generator should return the list of files to be created in the new application via its
262
+ `filelist` method.
263
+ If you don't make any changes to this then it will simply inherit the list of files defined
264
+ by the generator's parent class.
265
+
266
+ The filelist is also used to define any directories or symlinks that should be created.
267
+ The generator class created by the `origen app_gen:new` command contains a commented example of how to add or
268
+ remove the various elements from the filelist.
269
+
270
+ Some application generators may not make any changes to the filelist and will simply augment
271
+ the basic application/plugin shell by adding additional code to some of the existing files.
272
+
273
+ This can be done by either overriding the source file by defining it in the generator's own
274
+ source directory, or by post-modifying the files after the filelist has been rendered as described further
275
+ down.
276
+
277
+
278
+ **Warning!** While it is tempting (and easier) to simply copy a source file and then
279
+ edit it as required for your target application, this will make your generator harder to maintain as it
280
+ will not automatically pick up changes and improvements to the master templates that will occur over time.
281
+ Therefore it is always preferable to post-modify the file to delete sections or to modify or add additional code
282
+ whenever possible.
283
+
284
+ **Note that developers should not add logic to the application/plugin master source files to
285
+ implement generator specific output. This approach is not scalable as in the future this plugin
286
+ is expected to support many different application types.**
287
+
288
+ Instead, individual generators must either completely override or post-modify the master files
289
+ as appropriate.
290
+
291
+ #### Templates
292
+
293
+ All files in the file list will be compiled unless explicitly marked with `copy: true`
294
+ or if the destination file name ends in `.erb`.
295
+
296
+ ERB markup can be used the same way as in regular Origen templates with the following exceptions:
297
+
298
+ Whole line Ruby is not enabled (a limitation imposed by Thor), therefore instead of this:
299
+
300
+ ~~~eruby
301
+ % if x_is_true
302
+ Include something
303
+ % end
304
+ ~~~
305
+
306
+ You must do:
307
+
308
+ ~~~eruby
309
+ <% if x_is_true -%>
310
+ Include something
311
+ <% end -%>
312
+ ~~~
313
+
314
+ Access to variables collected by your generator at runtime is done by assigning them to instance
315
+ variables (instead of the options hash used by the Origen compiler).
316
+
317
+ So for example if you have your user input a product name, then you should assign that to an
318
+ instance variable:
319
+
320
+ ~~~ruby
321
+ @product_name = get_product_name
322
+ ~~~
323
+
324
+ Then in the template:
325
+
326
+ ~~~eruby
327
+ The product name is <%= @product_name %>
328
+ ~~~
329
+
330
+ By convention, templates in this plugin do not end in `.erb` and this is reserved
331
+ for files that would become `.erb` files in the end application.
332
+
333
+ ### Post Generation Modifications
334
+
335
+ It is better to customize any files that are common to all applications
336
+ by post modification rather than by completely overriding the entire file.
337
+
338
+ To do this you have access to the Thor Action methods described here:
339
+ [Thor Action API](http://www.rubydoc.info/github/wycats/thor/Thor/Actions)
340
+
341
+ You can see some examples of these being used in the `enable` method in
342
+ `lib/app_generators/new.rb` where they are used to add the new generator details
343
+ to `lib/origen_app_generators.rb`.
344
+
345
+ As a quick example say you wanted to add a method to `config/application.rb`, this
346
+ could be achieved by injecting it at the end of the class like this:
347
+
348
+ ~~~ruby
349
+ # Always ensure the filelist has been rendered first
350
+ def generate_files
351
+ build_filelist
352
+ end
353
+
354
+ # Add a custom domain method to config/application.rb
355
+ def add_method_to_application
356
+ # Define a regular expression to define a point in the file where you want to inject, in this
357
+ # case the 'end' of the class definition (the only 'end' that occurs at the beginning of a line)
358
+ end_of_class = /^end/
359
+ # Define the code snippet
360
+ code = <<-END
361
+ def some_domain_specific_method
362
+ do_something
363
+ end
364
+ END
365
+ # Now inject it
366
+ inject_into_file "config/application.rb", code, before: end_of_class
367
+ end
368
+ ~~~
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ # This is used to boot the generator in an environment with no
3
+ # Origen application loaded.
4
+ # This emulates how it will run when generating an app and means
5
+ # that any unintended dependencies on a real app environment will
6
+ # be highlighted during test.
7
+
8
+ $LOAD_PATH.unshift ARGV.shift
9
+ $LOAD_PATH.unshift ARGV.shift
10
+ $LOAD_PATH.unshift ARGV.shift
11
+
12
+ require 'fileutils'
13
+ require 'origen'
14
+
15
+ # Prevent the bundle from loading by running this outside of the
16
+ if Origen.os.windows?
17
+ tmp_dir = 'C:/tmp/my_app_generators/new_app'
18
+ else
19
+ tmp_dir = '/tmp/my_app_generators/new_app'
20
+ end
21
+ FileUtils.rm_rf tmp_dir if File.exist?(tmp_dir)
22
+ FileUtils.mkdir_p tmp_dir
23
+
24
+ begin
25
+ Dir.chdir tmp_dir do
26
+ # For some reason this is not being defined by require origen anymore
27
+ User = Origen::Users::User unless defined? User
28
+ require 'origen_app_generators'
29
+ load_generators = ARGV.shift
30
+ OrigenAppGenerators.unload_generators unless ARGV[0]
31
+ require load_generators if File.exist?(load_generators)
32
+
33
+ OrigenAppGenerators.invoke('my_app')
34
+ end
35
+ ensure
36
+ FileUtils.mv "#{tmp_dir}/my_app", 'output' if File.exist?("#{tmp_dir}/my_app")
37
+ puts
38
+ puts "Ignore the above, your new app is in: output/my_app"
39
+ end
@@ -0,0 +1,153 @@
1
+ require 'origen'
2
+ class OrigenAppGeneratorsApplication < Origen::Application
3
+ # This information is used in headers and email templates, set it specific
4
+ # to your application
5
+ config.name = "Origen App Generators"
6
+ config.initials = "Origen_App_Generators"
7
+ config.rc_url = "ssh://git@github.com:Origen-SDK/origen_app_generators.git"
8
+ config.release_externally = true
9
+
10
+ # To enable deployment of your documentation to a web server (via the 'origen web'
11
+ # command) fill in these attributes. The example here is configured to deploy to
12
+ # the origen.freescale.net domain, which is an easy option if you don't have another
13
+ # server already in mind. To do this you will need an account on CDE and to be a member
14
+ # of the 'origen' group.
15
+ config.web_directory = "/proj/.web_origen/html/origen_app_generators"
16
+ config.web_domain = "http://origen-sdk.org/origen_app_generators"
17
+
18
+ # When false Origen will be less strict about checking for some common coding errors,
19
+ # it is recommended that you leave this to true for better feedback and easier debug.
20
+ # This will be the default setting in Origen v3.
21
+ config.strict_errors = true
22
+
23
+ # See: http://origen.freescale.net/origen/latest/guides/utilities/lint/
24
+ config.lint_test = {
25
+ # Require the lint tests to pass before allowing a release to proceed
26
+ run_on_tag: true,
27
+ # Auto correct violations where possible whenever 'origen lint' is run
28
+ auto_correct: true,
29
+ # Limit the testing for large legacy applications
30
+ #level: :easy,
31
+ # Run on these directories/files by default
32
+ #files: ["lib", "config/application.rb"],
33
+ }
34
+
35
+ # Versioning is based on a timestamp by default, if you would rather use semantic
36
+ # versioning, i.e. v1.0.0 format, then set this to true.
37
+ # In parallel go and edit config/version.rb to enable the semantic version code.
38
+ config.semantically_version = true
39
+
40
+ config.shared = {
41
+ #patterns: "pattern",
42
+ #templates: "templates",
43
+ #programs: "program",
44
+ command_launcher: "config/shared_commands.rb"
45
+ }
46
+
47
+ # An example of how to set application specific LSF parameters
48
+ #config.lsf.project = "msg.te"
49
+
50
+ # An example of how to specify a prefix to add to all generated patterns
51
+ #config.pattern_prefix = "nvm"
52
+
53
+ # An example of how to add header comments to all generated patterns
54
+ #config.pattern_header do
55
+ # cc "This is a pattern created by the example origen application"
56
+ #end
57
+
58
+ # By default all generated output will end up in ./output.
59
+ # Here you can specify an alternative directory entirely, or make it dynamic such that
60
+ # the output ends up in a setup specific directory.
61
+ #config.output_directory do
62
+ # "#{Origen.root}/output/#{$dut.class}"
63
+ #end
64
+
65
+ # Similary for the reference files, generally you want to setup the reference directory
66
+ # structure to mirror that of your output directory structure.
67
+ #config.reference_directory do
68
+ # "#{Origen.root}/.ref/#{$dut.class}"
69
+ #end
70
+
71
+ # This will automatically deploy your documentation after every tag
72
+ #def after_release_email(tag, note, type, selector, options)
73
+ # deployer = Origen.app.deployer
74
+ # if deployer.running_on_cde? && deployer.user_belongs_to_origen?
75
+ # command = "origen web compile --remote --api"
76
+ # if Origen.app.version.production?
77
+ # command += " --archive #{Origen.app.version}"
78
+ # end
79
+ # Dir.chdir Origen.root do
80
+ # system command
81
+ # end
82
+ # end
83
+ #end
84
+
85
+ # Ensure that all tests pass before allowing a release to continue
86
+ #def validate_release
87
+ # if !system("origen specs") || !system("origen examples")
88
+ # puts "Sorry but you can't release with failing tests, please fix them and try again."
89
+ # exit 1
90
+ # else
91
+ # puts "All tests passing, proceeding with release process!"
92
+ # end
93
+ #end
94
+
95
+ # To enabled source-less pattern generation create a class (for example PatternDispatcher)
96
+ # to generate the pattern. This should return false if the requested pattern has been
97
+ # dispatched, otherwise Origen will proceed with looking up a pattern source as normal.
98
+ #def before_pattern_lookup(requested_pattern)
99
+ # PatternDispatcher.new.dispatch_or_return(requested_pattern)
100
+ #end
101
+
102
+ # If you use pattern iterators you may come accross the case where you request a pattern
103
+ # like this:
104
+ # origen g example_pat_b0.atp
105
+ #
106
+ # However it cannot be found by Origen since the pattern name is actually example_pat_bx.atp
107
+ # In the case where the pattern cannot be found Origen will pass the name to this translator
108
+ # if it exists, and here you can make any substitutions to help Origen find the file you
109
+ # want. In this example any instances of _b\d, where \d means a number, are replaced by
110
+ # _bx.
111
+ #config.pattern_name_translator do |name|
112
+ # name.gsub(/_b\d/, "_bx")
113
+ #end
114
+
115
+ # If you want to use pattern iterators, that is the ability to generate multiple pattern
116
+ # variants from a single source file, then you can define the required behavior here.
117
+ # The examples below implement some of the iterators that were available in Origen 1,
118
+ # you can remove them if you don't want to use them, or of course modify or add new
119
+ # iterators specific to your application logic.
120
+
121
+ # By setting iterator
122
+ config.pattern_iterator do |iterator|
123
+ # Define a key that you will use to enable this in a pattern, here the iterator
124
+ # can be enabled like this: Pattern.create(by_setting: [1,2,3]) do
125
+ iterator.key = :by_setting
126
+
127
+ # The value passed from the pattern via the key comes in here as the first
128
+ # argument, the name applied here can be anything, but settings seem reasonable since
129
+ # an array of setting values is expected.
130
+ # The last argument &pattern is mandatory and represents the pattern block (the bit contained
131
+ # within Pattern.create do ... end)
132
+ iterator.loop do |settings, &pattern|
133
+ # Implement the loop however you like, here we loop for each value in the array
134
+ settings.each do |setting|
135
+ # Now call the pattern passing in the setting argument, this would be captured
136
+ # in the pattern like this:
137
+ # Pattern.create do |setting|
138
+ pattern.call(setting)
139
+ end
140
+ end
141
+
142
+ # Each pattern iteration needs a unique name, otherwise Origen will simply overwrite
143
+ # the same output file each time.
144
+ # The base pattern name and the pattern argument, in this case the setting, will be
145
+ # passed in here and whatever is returned is what will be used as the name.
146
+ iterator.pattern_name do |name, setting|
147
+ # Substiture _x in the name with the setting, _1, _2, etc.
148
+ name.gsub("_x", "_#{setting}")
149
+ end
150
+ end
151
+
152
+
153
+ end