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
data/lib/origen/log.rb CHANGED
@@ -9,33 +9,24 @@ module Origen
9
9
  # log.deprecate "Blah" # Deprecate message, always shown
10
10
  class Log
11
11
  require 'colored'
12
- require 'log4r'
13
- require 'log4r/outputter/fileoutputter'
14
-
15
- attr_accessor :msg_hash
16
- alias_method :messages, :msg_hash
12
+ require 'logger'
17
13
 
18
14
  LEVELS = [:normal, :verbose, :silent]
19
15
 
20
16
  def initialize
21
17
  @log_time_0 = @t0 = Time.new
22
18
  self.level = :normal
23
- @msg_hash = init_msg_hash
19
+ @custom_logs = {}
20
+ @interceptors = {}
24
21
  end
25
22
 
26
- def init_msg_hash
27
- msg_types = [:info, :warn, :error, :deprecate, :debug, :success]
28
- msg_hash = {}
29
- msg_types.each do |m|
30
- msg_hash[m] = Hash.new do |h, k|
31
- h[k] = []
32
- end
23
+ def console_only?(options = {})
24
+ if options.key?(:console_only)
25
+ option = options[:console_only]
26
+ else
27
+ option = self.class.console_only?
33
28
  end
34
- msg_hash
35
- end
36
-
37
- def console_only?
38
- self.class.console_only? || !Origen.app || Origen.running_globally?
29
+ option || !Origen.app || Origen.running_globally?
39
30
  end
40
31
 
41
32
  # Anything executed within the given block will log to the console only
@@ -69,16 +60,16 @@ module Origen
69
60
  case val
70
61
  when :normal
71
62
  # Output everything except debug statements
72
- console.level = Log4r::INFO
63
+ console.level = Logger::INFO
73
64
  # Output everything
74
- log_files.level = Log4r::DEBUG unless console_only?
65
+ log_files(:level=, Logger::DEBUG) unless console_only?
75
66
  when :verbose
76
- console.level = Log4r::DEBUG
77
- log_files.level = Log4r::DEBUG unless console_only?
67
+ console.level = Logger::DEBUG
68
+ log_files(:level=, Logger::DEBUG) unless console_only?
78
69
  when :silent
79
70
  # We don't use any fatal messages, so this is effectively OFF
80
- console.level = Log4r::FATAL
81
- log_files.level = Log4r::DEBUG unless console_only?
71
+ console.level = Logger::FATAL
72
+ log_files(:level=, Logger::DEBUG) unless console_only?
82
73
  end
83
74
 
84
75
  @level = val
@@ -89,78 +80,106 @@ module Origen
89
80
  @level
90
81
  end
91
82
 
92
- def validate_args(string, msg_type)
93
- return string, msg_type unless string.is_a? Symbol
94
- ['', string]
83
+ # @api private
84
+ #
85
+ # @example of an interceptor:
86
+ #
87
+ # # An interceptor ID is returned, this should be given to stop_intercepting
88
+ # @log_intercept_id = Origen.log.start_intercepting do |msg, type, options, original|
89
+ # if some_condition_is_true?
90
+ # # Handling it ourselves
91
+ # my_method(msg, type)
92
+ # else
93
+ # # Call the original Origen.log method (or the next interceptor in line)
94
+ # original.call(msg, type, options)
95
+ # end
96
+ # end
97
+ def start_intercepting(&block)
98
+ id = block.object_id
99
+ @interceptors[id] = block
100
+ id
95
101
  end
96
102
 
97
- def debug(string = '', msg_type = nil)
98
- string, msg_type = validate_args(string, msg_type)
99
- msg = format_msg('DEBUG', string)
100
- log_files.debug msg unless console_only?
101
- console.debug msg
102
- @msg_hash[:debug][msg_type] << msg
103
- nil
103
+ # @api private
104
+ def stop_intercepting(id)
105
+ @interceptors.delete(id)
104
106
  end
105
107
 
106
- def info(string = '', msg_type = nil)
107
- string, msg_type = validate_args(string, msg_type)
108
- msg = format_msg('INFO', string)
109
- log_files.info msg unless console_only?
110
- console.info msg
111
- @msg_hash[:info][msg_type] << msg
112
- nil
108
+ def debug(string = '', options = {})
109
+ string, options = sanitize_args(string, options)
110
+ PatSeq.add_thread(string) unless options[:no_thread_id]
111
+ intercept(string, :debug, options) do |msg, type, options|
112
+ msg = format_msg('DEBUG', msg)
113
+ log_files(:debug, msg) unless console_only?(options)
114
+ console.debug msg
115
+ nil
116
+ end
117
+ end
118
+
119
+ def info(string = '', options = {})
120
+ string, options = sanitize_args(string, options)
121
+ PatSeq.add_thread(string) unless options[:no_thread_id]
122
+ intercept(string, :info, options) do |msg, type, options|
123
+ msg = format_msg('INFO', msg)
124
+ log_files(:info, msg) unless console_only?(options)
125
+ console.info msg
126
+ nil
127
+ end
113
128
  end
114
129
  # Legacy methods
115
130
  alias_method :lputs, :info
116
131
  alias_method :lprint, :info
117
132
 
118
- def success(string = '', msg_type = nil)
119
- string, msg_type = validate_args(string, msg_type)
120
- msg = format_msg('SUCCESS', string)
121
- log_files.info msg unless console_only?
122
- console.info msg.green
123
- @msg_hash[:success][msg_type] << msg
124
- nil
133
+ def success(string = '', options = {})
134
+ string, options = sanitize_args(string, options)
135
+ PatSeq.add_thread(string) unless options[:no_thread_id]
136
+ intercept(string, :success, options) do |msg, type, options|
137
+ msg = format_msg('SUCCESS', msg)
138
+ log_files(:info, msg) unless console_only?(options)
139
+ console.info color_unless_remote(msg, :green)
140
+ nil
141
+ end
125
142
  end
126
143
 
127
- def deprecate(string = '', msg_type = nil)
128
- string, msg_type = validate_args(string, msg_type)
129
- msg = format_msg('DEPRECATED', string)
130
- log_files.warn msg unless console_only?
131
- console.warn msg.yellow
132
- @msg_hash[:deprecate][msg_type] << msg
133
- nil
144
+ def deprecate(string = '', options = {})
145
+ string, options = sanitize_args(string, options)
146
+ PatSeq.add_thread(string) unless options[:no_thread_id]
147
+ intercept(string, :deprecate, options) do |msg, type, options|
148
+ msg = format_msg('DEPRECATED', msg)
149
+ log_files(:warn, msg) unless console_only?(options)
150
+ console.warn color_unless_remote(msg, :yellow)
151
+ nil
152
+ end
134
153
  end
135
154
  alias_method :deprecated, :deprecate
136
155
 
137
- def warn(string = '', msg_type = nil)
138
- string, msg_type = validate_args(string, msg_type)
139
- msg = format_msg('WARNING', string)
140
- log_files.warn msg unless console_only?
141
- console.warn msg.yellow
142
- @msg_hash[:warn][msg_type] << msg
143
- nil
156
+ def warn(string = '', options = {})
157
+ string, options = sanitize_args(string, options)
158
+ PatSeq.add_thread(string) unless options[:no_thread_id]
159
+ intercept(string, :warn, options) do |msg, type, options|
160
+ msg = format_msg('WARNING', msg)
161
+ log_files(:warn, msg) unless console_only?(options)
162
+ console.warn color_unless_remote(msg, :yellow)
163
+ nil
164
+ end
144
165
  end
145
166
  alias_method :warning, :warn
146
167
 
147
- def error(string = '', msg_type = nil)
148
- string, msg_type = validate_args(string, msg_type)
149
- msg = format_msg('ERROR', string)
150
- log_files.error msg unless console_only?
151
- console.error msg.red
152
- @msg_hash[:error][msg_type] << msg
153
- nil
168
+ def error(string = '', options = {})
169
+ string, options = sanitize_args(string, options)
170
+ PatSeq.add_thread(string) unless options[:no_thread_id]
171
+ intercept(string, :error, options) do |msg, type, options|
172
+ msg = format_msg('ERROR', msg)
173
+ log_files(:error, msg) unless console_only?(options)
174
+ console.error color_unless_remote(msg, :red)
175
+ nil
176
+ end
154
177
  end
155
178
 
156
179
  # Made these all class methods so that they can be read without
157
180
  # instantiating a new logger (mainly for use by the origen save command)
158
181
  def self.log_file
159
- "#{log_file_directory}/last.txt"
160
- end
161
-
162
- def self.rolling_log_file
163
- "#{log_file_directory}/rolling.txt"
182
+ File.join(log_file_directory, 'last.txt')
164
183
  end
165
184
 
166
185
  def self.log_file_directory
@@ -179,42 +198,169 @@ module Origen
179
198
  level == :verbose
180
199
  end
181
200
 
182
- # Force logger to write any buffered output
201
+ # Force the logger to write any buffered output to the log files
183
202
  def flush
184
- if Origen.app
185
- log_files.outputters.each(&:flush)
203
+ @open_logs.each do |logger, file|
204
+ file.flush
186
205
  end
187
- console.outputters.each(&:flush)
206
+ nil
188
207
  end
189
208
 
190
- private
209
+ # Mainly intended for testing the logger, this will return the log level to the default (:normal)
210
+ # and close all log files, such that any further logging will be done to a new file(s)
211
+ def reset
212
+ self.level = :normal
213
+ flush
214
+ close_log(@last_file)
215
+ @last_file = nil
216
+ close_log(@job_file)
217
+ @job_file = nil
218
+ @custom_logs.each do |name, log|
219
+ close_log(log)
220
+ end
221
+ @custom_logs = {}
222
+ end
191
223
 
192
- # Returns a Log4r instance that will send to the console
193
- def console
194
- @console ||= begin
195
- console = Log4r::Logger.new 'console'
196
- # console.level = QUIET
197
- out = Log4r::Outputter.stdout
198
- out.formatter = format
199
- console.outputters << out
200
- console
201
- end
202
- end
203
-
204
- # Returns a Log4r instance that will send to the log files
205
- def log_files
206
- @log_files ||= begin
207
- log_files = Log4r::Logger.new 'log_files'
208
- # log_files.level = QUIET
209
- file = Log4r::FileOutputter.new('fileOutputter', filename: self.class.log_file, trunc: true)
210
- file.formatter = format
211
- log_files.outputters << file
224
+ # @api private
225
+ def start_job(name, type)
226
+ dir = File.join(Origen.config.log_directory, type.to_s)
227
+ if target = Origen.try(:target).try(:name)
228
+ dir = File.join(dir, target)
229
+ end
230
+ if env = Origen.try(:environment).try(:name)
231
+ dir = File.join(dir, env)
232
+ end
233
+ FileUtils.mkdir_p dir unless File.exist?(dir)
234
+ @@job_file_paths = {} unless defined?(@@job_file_paths)
235
+ # Make sure the log name is unique in this run, duplication and overwrite can occur in cases where
236
+ # a pattern is run multiple times during a simulation
237
+ @job_file_path = File.join(dir, "#{name}.txt")
238
+ if n = @@job_file_paths[@job_file_path]
239
+ @@job_file_paths[@job_file_path] += 1
240
+ @job_file_path = File.join(dir, "#{name}_#{n}.txt")
241
+ else
242
+ @@job_file_paths[@job_file_path] = 1
243
+ end
244
+ FileUtils.rm_f(@job_file_path) if File.exist?(@job_file_path)
245
+ @job_file = open_log(@job_file_path)
246
+ end
247
+
248
+ # @api private
249
+ def stop_job
250
+ if @job_file
251
+ if tester && tester.respond_to?(:log_file_written)
252
+ tester.log_file_written @job_file_path
253
+ else
254
+ Origen.log.info "Log file written to: #{@job_file_path}"
255
+ end
256
+ flush
257
+ close_log(@job_file)
258
+ @job_file = nil
259
+ end
260
+ end
261
+
262
+ def method_missing(method, *args, &block)
263
+ @custom_logs[method.to_sym] ||= begin
264
+ log_file = File.join(Log.log_file_directory, "#{method}.txt")
212
265
  unless Origen.running_remotely?
213
- rolling_file = Log4r::RollingFileOutputter.new('rollingfileOutputter', filename: self.class.rolling_log_file, trunc: false, maxsize: 5_242_880, max_backups: 10)
214
- rolling_file.formatter = format
215
- log_files.outputters << rolling_file
266
+ FileUtils.mv log_file, "#{log_file}.old" if File.exist?(log_file)
216
267
  end
217
- log_files
268
+ open_log(log_file)
269
+ end
270
+ msg = args.shift
271
+ options = args.shift || {}
272
+ if options.key?(:format) && !options[:format]
273
+ msg = "#{msg}\n"
274
+ else
275
+ msg = format_msg(method.to_s.upcase, msg)
276
+ end
277
+ @custom_logs[method.to_sym].info(msg)
278
+ end
279
+
280
+ private
281
+
282
+ def intercept(msg, type, options, &block)
283
+ if @interceptors.size > 0
284
+ call_interceptor(@interceptors.values, msg, type, options, &block)
285
+ else
286
+ yield(msg, type, options)
287
+ end
288
+ end
289
+
290
+ def call_interceptor(interceptors, msg, type, options, &original)
291
+ interceptor = interceptors.shift
292
+ if interceptors.empty?
293
+ func = -> (msg, type, options) { original.call(msg, type, options) }
294
+ else
295
+ func = -> (msg, type, options) { call_interceptor(interceptors, msg, type, options, &original) }
296
+ end
297
+ interceptor.call(msg, type, options, func)
298
+ end
299
+
300
+ def sanitize_args(*args)
301
+ message = ''
302
+ options = {}
303
+ args.each do |arg|
304
+ if arg.is_a?(String)
305
+ message = arg
306
+ elsif arg.is_a?(Hash)
307
+ options = arg
308
+ end
309
+ end
310
+ [message, options]
311
+ end
312
+
313
+ # When running on an LSF client, the console log output is captured to a file. Color codings in files just
314
+ # add noise, so inhibit them in this case since it is not providing any visual benefit to the user
315
+ def color_unless_remote(msg, color)
316
+ if Origen.running_remotely?
317
+ msg
318
+ else
319
+ msg.send(color)
320
+ end
321
+ end
322
+
323
+ # Returns a logger instance that will send to the console
324
+ def console
325
+ @console ||= open_log(STDOUT)
326
+ end
327
+
328
+ # Returns a logger instance that will send to the log/last.txt file
329
+ def last_file
330
+ @last_file ||= begin
331
+ # Preserve one prior version of the log file
332
+ FileUtils.mv Log.log_file, "#{Log.log_file}.old" if File.exist?(Log.log_file)
333
+ open_log(Log.log_file)
334
+ end
335
+ end
336
+
337
+ # Sends the given method and arguments to all file logger instances
338
+ def log_files(method, *args)
339
+ # When running remotely on an LSF client, the LSF manager will capture STDOUT (i.e. the console log output)
340
+ # and save it to a log file.
341
+ # Don't write to the last log file in that case because we would have multiple processes all vying to
342
+ # write to it at the same time.
343
+ last_file.send(method, *args) unless Origen.running_remotely?
344
+ @job_file.send(method, *args) if @job_file
345
+ end
346
+
347
+ def open_log(file)
348
+ @open_logs ||= {}
349
+ unless file.class == IO
350
+ file = File.open(file, 'w+')
351
+ end
352
+ l = Logger.new(file)
353
+ l.formatter = proc do |severity, dateime, progname, msg|
354
+ msg
355
+ end
356
+ @open_logs[l] = file
357
+ l
358
+ end
359
+
360
+ def close_log(logger)
361
+ if logger
362
+ @open_logs.delete(logger)
363
+ logger.close
218
364
  end
219
365
  end
220
366
 
@@ -237,13 +383,9 @@ module Origen
237
383
  delta_t = '%0.3f' % delta_t
238
384
  delta_t0 = (log_time_1.to_f - @t0.to_f).round(6)
239
385
  delta_t0 = '%0.3f' % delta_t0
240
- msg = "[#{type}]".ljust(13) + "#{delta_t0}[#{delta_t}]".ljust(16) + "|| #{msg}"
386
+ msg = "[#{type}]".ljust(13) + "#{delta_t0}[#{delta_t}]".ljust(16) + "|| #{msg}\n"
241
387
  @log_time_0 = log_time_1
242
388
  msg
243
389
  end
244
-
245
- def format
246
- Log4r::PatternFormatter.new(pattern: '%m')
247
- end
248
390
  end
249
391
  end
data/lib/origen/model.rb CHANGED
@@ -43,6 +43,12 @@ module Origen
43
43
  end
44
44
  end
45
45
 
46
+ # Returns a frozen hash containing any attributes that were
47
+ # derived from a block definition
48
+ def attributes
49
+ @attributes ||= {}.freeze
50
+ end
51
+
46
52
  def inspect
47
53
  if controller
48
54
  "<Model/Controller: #{self.class}:#{object_id}/#{controller.class}:#{controller.object_id}>"
@@ -63,7 +69,7 @@ module Origen
63
69
 
64
70
  # Returns true if the model is the current DUT/top-level model
65
71
  def is_top_level?
66
- Origen.top_level == self
72
+ respond_to?(:includes_origen_top_level?)
67
73
  end
68
74
  alias_method :is_dut?, :is_top_level?
69
75
  alias_method :top_level?, :is_top_level?
@@ -75,6 +81,21 @@ module Origen
75
81
  self
76
82
  end
77
83
 
84
+ # Returns the application instance that defines the model, often the current app but it could
85
+ # also be one of the plugins.
86
+ # Returns nil if the application cannot be resolved, usually because the model's class has
87
+ # not been correctly namespaced.
88
+ def app
89
+ @app ||= Origen::Application.from_namespace(self.class.to_s)
90
+ end
91
+
92
+ # Load the block definitions from the given path to the model.
93
+ # Returns true if a block is found and loaded, otherwise nil.
94
+ def load_block(path, options = {})
95
+ options[:path] = path
96
+ Origen::Loader.load_block(self, options)
97
+ end
98
+
78
99
  def ==(obj)
79
100
  if obj.is_a?(Origen::SubBlocks::Placeholder)
80
101
  obj = obj.materialize