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
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Converts RubyGems boundaries to RPM requirements and conflicts.
4
+ class Baltix::Deps
5
+ class << self
6
+ # Converts a gem requirement to its strictest RPM lower bound.
7
+ # @param req [Gem::Requirement] the combined source constraints
8
+ # @return [Array] lower-bound operator and version, or an empty array for empty input
9
+ # If no lower bound is given, an inclusive zero minimum keeps the gem
10
+ # required while maximums and individual exclusions become conflicts.
11
+ # Excluded versions never change the minimum.
12
+ def lower_to_rpm req
13
+ minimum =
14
+ req.requirements.reduce([]) do |res, r|
15
+ merge(res, debound(r))
16
+ end
17
+
18
+ minimum.empty? && !req.requirements.empty? ? ['>=', Gem::Version.new(0)] : minimum
19
+ end
20
+
21
+ # Converts the strictest source maximum into an RPM conflict boundary.
22
+ # @param req [Gem::Requirement] combined dependency requirements
23
+ # @return [Array] conflict operator and version, or an empty array without a maximum
24
+ # If several upper bounds exist, the lowest version is selected. At equal
25
+ # versions an inclusive conflict wins because it excludes the stricter range.
26
+ def upper_negate_to_rpm req
27
+ req.requirements.filter_map {|requirement| negate(requirement) }.min_by do |operator, version|
28
+ [version, operator == '>=' ? 0 : 1]
29
+ end || []
30
+ end
31
+
32
+ # Converts each excluded gem version to its own exact RPM conflict.
33
+ # Prerelease versions retain their suffix; they must not exclude the release.
34
+ def exclusions_to_rpm req
35
+ req.requirements.find_all {|operator, _| operator == '!=' }.map do |_, version|
36
+ ['=', version]
37
+ end.tap(&:uniq!)
38
+ end
39
+
40
+ # Extracts a lower RPM boundary from one source constraint.
41
+ # @param req [Array<String, Gem::Version>] source operator and version
42
+ # @return [Array<String, Gem::Version>, nil] lower boundary, or nil without a minimum
43
+ # Pessimistic constraints use their release minimum. Exclusions and upper
44
+ # bounds do not supply a minimum.
45
+ def debound req
46
+ ver = Gem::Version.new(req[1].to_s.tr('x', '0'))
47
+
48
+ case req[0]
49
+ when '~>'
50
+ ['>=', ver.release]
51
+ when '>=', '>', '='
52
+ [req[0], ver.release]
53
+ end
54
+ end
55
+
56
+ # Converts a source upper boundary to an RPM conflict boundary.
57
+ # @param req [Array<String, Gem::Version>] source operator and version
58
+ # @return [Array<String, Gem::Version>, nil] conflict boundary, or nil without a maximum
59
+ # Pessimistic limits use the bumped release; < becomes >= and <= becomes >.
60
+ # Individual exclusions are rendered separately by exclusions_to_rpm.
61
+ def negate req
62
+ ver = Gem::Version.new(req[1].to_s.tr('x', '0'))
63
+
64
+ case req[0]
65
+ when '~>'
66
+ ['>=', ver.bump]
67
+ when '<'
68
+ ['>=', ver.release]
69
+ when '<='
70
+ ['>', ver.release]
71
+ end
72
+ end
73
+
74
+ # TODO: for requirement
75
+ # +merge+ enstricts requirement
76
+ # >= 4 & >= 5 => >= 5
77
+ # > 5 ^ > 4 => > 5
78
+ #
79
+ # > 5 & >= 4 => > 5
80
+ # > 4 & >= 4 => > 4
81
+ # > 4 & >= 4.x => >= 4.x
82
+ #
83
+ # >= 4 & > 4 => > 4
84
+ # >= 4 & > 5 => > 5
85
+ # >= 5 & > 4 => >= 5
86
+ #
87
+ MERGE_CONDS = {
88
+ '>=' => {
89
+ code: -1
90
+ }
91
+ }.freeze
92
+
93
+ # Selects the strongest of two lower dependency boundaries.
94
+ # @param req1 [Array<String, Gem::Version>, nil] first =, >= or > boundary
95
+ # @param req2 [Array<String, Gem::Version>, nil] second =, >= or > boundary
96
+ # @return [Array<String, Gem::Version>, nil] the selected boundary
97
+ # If either boundary is empty, the other is returned. The greater version
98
+ # wins; at equal versions > takes priority over = and >=. Exact equality
99
+ # otherwise takes priority over >=. Neither argument is modified.
100
+ def merge req1, req2
101
+ return req1 if req2.blank?
102
+ return req2 if req1.blank?
103
+
104
+ [req1, req2].max_by do |operator, version|
105
+ [version, if operator == '>'
106
+ 2
107
+ else
108
+ operator == '=' ? 1 : 0
109
+ end]
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Preserves all explicitly supplied bounds and exclusions for each gem.
4
+ module Baltix::Spec::Rpm::Env::Requirements
5
+ DECLARATION = /\A\s*([\w.-]+)\s*(~>|>=|<=|!=|=|>|<)\s*(\S+)\s*\z/
6
+
7
+ def self.parse value, separator = /,/
8
+ value.to_s.split(separator).reject {|entry| entry.strip.empty? }.each_with_object({}) do |entry, result|
9
+ match = DECLARATION.match(entry)
10
+
11
+ raise(ArgumentError, "Invalid gem dependency override: #{entry}") unless match
12
+
13
+ requirement = "#{match[2]} #{match[3]}"
14
+
15
+ Gem::Requirement.new(requirement)
16
+
17
+ (result[match[1]] ||= []) << requirement
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'baltix/spec/rpm'
4
+
5
+ # Translates existing Ruby RPM controls into the ordinary Baltix options.
6
+ class Baltix::Spec::Rpm::Env
7
+ HANDLERS = {
8
+ 'RPM_RUBY_BINDIR' => :option_bindir, 'RPM_RUBY' => :option_rubyprog,
9
+ 'RPM_RUBY_IGNORE_NAME_LIST' => :option_ignore_names,
10
+ 'RPM_RUBY_REGARD_NAME_LIST' => :option_regard_names,
11
+ 'RPM_RUBY_IGNORE_PATH_TOKEN_LIST' => :option_ignore_path_tokens,
12
+ 'RPM_RUBY_REGARD_PATH_TOKEN_LIST' => :option_regard_path_tokens
13
+ }.freeze
14
+ SCALARS = %w[RPM_RUBY_BINDIR RPM_RUBY].freeze
15
+
16
+ def self.restore_package_identity options, requested
17
+ options.delete_field(:name) { nil } unless requested.to_h.key?(:name)
18
+ end
19
+
20
+ def initialize env = ENV
21
+ @env = env
22
+ end
23
+
24
+ def apply options, &block
25
+ HANDLERS.each do |variable, handler|
26
+ value = @env[variable]
27
+
28
+ next if value.nil? || value.empty?
29
+
30
+ yield(handler, SCALARS.include?(variable) ? value : list(value))
31
+ end
32
+ apply_aliases(options, &block)
33
+
34
+ apply_metadata(options)
35
+ end
36
+
37
+ def list value
38
+ value.to_s.split(',').map(&:strip).tap {|values| values.reject!(&:empty?) }
39
+ end
40
+
41
+ def apply_aliases options
42
+ groups = @env.fetch('RPM_RUBY_ALIAS_NAME_LIST', '').split(':').map {|value| list(value) }
43
+
44
+ groups.reject!(&:empty?)
45
+ groups.each {|group| yield(:option_alias_names, group) }
46
+
47
+ options.alias_names = groups.to_h {|name, *aliases| [name, aliases] } unless groups.empty?
48
+ end
49
+
50
+ def apply_metadata options
51
+ options.replace_list = (options.replace_list || {}).merge(replacements)
52
+ options.version_replaces = (options.version_replaces || {}).merge(versions)
53
+
54
+ { rpm_package_name: 'RPM_PACKAGE_NAME', release: 'RPM_PACKAGE_RELEASE' }.each do |key, variable|
55
+ options[key] = @env[variable] unless @env[variable].to_s.empty?
56
+ end
57
+ end
58
+
59
+ def replacements
60
+ old = Requirements.parse(@env['RPM_RUBY_GEMVERSION_REPLACE_LIST'], /[,;:]/)
61
+
62
+ old.merge(Requirements.parse(@env['RPM_RUBY_USE_GEM_DEPENDENCY_LIST']))
63
+ end
64
+
65
+ def versions
66
+ list(@env['RPM_RUBY_USE_GEM_VERSION_LIST']).to_h do |entry|
67
+ name, version = entry.split(':', 2)
68
+
69
+ raise(ArgumentError, "Invalid gem version override: #{entry}") unless name && version
70
+
71
+ [name, Gem::Version.new(version).to_s]
72
+ end
73
+ end
74
+ end
75
+
76
+ require 'baltix/spec/rpm/env/requirements'
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Matches a unique executable RPM using literal installed command paths and their source gems.
4
+ class Baltix::Spec::Rpm
5
+ protected
6
+
7
+ # Finds an existing executable RPM by its literal installed command paths.
8
+ # @param source [Source::Base] source providing the public executable metadata
9
+ # @param candidates [Array<OpenStruct>] parsed subpackages
10
+ # @return [OpenStruct, nil] the sole matching RPM package, or nil
11
+ # Names alone may not match a user-selected RPM name. Exact bindir entries
12
+ # can identify it, provided every known command there is provided by this source.
13
+ # Shared commands, mixed-source packages and multiple candidate RPMs do not
14
+ # select an arbitrary RPM package. Globs do not identify installed commands.
15
+ def executable_package_state source, candidates
16
+ return nil unless source.is_a?(Baltix::Source::Gem) && !source.spec.executables.empty?
17
+
18
+ command_sources = executable_command_sources
19
+ matching = candidates.select {|package| executable_package_matches?(package, source, command_sources) }
20
+
21
+ matching.one? ? matching.first : nil
22
+ end
23
+
24
+ def executable_command_sources
25
+ command_sources = Hash.new {|hash, command| hash[command] = [] }
26
+
27
+ sources.grep(Baltix::Source::Gem).each do |gem_source|
28
+ gem_source.spec.executables.each {|command| command_sources[command] |= [gem_source] }
29
+ end
30
+
31
+ command_sources
32
+ end
33
+
34
+ def executable_package_matches? package, source, command_sources
35
+ kind = package.name.kind || package.name.approximate_kind
36
+
37
+ return false unless EXECUTABLE_PACKAGE_KINDS.include?(kind)
38
+
39
+ commands = packaged_command_names(package).select {|command| command_sources.key?(command) }
40
+
41
+ !commands.empty? && commands.all? {|command| command_sources[command] == [source] }
42
+ end
43
+
44
+ def packaged_command_names package
45
+ lines = Array(of_state(:preserved_file_lists)&.[](package.name.original_fullname))
46
+
47
+ lines.filter_map {|line| line.strip[%r{\A%(?:_bindir|\{_bindir\})/([^\s*?\[\]]+)\z}, 1] }
48
+ end
49
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Retains manual package files while regenerating Ruby layout and known executable entries.
4
+ class Baltix::Spec::Rpm
5
+ # Selects retained manual file entries for a generated package.
6
+ # @param package [Rpm, Secondary] package whose original file list is requested
7
+ # @return [Array<String>] custom file entries absent from automatic Ruby lists
8
+ # Generated plugin files are assigned to their source libraries.
9
+ # State-only application packages retain other entries. Source-backed
10
+ # packages omit old documentation/Ruby layout macros and duplicate executable
11
+ # entries because those are regenerated from current metadata. Gem-backed
12
+ # packages omit bindir globs and paths belonging to declared executables, even
13
+ # when these occur in a library or documentation file list. Non-gem executable
14
+ # packages omit entries matching their known commands. Other manual files remain.
15
+ def preserved_files package
16
+ lines = preserved_file_lines(package).reject {|line| is_plugin_file_generated?(line) }
17
+
18
+ return lines if package.source.is_a?(Baltix::Source::Fake)
19
+
20
+ gem_source = package.source.is_a?(Baltix::Source::Gem)
21
+ executable_paths = preserved_executable_paths(package, gem_source)
22
+
23
+ lines.reject {|line| generated_file_entry?(package, line, executable_paths, gem_source) }
24
+ end
25
+
26
+ def preserved_file_lines package
27
+ lists = state.preserved_file_lists || {}.to_os
28
+ key = package.state.name&.original_fullname || package.name.original_fullname
29
+
30
+ Array(lists[key]).reject {|line| line.strip.empty? }
31
+ end
32
+
33
+ def preserved_executable_paths package, gem_source
34
+ (gem_source || package.is_exec? ? package.executables : []).map {|file| "%_bindir/#{file}" }
35
+ end
36
+
37
+ def generated_file_entry? package, line, executable_paths, gem_source
38
+ path = line.strip.sub(/\A%\{_bindir\}/, '%_bindir')
39
+
40
+ path.sub(/\A%\{_libexecdir\}/, '%_libexecdir') == package.site_data_directory ||
41
+ line.match?(/^\s*%(?:doc\b|ruby_(?:gem|site|ri|include)|rubygem_)/) ||
42
+ (gem_source && path.match?(%r{\A%_bindir/.*[*?\[]})) ||
43
+ executable_paths.any? {|file| File.fnmatch?(path, file) }
44
+ end
45
+
46
+ def is_plugin_file_generated? line
47
+ name = line.strip[%r{\A%(?:ruby_gemsplugindir|\{ruby_gemsplugindir\})/([^/]+)_plugin\.rb\z}, 1]
48
+
49
+ name && space.valid_sources.any? do |source|
50
+ source.is_a?(Baltix::Source::Gem) && source.name == name && source.rubygems_plugin_file
51
+ end
52
+ end
53
+
54
+ # Detects manual files that need a separately declared RPM package.
55
+ # @param package_name [Name, nil] original package name from the parsed spec
56
+ # @return [Boolean] whether non-generated file entries remain for this package
57
+ # Ruby/documentation layout macros and executables already provided by known
58
+ # sources do not keep obsolete aliases alive. A missing package name has no files.
59
+ def has_custom_packaging_files? package_name
60
+ return false unless package_name
61
+
62
+ lists = state.preserved_file_lists || {}.to_os
63
+ executables = space.valid_sources.grep(Baltix::Source::Gem).flat_map {|source| source.spec.executables }
64
+
65
+ Array(lists[package_name.original_fullname]).any? {|line| custom_package_entry?(line, executables) }
66
+ end
67
+
68
+ def custom_package_entry? line, executables
69
+ !line.strip.empty? && !line.match?(/^\s*%(?:doc\b|ruby_|rubygem_)/) &&
70
+ !is_plugin_file_generated?(line) && executables.none? {|file| line.strip == "%_bindir/#{file}" }
71
+ end
72
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Compiles nested ALT condition paths and resolves only declared feature aliases.
4
+ class Baltix::Spec::Rpm
5
+ protected
6
+
7
+ # Uses native if directives below an existing condition for ALT RPM skip mode.
8
+ # @param guards [Array<Array<String>>] nested source paths
9
+ # @param outer_depth [Integer] enclosing conditions emitted by the caller
10
+ # @return [Array<Array<String>>] paths safe inside disabled branches
11
+ def compile_guard_paths guards, outer_depth: 0
12
+ guards.each_with_index.map do |branch, depth|
13
+ branch = normalized_guard_branch(branch)
14
+
15
+ next branch if (depth + outer_depth).zero?
16
+
17
+ branch.map {|line| compile_native_guard(line) }
18
+ end
19
+ end
20
+
21
+ def compile_native_guard line
22
+ line.sub(/^%if_(with|without|enabled|disabled)\s+([\w.+-]+)(\s*(?:#.*)?)$/) do
23
+ flag = GUARD_FLAG_NAMES.fetch(::Regexp.last_match(1), ::Regexp.last_match(1))
24
+
25
+ "%if 0%{?_#{flag}_#{::Regexp.last_match(2)}:1}#{::Regexp.last_match(3)}"
26
+ end
27
+ end
28
+
29
+ def build_dependency_guard_paths tag, dependency, outer_depth:
30
+ return [[]] if part_macro_prerequisite?(tag, dependency)
31
+
32
+ imported = of_state(:header_dependency_guards)&.[](tag)&.[](dependency)
33
+ paths = imported ? normalize_dependency_paths(imported) : default_build_dependency_paths(tag, dependency)
34
+ optional = optional_build_guard(tag, dependency, outer_depth: outer_depth)
35
+
36
+ optional ? paths.map {|path| path | [[optional]] } : paths
37
+ end
38
+
39
+ def default_build_dependency_paths tag, dependency
40
+ [ruby_build_dependency?(tag, dependency) ? shared_ruby_guards : []]
41
+ end
42
+
43
+ def optional_build_guard tag, dependency, outer_depth:
44
+ return unless outer_depth.zero? && %w[BuildRequires BuildConflicts].include?(tag)
45
+
46
+ name = dependency[/\A(?:gem|rubygem|ruby-gem)\(([^)]+)\)/, 1]
47
+ parts = optional_build_parts_for(name)
48
+
49
+ return if parts.empty?
50
+ return "%if_enabled #{parts.first}" if parts.one?
51
+
52
+ tests = parts.sort.map! {|part| "0%{?_enable_#{part}:1}" }
53
+
54
+ "%if #{tests.join(' || ')}"
55
+ end
56
+
57
+ def normalize_dependency_paths paths
58
+ paths.any?(&:empty?) ? [[]] : paths
59
+ end
60
+
61
+ def ruby_build_dependency? tag, dependency
62
+ tools = of_default(:build_pre_requires).flat_map(&:split) | %w[libruby-devel ruby-devel ruby]
63
+
64
+ dependency.match?(/\A(?:gem|rubygem|ruby-gem)\(/) ||
65
+ (tag == 'BuildRequires(pre)' && tools.include?(dependency.split.first))
66
+ end
67
+
68
+ # Resolves separator variants only against feature declarations in this spec.
69
+ # @param line [String] original RPM condition
70
+ # @return [String] condition using its uniquely declared flag, or the original
71
+ # With/without and enable/disable are separate flag namespaces. Exact names
72
+ # take priority; undeclared and ambiguous references are not guessed.
73
+ def declared_feature_reference line
74
+ match = line.match(/\A(?<prefix>%if_(?<mode>with|without|enabled|disabled)\s+)
75
+ (?<flag>[\w.+-]+)(?<tail>\s*(?:\#.*)?)\z/x)
76
+
77
+ return line unless match
78
+
79
+ names = declared_guard_names(match[:mode])
80
+
81
+ return line if names.include?(match[:flag])
82
+
83
+ candidates = names.select {|name| name.tr('-', '_') == match[:flag].tr('-', '_') }
84
+
85
+ return line unless candidates.one?
86
+
87
+ "#{match[:prefix]}#{candidates.first}#{match[:tail]}"
88
+ end
89
+
90
+ def declared_guard_names mode
91
+ family = %w[with without].include?(mode) ? 'with|without' : 'enable|disable'
92
+
93
+ custom_macros.filter_map {|macro| macro[/\A%def_(?:#{family})\s+([\w.+-]+)(?:\s|$)/, 1] }.tap(&:uniq!)
94
+ end
95
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Restores manual subpackages and their supporting source package identity.
4
+ class Baltix::Spec::Rpm
5
+ protected
6
+
7
+ def imported_secondary candidate, secondaries
8
+ source = Baltix::Source::Fake.new
9
+ host = secondaries.find {|secondary| secondary.name.eql_by?(:name, candidate.name) }
10
+
11
+ host ||= self if name.eql_by?(:name, candidate.name)
12
+
13
+ Secondary.new(doc: self, kind: imported_secondary_kind(candidate), host: host, state: candidate, source: source,
14
+ options: {
15
+ name: candidate.name, gem_versionings: gem_versionings, available_gem_list: available_gem_list
16
+ })
17
+ end
18
+
19
+ def imported_secondary_kind candidate
20
+ if distinct_root_package? && candidate.rpm_name && candidate.name.prefix.nil?
21
+ :app
22
+ else
23
+ candidate.name.kind || (candidate.name.prefix.nil? ? :exec : nil)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the layout that RPM installs reuse after buildroot processing.
4
+ module Baltix::Spec::Rpm::Layout
5
+ EXTENSION_MODE = 0o644
6
+ VCS_FILES = %w[.cvsignore .gitignore .hgignore .svnignore].freeze
7
+ VCS_DIRECTORIES = %w[.hg .svn].freeze
8
+
9
+ def self.has_vcs_metadata? path
10
+ components = path.split('/')
11
+
12
+ VCS_FILES.include?(components.pop) || VCS_DIRECTORIES.any? {|name| components.include?(name) }
13
+ end
14
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Maps manual pages to RPM manifests.
4
+ class Baltix::Spec::Rpm
5
+ # Lists installed manual pages absent from retained file lists.
6
+ # @param package [Rpm, Secondary] package whose automatic manifest is rendered
7
+ # @return [Array<String>] explicit RPM manual paths with compression wildcards
8
+ # Executable RPMs own pages for commands. Other generated pages belong to
9
+ # the library or application that supplies them, under the doc switch.
10
+ # Active retained entries in any emitted package suppress automatic copies,
11
+ # including braced paths, attributes and explicit compression suffixes.
12
+ def manpage_entries package
13
+ target = space.targets.find {|item| item.source == package.source }
14
+
15
+ return [] unless target && is_manpage_package?(package, target)
16
+
17
+ ready, generated = unowned_rpm_manuals(target.source)
18
+
19
+ ready + guarded_ronn_entries(package, target, generated)
20
+ end
21
+
22
+ def unowned_rpm_manuals source
23
+ patterns = retained_manpage_patterns
24
+
25
+ rpm_manual_paths(source).map do |entries|
26
+ entries.reject {|file| retained_manpage?(file, patterns) }.map! {|file| "#{file}*" }
27
+ end
28
+ end
29
+
30
+ def guarded_ronn_entries package, target, entries
31
+ return entries if entries.empty? || target.manual_part == :exec
32
+
33
+ depth = section_guards_for(package, :files).size
34
+ guards = compile_guard_paths([['%if_enabled doc']], outer_depth: depth)
35
+
36
+ [*guards.flatten, *entries, '%endif']
37
+ end
38
+
39
+ def rpm_manual_paths source
40
+ generated, ready = source.manual_pages.partition {|file| file.end_with?('.ronn') }
41
+
42
+ ready = [] unless source.is_a?(Baltix::Source::Gem)
43
+
44
+ [ready, generated].map {|files| files.map {|file| "%_mandir/#{source.manual_destination(file)}" }}
45
+ end
46
+
47
+ def is_manpage_package? package, target
48
+ target.manual_part == :exec ? package.is_exec? : package.is_lib? || package.is_app?
49
+ end
50
+
51
+ def retained_manpage_patterns
52
+ retained =
53
+ if state.preserved_file_lists.present?
54
+ ([self] + valid_secondaries).flat_map {|item| preserved_files(item) }
55
+ else
56
+ []
57
+ end
58
+
59
+ retained.reject {|line| line.lstrip.start_with?('#') }.filter_map do |line|
60
+ line[%r{%(?:_mandir|\{_mandir\})/\S+}]&.sub('%{_mandir}', '%_mandir')
61
+ end
62
+ end
63
+
64
+ def retained_manpage? file, patterns
65
+ paths = [file, file.sub(%r{(?<=/)(?:man[1-8])/}, '')]
66
+
67
+ MANPAGE_SUFFIXES.any? do |suffix|
68
+ patterns.any? {|pattern| paths.any? {|path| File.fnmatch?(pattern, path + suffix) }}
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Normalizes repository, license, source archive and configured build-task metadata.
4
+ class Baltix::Spec::Rpm
5
+ protected
6
+
7
+ # Normalizes a repository URL for the generated Vcs tag.
8
+ # @param value_in [String, nil] explicit or imported repository URL
9
+ # @return [String, nil] normalized repository URL ending in one .git, or nil
10
+ # Known hosting rules also derive a repository from the homepage when no
11
+ # Vcs value is supplied. Existing repeated .git suffixes are collapsed so
12
+ # rendering and reparsing the same spec do not change its revision.
13
+ def _vcs value_in
14
+ pre =
15
+ URL_MATCHER.reduce(value_in) do |res, (rule, e)|
16
+ vcs = res || uri
17
+
18
+ vcs && (match = vcs.match(rule)) && e[match] || res
19
+ end
20
+
21
+ pre && "#{pre.sub(/(?:\.git)+\z/i, '')}.git".downcase
22
+ end
23
+
24
+ def _source_files value_in
25
+ source_files = value_in.dup
26
+ defaults = of_default(:source_files)[:'0']
27
+
28
+ source_files[:'0'] = defaults if source_files[:'0'] != defaults
29
+
30
+ source_files
31
+ end
32
+
33
+ def _licenses value_in
34
+ list = sources.map(&:licenses).tap(&:flatten!).tap(&:uniq!)
35
+
36
+ list = package_license_defaults(value_in) if default_license_configured?
37
+ list = value_in.blank? ? ['Unlicense'] : value_in if list.blank?
38
+
39
+ Array(list).map do |license|
40
+ Baltix::License.parse(license, replacements: options.license_replacement_list)
41
+ end.tap(&:uniq!)
42
+ end
43
+
44
+ def default_license_configured?
45
+ return false unless options.default_license
46
+
47
+ !options.default_license.to_s.strip.empty?
48
+ end
49
+
50
+ def package_license_defaults value_in
51
+ owners = ([source] + valid_secondaries.map(&:source)).compact.tap(&:uniq!)
52
+
53
+ owners.flat_map {|owner| effective_owner_licenses(owner, value_in) }.tap(&:uniq!)
54
+ end
55
+
56
+ def effective_owner_licenses owner, value_in
57
+ declared = Array(owner.licenses).reject {|license| license.to_s.strip.empty? }
58
+
59
+ declared = Array(value_in) if declared.empty? && owner == source
60
+
61
+ declared.empty? ? [options.default_license] : declared
62
+ end
63
+
64
+ # Preserves rake tasks configured in options or an existing spec.
65
+ # @param value_in [String, Array<String>, nil] tasks supplied by options or source state
66
+ # @return [Array<String>] unique configured task names in their original order
67
+ # If the spec uses ruby_on_build_rake_tasks, its values are retained. If it
68
+ # uses the legacy ruby_build --pre option, those tasks are retained as well.
69
+ # Missing declarations contribute no tasks; duplicates are emitted once.
70
+ def _rake_build_tasks value_in
71
+ /--pre=(?<list>[^\s]*)/ =~ Array(variables.ruby_build).join(' ')
72
+
73
+ [value_in, of_state(:ruby_on_build_rake_tasks), variables.ruby_on_build_rake_tasks,
74
+ list].flatten.tap(&:compact!).flat_map do |tasks|
75
+ tasks.to_s.split(',')
76
+ end.reject(&:empty?).tap(&:uniq!)
77
+ end
78
+ end