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/i18n.rb CHANGED
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'baltix/version'
2
4
 
5
+ # Loads localized packaging summaries and descriptions.
3
6
  module Baltix::I18n
4
7
  class << self
5
8
  def locale_trees
@@ -7,43 +10,43 @@ module Baltix::I18n
7
10
  end
8
11
 
9
12
  def default_locale
10
- @default_locale ||= locales.sort do |x, y|
11
- x == "en_US.UTF-8" && -1 || y == "en_US.UTF-8" && 1 || 0
12
- end.first
13
+ @default_locale ||=
14
+ locales.min do |x, y|
15
+ x == 'en_US.UTF-8' && -1 || y == 'en_US.UTF-8' && 1 || 0
16
+ end
13
17
  end
14
18
 
15
19
  def locales
16
- @locales ||= Dir[File.join(File.dirname(__FILE__), "..", "..", "locale", "*.yaml")].map do |file|
17
- File.basename(file, ".yaml")
18
- end
20
+ @locales ||=
21
+ Dir[File.join(File.dirname(__FILE__), '..', '..', 'locale', '*.yaml')].map do |file|
22
+ File.basename(file, '.yaml')
23
+ end
19
24
  end
20
25
 
21
26
  def defaulted_locales
22
- @defaulted_locales ||= locales.map { |locale| locale == default_locale && "" || locale }
27
+ @defaulted_locales ||= locales.map {|locale| locale == default_locale && '' || locale }
23
28
  end
24
29
 
25
30
  def locale_tree locale
26
31
  return locale_trees[locale] if locale_trees[locale]
27
32
 
28
- file = File.join(File.dirname(__FILE__), "..", "..", "locale", "#{locale}.yaml")
33
+ file = File.join(File.dirname(__FILE__), '..', '..', 'locale', "#{locale}.yaml")
29
34
 
30
- YAML.load(IO.read(file))
35
+ Baltix.load(File.read(file))
31
36
  end
32
37
 
33
38
  def t! path, options = {}
34
- parts = path.to_s.split(".")
35
39
  locale = options[:locale].blank? && default_locale || options[:locale]
36
- #binding.pry
37
- line = parts.reduce(locale_tree(locale)) { |r, part| [ r[part] ].flatten.first }
40
+ line = path.to_s.split('.').reduce(locale_tree(locale)) {|tree, part| [tree[part]].flatten.first }
38
41
 
39
- line.gsub(/%\w+/) do |str|
40
- /%(?<name>\w+)/ =~ str
42
+ line.gsub(/%\w+/) {|token| translation_variable(token.delete_prefix('%'), options[:binding]) }
43
+ end
41
44
 
42
- if options[:binding].local_variable_defined?(name)
43
- options[:binding].local_variable_get(name)
44
- elsif options[:binding].instance_variable_defined?("@#{name}")
45
- options[:binding].instance_variable_get(:"@#{name}")
46
- end
45
+ def translation_variable name, context
46
+ if context.local_variable_defined?(name)
47
+ context.local_variable_get(name)
48
+ elsif context.instance_variable_defined?("@#{name}")
49
+ context.instance_variable_get(:"@#{name}")
47
50
  end
48
51
  end
49
52
 
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Captures ALT filenames, links, unambiguous headings and exact license-file hashes.
4
+ class Baltix::License::Catalog
5
+ def self.capture directory
6
+ root = File.realpath(directory)
7
+ licenses = {}
8
+ aliases = {}
9
+
10
+ Dir.children(root).sort.each {|name| capture_catalog_entry(root, name, licenses, aliases) }
11
+
12
+ { 'source_directory' => root, 'licenses' => licenses, 'aliases' => aliases }
13
+ end
14
+
15
+ def self.capture_catalog_entry root, name, licenses, aliases
16
+ return if name.start_with?('.')
17
+
18
+ file = contained_license_file(root, name)
19
+
20
+ return unless file
21
+
22
+ label = File.basename(file)
23
+
24
+ aliases[name] = label if name != label
25
+
26
+ licenses[label] = captured_license(file) unless licenses.key?(label)
27
+ end
28
+
29
+ def self.contained_license_file root, name
30
+ file = File.realpath(File.join(root, name))
31
+
32
+ file if File.dirname(file) == root && File.file?(file)
33
+ rescue Errno::ENOENT, Errno::ELOOP
34
+ nil
35
+ end
36
+
37
+ def self.captured_license file
38
+ bytes = File.binread(file)
39
+
40
+ { 'title' => captured_title(bytes), 'sha256' => Digest::SHA256.hexdigest(bytes) }
41
+ end
42
+
43
+ def self.captured_title bytes
44
+ paragraph = bytes.dup.force_encoding('UTF-8').scrub.lstrip.lines.take_while {|line| !line.strip.empty? }
45
+
46
+ paragraph.map!(&:strip)
47
+
48
+ heading = paragraph.join(' ')
49
+
50
+ heading if unambiguous_title?(paragraph, heading)
51
+ end
52
+
53
+ def self.unambiguous_title? paragraph, heading
54
+ paragraph.size <= 3 && heading.match?(/\blicen[cs]e\b/i) &&
55
+ !heading.match?(/\A(?:the\s+)?licen[cs]e(?:\s+agreement)?\z/i) &&
56
+ !paragraph.first.to_s.match?(/\Acopyright\b/i)
57
+ end
58
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'digest'
5
+
6
+ # The maintenance utility can load the catalog without the complete parser.
7
+ module Baltix::License
8
+ end
9
+
10
+ # ALT filenames and explicit symbolic links define the available RPM labels.
11
+ # Equal license texts do not imply equal only/or-later permissions.
12
+ class Baltix::License::Catalog
13
+ SYSTEM_DIRECTORY = '/usr/share/license'
14
+ SNAPSHOT = File.expand_path('../../../data/alt-licenses/licenses.json', __dir__)
15
+
16
+ def self.title_key value
17
+ value.to_s.encode('UTF-8', invalid: :replace, undef: :replace)
18
+ .unicode_normalize(:nfkc).downcase.delete(%q("'“”‘’))
19
+ .gsub(/\bv\s*\.\s*(?=\d)/, 'v').gsub(/[[:space:]]+/, ' ').strip
20
+ end
21
+
22
+ def self.identifier_key value
23
+ value.to_s.strip.downcase.gsub(/[[:space:]]+/, '-')
24
+ end
25
+
26
+ def self.from_directory directory
27
+ new(capture(directory))
28
+ end
29
+
30
+ def self.load directory = SYSTEM_DIRECTORY
31
+ File.directory?(directory) ? from_directory(directory) : new(JSON.parse(File.read(SNAPSHOT, encoding: 'UTF-8')))
32
+ end
33
+
34
+ def initialize data
35
+ licenses = data.fetch('licenses')
36
+ @exact = licenses.keys.to_h {|label| [label, label] }.merge(data.fetch('aliases'))
37
+ @identifiers = identifier_index
38
+ @titles = title_index(licenses)
39
+ end
40
+
41
+ def identifier value
42
+ @exact[value.to_s.strip] || unique(@identifiers[self.class.identifier_key(value)])
43
+ end
44
+
45
+ def title value
46
+ unique(@titles[self.class.title_key(value)])
47
+ end
48
+
49
+ private
50
+
51
+ def identifier_index
52
+ grouped = @exact.group_by {|name, _label| self.class.identifier_key(name) }
53
+
54
+ unique_label_groups(grouped)
55
+ end
56
+
57
+ def title_index licenses
58
+ titles =
59
+ licenses.filter_map do |label, entry|
60
+ [self.class.title_key(entry['title']), label] if entry['title']
61
+ end
62
+
63
+ unique_label_groups(titles.group_by(&:first))
64
+ end
65
+
66
+ def unique_label_groups groups
67
+ groups.transform_values {|pairs| pairs.map(&:last).tap(&:uniq!) }
68
+ end
69
+
70
+ def unique labels
71
+ labels.first if labels&.one?
72
+ end
73
+ end
74
+
75
+ require_relative 'catalog/capture'
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'license/catalog'
5
+
6
+ # Normalizes upstream license names using the ALT license catalog.
7
+ module Baltix::License
8
+ SPDX_LIST =
9
+ JSON.parse(File.read(File.expand_path('../../data/spdx/licenses.json', __dir__), encoding: 'UTF-8')).freeze
10
+ SPDX_NAMES = SPDX_LIST.fetch('licenses').group_by {|license| Catalog.title_key(license.fetch('name')) }
11
+ .transform_values do |licenses|
12
+ licenses.map do |license|
13
+ license.fetch('licenseId')
14
+ end.tap(&:uniq!)
15
+ end.freeze
16
+
17
+ class << self
18
+ def catalog
19
+ @catalog ||= Catalog.load
20
+ end
21
+
22
+ def replacement_map value
23
+ return {} if value.nil?
24
+ raise(ArgumentError, 'license replacements must be a mapping') unless value.respond_to?(:each_pair)
25
+
26
+ configured =
27
+ value.each_pair.to_h do |original, replacement|
28
+ unless valid_replacement?(original, replacement)
29
+ raise(ArgumentError, 'license replacement names and values must be non-empty strings')
30
+ end
31
+
32
+ [original.to_s, replacement]
33
+ end
34
+
35
+ validate_final_labels(configured)
36
+
37
+ configured
38
+ end
39
+
40
+ def valid_replacement? original, replacement
41
+ (original.is_a?(String) || original.is_a?(Symbol)) && !original.to_s.strip.empty? &&
42
+ replacement.is_a?(String) && !replacement.strip.empty?
43
+ end
44
+
45
+ def validate_final_labels configured
46
+ configured.each_value do |target|
47
+ if configured.key?(target) && configured[target] != target
48
+ raise(ArgumentError,
49
+ 'license replacement targets must be final labels; chains and cycles are not supported')
50
+ end
51
+ end
52
+ end
53
+
54
+ # Applies one exact caller replacement before ALT catalog normalization.
55
+ # Replacement values are final; chains are not expanded.
56
+ def parse license, replacements: nil, catalog: self.catalog
57
+ configured = replacement_map(replacements)
58
+
59
+ return configured[license.to_s] if configured.key?(license.to_s)
60
+ return license if configured.value?(license)
61
+
62
+ normalized = catalog_label(license, catalog)
63
+
64
+ configured.fetch(normalized.to_s, normalized)
65
+ end
66
+
67
+ def catalog_label license, catalog
68
+ identifier = catalog.identifier(license)
69
+ standard = Array(SPDX_NAMES[Catalog.title_key(license)]).filter_map do |name|
70
+ catalog.identifier(name)
71
+ end.tap(&:uniq!)
72
+
73
+ identifier || (standard.first if standard.one?) || catalog.title(license) || license
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Captures metadata and restores the caller streams and Rake application even on failure.
4
+ module Baltix::Loader
5
+ # Evaluates package metadata while capturing output independently of Tempfile wrappers.
6
+ # @param file [String] metadata file to evaluate
7
+ # @param dir [String] source directory used by the sandbox
8
+ # @return [OpenStruct] captured objects and logs, or empty object data on failure
9
+ # Matching preloaders run before evaluation. The underlying IO is duplicated
10
+ # so garbage collection of a temporary wrapper cannot close the original log.
11
+ # Failures are reported and the original global streams and Rake application
12
+ # are always restored. Metadata keeps its captured application, while the
13
+ # caller's tasks remain attached to the caller's original application.
14
+ def load_file file, dir
15
+ previous = loader_context
16
+
17
+ debug("Loading file: #{file}")
18
+
19
+ tmpio = Tempfile.new('loader')
20
+ $stdout = $stderr = tmpio.to_io.dup
21
+
22
+ run_metadata_preloaders(file)
23
+
24
+ mod = new_metadata_module
25
+
26
+ mod.load_file(file, dir, type_hash)
27
+
28
+ captured_metadata(mod, tmpio)
29
+ rescue StandardError, ScriptError, SystemExit => error
30
+ failed_metadata(mod, tmpio, error)
31
+ ensure
32
+ restore_loader_context(previous)
33
+ end
34
+
35
+ def loader_context
36
+ { rake: ::Rake.instance_variable_get(:@application), stdout: $stdout, stderr: $stderr,
37
+ rbconfig: RbConfig::CONFIG.dup, makeconfig: RbConfig::MAKEFILE_CONFIG.dup }
38
+ end
39
+
40
+ def restore_loader_context previous
41
+ $stderr = previous[:stderr]
42
+ $stdout = previous[:stdout]
43
+ ::Rake.application = previous[:rake]
44
+
45
+ RbConfig::CONFIG.replace(previous[:rbconfig])
46
+
47
+ RbConfig::MAKEFILE_CONFIG.replace(previous[:makeconfig])
48
+ end
49
+
50
+ def new_metadata_module
51
+ module_name = "M#{Random.srand}"
52
+
53
+ module_eval(<<~METADATA_MODULE, __FILE__, __LINE__ + 1)
54
+ module #{module_name} # module M1234
55
+ extend(::Baltix::Loader::Certain)
56
+ end
57
+ METADATA_MODULE
58
+ end
59
+
60
+ def run_metadata_preloaders file
61
+ pre_loaders.each do |matcher, callback|
62
+ callback[*[file][0...callback.arity]] if file&.match?(matcher)
63
+ end
64
+ end
65
+
66
+ def captured_metadata mod, io
67
+ io.rewind
68
+
69
+ result = OpenStruct.new(mod: mod, log: io.readlines, errlog: io.readlines)
70
+
71
+ mod.instance_variables.reduce(result) do |state, variable|
72
+ name = variable.to_s.delete_prefix('@')
73
+
74
+ state.merge(name => mod.instance_variable_get(variable))
75
+ end
76
+ end
77
+
78
+ def failed_metadata mod, io, error
79
+ warn(error.message)
80
+
81
+ log = remaining_loader_log(io)
82
+
83
+ OpenStruct.new(mod: mod, object_hash: {}, log: log, errlog: log, object_ids: {})
84
+ end
85
+
86
+ def remaining_loader_log io
87
+ io.readlines
88
+ rescue IOError
89
+ ''
90
+ end
91
+ end
@@ -1,11 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Cmake based compilable gemspec detection, no gemspec is actually returned
2
4
  # Sample gem is: hiredis
3
5
  #
4
6
  module Baltix::Loader::Cmake
5
- def cmake file
6
- log_in = `cmake .`
7
+ def cmake _file, _dir
8
+ log_in = `echo`
9
+
7
10
  debug(log_in)
8
11
  rescue Errno::ENOENT
9
- error "Error: cmake is required to properly detect the gem"
12
+ error('Error: cmake is required to properly detect the gem')
10
13
  end
11
14
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Evaluates upstream metadata while restoring its search paths and output streams.
4
+ module Baltix::Loader::Certain
5
+ def load_file file, dir, type_hash
6
+ @dir = dir
7
+ @stack = []
8
+ @requires = []
9
+
10
+ store_object_hash(type_hash)
11
+ evaluate_with_source_paths(file, type_hash)
12
+
13
+ self
14
+ rescue StandardError, ScriptError, SystemExit => error
15
+ debug("[#{error.class}]: #{error.message}\n\t#{error.backtrace.join("\n\t")}")
16
+
17
+ self
18
+ end
19
+
20
+ def evaluate_with_source_paths file, type_hash
21
+ value = nil
22
+
23
+ push
24
+ Dir.chdir(File.dirname(file)) { value = evaluate_metadata_file(file) }
25
+ ensure
26
+ debug("value: #{value.inspect}")
27
+ pop
28
+ store_object_hash(type_hash)
29
+ end
30
+
31
+ def evaluate_metadata_file file
32
+ basename = File.basename(file)
33
+ code = File.read(file, mode: 'r:UTF-8:-')
34
+
35
+ evaluate_metadata_code(code, basename)
36
+ end
37
+
38
+ def evaluate_metadata_code code, basename
39
+ stderr = $stderr.dup
40
+ stdout = $stdout.dup
41
+
42
+ instance_eval(code, basename)
43
+ rescue StandardError, ScriptError, SystemExit
44
+ load(basename, true)
45
+ ensure
46
+ $stderr = stderr
47
+ $stdout = stdout
48
+ end
49
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'baltix/concerns'
4
+
5
+ # Records gems and required files declared by extension configuration.
6
+ module Baltix::Loader::Extconf
7
+ include Baltix::Concerns::ExtensionMetadata
8
+
9
+ def specifics
10
+ @specifics ||= {}
11
+ end
12
+
13
+ def ext_file file, rootdir
14
+ dir = File.dirname(file)
15
+
16
+ Dir.chdir(dir) do
17
+ mods[file] ||= preserve_extension_files(dir) { load_file(file, rootdir) }
18
+
19
+ specifics[file] = {
20
+ gems: mods[file].gems || [],
21
+ requires: mods[file].requires || []
22
+ }
23
+ end
24
+
25
+ nil
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Loads project features with their full source filename and preserves missing-feature semantics.
4
+ module Baltix::Loader::Certain
5
+ # Loads a metadata dependency while preserving its original source location.
6
+ # @param path [String] feature requested by the imported project
7
+ # @param args [Array] additional arguments forwarded to the original loader
8
+ # @return [Object, false] the evaluated result, or false for an absent/cyclic feature
9
+ # Embedded adapters take priority. Project files retain their full filename
10
+ # so __dir__ and require_relative resolve sibling helpers correctly. Other
11
+ # features use Ruby's loader; a missing requested feature returns false,
12
+ # while errors in its own dependencies propagate. Cycles are not reloaded.
13
+ def require path, *args
14
+ return true if require_embedded(path)
15
+
16
+ files = project_feature_files(path)
17
+
18
+ @requires.push(path)
19
+
20
+ files.empty? ? require_external_feature(path, *args) : evaluate_project_feature(files.first)
21
+ end
22
+
23
+ def project_feature_files path
24
+ paths =
25
+ $LOAD_PATH.map do |entry|
26
+ root = %r{^/}.match?(entry) ? entry : File.join(Dir.pwd, entry)
27
+
28
+ File.expand_path(File.join(root, "#{path}*"))
29
+ end
30
+
31
+ paths.flat_map {|pattern| Dir[pattern] }.uniq.grep(/#{@dir}/)
32
+ end
33
+
34
+ def require_external_feature path, *args
35
+ require_orig(path, *args)
36
+ rescue LoadError => error
37
+ raise unless error.path == path
38
+
39
+ false
40
+ end
41
+
42
+ def evaluate_project_feature file
43
+ code = File.read(file, mode: 'r:UTF-8:-')
44
+
45
+ return false if @stack.include?(file)
46
+
47
+ begin
48
+ @stack.push(file)
49
+ instance_eval(code, file)
50
+ ensure
51
+ @stack.pop
52
+ end
53
+ end
54
+ end
@@ -1,36 +1,51 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # GIT-VERSION-GEN version generator based gemspec preparser
2
4
  # example: "kgio" gem
3
5
  #
4
6
  module Baltix::Loader::GitVersionGen
5
- def git_version_gen execfile
6
- IO.popen(execfile) do |io|
7
- debug(io.readlines)
8
- end
7
+ def git_version_gen execfile, _dir
8
+ IO.popen(execfile) {|io| debug(io.readlines) }
9
9
 
10
10
  dir = File.dirname(execfile)
11
- version_line = IO.read(File.join(dir, "GIT-VERSION-FILE"))
12
- if /=(?<version>.*)/ =~ version_line
13
- ENV["VERSION"] = version.strip
11
+
12
+ Dir.chdir(dir) do
13
+ read_generated_git_version(execfile, dir)
14
+ write_git_manifests
15
+ `make -C Documentation` if File.directory?('Documentation')
16
+ write_hidden_git_manifest unless File.exist?('.manifest') && File.exist?('.gem-manifest')
14
17
  end
15
18
 
16
- # dot manifest generation
17
- files = Dir["*/**/*"].select {|x| File.file?(x) }
18
- File.open(".manifest", "w+") {|f| f.puts(files.join("\n"))}
19
+ nil
20
+ end
21
+
22
+ def read_generated_git_version execfile, dir
23
+ `#{execfile}`
19
24
 
20
- # make documentaion
21
- if File.directory?('Documentation')
22
- `make -C Documentation`
23
- end
25
+ version_line = File.read(File.join(dir, 'GIT-VERSION-FILE'))
26
+
27
+ return unless /=(?<version>.*)/ =~ version_line
24
28
 
25
- if !File.exist?('.manifest') || !File.exist?('.gem-manifest')
26
- files = Dir.glob("**/*", File::FNM_DOTMATCH).reject do |f|
27
- /\/\.git/ =~ f || File.directory?(f)
29
+ ENV['VERSION'] = version.strip
30
+ end
31
+
32
+ def write_git_manifests
33
+ files = Dir['*/**/*'].select {|file| File.file?(file) }
34
+ docs = files.grep(/(README.*|.*\.rb)/i)
35
+
36
+ File.open('.manifest', 'w+') {|file| file.puts(files.join("\n")) }
37
+
38
+ File.open('.document', 'w+') {|file| file.puts(docs.join("\n")) }
39
+ end
40
+
41
+ def write_hidden_git_manifest
42
+ files =
43
+ Dir.glob('**/*', File::FNM_DOTMATCH).reject do |file|
44
+ file.include?('/.git') || File.directory?(file)
28
45
  end
29
46
 
30
- File.open(File.join('.gem-manifest'), "w") { |f| f.puts files }
31
- FileUtils.cp('.gem-manifest', '.manifest')
32
- end
47
+ File.open('.gem-manifest', 'w') {|file| file.puts(files) }
33
48
 
34
- nil
49
+ FileUtils.cp('.gem-manifest', '.manifest')
35
50
  end
36
51
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Applies Mast metadata through ordinary gemspec writers, methods and nested fields.
4
+ module Baltix::Loader::Mast
5
+ def value_for value_in, data_in
6
+ case value_in
7
+ when Symbol then mast_path_value(value_in, data_in)
8
+ when Proc then value_in[data_in]
9
+ when NilClass then nil
10
+ when Array then value_in.reduce(nil) {|result, value| result || value_for(value, data_in) }
11
+ else value_in
12
+ end
13
+ end
14
+
15
+ def mast_path_value path, data
16
+ path.to_s.split('.').reduce(data) do |value, key|
17
+ value.is_a?(Hash) || value.is_a?(Array) && key.is_a?(Integer) ? value[key] : nil
18
+ end
19
+ end
20
+
21
+ def mast_specification file, paths
22
+ Gem::Specification.new do |spec|
23
+ data = mast_manifest_data(file, paths)
24
+
25
+ PROPS.each do |name, rule|
26
+ value = value_for(rule, data)
27
+
28
+ apply_mast_property(spec, name, value) if value
29
+ end
30
+ end
31
+ end
32
+
33
+ def apply_mast_property spec, name, value
34
+ /^(?:_(?<method>[^.]+)|(?<nested>[^.]+\..+)|.*)/ =~ name.to_s
35
+
36
+ if method
37
+ apply_mast_method(spec, method, value)
38
+ elsif nested
39
+ apply_mast_path(spec, nested, value)
40
+ else
41
+ spec.send("#{name}=", value)
42
+ end
43
+ end
44
+
45
+ def apply_mast_method spec, method, value
46
+ if value.is_a?(Array)
47
+ value.each {|arguments| spec.send(method, *arguments) }
48
+ else
49
+ spec.send(method, value)
50
+ end
51
+ end
52
+
53
+ def apply_mast_path spec, path_in, value
54
+ path = path_in.split('.')
55
+
56
+ path[0..-2].reduce(spec) {|result, name| result.send(name) }.send(:[]=, path[-1], value)
57
+ end
58
+ end