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
@@ -1,5 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Parses RPM metadata while retaining manual sections and feature guards.
1
4
  class Baltix::Spec::Rpm::Parser
2
5
  MATCHER = /^Name:\s+([^\s]+)/i
6
+ SCRIPT_SECTIONS = %w[prep build install check clean conf generate_buildrequires
7
+ pretrans posttrans preuntrans postuntrans preun postun pre post verifyscript
8
+ triggerprein triggerin triggerun triggerpostun filetriggerin filetriggerun
9
+ filetriggerpostun transfiletriggerin transfiletriggerun transfiletriggerpostun].freeze
10
+ SECTION_HEADER = /^%(#{(SCRIPT_SECTIONS + %w[package description files changelog]).join('|')})(?:\s|$)/
11
+
12
+ # File-list directives remain manifest text, even when their arguments contain spaces.
13
+ FILE_DIRECTIVES = %w[attr defattr verify defverify config doc docdir dir ghost
14
+ license exclude lang caps artifact pubkey].freeze
15
+
16
+ DEPENDENCY_TOKEN_GROUPS = { '(' => ')', '{' => '}' }.freeze
17
+
18
+ # The first matching rule handles a character without evaluating its contents.
19
+ # Matchers and actions receive the character, its index and the scanner state.
20
+ # Escape and quote rules precede grouping and whitespace rules so delimiters
21
+ # inside escaped or quoted text remain part of their original token.
22
+ DEPENDENCY_TOKEN_SCHEME = {
23
+ escaped: [
24
+ ->(_character, _index, state) { state[:escaped] },
25
+ ->(_character, _index, state) { state[:escaped] = false }
26
+ ],
27
+ escape: [
28
+ ->(character, _index, _state) { character == '\\' },
29
+ ->(_character, _index, state) { state[:escaped] = true }
30
+ ],
31
+ quote_end: [
32
+ ->(character, _index, state) { character == state[:quote] },
33
+ ->(_character, _index, state) { state[:quote] = nil }
34
+ ],
35
+ quoted: [
36
+ ->(_character, _index, state) { state[:quote] },
37
+ ->(_character, _index, _state) {}
38
+ ],
39
+ quote_start: [
40
+ ->(character, _index, _state) { %q("').include?(character) },
41
+ ->(character, _index, state) { state[:quote] = character }
42
+ ],
43
+ group_start: [
44
+ ->(character, _index, _state) { DEPENDENCY_TOKEN_GROUPS.key?(character) },
45
+ ->(character, _index, state) { state[:closing] << DEPENDENCY_TOKEN_GROUPS[character] }
46
+ ],
47
+ group_end: [
48
+ ->(character, _index, state) { character == state[:closing].last },
49
+ ->(_character, _index, state) { state[:closing].pop }
50
+ ],
51
+ token_end: [
52
+ ->(character, index, state) { character.match?(/\s/) && state[:closing].empty? && state[:start] < index },
53
+ lambda do |_character, index, state|
54
+ state[:tokens] << state[:text][state[:start]...index]
55
+
56
+ state[:start] = index + 1
57
+ end
58
+ ],
59
+ whitespace: [
60
+ ->(character, _index, state) { character.match?(/\s/) && state[:closing].empty? },
61
+ ->(_character, index, state) { state[:start] = index + 1 }
62
+ ],
63
+ text: [
64
+ ->(_character, _index, _state) { true },
65
+ ->(_character, _index, _state) {}
66
+ ]
67
+ }.transform_values(&:freeze).freeze
68
+
69
+ COMMENT_DEPENDENCY_RE = /
70
+ \A([ \t]*\#+[ \t]*
71
+ (?:BuildPreReq|(?:Build)?Requires(?:\([^)]*\))?|(?:Build)?Conflicts|Provides|Obsoletes):[ \t]*)
72
+ (.*?)(?:\r?\n)?\z
73
+ /ix
74
+
75
+ PACKAGE_VERSION_FIELDS = %w[version epoch release].freeze
3
76
 
4
77
  SCHEME = {
5
78
  name: {
@@ -54,13 +127,18 @@ class Baltix::Spec::Rpm::Parser
54
127
  },
55
128
  build_pre_requires: {
56
129
  non_contexted: true,
57
- regexp: /(?:BuildPreReq|BuildRequires\(pre\)):\s+([\w\s<=>\.\-_]+)/i,
130
+ regexp: /^(?:BuildPreReq|BuildRequires\(pre\)):\s*([^#]+)/i,
58
131
  parse_func: :parse_dep
59
132
  },
60
133
  build_requires: {
61
134
  non_contexted: true,
62
135
  regexp: /^BuildRequires:\s*([^#]+)/i,
63
- parse_func: :parse_dep
136
+ parse_func: :parse_build_requires
137
+ },
138
+ build_conflicts: {
139
+ non_contexted: true,
140
+ regexp: /^BuildConflicts:\s*([^#]+)/i,
141
+ parse_func: :parse_build_conflicts
64
142
  },
65
143
  obsoletes: {
66
144
  regexp: /^Obsoletes:\s*([^#]+)/i,
@@ -68,7 +146,7 @@ class Baltix::Spec::Rpm::Parser
68
146
  },
69
147
  provides: {
70
148
  regexp: /^Provides:\s*([^#]+)/i,
71
- parse_func: :parse_dep
149
+ parse_func: :parse_provides
72
150
  },
73
151
  requires: {
74
152
  regexp: /^Requires:\s*([^#]+)/i,
@@ -78,11 +156,32 @@ class Baltix::Spec::Rpm::Parser
78
156
  regexp: /^Conflicts:\s*([^#]+)/i,
79
157
  parse_func: :parse_dep
80
158
  },
81
- ignored_names: {
159
+ ignored_path_tokens: {
160
+ non_contexted: true,
161
+ regexp: /^%(ruby_ignore_path_tokens)\s+([^\s$]+)/i,
162
+ parse_func: :parse_ignore
163
+ },
164
+ regarded_path_tokens: {
82
165
  non_contexted: true,
83
- regexp: /(^%ruby_ignore|--ignore=)\s*([^\s$]+)/i,
166
+ regexp: /^%(ruby_regard_path_tokens)\s+([^\s$]+)/i,
84
167
  parse_func: :parse_ignore
85
168
  },
169
+ use_gem_version_list: {
170
+ non_contexted: true,
171
+ regexp: /^%ruby_use_gem_version\s+([^\s#]+)/i,
172
+ parse_func: :parse_use_gem_versions
173
+ },
174
+ ignored_names: {
175
+ non_contexted: true,
176
+ # Match the complete modern or legacy macro name before reading its list.
177
+ regexp: /(^%ruby_ignore(?:_names)?[ \t]+|(?:^|\s)--ignore=)([^\s]+)/i,
178
+ parse_func: :parse_ignored_names
179
+ },
180
+ regarded_names: {
181
+ non_contexted: true,
182
+ regexp: /(^%ruby_regard_names[ \t]+)([^\s]+)/i,
183
+ parse_func: :parse_ignored_names
184
+ },
86
185
  descriptions: {
87
186
  regexp: /^%description\s*([^\s].*)?/i,
88
187
  parse_func: :parse_description
@@ -123,7 +222,9 @@ class Baltix::Spec::Rpm::Parser
123
222
  },
124
223
  context: {
125
224
  non_contexted: true,
126
- regexp: /^%(?:(?:global|define)|((?!description|package|files)[^\s]+))\s+(?:([^\s]+)\s+([^\s].*)|(.*))/i,
225
+ regexp: /^% (?: (?:global|define) |
226
+ ((?!description|package|files|(?:#{FILE_DIRECTIVES.join('|')})\b)[^\s]+) )
227
+ \s+ (?:([^\s]+)\s+([^\s].*)|(.*))/ix,
127
228
  parse_func: :parse_context
128
229
  },
129
230
  comment: {
@@ -132,281 +233,35 @@ class Baltix::Spec::Rpm::Parser
132
233
  }
133
234
  }.to_os(hash: true)
134
235
 
135
- def source source_in
136
- if source_in.respond_to?(:readlines)
137
- source_in.rewind
138
- source_in.readlines
139
- else
140
- source_in.split("\n")
141
- end
142
- end
143
-
144
- def parse source_in, options = {}
145
- context = {}.to_os
146
- matched = {}.to_os
147
- match = nil
148
- state_in = {
149
- "context" => {
150
- "__options" => options.to_os,
151
- "__custom" => { 'gemname' => '%pkgname' }.to_os
152
- }
153
- }.to_os(hash: true)
154
-
155
- state = source(source_in).reduce(state_in) do |state, line|
156
- SCHEME.find do |key, rule|
157
- match = rule.is_a?(Regexp) && rule.match(line) ||
158
- rule.is_a?(OpenStruct) && rule[:regexp] && rule[:regexp].match(line)
159
-
160
- if match
161
- if matched.name
162
- if matched.name != key
163
- # binding.pry if matched[:match][0] =~ /description/
164
- store_value(state, matched[:match], matched[:name], matched[:flow], context)
165
- matched = { name: key.to_s, flow: "", match: match }.to_os
166
- end
167
- else
168
- matched = { name: key.to_s, flow: "", match: match }.to_os
169
- end
170
- end
171
- end
172
-
173
- if matched.name
174
- if matched.flow
175
- matched.flow << line + "\n"
176
- else
177
- matched.flow = line + "\n"
178
- end
179
- else
180
- matched = { name: "comment", flow: line + "\n", match: [] }.to_os
181
- end
182
-
183
- state
184
- end
185
-
186
- store_value(state, matched.match, matched.name, matched.flow, context)
187
-
188
- #binding.pry
189
- state
190
- end
191
-
192
- def store_value opts, match, key, flow, context
193
- data = SCHEME[key]
194
- rule = data.is_a?(OpenStruct) && data.rule || data
195
- parse_func = data.is_a?(OpenStruct) && data.parse_func || :parse_default
196
- non_contexted = data.is_a?(OpenStruct) && data.non_contexted
197
- reflown = reeval(flow, opts)
198
- rematched = match.to_a.map { |x| x.is_a?(String) && reeval(x, opts) || x }
199
- value = method(parse_func)[rematched, reflown, opts, context]
200
- mode = data.is_a?(OpenStruct) && data.mode || :append
201
- copts = !non_contexted && context.name && opts.secondaries.find do |sec|
202
- #binding.pry
203
- sec.name == Baltix::Spec::Rpm::Name.parse(
204
- context.name,
205
- support_name: opts.name,
206
- aliases: aliased_names(opts))
207
- end || opts
208
- #binding.pry if key =~ /summar/
209
- #binding.pry if context[:kind]
210
- if !non_contexted && context.kind && context.kind.to_s != copts["name"].kind
211
- copts["name"] =
212
- Baltix::Spec::Rpm::Name.parse(copts["name"].original_fullname,
213
- kind: context.kind,
214
- support_name: copts["name"].support_name)
215
- end
216
-
217
- copts[key] =
218
- case copts[key]
219
- when NilClass
220
- value
221
- when Array
222
- copts[key] | [ value.is_a?(OpenStruct) && value || value ].flatten
223
- when OpenStruct
224
- copts[key].deep_merge(value, mode: mode)
225
- else
226
- value
227
- end
228
-
229
- #binding.pry if key =~ /summar/
230
- opts
231
- end
232
-
233
- def secondary_for_context opts, context
234
- opts.secondaries.find do |sec|
235
- #binding.pry
236
- sec.name == Baltix::Spec::Rpm::Name.parse(
237
- context.name,
238
- support_name: opts.name,
239
- aliases: aliased_names(opts))
240
- end
241
- end
242
-
243
- def reeval flow, opts
244
- #binding.pry if flow =~ /%gemname/
245
- [opts.context.__options, opts.context.__macros, opts, opts.context.__custom].compact.reduce(flow) do |reflown_in, source|
246
- source.table.keys.sort_by {|x|x.size}.reverse.reduce(reflown_in) do |reflown, name|
247
- next reflown if /context|__macros|__options/ =~ name
248
- value = source[name]
249
- #binding.pry if flow =~ /%gemname/ && name =~ /%gemname/
250
- r = reflown.dup
251
- r.gsub!(/%({#{name}}|#{name})/, value.to_s) && value.is_a?(String) && /^%/ =~ value ? reeval(r, opts) : r
252
- end
253
- end || raise #flow
254
- end
255
-
256
- def parse_name match, *_
257
- Baltix::Spec::Rpm::Name.parse(match[1])
258
- end
259
-
260
- def parse_comment match, flow, *_
261
- flow
262
- end
263
-
264
- def parse_file match, *_
265
- { match[1] || "0" => match[2] }.to_os
266
- end
267
-
268
- def parse_file_list match, flow, opts, context
269
- kind = {
270
- lib: /ruby_gemspec|ruby_gemlibdir/,
271
- doc: /ruby_gemdocdir/,
272
- exec: /_bindir/,
273
- }.find { |(k, re)| re =~ flow }&.[](0)
274
- context.replace(parse_context_line(match[1], opts).merge(kind: kind))
275
- splitten_flow(flow)
276
- end
277
-
278
- def parse_changes _, flow, *_
279
- rows = flow.split("\n* ").map { |p| p.strip }.compact.map { |p| p.split("\n") }
280
-
281
- rows[1..-1].map do |row|
282
- /(?<date>^\w+\s+\w+\s+\w+\s+\w+)\s+(?<author>.*)\s*(?:<(?<email>.*)>)\s+(?:(?<epoch>[0-9]+):)?(?<version>[\w\.]+)(?:-(?<release>[\w\._]+))?$/ =~ row[0]
283
-
284
- {
285
- date: date,
286
- author: author.strip,
287
- email: email,
288
- version: Gem::Version.new(version),
289
- release: release,
290
- epoch: epoch,
291
- description: row[1..-1].join("\n")
292
- }.to_os
293
- end.reverse
294
- end
295
-
296
- def parse_dep match, *_
297
- deps = match[1].scan(/[^\s]+(?:\s+[<=>]+\s+[^\s]+)?/)
298
- deps.reject {|d| /^(gem|rubygem|ruby-gem)\(/ =~ d }
299
- end
300
-
301
- def parse_ignore match, *_
302
- match[2].split(/,/).map {|x| x =~ /^\/(.*)/ && /#{$1}/ || x }
303
- end
304
-
305
- def parse_default match, *_
306
- match[1]
307
- end
308
-
309
- def parse_plain_section _, flow, *_
310
- splitten_flow(flow)
311
- end
312
-
313
- # secondary without suffix by default has kind of lib
314
- def parse_secondary match, flow, opts, context
315
- context.replace(parse_context_line(match[1], opts))
316
- name = Baltix::Spec::Rpm::Name.parse(context.name, support_name: opts.name, aliases: aliased_names(opts))
317
-
318
- [{ "name" => name, "version" => opts.version, "release" => opts.release, "summaries" => opts.summaries.dup }.to_os ]
319
- end
320
-
321
- def parse_description match, flow, opts, context
322
- context.replace(parse_context_line(match[1], opts))
323
- { context.cp || Baltix::I18n.default_locale => splitten_flow(flow) }.to_os
324
- end
325
-
326
- def parse_license match, *_
327
- match[1].split(/(?: or |\/)/).map(&:strip)
328
- end
236
+ protected
329
237
 
330
- def parse_summary match, _, opts, *_
331
- opts.summary = match[2]
332
- { match[1] || Baltix::I18n.default_locale => match[2] }.to_os
238
+ def splitten_flow flow
239
+ (flow.split("\n").drop(1) || []).join("\n")
333
240
  end
334
241
 
335
- def parse_context match, *_
336
- if match[1]
337
- {
338
- "__macros" => {
339
- match[1] => match[4]&.strip || [match[2], match[3]].compact.join(" ").strip
340
- }
341
- }.to_os(hash: true)
342
- elsif match[2]
343
- {
344
- "__macros" => {
345
- match[2] => match[5]&.strip || [match[3], match[4]].compact.join(" ").strip
346
- }
347
- }.to_os(hash: true)
348
- else
349
- { match[3] => match[4] }.to_os
242
+ class << self
243
+ def match? source_in
244
+ MATCHER =~ source_in
350
245
  end
351
246
  end
247
+ end
352
248
 
353
- def parse_version match, *_
354
- Gem::Version.new(match[1])
355
- end
249
+ require 'baltix/spec/rpm/parser/flow'
356
250
 
357
- def parse_packager match, *_
358
- OpenStruct.new(name: match[1]&.strip, email: match[2]&.strip)
359
- end
251
+ require 'baltix/spec/rpm/parser/sections'
360
252
 
361
- def parse_context_line line, opts
362
- key = nil
363
- context = line.to_s.split(/\s+/).reduce({}.to_os) do |res, arg|
364
- #binding.pry
365
- case arg
366
- when '-l'
367
- key = :cp
368
- when '-n'
369
- key = :fullname
370
- else
371
- case key
372
- when :cp
373
- res.cp = arg
374
- when :fullname
375
- res.name = arg
376
- else
377
- res.name = "#{opts.name}-#{arg}"
378
- end
379
- end
253
+ require 'baltix/spec/rpm/parser/header_dependencies'
380
254
 
381
- res
382
- end
255
+ require 'baltix/spec/rpm/parser/file_sections'
383
256
 
384
- if context.name
385
- opts.secondaries ||= []
386
- # name = Baltix::Spec::Rpm::Name.parse(context[:name])
387
- # binding.pry
388
- # sel = opts["secondaries"].select { |sec| sec.name == name }
257
+ require 'baltix/spec/rpm/parser/values'
389
258
 
390
- # opts["secondaries"] << { "name" => name }.to_os if sel.blank?
391
- end
392
- # binding.pry
259
+ require 'baltix/spec/rpm/parser/macros'
393
260
 
394
- context
395
- end
261
+ require 'baltix/spec/rpm/parser/dependencies'
396
262
 
397
- def aliased_names opts
398
- opts.context.__options&.aliased_names
399
- end
400
-
401
- protected
263
+ require 'baltix/spec/rpm/parser/comments'
402
264
 
403
- def splitten_flow flow
404
- (flow.split("\n")[1..-1] || []).join("\n")
405
- end
265
+ require 'baltix/spec/rpm/parser/context'
406
266
 
407
- class << self
408
- def match? source_in
409
- MATCHER =~ source_in
410
- end
411
- end
412
- end
267
+ require 'baltix/spec/rpm/parser/metadata'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Applies exec switches to generated commands and pages while retaining manual package files.
4
+ class Baltix::Spec::Rpm
5
+ def exec_file_guards package
6
+ return [] if part_switch(package) == 'exec'
7
+
8
+ compile_guard_paths([['%if_enabled exec']], outer_depth: section_guards_for(package, :files).size)
9
+ end
10
+
11
+ def exec_file_entries package
12
+ package.executables.map {|file| "%_bindir/#{file}" } + manpage_entries(package) +
13
+ preserved_exec_manpages(package)
14
+ end
15
+
16
+ def part_preserved_files package
17
+ files = preserved_files(package)
18
+
19
+ return files unless package.is_exec?
20
+
21
+ without_empty_exec_guards(files.map {|line| exec_feature_reference(line) } - preserved_exec_manpages(package))
22
+ end
23
+
24
+ def plugin_file_name package
25
+ return unless package.is_lib? && package.source.is_a?(Baltix::Source::Gem) &&
26
+ package.source.rubygems_plugin_file
27
+
28
+ "%ruby_gemsplugindir/#{package.source.name}_plugin.rb"
29
+ end
30
+
31
+ protected
32
+
33
+ def manual_exec_part? package
34
+ part_preserved_files(package).any? {|line| !line.lstrip.start_with?('#') }
35
+ end
36
+
37
+ def without_empty_exec_guards lines
38
+ lines.each_with_object([]) do |line, retained|
39
+ if line.strip == '%endif' && exec_guard_line?(retained.last)
40
+ retained.pop
41
+ else
42
+ retained << line
43
+ end
44
+ end
45
+ end
46
+
47
+ def exec_guard_line? line
48
+ line&.match?(/^%if_enabled\s+exec\s*$/) || line&.strip == '%if 0%{?_enable_exec:1}'
49
+ end
50
+
51
+ def preserved_exec_manpages package
52
+ preserved_files(package).select {|line| exec_manpage_entry?(package, line) }
53
+ end
54
+
55
+ def exec_manpage_entry? package, line
56
+ return false if line.lstrip.start_with?('#') || !package.source.is_a?(Baltix::Source::Gem)
57
+
58
+ pattern = line[%r{%(?:_mandir|\{_mandir\})/\S+}]&.sub('%{_mandir}', '%_mandir')
59
+
60
+ return false unless pattern
61
+
62
+ rpm_manual_paths(package.source).flatten.any? {|file| retained_manpage?(file, [pattern]) }
63
+ end
64
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Replaces only the generated part-macro prelude and its otherwise empty guards.
4
+ class Baltix::Spec::Rpm
5
+ protected
6
+
7
+ def without_part_prelude script
8
+ lines = script.lines.map(&:chomp)
9
+
10
+ lines.shift while lines.first&.start_with?(DISABLED_PARTS_EXPORT)
11
+
12
+ lines.drop(part_prelude_size(lines)).join("\n")
13
+ end
14
+
15
+ def part_prelude_size lines
16
+ depth = 0
17
+
18
+ lines.each_with_index do |line, index|
19
+ case part_prelude_line(line)
20
+ when :macro then return closing_part_guards?(lines, index, depth) ? index + depth + 1 : 0
21
+ when :open then depth += 1
22
+ when :branch then return 0 if depth.zero?
23
+ else return 0
24
+ end
25
+ end
26
+
27
+ 0
28
+ end
29
+
30
+ def part_prelude_line line
31
+ return :macro if line.strip == LEGACY_PARTS_MACRO
32
+ return :open if SectionDocument::IF.match?(line)
33
+ return :branch if SectionDocument::BRANCH.match?(line)
34
+
35
+ :other
36
+ end
37
+
38
+ def closing_part_guards? lines, index, depth
39
+ closing = lines.slice(index + 1, depth)
40
+
41
+ closing && closing.size == depth && closing.all? {|line| line.strip == '%endif' }
42
+ end
43
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Removes previous generated script scaffolding without changing custom commands.
4
+ class Baltix::Spec::Rpm
5
+ def part_selection_script section
6
+ script = preserved_script(section)
7
+
8
+ return script unless part_selection_supported?
9
+
10
+ without_part_prelude(script)
11
+ end
12
+
13
+ def check_script
14
+ script = preserved_script(:check)
15
+
16
+ return script unless check_guarded_script?(script)
17
+
18
+ script.lines.map(&:chomp).drop(1).tap(&:pop).join("\n")
19
+ end
20
+
21
+ protected
22
+
23
+ def check_guarded_script? script
24
+ lines = script.lines.filter_map {|line| line.strip unless line.strip.empty? }
25
+
26
+ return false unless lines.first&.match?(/^%if_enabled\s+check$/)
27
+
28
+ depth = 0
29
+
30
+ lines.each_with_index do |line, index|
31
+ depth = check_condition_depth(line, depth)
32
+
33
+ return false unless continuing_check_guard?(line, depth, index == lines.size - 1)
34
+ end
35
+
36
+ depth.zero?
37
+ end
38
+
39
+ def check_condition_depth line, depth
40
+ if SectionDocument::IF.match?(line)
41
+ depth + 1
42
+ elsif SectionDocument::ENDIF.match?(line)
43
+ depth - 1
44
+ else
45
+ depth
46
+ end
47
+ end
48
+
49
+ def continuing_check_guard? line, depth, last
50
+ (depth.positive? || last) && !(depth == 1 && SectionDocument::BRANCH.match?(line))
51
+ end
52
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Derives optional RPM parts from current source metadata and forwards build switches to setup.
4
+ class Baltix::Spec::Rpm
5
+ PART_SWITCHES = { doc: 'doc', devel: 'devel', exec: 'exec' }.freeze
6
+ DISABLED_PARTS_EXPORT = 'export RPM_RUBY_DISABLED_PARTS='
7
+ LEGACY_PARTS_MACRO = '%baltix_without_parts'
8
+
9
+ def part_switch package
10
+ return if package.source.is_a?(Baltix::Source::Fake)
11
+ return if package.is_exec? && manual_exec_part?(package)
12
+
13
+ PART_SWITCHES[package.kind]
14
+ end
15
+
16
+ def has_part? kind
17
+ valid_secondaries.any? {|package| package.kind == kind && !package.source.is_a?(Baltix::Source::Fake) }
18
+ end
19
+
20
+ def optional_parts
21
+ build_parts = optional_build_dependency_parts.values.flatten
22
+
23
+ PART_SWITCHES.keys.filter_map {|kind| kind.to_s if has_part?(kind) || build_parts.include?(kind) } +
24
+ (has_checks? ? ['check'] : [])
25
+ end
26
+
27
+ def has_checks?
28
+ has_check_requires? || has_check_conflicts? ||
29
+ sources.any? {|item| item.testfiles.any? || setup_test_script?(item) } || custom_check_script?
30
+ end
31
+
32
+ protected
33
+
34
+ def part_selection_supported?
35
+ sources.any? {|item| !item.is_a?(Baltix::Source::Fake) && File.file?(item.source_file.to_s) }
36
+ end
37
+
38
+ def setup_test_script? item
39
+ %w[.setup/test.rb .setup/test.sh .setup/testrc.rb].any? {|path| File.file?(File.join(item.rootdir, path)) }
40
+ end
41
+
42
+ def custom_check_script?
43
+ script = preserved_script(:check)
44
+
45
+ script.lines.any? do |line|
46
+ !line.strip.empty? && !line.match?(/^\s*(?:#|%ruby_test\s*(?:#.*)?$|%if\w*\b|%else\b|%endif\b)/)
47
+ end
48
+ end
49
+
50
+ def part_macro_prerequisite? tag, dependency
51
+ tag == 'BuildRequires(pre)' && dependency.split.first == 'rpm-macros-ruby' && part_selection_supported?
52
+ end
53
+
54
+ def _part_selection_prerequisites value
55
+ return value unless part_selection_supported?
56
+
57
+ prerequisites = plain_prerequisites(value)
58
+
59
+ prerequisites.delete('setup-rb')
60
+ prerequisites.delete('rpm-macros-ruby')
61
+
62
+ grouped_prerequisites((prerequisites + ['setup-rb >= 5.999.15', 'rpm-macros-ruby >= 1:3.3.12-alt6']).uniq,
63
+ of_default(:build_pre_requires).flat_map(&:split))
64
+ end
65
+ end