baltix 0.1.1 → 0.2

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 (308) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/README.md +136 -10
  4. data/Rakefile +8 -3
  5. data/baltix.gemspec +47 -29
  6. data/bin/console +4 -3
  7. data/data/alt-licenses/README.md +26 -0
  8. data/data/alt-licenses/licenses.json +2991 -0
  9. data/data/alt-rpm/README.md +21 -0
  10. data/data/alt-rpm/architectures.json +613 -0
  11. data/data/spdx/README.md +22 -0
  12. data/data/spdx/licenses.json +9287 -0
  13. data/docs/action-flow.md +42 -0
  14. data/docs/actor-integration.md +71 -0
  15. data/docs/alt-architectures.md +27 -0
  16. data/docs/cleanup-actors.md +14 -0
  17. data/docs/dependency-actions.md +22 -0
  18. data/docs/installation-actors.md +35 -0
  19. data/docs/pkglist.md +56 -0
  20. data/docs/plans/revision-003.md +328 -0
  21. data/docs/plans/revision-004.md +416 -0
  22. data/docs/plans/revision-005.md +431 -0
  23. data/docs/plans/revision-006.md +439 -0
  24. data/docs/plans/revision-007.md +441 -0
  25. data/docs/plans/revision-008.md +445 -0
  26. data/docs/plans/revision-009.md +450 -0
  27. data/docs/plans/revision-010.md +486 -0
  28. data/docs/plans/revision-011.md +500 -0
  29. data/docs/plans/revision-012.md +501 -0
  30. data/docs/plans/revision-013.md +501 -0
  31. data/docs/plans/revision-014.md +501 -0
  32. data/docs/plans/revision-015.md +502 -0
  33. data/docs/plans/revision-016.md +503 -0
  34. data/docs/plans/revision-017.md +504 -0
  35. data/docs/plans/revision-018.md +505 -0
  36. data/docs/plans/revision-019.md +510 -0
  37. data/docs/plans/revision-020.md +524 -0
  38. data/docs/plans/revision-021.md +542 -0
  39. data/docs/plans/revision-022.md +542 -0
  40. data/docs/plans/revision-023.md +545 -0
  41. data/docs/plans/revision-024.md +567 -0
  42. data/docs/plans/revision-025.md +583 -0
  43. data/docs/plans/revision-026.md +241 -0
  44. data/docs/plans/revision-027.md +305 -0
  45. data/docs/plans/revision-028.md +298 -0
  46. data/docs/plans/revision-029.md +288 -0
  47. data/docs/rpm-action-macros.md +52 -0
  48. data/docs/rpm-parts.md +53 -0
  49. data/docs/ruby-dependencies.md +217 -0
  50. data/docs/ruby-policy-2.1.md +28 -0
  51. data/docs/ruby-versioning.md +61 -0
  52. data/docs/space-format.md +58 -0
  53. data/exe/baltix +1 -0
  54. data/lib/baltix/action_flow/files.rb +49 -0
  55. data/lib/baltix/action_flow/inputs.rb +60 -0
  56. data/lib/baltix/action_flow/journal.rb +60 -0
  57. data/lib/baltix/action_flow/options.rb +60 -0
  58. data/lib/baltix/action_flow.rb +65 -0
  59. data/lib/baltix/actor/build/collect.rb +72 -0
  60. data/lib/baltix/actor/build/compile.rb +25 -0
  61. data/lib/baltix/actor/build/extconf.rb +14 -0
  62. data/lib/baltix/actor/build/make.rb +18 -0
  63. data/lib/baltix/actor/build/postprocess.rb +14 -0
  64. data/lib/baltix/actor/build/rake.rb +18 -0
  65. data/lib/baltix/actor/build/ronn.rb +55 -0
  66. data/lib/baltix/actor/build.rb +87 -0
  67. data/lib/baltix/actor/clean/remove.rb +45 -0
  68. data/lib/baltix/actor/clean.rb +37 -0
  69. data/lib/baltix/actor/config.rb +12 -0
  70. data/lib/baltix/actor/copy.rb +22 -7
  71. data/lib/baltix/actor/distclean.rb +20 -0
  72. data/lib/baltix/actor/doc/collect.rb +39 -0
  73. data/lib/baltix/actor/doc/generate.rb +47 -0
  74. data/lib/baltix/actor/doc/inputs.rb +25 -0
  75. data/lib/baltix/actor/doc.rb +70 -0
  76. data/lib/baltix/actor/gen.rb +19 -0
  77. data/lib/baltix/actor/install/data.rb +18 -0
  78. data/lib/baltix/actor/install/documentation.rb +48 -0
  79. data/lib/baltix/actor/install/executable.rb +27 -0
  80. data/lib/baltix/actor/install/extension.rb +44 -0
  81. data/lib/baltix/actor/install/headers.rb +10 -0
  82. data/lib/baltix/actor/install/library.rb +13 -0
  83. data/lib/baltix/actor/install/metadata.rb +21 -0
  84. data/lib/baltix/actor/install/paths.rb +73 -0
  85. data/lib/baltix/actor/install/plugin.rb +25 -0
  86. data/lib/baltix/actor/install/record.rb +48 -0
  87. data/lib/baltix/actor/install/shebang.rb +29 -0
  88. data/lib/baltix/actor/install/transfer.rb +64 -0
  89. data/lib/baltix/actor/install/trees.rb +34 -0
  90. data/lib/baltix/actor/install.rb +71 -0
  91. data/lib/baltix/actor/link.rb +15 -6
  92. data/lib/baltix/actor/make.rb +14 -0
  93. data/lib/baltix/actor/predeps/write.rb +51 -0
  94. data/lib/baltix/actor/predeps.rb +41 -0
  95. data/lib/baltix/actor/provides.rb +12 -0
  96. data/lib/baltix/actor/requires.rb +12 -0
  97. data/lib/baltix/actor/show.rb +26 -0
  98. data/lib/baltix/actor/spec.rb +6 -3
  99. data/lib/baltix/actor/test/record.rb +8 -0
  100. data/lib/baltix/actor/test/run.rb +30 -0
  101. data/lib/baltix/actor/test/select.rb +16 -0
  102. data/lib/baltix/actor/test.rb +41 -0
  103. data/lib/baltix/actor/touch.rb +14 -5
  104. data/lib/baltix/actor.rb +43 -26
  105. data/lib/baltix/cli/dependency_options.rb +63 -0
  106. data/lib/baltix/cli/options/action.rb +32 -0
  107. data/lib/baltix/cli/options.rb +280 -0
  108. data/lib/baltix/cli/output_options.rb +56 -0
  109. data/lib/baltix/cli/rake_tasks.rb +59 -0
  110. data/lib/baltix/cli/source_options.rb +52 -0
  111. data/lib/baltix/cli.rb +130 -116
  112. data/lib/baltix/concerns/command.rb +52 -0
  113. data/lib/baltix/concerns/configuration.rb +39 -0
  114. data/lib/baltix/concerns/dependency_output.rb +21 -0
  115. data/lib/baltix/concerns/extension_metadata.rb +44 -0
  116. data/lib/baltix/concerns/file_destination.rb +14 -0
  117. data/lib/baltix/concerns/inspection.rb +27 -0
  118. data/lib/baltix/concerns/parts.rb +16 -0
  119. data/lib/baltix/concerns/target_paths.rb +57 -0
  120. data/lib/baltix/concerns.rb +11 -0
  121. data/lib/baltix/core_extensions/gem_dependency.rb +24 -0
  122. data/lib/baltix/core_extensions/gem_requirement.rb +45 -0
  123. data/lib/baltix/core_extensions/open_struct_merge.rb +62 -0
  124. data/lib/baltix/deps/executables.rb +30 -0
  125. data/lib/baltix/deps/packages.rb +32 -0
  126. data/lib/baltix/deps.rb +103 -194
  127. data/lib/baltix/dsl/dependency_groups.rb +77 -0
  128. data/lib/baltix/dsl/dependency_sources.rb +100 -0
  129. data/lib/baltix/dsl/filtering.rb +26 -0
  130. data/lib/baltix/dsl/loading.rb +72 -0
  131. data/lib/baltix/dsl/merging.rb +74 -0
  132. data/lib/baltix/dsl/rendering.rb +54 -0
  133. data/lib/baltix/dsl/requirements.rb +77 -0
  134. data/lib/baltix/dsl/temporary_files.rb +36 -0
  135. data/lib/baltix/dsl.rb +66 -273
  136. data/lib/baltix/executable_dependencies/features.rb +53 -0
  137. data/lib/baltix/executable_dependencies/library.rb +21 -0
  138. data/lib/baltix/executable_dependencies/library_features.rb +34 -0
  139. data/lib/baltix/executable_dependencies/syntax.rb +102 -0
  140. data/lib/baltix/executable_dependencies.rb +102 -0
  141. data/lib/baltix/extensions/bones.rb +173 -0
  142. data/lib/baltix/extensions/echoe.rb +143 -0
  143. data/lib/baltix/extensions/hoe/metadata.rb +89 -0
  144. data/lib/baltix/extensions/hoe/options.rb +84 -0
  145. data/lib/baltix/extensions/hoe/readme.rb +29 -0
  146. data/lib/baltix/extensions/hoe.rb +146 -0
  147. data/lib/baltix/extensions/jeweler.rb +95 -0
  148. data/lib/baltix/extensions/levitate.rb +74 -0
  149. data/lib/baltix/extensions/olddoc.rb +42 -0
  150. data/lib/baltix/extensions.rb +340 -419
  151. data/lib/baltix/i18n.rb +22 -19
  152. data/lib/baltix/license/catalog/capture.rb +58 -0
  153. data/lib/baltix/license/catalog.rb +75 -0
  154. data/lib/baltix/license.rb +76 -0
  155. data/lib/baltix/loader/capture.rb +91 -0
  156. data/lib/baltix/loader/cmake.rb +6 -3
  157. data/lib/baltix/loader/evaluation.rb +49 -0
  158. data/lib/baltix/loader/extconf.rb +27 -0
  159. data/lib/baltix/loader/feature_loading.rb +54 -0
  160. data/lib/baltix/loader/git-version-gen.rb +36 -21
  161. data/lib/baltix/loader/mast/properties.rb +58 -0
  162. data/lib/baltix/loader/mast.rb +97 -109
  163. data/lib/baltix/loader/object_capture.rb +27 -0
  164. data/lib/baltix/loader/olddoc.gemspec.erb +31 -0
  165. data/lib/baltix/loader/pom.rb +36 -16
  166. data/lib/baltix/loader/rookbook.rb +19 -14
  167. data/lib/baltix/loader/yaml.rb +9 -5
  168. data/lib/baltix/loader.rb +85 -132
  169. data/lib/baltix/log.rb +26 -27
  170. data/lib/baltix/rake/metadata_adapter.rb +30 -0
  171. data/lib/baltix/rake/task_context.rb +59 -0
  172. data/lib/baltix/rake/task_libraries.rb +73 -0
  173. data/lib/baltix/rake.rb +62 -12
  174. data/lib/baltix/source/base/dependencies.rb +81 -0
  175. data/lib/baltix/source/base/file_queries.rb +67 -0
  176. data/lib/baltix/source/base/file_tree.rb +70 -0
  177. data/lib/baltix/source/base/metadata.rb +140 -0
  178. data/lib/baltix/source/base/options.rb +71 -0
  179. data/lib/baltix/source/base/roots.rb +53 -0
  180. data/lib/baltix/source/base.rb +95 -377
  181. data/lib/baltix/source/fake.rb +89 -5
  182. data/lib/baltix/source/gem/delegation.rb +32 -0
  183. data/lib/baltix/source/gem/dependencies.rb +69 -0
  184. data/lib/baltix/source/gem/discovery.rb +72 -0
  185. data/lib/baltix/source/gem/file_trees.rb +114 -0
  186. data/lib/baltix/source/gem/forwarding.rb +12 -0
  187. data/lib/baltix/source/gem/metadata.rb +104 -0
  188. data/lib/baltix/source/gem/specification.rb +65 -0
  189. data/lib/baltix/source/gem.rb +65 -312
  190. data/lib/baltix/source/gemfile.rb +55 -5
  191. data/lib/baltix/source/rakefile.rb +12 -5
  192. data/lib/baltix/source.rb +36 -24
  193. data/lib/baltix/space/configuration.rb +54 -0
  194. data/lib/baltix/space/data/collections.rb +33 -0
  195. data/lib/baltix/space/data/gem_metadata.rb +79 -0
  196. data/lib/baltix/space/data/models.rb +20 -0
  197. data/lib/baltix/space/data/values.rb +72 -0
  198. data/lib/baltix/space/data.rb +53 -0
  199. data/lib/baltix/space/dependencies.rb +53 -0
  200. data/lib/baltix/space/filters.rb +96 -0
  201. data/lib/baltix/space/initialization.rb +124 -0
  202. data/lib/baltix/space/metadata.rb +130 -0
  203. data/lib/baltix/space/source_order.rb +43 -0
  204. data/lib/baltix/space/source_selection.rb +136 -0
  205. data/lib/baltix/space/source_status.rb +114 -0
  206. data/lib/baltix/space/spec.rb +3 -0
  207. data/lib/baltix/space.rb +87 -367
  208. data/lib/baltix/spec/rpm/aliases.rb +79 -0
  209. data/lib/baltix/spec/rpm/arch.rb +119 -0
  210. data/lib/baltix/spec/rpm/available_overrides.rb +106 -0
  211. data/lib/baltix/spec/rpm/build_dependencies.rb +132 -0
  212. data/lib/baltix/spec/rpm/build_queries.rb +61 -0
  213. data/lib/baltix/spec/rpm/changelog.rb +115 -0
  214. data/lib/baltix/spec/rpm/dependency_overrides.rb +83 -0
  215. data/lib/baltix/spec/rpm/dependency_policy.rb +69 -0
  216. data/lib/baltix/spec/rpm/deps.rb +113 -0
  217. data/lib/baltix/spec/rpm/env/requirements.rb +20 -0
  218. data/lib/baltix/spec/rpm/env.rb +76 -0
  219. data/lib/baltix/spec/rpm/executable_packages.rb +49 -0
  220. data/lib/baltix/spec/rpm/file_manifest.rb +72 -0
  221. data/lib/baltix/spec/rpm/guard_compilation.rb +95 -0
  222. data/lib/baltix/spec/rpm/imported_secondaries.rb +26 -0
  223. data/lib/baltix/spec/rpm/layout.rb +14 -0
  224. data/lib/baltix/spec/rpm/manpages.rb +71 -0
  225. data/lib/baltix/spec/rpm/metadata.rb +78 -0
  226. data/lib/baltix/spec/rpm/name/equality.rb +68 -0
  227. data/lib/baltix/spec/rpm/name/formatting.rb +33 -0
  228. data/lib/baltix/spec/rpm/name/parsing.rb +58 -0
  229. data/lib/baltix/spec/rpm/name.rb +77 -108
  230. data/lib/baltix/spec/rpm/packaged_versions.rb +107 -0
  231. data/lib/baltix/spec/rpm/parser/comments.rb +35 -0
  232. data/lib/baltix/spec/rpm/parser/context.rb +50 -0
  233. data/lib/baltix/spec/rpm/parser/dependencies.rb +91 -0
  234. data/lib/baltix/spec/rpm/parser/file_sections.rb +68 -0
  235. data/lib/baltix/spec/rpm/parser/flow.rb +84 -0
  236. data/lib/baltix/spec/rpm/parser/header_dependencies.rb +36 -0
  237. data/lib/baltix/spec/rpm/parser/macros.rb +43 -0
  238. data/lib/baltix/spec/rpm/parser/metadata.rb +106 -0
  239. data/lib/baltix/spec/rpm/parser/sections.rb +88 -0
  240. data/lib/baltix/spec/rpm/parser/values.rb +85 -0
  241. data/lib/baltix/spec/rpm/parser.rb +124 -269
  242. data/lib/baltix/spec/rpm/part_files.rb +64 -0
  243. data/lib/baltix/spec/rpm/part_prelude.rb +43 -0
  244. data/lib/baltix/spec/rpm/part_scripts.rb +52 -0
  245. data/lib/baltix/spec/rpm/part_switches.rb +65 -0
  246. data/lib/baltix/spec/rpm/pkglist/header.rb +73 -0
  247. data/lib/baltix/spec/rpm/pkglist/provides.rb +57 -0
  248. data/lib/baltix/spec/rpm/pkglist.rb +116 -0
  249. data/lib/baltix/spec/rpm/preparation.rb +73 -0
  250. data/lib/baltix/spec/rpm/rendering.rb +66 -0
  251. data/lib/baltix/spec/rpm/repository_application.rb +33 -0
  252. data/lib/baltix/spec/rpm/revision.rb +58 -0
  253. data/lib/baltix/spec/rpm/root_source.rb +48 -0
  254. data/lib/baltix/spec/rpm/scripts.rb +85 -0
  255. data/lib/baltix/spec/rpm/secondaries.rb +82 -0
  256. data/lib/baltix/spec/rpm/secondary.rb +117 -64
  257. data/lib/baltix/spec/rpm/secondary_parts.rb +84 -0
  258. data/lib/baltix/spec/rpm/section_document.rb +84 -0
  259. data/lib/baltix/spec/rpm/section_guards.rb +116 -0
  260. data/lib/baltix/spec/rpm/source_selection.rb +82 -0
  261. data/lib/baltix/spec/rpm/spec_core/architecture.rb +28 -0
  262. data/lib/baltix/spec/rpm/spec_core/attributes.rb +89 -0
  263. data/lib/baltix/spec/rpm/spec_core/availability.rb +60 -0
  264. data/lib/baltix/spec/rpm/spec_core/dependency_rendering.rb +83 -0
  265. data/lib/baltix/spec/rpm/spec_core/descriptions.rb +77 -0
  266. data/lib/baltix/spec/rpm/spec_core/documentation.rb +48 -0
  267. data/lib/baltix/spec/rpm/spec_core/executable_names.rb +37 -0
  268. data/lib/baltix/spec/rpm/spec_core/host_names.rb +60 -0
  269. data/lib/baltix/spec/rpm/spec_core/interpreters.rb +103 -0
  270. data/lib/baltix/spec/rpm/spec_core/names.rb +80 -0
  271. data/lib/baltix/spec/rpm/spec_core/obsoletes.rb +38 -0
  272. data/lib/baltix/spec/rpm/spec_core/package_dependencies.rb +74 -0
  273. data/lib/baltix/spec/rpm/spec_core/plain_dependencies.rb +60 -0
  274. data/lib/baltix/spec/rpm/spec_core/pre_name.rb +23 -0
  275. data/lib/baltix/spec/rpm/spec_core/provides.rb +104 -0
  276. data/lib/baltix/spec/rpm/spec_core/readme.rb +78 -0
  277. data/lib/baltix/spec/rpm/spec_core/registration.rb +18 -0
  278. data/lib/baltix/spec/rpm/spec_core/runtime_dependencies.rb +81 -0
  279. data/lib/baltix/spec/rpm/spec_core/summaries.rb +64 -0
  280. data/lib/baltix/spec/rpm/spec_core/text_wrapping.rb +36 -0
  281. data/lib/baltix/spec/rpm/spec_core/versioning.rb +75 -0
  282. data/lib/baltix/spec/rpm/spec_core/versions.rb +94 -0
  283. data/lib/baltix/spec/rpm/spec_core.rb +75 -527
  284. data/lib/baltix/spec/{rpm.erb → rpm/template.erb} +131 -31
  285. data/lib/baltix/spec/rpm.rb +253 -644
  286. data/lib/baltix/spec.rb +16 -14
  287. data/lib/baltix/target/gem.rb +61 -0
  288. data/lib/baltix/target/site.rb +40 -0
  289. data/lib/baltix/target.rb +16 -0
  290. data/lib/baltix/version.rb +3 -1
  291. data/lib/baltix.rb +77 -5
  292. data/locale/en_US.UTF-8.yaml +4 -1
  293. data/locale/ru_RU.UTF-8.yaml +7 -1
  294. data/rpm/baltix.env +4 -0
  295. data/rpm/baltix.prov +8 -0
  296. data/rpm/baltix.prov.files +6 -0
  297. data/rpm/baltix.req +8 -0
  298. data/rpm/baltix.req.files +6 -0
  299. data/rpm/macros.baltix +24 -0
  300. data/utils/rubocop/compact_block_braces.rb +39 -0
  301. data/utils/rubocop/spacing.rb +96 -0
  302. data/utils/update_alt_architectures.rb +57 -0
  303. data/utils/update_alt_licenses.rb +19 -0
  304. data/utils/update_spdx_licenses.rb +21 -0
  305. metadata +526 -17
  306. data/.github/workflows/ci.yml +0 -44
  307. data/.gitignore +0 -10
  308. data/TODO +0 -84
data/lib/baltix/loader.rb CHANGED
@@ -1,99 +1,73 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
4
+ require 'tempfile'
2
5
 
3
6
  require 'baltix'
4
7
  require 'baltix/log'
5
8
 
9
+ # Evaluates upstream metadata with captured objects and restored process state.
6
10
  module Baltix::Loader
7
11
  include Baltix::Log
8
12
 
13
+ # Captures metadata declarations in an isolated evaluation context.
9
14
  module Certain
10
15
  include Baltix::Log
11
16
  include Rake::DSL
12
17
 
13
18
  attr_reader :object_hash, :object_ids
14
19
 
15
- alias_method :require_orig, :require
20
+ alias require_orig require
16
21
 
17
- def require *args
18
- require_orig(*args)
19
- rescue LoadError
20
- true
21
- end
22
+ def require_embedded path
23
+ return if File.absolute_path?(path)
22
24
 
23
- def store_object_hash type_hash
24
- object_hash =
25
- type_hash.map do |(klass, types)|
26
- objects = types.split(',').map do |type|
27
- begin
28
- ObjectSpace.each_object(type.constantize).map { |h| h }
29
- rescue NameError
30
- []
31
- end
32
- end.flatten
33
-
34
- [klass, objects]
35
- end.to_h
36
-
37
- if @object_hash
38
- @object_ids = object_hash.map do |(k, oh)|
39
- [k, oh.map {|h| h.__id__ } - @object_hash[k].map {|h| h.__id__ }]
40
- end.to_h
25
+ begin
26
+ # try loading extension
27
+ require_relative("extensions/#{path}")
28
+ rescue LoadError
29
+ nil # Use normal feature loading when no embedded adapter exists.
30
+ else
31
+ true
41
32
  end
33
+ end
42
34
 
43
- @object_hash = object_hash
35
+ def method_missing name, *parms, **parmh
36
+ execs = instance_variables.include?(:@execs) ? instance_variable_get(:@execs) : []
37
+
38
+ execs << [name, parms, parmh]
39
+
40
+ instance_variable_set(:@execs, execs)
44
41
  end
45
42
 
46
- def load_file file, type_hash
47
- # NOTE this forces not to share namespace but avoid exception when calling
48
- # main space methods, see Rakefile of racc gem
49
- # also named module is required instead of anonymous one to allow root level defined methods access
50
- store_object_hash(type_hash)
51
- value = nil
43
+ # alias_method :orig_gem, :gem
44
+ # define_method :gem do |*args|
45
+ def gem name, *args
46
+ gems = instance_variables.include?(:@gems) ? instance_variable_get(:@gems) : []
52
47
 
53
- begin
54
- push
55
- Dir.chdir(File.dirname(file)) do
56
- _file = File.basename(file).untaint
57
- code = File.read(file, mode: 'r:UTF-8:-')
58
- code.untaint
59
-
60
- value =
61
- begin
62
- # evaluation required not to lost loaded object,
63
- # the instance_eval is used in favor of eval to avoid lost predefined vars
64
- # like for chef-utils gem
65
- instance_eval(code, _file)
66
- rescue Exception
67
- # thrown for setup gem
68
- load(File.basename(file), true)
69
- end
70
- end
71
- rescue Exception => e
72
- raise e
73
- ensure
74
- debug("value: #{value.inspect}")
75
- pop
76
- store_object_hash(type_hash)
77
- end
48
+ gems.push(name => args)
49
+ instance_variable_set(:@gems, gems)
78
50
 
79
- self
80
- rescue Exception => e
81
- debug("[#{e.class}]: #{e.message}\n\t#{e.backtrace.join("\n\t")}")
51
+ true
52
+ end
82
53
 
83
- self
54
+ def respond_to_missing? _name, _include_private = false
55
+ true # The metadata recorder accepts arbitrary DSL declarations.
84
56
  end
85
57
 
86
58
  def push
87
- @paths = $:.dup
88
- debug("Stored paths are: " + @paths.join("\n\t"))
59
+ @paths = $LOAD_PATH.dup
60
+
61
+ debug("Stored paths are: #{@paths.join("\n\t")}")
89
62
  end
90
63
 
91
64
  def pop
92
- debug("Subtract paths: " + ($: - @paths).join("\n\t"))
93
- # NOTE this sequency of merging is required to correct loading libs leads
65
+ debug("Subtract paths: #{($LOAD_PATH - @paths).join("\n\t")}")
66
+ # NOTE: this sequency of merging is required to correct loading libs leads
94
67
  # to show warning and break building rdoc documentation
95
- $:.replace(@paths | $:)
96
- debug("Replaced paths with: " + $:.join("\n\t"))
68
+ $LOAD_PATH.replace(@paths | $LOAD_PATH)
69
+
70
+ debug("Replaced paths with: #{$LOAD_PATH.join("\n\t")}")
97
71
  end
98
72
  end
99
73
 
@@ -106,87 +80,66 @@ module Baltix::Loader
106
80
  end
107
81
 
108
82
  def type_hash
109
- @type_hash ||=
110
- Baltix::Loader.extended_list.map do |kls|
111
- type =
112
- begin
113
- kls.const_get('TYPE')
114
- rescue
115
- nil
116
- end
117
-
118
- [kls, type]
119
- end.select {|(_, type)| type }.to_h
120
- end
83
+ @type_hash ||= Baltix::Loader.extended_list.filter_map do |klass|
84
+ type = loader_object_type(klass)
121
85
 
122
- def pre_loaders
123
- @pre_loaders ||=
124
- Baltix::Loader.extended_list.map do |kls|
125
- begin
126
- kls.const_get('PRELOAD_MATCHER')&.map do |k, v|
127
- [k, v.is_a?(Symbol) && kls.singleton_method(v) || v]
128
- end.to_h || {}
129
- rescue
130
- {}
131
- end
132
- end.reduce {|res, hash| res.merge(hash) }
86
+ [klass, type] if type
87
+ end.to_h
133
88
  end
134
89
 
135
- def mods
136
- @@mods ||= {}
90
+ def loader_object_type klass
91
+ klass.const_get('TYPE')
92
+ rescue StandardError
93
+ nil
137
94
  end
138
95
 
139
- def load_file file
140
- debug("Loading file: #{file}")
141
- stdout = $stdout
142
- stderr = $stderr
143
- $stdout = $stderr = Tempfile.new('loader')
96
+ def pre_loaders
97
+ @pre_loaders ||= Baltix::Loader.extended_list.map {|klass| loader_preload_map(klass) }
98
+ .reduce {|previous, current| previous.merge(current) }
99
+ end
144
100
 
145
- pre_loaders.each do |(m, preload_method)|
146
- if file =~ m
147
- args = [file][0...preload_method.arity]
148
- preload_method[*args]
149
- end
150
- end
101
+ def loader_preload_map klass
102
+ klass.const_get('PRELOAD_MATCHER')&.transform_values do |value|
103
+ value.is_a?(Symbol) && klass.singleton_method(value) || value
104
+ end || {}
105
+ rescue StandardError
106
+ {}
107
+ end
151
108
 
152
- module_name = "M" + Random.srand.to_s
153
- mod_code = <<-END
154
- module #{module_name}
155
- extend(::Baltix::Loader::Certain)
156
- end
157
- END
158
-
159
- mod = module_eval(mod_code)
160
- mod.load_file(file, type_hash)
161
- $stdout.rewind
162
- $stderr.rewind
163
- log = $stdout.readlines
164
- errlog = $stderr.readlines
165
-
166
- OpenStruct.new(mod: mod, log: log, errlog: errlog, object_hash: mod.object_hash, diff_ids: mod.object_ids)
167
- rescue Exception => e
168
- warn(e.message)
169
-
170
- OpenStruct.new(mod: mod, object_hash: {}, log: log, errlog: errlog, diff_ids: [])
171
- ensure
172
- $stderr = stderr
173
- $stdout = stdout
109
+ def self.module_cache
110
+ @module_cache ||= {}
174
111
  end
175
112
 
176
- def app_file file, &block
177
- mods[file] ||= load_file(file)
113
+ def mods
114
+ Baltix::Loader.module_cache
115
+ end
178
116
 
117
+ def app_file file, dir = Dir.pwd
118
+ mods[file] ||= load_file(file, dir)
179
119
  mod = mods[file].dup
180
- objects = mod.diff_ids[self]&.map {|id| ObjectSpace._id2ref(id) }
120
+ objects = imported_module_objects(mod, file)
181
121
 
182
- debug("Object ids for '#{file}' are: #{mod.diff_ids[self].inspect}")
183
- debug("Objects for '#{file}' are: #{objects.inspect}")
122
+ objects = [yield(objects)].flatten.tap(&:compact!) if block_given?
184
123
 
185
- if block_given?
186
- objects = [yield(objects)].flatten.compact
187
- end
188
124
  mod.objects = objects || []
189
125
 
190
126
  mod
191
127
  end
128
+
129
+ def imported_module_objects mod, file
130
+ objects = mod.object_ids[self]&.map {|id| ObjectSpace._id2ref(id) }
131
+
132
+ debug("Object ids for '#{file}' are: #{mod.object_ids[self].inspect}")
133
+ debug("Objects for '#{file}' are: #{objects.inspect}")
134
+
135
+ objects
136
+ end
192
137
  end
138
+
139
+ require 'baltix/loader/feature_loading'
140
+
141
+ require 'baltix/loader/object_capture'
142
+
143
+ require 'baltix/loader/evaluation'
144
+
145
+ require 'baltix/loader/capture'
data/lib/baltix/log.rb CHANGED
@@ -1,13 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Routes packaging diagnostics to configured streams.
1
4
  module Baltix::Log
2
5
  DEFAULT_IO_NAMES = {
3
6
  none: nil,
4
7
  error: 'stderr',
5
8
  warn: 'stderr',
6
9
  info: 'stderr',
7
- debug: 'stderr',
8
- }
10
+ debug: 'stderr'
11
+ }.freeze
9
12
 
10
- DEFAULT_IO_NAMES.keys.each do |key|
13
+ DEFAULT_IO_NAMES.each_key do |key|
11
14
  define_method(key) {|message| log(key, message) if level_match(key) }
12
15
  end
13
16
 
@@ -21,15 +24,15 @@ module Baltix::Log
21
24
 
22
25
  class << self
23
26
  def prefix_for kind, prefix
24
- @@prefix[kind] = prefix
27
+ @prefix[kind] = prefix
25
28
  end
26
29
 
27
30
  def prefix
28
- @@prefix ||= default_prefix(ios)
31
+ @prefix ||= default_prefix(ios)
29
32
  end
30
33
 
31
34
  def default_prefix ios
32
- ios.keys.map {|kind| [kind, "[baltix][#{kind.upcase}]> " ] }.to_h
35
+ ios.keys.to_h {|kind| [kind, "[baltix][#{kind.upcase}]> "] }
33
36
  end
34
37
 
35
38
  def setup_kind kind, io
@@ -37,37 +40,33 @@ module Baltix::Log
37
40
  end
38
41
 
39
42
  def ios
40
- @@ios ||= io_name_parse(DEFAULT_IO_NAMES)
43
+ @ios ||= io_name_parse(DEFAULT_IO_NAMES)
41
44
  end
42
45
 
43
46
  def level
44
- @@level ||= :info
47
+ @level ||= :info
45
48
  end
46
49
 
47
50
  def setup level = :info, io_names = DEFAULT_IO_NAMES, prefix = nil
48
- @@ios = io_name_parse(io_names)
49
- @@level = level
50
- @@prefix = prefix || default_prefix(ios)
51
+ @ios = io_name_parse(io_names)
52
+ @level = level
53
+ @prefix = prefix || default_prefix(ios)
51
54
  end
52
55
 
53
56
  def io_name_parse io_names
54
- io_names.map do |(kind, io_name)|
55
- io =
56
- case io_name
57
- when '-', 'stdout'
58
- $stdout
59
- when '--', 'stderr'
60
- $stderr
61
- when '', nil
62
- nil
63
- else
64
- File.open(io_name, 'a+')
65
- end
66
-
67
- [kind, io]
68
- end.to_h
57
+ io_names.to_h.transform_values {|name| open_log_stream(name) }
69
58
  end
70
59
 
71
- at_exit { (@@ios rescue {}).values.each {|v| v.close if v.is_a?(File) } }
60
+ def open_log_stream name
61
+ case [name].flatten.first
62
+ when '-', 'stdout' then $stdout
63
+ when '--', 'stderr' then $stderr
64
+ when '', nil then nil
65
+ else File.open(name, 'a+')
66
+ end
67
+ end
68
+ at_exit do
69
+ (@ios || {}).each_value {|v| v.close if v.is_a?(File) }
70
+ end
72
71
  end
73
72
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Recognizes metadata adapters without forcing unloaded Ruby constants.
4
+ class Baltix::Rake
5
+ # Recognizes metadata adapters even after an autoload was restored elsewhere.
6
+ # @param name [Symbol] registered metadata library constant
7
+ # @param value [Object] already loaded constant; no autoload is triggered
8
+ # @param location [String, false, nil] Ruby's reported constant source filename
9
+ # @param root [String] absolute adapter directory prefix
10
+ # @return [Boolean] whether the constant belongs to a metadata adapter
11
+ # Ruby may retain the autoload declaration's location after loading its file.
12
+ # Method definitions still identify the actual adapter. C-defined constants
13
+ # have no Ruby filename and are treated as real libraries unless known otherwise.
14
+ def self.metadata_adapter? name, value, location, root
15
+ return true if (@metadata_libraries || {})[name].equal?(value)
16
+ return true if adapter_source?(location, root)
17
+ return false unless value.is_a?(Module)
18
+
19
+ local_definitions(value).any? {|definition| adapter_source?(definition.source_location&.first, root) }
20
+ end
21
+
22
+ def self.local_definitions value
23
+ value.singleton_methods(false).map {|name| value.method(name) } |
24
+ value.instance_methods(false).map {|name| value.instance_method(name) }
25
+ end
26
+
27
+ def self.adapter_source? location, root
28
+ location.is_a?(String) && location.start_with?(root)
29
+ end
30
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Restores process and Rake state around explicit upstream task execution.
4
+ class Baltix::Rake
5
+ private
6
+
7
+ def normalized_task_names task_names
8
+ task_names.map {|name| name.to_s.delete_prefix('@') }.tap {|items| items.reject!(&:empty?) }.uniq
9
+ end
10
+
11
+ def capture_task_context
12
+ clean = CLEAN_CONSTANTS.filter_map do |name|
13
+ [name, Object.const_get(name, false)] if Object.const_defined?(name, false)
14
+ end.to_h
15
+
16
+ { application: ::Rake.application, directory: Dir.pwd, clean: clean,
17
+ clean_library: $LOADED_FEATURES.find {|file| file.end_with?('/rake/clean.rb') }}
18
+ end
19
+
20
+ def load_task_application clean_library
21
+ Dir.chdir(File.dirname(rakefile))
22
+
23
+ @app = ::Rake::Application.new
24
+ @tasks = nil
25
+ ::Rake.application = @app
26
+
27
+ @app.init('rake', ['--rakefile', rakefile])
28
+ clear_clean_constants
29
+ clean_library ? Kernel.load(clean_library) : require('rake/clean')
30
+
31
+ @app.load_rakefile
32
+ end
33
+
34
+ def invoke_tasks names
35
+ names.each {|name| @app.invoke_task(name) }
36
+ ensure
37
+ @app.thread_pool.join
38
+ end
39
+
40
+ def clear_clean_constants
41
+ CLEAN_CONSTANTS.each {|name| Object.send(:remove_const, name) if Object.const_defined?(name, false) }
42
+ end
43
+
44
+ def restore_task_context previous
45
+ ::Rake.application = previous[:application]
46
+
47
+ Dir.chdir(previous[:directory])
48
+ clear_clean_constants
49
+ previous[:clean].each {|name, value| Object.const_set(name, value) }
50
+
51
+ $LOADED_FEATURES.delete_if {|file| file.end_with?('/rake/clean.rb') } unless previous[:clean_library]
52
+ end
53
+
54
+ def invalidate_task_metadata
55
+ root = "#{File.dirname(rakefile)}/"
56
+
57
+ self.class.mods.delete_if {|file, _| File.expand_path(file).start_with?(root) }
58
+ end
59
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Temporarily exposes real task libraries and restores metadata adapters afterward.
4
+ class Baltix::Rake
5
+ # Temporarily exposes real task libraries in place of metadata adapters.
6
+ # @yield executes Rakefile loading and task invocation in the library scope
7
+ # @return [Object] the block's return value
8
+ # Takes no parameters. Adapter constants and autoloads are restored even
9
+ # when the block raises. Previously required real libraries are reused so
10
+ # Ruby's require cache does not leave an adapter active during later runs.
11
+ def self.with_task_libraries
12
+ previous = {}
13
+ libraries = @task_libraries ||= {}
14
+
15
+ Baltix::METADATA_LIBRARIES.each_key {|name| expose_task_library(name, previous, libraries) }
16
+
17
+ yield
18
+ ensure
19
+ restore_task_libraries(previous, libraries)
20
+ end
21
+
22
+ def self.expose_task_library name, previous, libraries
23
+ snapshot = constant_snapshot(name)
24
+ previous[name] = snapshot
25
+
26
+ return if snapshot.first == :constant && !remember_metadata_adapter?(name, snapshot.last)
27
+
28
+ remove_top_constant(name)
29
+
30
+ Object.const_set(name, libraries[name]) if libraries.key?(name)
31
+ end
32
+
33
+ def self.constant_snapshot name
34
+ autoload = Object.autoload?(name)
35
+
36
+ return [:autoload, autoload] if autoload
37
+ return [:constant, Object.const_get(name, false)] if Object.const_defined?(name, false)
38
+
39
+ [:absent, nil]
40
+ end
41
+
42
+ def self.remember_metadata_adapter? name, value
43
+ location = Object.const_source_location(name)&.first
44
+
45
+ return false unless metadata_adapter?(name, value, location, ADAPTER_ROOT)
46
+
47
+ (@metadata_libraries ||= {})[name] = value
48
+
49
+ true
50
+ end
51
+
52
+ def self.remove_top_constant name
53
+ Object.send(:remove_const, name) if Object.const_defined?(name, false)
54
+ end
55
+
56
+ def self.restore_task_libraries previous, libraries
57
+ previous.each do |name, (kind, value)|
58
+ remember_task_library(name, libraries)
59
+ remove_top_constant(name)
60
+ Object.const_set(name, value) if kind == :constant
61
+ Object.autoload(name, value) if kind == :autoload
62
+ end
63
+ end
64
+
65
+ def self.remember_task_library name, libraries
66
+ return unless Object.const_defined?(name, false) && !Object.autoload?(name)
67
+
68
+ value = Object.const_get(name, false)
69
+ location = Object.const_source_location(name)&.first
70
+
71
+ libraries[name] = value unless metadata_adapter?(name, value, location, ADAPTER_ROOT)
72
+ end
73
+ end
data/lib/baltix/rake.rb CHANGED
@@ -1,14 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # used in digest-crc gem as an extension compiler
2
4
  #
3
5
  require 'baltix/loader'
4
6
 
7
+ # Runs requested upstream tasks while preserving the caller Rake context.
5
8
  class Baltix::Rake
6
9
  extend ::Baltix::Loader
7
10
 
8
11
  class InvalidRakefileError < StandardError; end
9
12
 
13
+ CLEAN_CONSTANTS = %i[CLEAN CLOBBER].freeze
14
+ ADAPTER_ROOT = "#{File.join(__dir__, 'extensions')}/".freeze
15
+
10
16
  TYPE = 'Rake::Application'
11
- PRELOAD_MATCHER = { /\/rakefile(.rb)?$/i => :preload }
17
+ PRELOAD_MATCHER = { %r{/rakefile(.rb)?$}i => :preload }.freeze
12
18
 
13
19
  attr_reader :app, :rakefile, :options
14
20
 
@@ -24,29 +30,67 @@ class Baltix::Rake
24
30
  @tasks ||= @app&.tasks || []
25
31
  end
26
32
 
33
+ # Executes one task using its real build libraries in the current Ruby process.
34
+ # @param task_name [String] task name, optionally carrying the legacy @ marker
35
+ # @return [Array<String>] the executed task name without a legacy marker
27
36
  def run_task task_name
28
- if @app
29
- Rake.instance_variable_set(:@application, @app)
37
+ run_tasks([task_name])
38
+ end
30
39
 
31
- Dir.chdir(@app.original_dir) do
32
- @app.invoke_task(task_name)
33
- end
40
+ # Loads the complete Rakefile and invokes tasks in their requested order.
41
+ # @param task_names [Array<String>] task names, with optional legacy @ markers
42
+ # @param mode [Symbol, nil] :if_defined skips names absent from this Rakefile
43
+ # @return [Array<String>] executed task names, with duplicates removed
44
+ # Legacy markers are stripped without starting a separate Ruby interpreter.
45
+ # Real libraries supply plugin tasks; metadata adapters are restored afterward.
46
+ # Task failures propagate, and the previous Rake application and directory are
47
+ # restored after parallel workers finish, even when a task fails. Metadata imported
48
+ # from the project is invalidated so generated files are seen by later actors.
49
+ # Rake cleaning tasks are reloaded when cached, or required normally otherwise; the
50
+ # caller's CLEAN/CLOBBER lists and cleaning-library require state are restored.
51
+ def run_tasks task_names, mode = nil
52
+ previous = capture_task_context
53
+ names = normalized_task_names(task_names)
54
+
55
+ self.class.with_task_libraries do
56
+ load_task_application(previous[:clean_library])
57
+ names = names.select {|name| @app.lookup(name) } if mode == :if_defined
58
+ invoke_tasks(names)
34
59
  end
35
- rescue Exception => e
36
- warn "#{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
60
+
61
+ names
62
+ ensure
63
+ restore_task_context(previous) if previous
64
+ invalidate_task_metadata
37
65
  end
38
66
 
67
+ private
68
+
69
+ # Creates a Rakefile reader or a deferred task runner.
70
+ # @param rakefile [String] path to an existing Rakefile
71
+ # @param options [Hash] :runtime skips metadata import before task execution
72
+ # @return [Baltix::Rake] the initialized reader or runner
73
+ # Missing files raise InvalidRakefileError. Runtime runners load the actual
74
+ # build libraries when run_tasks is called; other readers retain metadata mode.
39
75
  def initialize rakefile, options = {}
40
- raise InvalidRakefileError unless File.file?(rakefile)
76
+ raise(InvalidRakefileError) unless File.file?(rakefile)
41
77
 
42
- @rakefile = rakefile
78
+ @rakefile = File.expand_path(rakefile)
43
79
  @options = options
44
- @app = self.class.load(rakefile).objects.first
80
+
81
+ @app = self.class.load(@rakefile).objects.first unless options[:runtime]
45
82
  end
46
83
 
47
84
  class << self
48
- # preload callback
85
+ # Clears cached build metadata before a Rakefile is imported.
86
+ # Takes no parameters.
87
+ # @return [nil] the cleared Rake application
88
+ # If the loaded Hoe implementation supports resetting, its project state
89
+ # is cleared too.
90
+ # An unused Hoe autoload is left untouched.
49
91
  def preload
92
+ ::Hoe.reset if Object.const_defined?(:Hoe) && !Object.autoload?(:Hoe) && ::Hoe.respond_to?(:reset)
93
+
50
94
  Rake.instance_variable_set(:@application, nil)
51
95
  end
52
96
 
@@ -55,3 +99,9 @@ class Baltix::Rake
55
99
  end
56
100
  end
57
101
  end
102
+
103
+ require 'baltix/rake/task_context'
104
+
105
+ require 'baltix/rake/task_libraries'
106
+
107
+ require 'baltix/rake/metadata_adapter'