origen 0.38.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/bin/origen +1 -236
  3. data/config/application.rb +10 -1
  4. data/config/version.rb +1 -1
  5. data/lib/origen/{boot_api.rb → boot/api.rb} +2 -2
  6. data/lib/origen/boot/app.rb +324 -0
  7. data/lib/origen/boot.rb +287 -0
  8. data/lib/origen/commands/archive.rb +175 -0
  9. data/lib/origen/commands/extract.rb +43 -0
  10. data/lib/origen/commands/new.rb +33 -23
  11. data/lib/origen/commands.rb +4 -1
  12. data/lib/origen/commands_global.rb +3 -2
  13. data/lib/origen/operating_systems.rb +4 -0
  14. data/lib/origen/revision_control.rb +1 -1
  15. data/lib/origen/site_config.rb +4 -1
  16. data/lib/origen.rb +3 -2
  17. data/origen_app_generators/Gemfile +16 -0
  18. data/origen_app_generators/Gemfile.lock +147 -0
  19. data/origen_app_generators/LICENSE +21 -0
  20. data/origen_app_generators/README.md +368 -0
  21. data/origen_app_generators/Rakefile +10 -0
  22. data/origen_app_generators/bin/boot.rb +37 -0
  23. data/{bin → origen_app_generators/bin}/fix_my_workspace +0 -0
  24. data/origen_app_generators/config/application.rb +153 -0
  25. data/origen_app_generators/config/boot.rb +1 -0
  26. data/origen_app_generators/config/commands.rb +63 -0
  27. data/origen_app_generators/config/shared_commands.rb +172 -0
  28. data/origen_app_generators/config/version.rb +8 -0
  29. data/origen_app_generators/doc/history +213 -0
  30. data/origen_app_generators/lib/origen_app_generators/application.rb +62 -0
  31. data/origen_app_generators/lib/origen_app_generators/base.rb +231 -0
  32. data/origen_app_generators/lib/origen_app_generators/empty_application.rb +15 -0
  33. data/origen_app_generators/lib/origen_app_generators/empty_plugin.rb +15 -0
  34. data/origen_app_generators/lib/origen_app_generators/new.rb +162 -0
  35. data/origen_app_generators/lib/origen_app_generators/origen_infrastructure/app_generator_plugin.rb +109 -0
  36. data/origen_app_generators/lib/origen_app_generators/plugin.rb +58 -0
  37. data/origen_app_generators/lib/origen_app_generators/sub_block_parser.rb +81 -0
  38. data/origen_app_generators/lib/origen_app_generators/test_engineering/stand_alone_application.rb +236 -0
  39. data/origen_app_generators/lib/origen_app_generators/test_engineering/test_block.rb +162 -0
  40. data/origen_app_generators/lib/origen_app_generators.rb +123 -0
  41. data/origen_app_generators/lib/tasks/app_generators.rake +6 -0
  42. data/origen_app_generators/lib/tasks/new_app_tests.rake +8 -0
  43. data/origen_app_generators/origen_app_generators.gemspec +33 -0
  44. data/origen_app_generators/spec/spec_helper.rb +49 -0
  45. data/origen_app_generators/spec/sub_block_spec.rb +36 -0
  46. data/origen_app_generators/target/debug.rb +8 -0
  47. data/origen_app_generators/target/default.rb +8 -0
  48. data/origen_app_generators/target/production.rb +0 -0
  49. data/origen_app_generators/templates/app_generators/application/Gemfile +19 -0
  50. data/origen_app_generators/templates/app_generators/application/Rakefile +7 -0
  51. data/origen_app_generators/templates/app_generators/application/config/application.rb +125 -0
  52. data/origen_app_generators/templates/app_generators/application/config/boot.rb +4 -0
  53. data/origen_app_generators/templates/app_generators/application/config/commands.rb +79 -0
  54. data/origen_app_generators/templates/app_generators/application/config/maillist_dev.txt +4 -0
  55. data/origen_app_generators/templates/app_generators/application/config/maillist_prod.txt +3 -0
  56. data/origen_app_generators/templates/app_generators/application/config/version.rb +8 -0
  57. data/origen_app_generators/templates/app_generators/application/doc/history +0 -0
  58. data/origen_app_generators/templates/app_generators/application/dot_keep +0 -0
  59. data/origen_app_generators/templates/app_generators/application/lib/app.rake +6 -0
  60. data/origen_app_generators/templates/app_generators/application/lib/module.rb +22 -0
  61. data/origen_app_generators/templates/app_generators/application/lib/top_level.rb +12 -0
  62. data/origen_app_generators/templates/app_generators/application/origen_core_session +2 -0
  63. data/origen_app_generators/templates/app_generators/application/spec/spec_helper.rb +44 -0
  64. data/origen_app_generators/templates/app_generators/application/target/debug.rb +8 -0
  65. data/origen_app_generators/templates/app_generators/application/target/default.rb +1 -0
  66. data/origen_app_generators/templates/app_generators/application/target/production.rb +4 -0
  67. data/origen_app_generators/templates/app_generators/application/templates/web/index.md.erb +19 -0
  68. data/origen_app_generators/templates/app_generators/application/templates/web/layouts/_basic.html.erb +13 -0
  69. data/origen_app_generators/templates/app_generators/application/templates/web/partials/_navbar.html.erb +20 -0
  70. data/origen_app_generators/templates/app_generators/application/templates/web/release_notes.md.erb +5 -0
  71. data/origen_app_generators/templates/app_generators/new/generator.rb +102 -0
  72. data/origen_app_generators/templates/app_generators/new/info.md.erb +9 -0
  73. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/config/load_generators.rb +6 -0
  74. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/application.rb +54 -0
  75. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/base.rb +55 -0
  76. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/module.rb +28 -0
  77. data/origen_app_generators/templates/app_generators/origen_infrastructure/app_generator_plugin/lib/plugin.rb +64 -0
  78. data/origen_app_generators/templates/app_generators/plugin/Gemfile +26 -0
  79. data/origen_app_generators/templates/app_generators/plugin/Rakefile +10 -0
  80. data/origen_app_generators/templates/app_generators/plugin/config/boot.rb +24 -0
  81. data/origen_app_generators/templates/app_generators/plugin/gemspec.rb +42 -0
  82. data/origen_app_generators/templates/app_generators/plugin/lib/README +4 -0
  83. data/origen_app_generators/templates/app_generators/plugin/lib_dev/README +5 -0
  84. data/origen_app_generators/templates/app_generators/plugin/templates/web/index.md.erb +37 -0
  85. data/origen_app_generators/templates/app_generators/plugin/templates/web/partials/_navbar_external.html.erb +20 -0
  86. data/origen_app_generators/templates/app_generators/plugin/templates/web/partials/_navbar_internal.html.erb +20 -0
  87. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/Gemfile +23 -0
  88. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/j750.rb +1 -0
  89. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/jlink.rb +1 -0
  90. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/uflex.rb +1 -0
  91. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/environment/v93k.rb +1 -0
  92. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/ip_block.rb +23 -0
  93. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/ip_block_controller.rb +5 -0
  94. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/top_level.rb +33 -0
  95. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/lib/top_level_controller.rb +21 -0
  96. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/pattern/example.rb +4 -0
  97. data/origen_app_generators/templates/app_generators/test_engineering/stand_alone_application/target/top_level.rb +4 -0
  98. data/origen_app_generators/templates/app_generators/test_engineering/test_block/environment/j750.rb +2 -0
  99. data/origen_app_generators/templates/app_generators/test_engineering/test_block/environment/ultraflex.rb +2 -0
  100. data/origen_app_generators/templates/app_generators/test_engineering/test_block/environment/v93k.rb +2 -0
  101. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib/controller.rb +12 -0
  102. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib/interface.rb +21 -0
  103. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib/model.rb +18 -0
  104. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib_dev/dut.rb +27 -0
  105. data/origen_app_generators/templates/app_generators/test_engineering/test_block/lib_dev/dut_controller.rb +26 -0
  106. data/origen_app_generators/templates/app_generators/test_engineering/test_block/pattern/example.rb +5 -0
  107. data/origen_app_generators/templates/app_generators/test_engineering/test_block/program/prb1.rb +11 -0
  108. data/origen_app_generators/templates/app_generators/test_engineering/test_block/target/default.rb +2 -0
  109. data/origen_site_config.yml +13 -2
  110. data/templates/git/gitignore.erb +0 -1
  111. metadata +99 -4
data/lib/origen.rb CHANGED
@@ -12,8 +12,9 @@ unless defined? RGen::ORIGENTRANSITION
12
12
  # by the site_config lookup.
13
13
  $_origen_invocation_pwd ||= Pathname.pwd
14
14
  require 'fileutils'
15
- require 'origen/site_config'
16
- require 'origen/operating_systems'
15
+ # Force these to re-load since they could have been loaded from an earlier version of Origen during boot
16
+ load 'origen/site_config.rb'
17
+ load 'origen/operating_systems.rb'
17
18
  require 'origen/core_ext'
18
19
  require 'origen/acronyms'
19
20
  require 'origen/callbacks'
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in origen_app_generators.gemspec
4
+ gemspec
5
+
6
+ # DO NOT ADD ANY RUNTIME GEMS HERE, WHEN THESE GENERATORS ARE INVOKED TO
7
+ # GENERATE A NEW APPLICATION IT WILL NOT BE LAUNCHED FROM WITHIN A BUNDLED
8
+ # ENVIRONMENT.
9
+ #
10
+ # THEREFORE GENERATORS MUST NOT RELY ON ANY 3RD PARTY GEMS THAT ARE NOT
11
+ # PRESENT AS PART OF A STANDARD RGEN INSTALLATION - I.E. YOU CAN ONLY RELY
12
+ # ON THE GEMS THAT RGEN ITSELF DEPENDS ON.
13
+
14
+ gem 'byebug', '< 9.1.0'
15
+ gem 'origen_updater'
16
+ gem 'origen'
@@ -0,0 +1,147 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ origen_app_generators (1.2.0)
5
+ origen (>= 0.23.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.2.10)
11
+ i18n (~> 0.7)
12
+ minitest (~> 5.1)
13
+ thread_safe (~> 0.3, >= 0.3.4)
14
+ tzinfo (~> 1.1)
15
+ ast (2.3.0)
16
+ astrolabe (1.3.1)
17
+ parser (~> 2.2)
18
+ builder (3.2.3)
19
+ byebug (9.0.6)
20
+ coderay (1.1.2)
21
+ colored (1.2)
22
+ colorize (0.8.1)
23
+ concurrent-ruby (1.0.5)
24
+ cri (2.10.1)
25
+ colored (~> 1.2)
26
+ dentaku (2.0.11)
27
+ diff-lcs (1.3)
28
+ docile (1.1.5)
29
+ faraday (0.13.1)
30
+ multipart-post (>= 1.2, < 3)
31
+ geminabox (0.12.4)
32
+ builder
33
+ faraday
34
+ httpclient (>= 2.2.7)
35
+ nesty
36
+ sinatra (>= 1.2.7)
37
+ gems (0.8.3)
38
+ highline (1.7.10)
39
+ httparty (0.15.6)
40
+ multi_xml (>= 0.5.2)
41
+ httpclient (2.8.3)
42
+ i18n (0.9.1)
43
+ concurrent-ruby (~> 1.0)
44
+ json (2.1.0)
45
+ kramdown (1.16.2)
46
+ log4r (1.1.10)
47
+ method_source (0.9.0)
48
+ mini_portile2 (2.1.0)
49
+ minitest (5.10.3)
50
+ multi_xml (0.6.0)
51
+ multipart-post (2.0.0)
52
+ nanoc (3.8.0)
53
+ cri (~> 2.3)
54
+ nesty (1.0.2)
55
+ net-ldap (0.16.1)
56
+ nokogiri (1.7.2)
57
+ mini_portile2 (~> 2.1.0)
58
+ origen (0.28.2)
59
+ activesupport (~> 4.1)
60
+ bundler (~> 1.7)
61
+ coderay (~> 1.1)
62
+ colored (~> 1.2)
63
+ colorize (~> 0.8.1)
64
+ dentaku (~> 2)
65
+ geminabox (= 0.12.4)
66
+ gems (~> 0.8)
67
+ highline (~> 1.7)
68
+ httparty (~> 0.13)
69
+ kramdown (~> 1.5)
70
+ log4r (~> 1.1.10, ~> 1.1)
71
+ nanoc (~> 3.7)
72
+ net-ldap (~> 0.13)
73
+ nokogiri (= 1.7.2)
74
+ pry (~> 0.10)
75
+ rake (~> 10)
76
+ rspec (~> 3)
77
+ rspec-legacy_formatters (~> 1)
78
+ rubocop (= 0.30)
79
+ scrub_rb (~> 1.0)
80
+ simplecov (~> 0.9)
81
+ sinatra (~> 1)
82
+ thor (~> 0.19)
83
+ yard (~> 0.8)
84
+ origen_updater (0.7.0)
85
+ origen
86
+ parser (2.4.0.2)
87
+ ast (~> 2.3)
88
+ powerpack (0.1.1)
89
+ pry (0.11.3)
90
+ coderay (~> 1.1.0)
91
+ method_source (~> 0.9.0)
92
+ rack (1.6.8)
93
+ rack-protection (1.5.3)
94
+ rack
95
+ rainbow (2.2.2)
96
+ rake
97
+ rake (10.5.0)
98
+ rspec (3.7.0)
99
+ rspec-core (~> 3.7.0)
100
+ rspec-expectations (~> 3.7.0)
101
+ rspec-mocks (~> 3.7.0)
102
+ rspec-core (3.7.0)
103
+ rspec-support (~> 3.7.0)
104
+ rspec-expectations (3.7.0)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.7.0)
107
+ rspec-legacy_formatters (1.0.1)
108
+ rspec (~> 3.0)
109
+ rspec-mocks (3.7.0)
110
+ diff-lcs (>= 1.2.0, < 2.0)
111
+ rspec-support (~> 3.7.0)
112
+ rspec-support (3.7.0)
113
+ rubocop (0.30.0)
114
+ astrolabe (~> 1.3)
115
+ parser (>= 2.2.0.1, < 3.0)
116
+ powerpack (~> 0.1)
117
+ rainbow (>= 1.99.1, < 3.0)
118
+ ruby-progressbar (~> 1.4)
119
+ ruby-progressbar (1.9.0)
120
+ scrub_rb (1.0.1)
121
+ simplecov (0.15.1)
122
+ docile (~> 1.1.0)
123
+ json (>= 1.8, < 3)
124
+ simplecov-html (~> 0.10.0)
125
+ simplecov-html (0.10.2)
126
+ sinatra (1.4.8)
127
+ rack (~> 1.5)
128
+ rack-protection (~> 1.4)
129
+ tilt (>= 1.3, < 3)
130
+ thor (0.20.0)
131
+ thread_safe (0.3.6)
132
+ tilt (2.0.8)
133
+ tzinfo (1.2.4)
134
+ thread_safe (~> 0.1)
135
+ yard (0.9.12)
136
+
137
+ PLATFORMS
138
+ ruby
139
+
140
+ DEPENDENCIES
141
+ byebug (< 9.1.0)
142
+ origen
143
+ origen_app_generators!
144
+ origen_updater
145
+
146
+ BUNDLED WITH
147
+ 1.16.1
@@ -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,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/app_tasks.rake, and they will automatically be available to Rake.
3
+
4
+ # Any task files found in lib/tasks/shared/*.rake will be available to other apps that
5
+ # include this app as a plugin
6
+
7
+ require "bundler/setup"
8
+ require "origen"
9
+
10
+ Origen.app.load_tasks
@@ -0,0 +1,37 @@
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('tmp')
34
+ end
35
+ ensure
36
+ FileUtils.mv "#{tmp_dir}/tmp", 'tmp' if File.exist?("#{tmp_dir}/tmp")
37
+ end
File without changes