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,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Matches RPM package identities by kind, aliases and supporting package.
4
+ class Baltix::Spec::Rpm::Name
5
+ def eql? other, deep = false
6
+ equivalent_name?(other) || deep && eql_by?(:support_name, other)
7
+ end
8
+
9
+ def equivalent_name? other
10
+ case other
11
+ when self.class
12
+ eql_by?(:kind, other) && eql_by?(:name, other)
13
+ when String, Symbol
14
+ (([autoname, fullname] | [aliases].flatten) & self.class.parse(other).aliases).any?
15
+ else
16
+ other.to_s == fullname
17
+ end
18
+ end
19
+
20
+ # equality
21
+ # https://stackoverflow.com/a/3422349/446267
22
+ def == other
23
+ eql?(other) || __id__ == other.__id__
24
+ end
25
+
26
+ # match operator
27
+ # https://stackoverflow.com/a/3422349/446267
28
+ def === other
29
+ eql?(other)
30
+ end
31
+
32
+ def =~ re
33
+ to_s =~ re
34
+ end
35
+
36
+ def eql_by? value, other_in
37
+ other = other_in.is_a?(String) ? self.class.parse(other_in) : other_in
38
+
39
+ compare_name_field(value, other)
40
+ end
41
+
42
+ def compare_name_field value, other
43
+ case value
44
+ when :name
45
+ shared_name_alias?(other)
46
+ when :kind
47
+ matching_kind?(other)
48
+ when :alias
49
+ (aliases & other.aliases).any?
50
+ when :support_name
51
+ matching_support_name?(other)
52
+ else
53
+ raise(UnsupportedMatchError)
54
+ end
55
+ end
56
+
57
+ def matching_kind? other
58
+ !kind || !other.kind || kind == other.kind
59
+ end
60
+
61
+ def matching_support_name? other
62
+ support_name === (other.is_a?(self.class) && other.support_name || other)
63
+ end
64
+
65
+ def shared_name_alias? other
66
+ ((alias_for(kind) | alias_for(nil)) & (other.alias_for(other.kind) | other.alias_for(nil))).any?
67
+ end
68
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Renders canonical names without losing an explicitly supplied RPM name.
4
+ class Baltix::Spec::Rpm::Name
5
+ def to_s
6
+ fullname
7
+ end
8
+
9
+ # +fullname+ returns newly reconstructed adopted full name based on the storen data.
10
+ # All the "." and "_" is replaced with "-", and "ruby" prefix with "gem".
11
+ #
12
+ # name.fullname #=> "gem-foo-bar-baz-doc"
13
+ #
14
+ def fullname
15
+ options&.[](:rpm_name) || [autoprefix, autoname, autosuffix].compact.join('-')
16
+ end
17
+
18
+ def original_fullname
19
+ options&.[](:rpm_name) || [prefix, name, suffix].compact.join('-')
20
+ end
21
+
22
+ def autoprefix
23
+ %w[doc lib devel].include?(kind) && !%w[app].include?(support_name&.kind) ? self.class.default_prefix : nil
24
+ end
25
+
26
+ def autoname n = name
27
+ n&.downcase&.gsub(/[._]/, '-')
28
+ end
29
+
30
+ def autosuffix
31
+ %w[doc devel].include?(kind) && kind || nil
32
+ end
33
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Parses literal RPM and gem names while retaining explicit aliases and options.
4
+ class Baltix::Spec::Rpm::Name
5
+ def self.parse_options name_in, options_in = {}
6
+ fullname, kind, match = parsed_name_parts(name_in)
7
+ alias_hash = parsed_aliases(match, fullname, options_in)
8
+ values = { kind: kind, name: fullname }.merge(options_in.dup)
9
+
10
+ values.merge(alias_map: alias_hash.merge((options_in[:alias_map] || {}).dup))
11
+ end
12
+
13
+ def self.parsed_name_parts name
14
+ if name.is_a?(self)
15
+ match = name.name.match(RULE)
16
+
17
+ [match.named_captures['full_name'], name.kind&.to_s, match]
18
+ elsif name.nil?
19
+ [nil, nil, {}]
20
+ else
21
+ [name, nil, name.match(RULE)]
22
+ end
23
+ end
24
+
25
+ def self.parsed_aliases match, fullname, options
26
+ kinds = [match['suffix'] || match['prefix'] && 'lib' || %w[exec app]].flatten
27
+ names = [match['name'], match['name']&.gsub(/[-._]+/, '-')].uniq
28
+
29
+ kinds.reduce({ nil => [options[:aliases], fullname].flatten.tap(&:compact!) }) do |aliases, kind|
30
+ aliases.merge({ kind.to_s => names })
31
+ end
32
+ end
33
+
34
+ # Creates an RPM library name from a literal gem name.
35
+ # @param gem_name [String] gemspec name, including any ruby- or gem- prefix
36
+ # @return [Baltix::Spec::Rpm::Name] library name retaining the complete gem name
37
+ # The explicit RPM prefix prevents a gem's own prefix from being treated
38
+ # as a legacy package prefix; ordinary punctuation aliases still apply.
39
+ def self.for_gem gem_name
40
+ parse("#{default_prefix}-#{gem_name}", name: gem_name, kind: 'lib', prefix: default_prefix)
41
+ end
42
+
43
+ # Retains a native RPM selector without Ruby prefix or punctuation rules.
44
+ # @param rpm_name [String] original absolute RPM package name, possibly with macros
45
+ # @param aliases [Array<String>] expanded names used for parsed-state lookup
46
+ # @return [Name] application identity whose rendered name stays literal
47
+ def self.for_rpm rpm_name, aliases: []
48
+ parse(rpm_name, kind: 'app', rpm_name: rpm_name, aliases: aliases)
49
+ end
50
+
51
+ def self.parse name_in, options_in = {}
52
+ options = parse_options(name_in, options_in)
53
+
54
+ options[:name] = options[:name].blank? ? (options[:aliases] || []).first : options[:name]
55
+
56
+ new(options)
57
+ end
58
+ end
@@ -1,155 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Resolves RPM names, aliases and package-kind suffixes.
1
4
  class Baltix::Spec::Rpm::Name
2
5
  class InvalidAdoptedNameError < StandardError; end
3
6
  class UnsupportedMatchError < StandardError; end
4
7
 
5
- PREFICES = %w(gem ruby rubygem)
8
+ PREFICES = %w[gem ruby rubygem].freeze
6
9
  RULE = /^(?<full_name>(?:(?<prefix>#{PREFICES.join('|')})-)?(?<name>.*?))(?:-(?<suffix>doc|devel))?$/
10
+ LIB_RULE = /^(?<full_name>(?<name>.*?))(?:-(?<suffix>doc|devel))?$/
7
11
 
8
- attr_reader :name, :kind, :suffix
9
- attr_accessor :support_name
12
+ attr_reader :name, :kind, :suffix, :options, :support_name
10
13
 
11
- def aliases
12
- @aliases ||= []
14
+ def self.from_h data
15
+ new(data).tap {|name| name.alias_map.replace(data.fetch(:alias_map)) }
13
16
  end
14
17
 
15
- def prefix
16
- @prefix ||= kind == "lib" && self.class.default_prefix || nil
18
+ def to_h
19
+ (options || {}).to_h.merge(name: name, kind: kind, prefix: prefix, suffix: suffix,
20
+ alias_map: alias_map, support_name: support_name)
17
21
  end
18
22
 
19
- def self.default_prefix
20
- "gem"
23
+ def approximate_kind
24
+ # Equal alias counts retain the last declared kind, as the sorted form did.
25
+ @approximate_kind ||= alias_map.to_a.reverse_each.find_all {|kind, _| kind }.max_by {|_, names| names.size }.first
21
26
  end
22
27
 
23
- def support_name= value
24
- case @support_name = value
25
- when NilClass
26
- @kind = kind == "exec" && "app" || @kind
27
- else
28
- @kind = kind == "app" && "exec" || @kind
29
- end
28
+ def alias_map
29
+ @alias_map ||= {}
30
30
  end
31
31
 
32
- def eql? other, deep = false
33
- case other
34
- when self.class
35
- self.eql_by?(:kind, other) && self.eql_by?(:name, other)
36
- when String, Symbol
37
- (([ autoname, fullname ] | [ aliases ].flatten) & self.class.parse(other).aliases).any?
38
- else
39
- other.to_s == self.fullname
40
- end || deep && self.eql_by?(:support_name, other)
41
- end
42
-
43
- def == other
44
- eql?(other)
32
+ def aliases
33
+ # alias_map.values.flatten(1).uniq
34
+ # TODO validate if it is really needed merge with support_name
35
+ alias_map.values.flatten(1).tap(&:uniq!) | (support_name&.aliases || [])
45
36
  end
46
37
 
47
- def === other
48
- eql?(other)
38
+ def prefix
39
+ @prefix ||= kind == 'lib' && self.class.default_prefix || nil
49
40
  end
50
41
 
51
- def =~ re
52
- to_s =~ re
42
+ def self.default_prefix
43
+ 'gem'
53
44
  end
54
45
 
55
- def to_s
56
- fullname
46
+ def support_name= value
47
+ @kind =
48
+ case @support_name = value
49
+ when NilClass
50
+ kind == 'exec' && 'app' || @kind
51
+ else
52
+ kind == 'app' && 'exec' || @kind
53
+ end
57
54
  end
58
55
 
59
56
  def merge other
60
57
  options =
61
- %w(prefix suffix name support_name kind).map do |prop|
62
- [ prop.to_sym, other.send(prop) || self.send(prop) ]
63
- end.to_h
58
+ %w[prefix suffix name support_name kind].to_h do |prop|
59
+ [prop.to_sym, other.send(prop) || send(prop)]
60
+ end
64
61
 
65
- self.class.new(options.merge(aliases: self.aliases | other.aliases))
62
+ self.class.new(options.merge(aliases: aliases | other.aliases))
66
63
  end
67
64
 
68
- def eql_by? value, other
69
- case value
70
- when :name
71
- ([ self.name, self.aliases ].flatten & [ other.name, other.aliases ].flatten).any?
72
- when :kind
73
- self.kind == other.kind
74
- when :support_name
75
- self.support_name === (other.is_a?(self.class) && other.support_name || other)
76
- else
77
- raise(UnsupportedMatchError.new)
78
- end
79
- end
65
+ def as kind
66
+ return dup if kind == self.kind
67
+
68
+ options_in = options.merge(kind: kind)
69
+ aliases = alias_for(kind)
70
+
71
+ options_in[:name] = aliases.min_by(&:size) unless aliases.blank?
80
72
 
81
- # +fullname+ returns newly reconstructed adopted full name based on the storen data.
82
- # All the "." and "_" is replaced with "-", and "ruby" prefix with "gem".
83
- #
84
- # name.fullname #=> "gem-foo-bar-baz-doc"
85
- #
86
- def fullname
87
- [ autoprefix, autoname, autosuffix ].compact.join("-")
73
+ self.class.new(options_in)
88
74
  end
89
75
 
90
- def original_fullname
91
- [ prefix, name, suffix ].compact.join("-")
76
+ def alias_for kind
77
+ alias_map[kind] || []
92
78
  end
93
79
 
94
- def autoprefix
95
- %w(exec app).include?(kind) || %w(app).include?(support_name&.kind) ? nil : self.class.default_prefix
80
+ protected
81
+
82
+ def alias_assign _options
83
+ kind_names = aliases_for_kind(alias_for(nil))
84
+
85
+ alias_map[kind] = alias_for(kind) ? alias_for(kind) | kind_names : kind_names
96
86
  end
97
87
 
98
- def autoname
99
- name&.downcase&.gsub(/[\._]/, "-")
88
+ def aliases_for_kind names
89
+ case kind
90
+ when 'doc', 'devel'
91
+ names.map {|name| [prefix, name, kind].compact.join('-') }
92
+ when 'lib'
93
+ names.map {|name| [prefix || default_prefix, autoname(name)].join('-') }
94
+ when 'exec', 'app'
95
+ names
96
+ else
97
+ []
98
+ end
100
99
  end
101
100
 
102
- def autosuffix
103
- %w(doc devel).include?(kind) && kind || nil
101
+ def kind_from_prefix
102
+ PREFICES.include?(@prefix) ? 'lib' : nil
104
103
  end
105
104
 
106
- protected
105
+ def initialize options_in = {}
106
+ options = self.class.parse_options(options_in[:name], options_in)
107
107
 
108
- def initialize options = {}
109
- @aliases = options.fetch(:aliases, []) | options.fetch(:name, "").gsub(/[\.\_]+/, "-").split(",")
108
+ @alias_map = options[:alias_map]
110
109
  @prefix = options[:prefix]
111
110
  @suffix = options[:suffix]
112
111
  @name = options[:name]
113
112
  @support_name = options[:support_name]
114
- @kind = options[:kind] && options[:kind].to_s ||
115
- @suffix ||
116
- @prefix && "lib" ||
117
- @support_name && "exec" || "app"
118
- end
113
+ @kind = options[:kind] ? options[:kind].to_s : kind_from_prefix
114
+ @options = options.freeze
119
115
 
120
- class << self
121
- def parse name_in, options_in = {}
122
- m, kind =
123
- if name_in.is_a?(self)
124
- [name_in.original_fullname.match(RULE), name_in.kind]
125
- else
126
- [name_in.match(RULE)]
127
- end
128
-
129
- aliases_in = (options_in[:aliases] || []).flatten.uniq
130
- subaliases = aliases_in - [ m["full_name"] ]
131
- #aliases = subaliases | [ m["full_name"] ]
132
-
133
- raise(InvalidAdoptedNameError) if !m
134
-
135
- prefixed = subaliases.size >= aliases_in.size
136
- options = {
137
- prefix: prefixed && m["prefix"] || nil,
138
- #prefix: subaliases.blank? && m["prefix"] || nil,
139
- #prefix: m["prefix"],
140
- suffix: m["suffix"],
141
- kind: kind,
142
- #name: m["name"],
143
- name: prefixed && m["name"] || m["full_name"],
144
- #name: subaliases.blank? && m["name"] || m["full_name"],
145
- }.merge(options_in).merge({
146
- aliases: subaliases | [ m["full_name"] ]
147
- })
148
-
149
- options[:name] = options[:name].blank? && options[:aliases].first || options[:name]
150
- #binding.pry if name_in =~ /ruby/
151
-
152
- new(options)
153
- end
116
+ alias_assign(options)
154
117
  end
155
118
  end
119
+
120
+ require 'baltix/spec/rpm/name/parsing'
121
+
122
+ require 'baltix/spec/rpm/name/equality'
123
+
124
+ require 'baltix/spec/rpm/name/formatting'
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Keeps aggregate and packaged gem versions without downgrading current source versions.
4
+ class Baltix::Spec::Rpm
5
+ protected
6
+
7
+ # Selects a component version for an aggregate Gemfile package without downgrades.
8
+ # @param value_in [String, Gem::Version] version selected by earlier pipeline stages
9
+ # @return [String, Gem::Version] component candidate, retained package version, or input
10
+ # If the main source is a Gemfile, its component candidate must not be lower
11
+ # than the main Version parsed from the existing spec. Without a candidate,
12
+ # or for another source type, the earlier pipeline value is retained.
13
+ # Component package versions are not changed by this main-package guard.
14
+ def _version_of_secondaries value_in
15
+ versions = secondary_version_frequencies
16
+
17
+ return value_in unless source.is_a?(Baltix::Source::Gemfile)
18
+
19
+ selected_aggregate_version(versions.max_by {|_, size| size }&.first, value_in)
20
+ end
21
+
22
+ def secondary_version_frequencies
23
+ grouped = secondaries.group_by {|secondary| secondary.source&.version }
24
+
25
+ grouped.select {|key, _| key }.transform_values(&:size)
26
+ end
27
+
28
+ def selected_aggregate_version candidate, fallback
29
+ previous = of_state(:version)
30
+
31
+ if candidate && previous && Gem::Version.new(candidate.to_s) < Gem::Version.new(previous.to_s)
32
+ previous
33
+ else
34
+ candidate || fallback
35
+ end
36
+ end
37
+
38
+ # Resolves explicitly packaged versions from the input spec and configuration.
39
+ # @param value_in [OpenStruct, nil] configured or parsed gem version strings
40
+ # @return [Array<Gem::Dependency>] selected exact versions for packaged gems
41
+ # Configured entries replace matching parsed entries. Stale input macros for
42
+ # current sources are removed when upstream has advanced beyond their version.
43
+ # If a current gem source is older than its input package, add an exact override
44
+ # for the packaged version. An existing explicit override remains authoritative;
45
+ # absent source names and newer upstream versions do not gain an override.
46
+ def _use_gem_version_list value_in
47
+ versions = (of_state(:use_gem_version_list) || {}.to_os).merge(value_in || {}.to_os)
48
+
49
+ valid_sources.grep(Baltix::Source::Gem).group_by(&:name).each do |name, candidates|
50
+ refresh_packaged_version(versions, name, candidates)
51
+ end
52
+
53
+ versions.map {|name, version| Gem::Dependency.new(name.to_s, Gem::Requirement.new(version)) }
54
+ end
55
+
56
+ def refresh_packaged_version versions, name, candidates
57
+ current = candidates.map {|candidate| Gem::Version.new(candidate.version.to_s) }.max
58
+ configured = of_options(:use_gem_version_list)
59
+
60
+ versions.delete_field(name) if stale_packaged_version?(versions, name, current, configured)
61
+ return if versions[name]
62
+
63
+ previous = input_gem_version(name)
64
+
65
+ versions[name] = previous.to_s if previous && previous > current
66
+ end
67
+
68
+ def stale_packaged_version? versions, name, current, configured
69
+ versions[name] && !(configured && configured[name]) && current > Gem::Version.new(versions[name].to_s)
70
+ end
71
+
72
+ # Finds the highest version already packaged for a current gem.
73
+ # @param gem_name [String] literal current gem name, including its own prefix
74
+ # @return [Gem::Version, nil] highest matching input version, or nil when absent
75
+ # Exact typed Provides contribute their own versions, independently of the RPM
76
+ # header. A matching header also contributes unless its typed capabilities name
77
+ # a different gem. Nonmatching and auxiliary package headers do not contribute.
78
+ def input_gem_version gem_name
79
+ packages = Array(state.secondaries)
80
+
81
+ packages = [state] + packages unless distinct_root_package?
82
+
83
+ packages.flat_map {|package| packaged_gem_versions(package, gem_name) }.max
84
+ end
85
+
86
+ def packaged_gem_versions package, gem_name
87
+ capabilities = Array(package.provides).grep(Gem::Dependency)
88
+ matching = capabilities.select {|capability| capability.name == gem_name }
89
+ versions = exact_capability_versions(matching)
90
+
91
+ versions << Gem::Version.new(package.version.to_s) if independent_gem_header?(package, gem_name, capabilities,
92
+ matching)
93
+
94
+ versions
95
+ end
96
+
97
+ def exact_capability_versions capabilities
98
+ capabilities.flat_map do |capability|
99
+ capability.requirement.requirements.filter_map {|operator, version| version if operator == '=' }
100
+ end
101
+ end
102
+
103
+ def independent_gem_header? package, gem_name, capabilities, matching
104
+ (!distinct_root_package? || matching.empty?) && package.version && package.name &&
105
+ package.name === Name.for_gem(gem_name) && (capabilities.empty? || matching.any?)
106
+ end
107
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Retains user prose and non-gem notes while removing stale commented gem declarations.
4
+ class Baltix::Spec::Rpm::Parser
5
+ # Keeps user prose and plain RPM notes while regenerating commented gem tags.
6
+ # @param flow [String] leading comment text from the input spec
7
+ # @return [String] comments without stale gem dependency declarations
8
+ # Gem tags are reconstructed from current metadata by the normal pipelines.
9
+ # Mixed declarations retain their non-gem RPM entries, and inline notes remain
10
+ # comments. Dependency-like text in ordinary prose is not a declaration.
11
+ def parse_comment _match, flow, *_
12
+ flow.lines.map {|line| parsed_comment_line(line) }.join
13
+ end
14
+
15
+ def parsed_comment_line line
16
+ declaration = line.match(COMMENT_DEPENDENCY_RE)
17
+
18
+ return line unless declaration
19
+
20
+ body, note = declaration[2].split('#', 2)
21
+ dependencies = parse_dep([nil, body])
22
+
23
+ return line unless dependencies.any?(Gem::Dependency)
24
+
25
+ retained_comment(declaration[1], dependencies.grep(String), note)
26
+ end
27
+
28
+ def retained_comment prefix, plain, note
29
+ retained = plain.empty? ? +'' : "#{prefix}#{plain.join(' ')}\n"
30
+
31
+ retained << "# #{note.strip}\n" if note
32
+
33
+ retained
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Resolves package selectors and language/file switches without evaluating Ruby.
4
+ class Baltix::Spec::Rpm::Parser
5
+ def parse_context_line line, opts
6
+ key = nil
7
+ context =
8
+ line.to_s.split(/\s+/).reduce({}.to_os) do |result, argument|
9
+ key = context_argument_key(key, argument, result, opts)
10
+
11
+ result
12
+ end
13
+
14
+ opts.secondaries ||= [] if context.name
15
+
16
+ context
17
+ end
18
+
19
+ def context_argument_key key, argument, result, opts
20
+ case argument
21
+ when '-l'
22
+ :cp
23
+ when '-n'
24
+ :fullname
25
+ when '-f'
26
+ :file
27
+ else
28
+ assign_context_argument(key, argument, result, opts)
29
+ end
30
+ end
31
+
32
+ def assign_context_argument key, argument, result, opts
33
+ return assign_context_property(key, argument, result) if %i[cp fullname file].include?(key)
34
+
35
+ result.name = "#{opts.name}-#{argument}"
36
+
37
+ key
38
+ end
39
+
40
+ def assign_context_property key, argument, result
41
+ result.cp = argument if key == :cp
42
+ result.name = argument if key == :fullname
43
+
44
+ nil
45
+ end
46
+
47
+ def aliased_names opts
48
+ opts.context.__options&.aliased_names
49
+ end
50
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Tokenizes RPM dependencies while retaining quoted expressions and explicit gem bounds.
4
+ class Baltix::Spec::Rpm::Parser
5
+ # Splits dependency tokens without evaluating embedded RPM or shell expressions.
6
+ # @param text [String] a dependency tag's value
7
+ # @return [Array<String>] tokens with their original grouped contents
8
+ # Whitespace separates tokens only outside parentheses, braces and quotes.
9
+ # Nested groups, quoted delimiters and escaped characters stay in their token.
10
+ # An unfinished group or quote is retained as text rather than partially split.
11
+ # The ordered schema chooses one action per character; empty trailing tokens
12
+ # are omitted. Neither RPM macros nor shell expressions are evaluated.
13
+ def dependency_tokens text
14
+ state = { text: text, tokens: [], start: 0, closing: [], quote: nil, escaped: false }
15
+
16
+ text.each_char.with_index do |character, index|
17
+ rule =
18
+ DEPENDENCY_TOKEN_SCHEME.each_value.find do |matcher, _action|
19
+ matcher.call(character, index, state)
20
+ end
21
+
22
+ rule.last.call(character, index, state)
23
+ end
24
+
25
+ state[:tokens] << text[state[:start]..]
26
+
27
+ state[:tokens].reject(&:empty?)
28
+ end
29
+
30
+ # Parses RPM dependency declarations into gem dependencies or package strings.
31
+ # @param match [Array<String>] captures with declarations at index 1
32
+ # @param preserve_versions [Boolean] whether to retain explicit gem constraints
33
+ # @return [Array<Gem::Dependency, String>] parsed gem and package dependencies
34
+ # If version preservation is enabled, a gem's explicit constraint is retained.
35
+ # Otherwise gem constraints default to >= 0. Non-gem declarations stay strings.
36
+ # A comparison token and following version are attached to the preceding name.
37
+ # Embedded expressions remain intact, including nested groups and quoted spaces.
38
+ def parse_dep match, *_, preserve_versions: false
39
+ dependency_declarations(dependency_tokens(match[1])).map do |declaration|
40
+ parsed_dependency(declaration, preserve_versions)
41
+ end
42
+ end
43
+
44
+ def dependency_declarations tokens
45
+ declarations = []
46
+
47
+ until tokens.empty?
48
+ declaration = tokens.shift
49
+
50
+ if tokens.first&.match?(/\A(?:[<=>]+|!=)\z/) && tokens[1]
51
+ declaration = [declaration, tokens.shift, tokens.shift].join(' ')
52
+ end
53
+ declarations << declaration
54
+ end
55
+
56
+ declarations
57
+ end
58
+
59
+ def parsed_dependency declaration, preserve_versions
60
+ if (gem = /\A(?:gem|rubygem|ruby-gem)\(([^)]+)\)/.match(declaration))
61
+ requirement = preserve_versions && declaration[gem.end(0)..].strip
62
+
63
+ Gem::Dependency.new(gem[1], requirement.present? ? requirement : '>= 0')
64
+ else
65
+ declaration
66
+ end
67
+ end
68
+
69
+ # Parses build requirements without discarding explicit gem version bounds.
70
+ # @param match [Array<String>] captures with build declarations at index 1
71
+ # @return [Array<Gem::Dependency, String>] gem requirements and RPM package strings
72
+ def parse_build_requires match, *_
73
+ parse_dep(match, preserve_versions: true)
74
+ end
75
+
76
+ # Parses RPM and gem capabilities without losing their declared versions.
77
+ # @param match [Array<String>] captures with capability declarations at index 1
78
+ # @return [Array<Gem::Dependency, String>] typed gem capabilities and RPM strings
79
+ def parse_provides match, *_
80
+ parse_dep(match, preserve_versions: true)
81
+ end
82
+
83
+ # Parses explicit build conflicts for non-gem RPM packages.
84
+ # @param match [Array<String>] captures with dependency declarations at index 1
85
+ # @return [Array<String>] package conflicts with their original version bounds
86
+ # Gem conflicts are excluded because source dependencies and available gem
87
+ # versions determine their regenerated bounds.
88
+ def parse_build_conflicts match, *_
89
+ parse_dep(match).grep(String)
90
+ end
91
+ end