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,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Preserves structured OpenStruct values while applying the public deep-merge modes.
4
+ module Extensions::OpenStruct
5
+ # +deep_merge+ deeply merges the Open Struct hash structure with the +other_in+ enumerating it key by key.
6
+ # +options+ are the options to change behaviour of the method. It allows two keys: :mode, and :dedup
7
+ # :mode can be :append, :prepend, or :replace. Append combines duplicate values
8
+ # into an array; prepend puts the incoming value before the stored value.
9
+ # when :replace it replace duplicate values with a last ones.
10
+ # :dedup key can be true, or false. It allows to deduplicate values when appending or prepending values.
11
+ # Examples:
12
+ # open_struct.deep_merge(other_open_struct)
13
+ # open_struct.deep_merge(other_open_struct, :prepend)
14
+ #
15
+ def deep_merge other_in, options_in = {}
16
+ return self if other_in.nil? || other_in.blank?
17
+
18
+ options = { mode: :replace }.merge(options_in)
19
+ other = baltix_merge_input(other_in)
20
+
21
+ other.reduce(to_os.dup) do |result, key, value|
22
+ result[key] = result.table.key?(key) ? baltix_merge_value(result[key], value, options) : value
23
+
24
+ result
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def baltix_merge_input other
31
+ case other
32
+ when ::OpenStruct then other.deep_dup
33
+ when ::Hash then other.to_os
34
+ else ::OpenStruct.new(nil => other.dup)
35
+ end
36
+ end
37
+
38
+ def baltix_merge_value previous, value, options
39
+ case value
40
+ when ::Hash then previous.to_os.deep_merge(value.to_os, options).to_h.transform_keys(&:to_s)
41
+ when ::OpenStruct then value.deep_merge(previous.to_os, options)
42
+ when ::Array then value | baltix_flat_values(previous)
43
+ when ::NilClass then previous
44
+ else baltix_merge_scalar(previous, value, options)
45
+ end
46
+ end
47
+
48
+ def baltix_merge_scalar previous, value, options
49
+ result =
50
+ case options[:mode]
51
+ when :append then baltix_flat_values(value, previous).uniq
52
+ when :prepend then baltix_flat_values(previous, value).uniq
53
+ else value
54
+ end
55
+
56
+ result.is_a?(::Array) && options[:dedup] ? result.uniq : result
57
+ end
58
+
59
+ def baltix_flat_values *values
60
+ values.compact.tap {|items| items.flatten!(1) }
61
+ end
62
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Derives interpreter commands from executable shebangs.
4
+ class Baltix::Deps
5
+ def deps_ruby_exec target
6
+ lines = target.public_executables.filter_map {|file| executable_first_line(target.root, file) }
7
+
8
+ lines.uniq.map! {|line| shebang_command(line) }.tap(&:uniq!)
9
+ end
10
+
11
+ def executable_first_line root, file
12
+ path = File.join(root, file)
13
+
14
+ if File.symlink?(path)
15
+ File.read(File.join(root, File.readlink(path)), mode: 'rb').split("\n").first
16
+ elsif File.exist?(path)
17
+ File.read(path, mode: 'rb').split("\n").first
18
+ end
19
+ end
20
+
21
+ def shebang_command line
22
+ match = /#!\s*(?<exec>\S+)/.match(line)
23
+
24
+ return match[:exec] if match
25
+
26
+ warn("Invalid shebang line '#{line}'")
27
+
28
+ nil
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'baltix/concerns'
4
+
5
+ # Reads the same package dependency values used by the RPM template.
6
+ class Baltix::Deps::Packages
7
+ include Baltix::Concerns::Parts
8
+
9
+ def initialize space
10
+ @space = space
11
+ end
12
+
13
+ def packages
14
+ spec = @space.spec
15
+ selected = [spec, *spec.valid_secondaries].select {|package| enabled?(package) }
16
+ name = @space.options.package
17
+
18
+ name ? selected.select {|package| package.name.to_s == name } : selected
19
+ end
20
+
21
+ def lists kind
22
+ packages.to_h {|package| [package.name.to_s, package.public_send(kind).reject(&:blank?).tap(&:uniq!)] }
23
+ end
24
+
25
+ def enabled? package
26
+ part = @space.spec.part_switch(package)
27
+
28
+ return part_enabled?(@space.options, part) if part
29
+
30
+ !@space.options[:"no_#{package.kind}"]
31
+ end
32
+ end
data/lib/baltix/deps.rb CHANGED
@@ -1,108 +1,119 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'baltix'
2
4
 
5
+ # Builds and converts dependency requirements for package kinds.
3
6
  class Baltix::Deps
4
- attr_reader :project
7
+ attr_reader :space
5
8
 
6
9
  REQS = {
7
10
  'lib' => {
8
- proc { |target| target.source.compilable? } => proc { |this| this.deps_ruby_version },
9
- proc { |target| target.source.valid? } => proc { |this, target| this.deps_dyno(target.source, 'lib', :dsl) },
11
+ proc {|target| target.source.compilable? } => proc(&:deps_ruby_version),
12
+ proc {|target| target.source.valid? } => proc {|this, target|
13
+ this.deps_dyno(target.source, 'lib', :dsl)
14
+ }
10
15
  },
11
16
  'bin' => {
12
- proc { |target| target.public_executables.any? } => proc { |this, target| this.deps_ruby_exec(target) },
13
- proc { |target| target.source.exefiles.any? &&
14
- target.source.is_a?(Baltix::Source::Gem) } => proc { |this, target| this.deps_dyno(target.source, 'bin', :dsl) },
17
+ proc {|target| target.public_executables.any? } => proc {|this, target|
18
+ this.deps_ruby_exec(target)
19
+ },
20
+ proc {|target|
21
+ target.source.exefiles.any? &&
22
+ target.source.is_a?(Baltix::Source::Gem)
23
+ } => proc {|this, target|
24
+ this.deps_dyno(target.source, 'bin', :dsl)
25
+ }
15
26
  },
16
27
  'doc' => {
17
- proc { |target| target.source.is_a?(Baltix::Source::Gem) } => proc { |this, target| this.deps_dyno(target.source, 'doc') },
28
+ proc {|target| target.source.is_a?(Baltix::Source::Gem) } => proc {|this, target|
29
+ this.deps_dyno(target.source, 'doc')
30
+ }
18
31
  },
19
32
  'devel' => {
20
- proc { |target|
33
+ proc {|target|
21
34
  target.source.is_a?(Baltix::Source::Gem) &&
22
35
  (target.source.inctree.any? ||
23
- target.source.dsl.original_deps.any?) } => proc { |this, target| this.deps_dyno(target.source, 'devel', :dsl) },
36
+ target.source.dsl.original_deps.any?)
37
+ } => proc {|this, target|
38
+ this.deps_dyno(target.source, 'devel', :dsl)
39
+ }
24
40
  }
25
- }
41
+ }.freeze
26
42
 
27
43
  PROVS = {
28
44
  'lib' => {
29
- proc { |target| target.source.is_a?(Baltix::Source::Gem) } => proc { |this, target| this.deps_gem_ext(target.source) },
45
+ proc {|target| target.source.is_a?(Baltix::Source::Gem) } => proc {|this, target|
46
+ this.deps_gem_ext(target.source)
47
+ }
30
48
  },
31
49
  'bin' => {
32
- proc { |target| target.public_executables.any? } => proc { |this, target| this.deps_execs(target) },
33
- },
34
- }
50
+ proc {|target| target.public_executables.any? } => proc {|this, target| this.deps_execs(target) }
51
+ }
52
+ }.freeze
35
53
 
36
54
  def targets
37
- if name = project.config.current_package_name
38
- project.targets.select { |target| target.source.has_name?(name) }
55
+ if (name = space.config.current_package_name)
56
+ space.targets.select {|target| target.source.has_name?(name) }
39
57
  else
40
- project.targets
58
+ space.targets
41
59
  end
42
60
  end
43
61
 
44
62
  def target_provs target, sets_in = nil
45
- sets = sets_in && [ sets_in ].flatten || PROVS.keys
63
+ target_sets(PROVS, target, sets_in)
64
+ end
46
65
 
47
- PROVS.select { |set, _| sets.include?(set) }.map do |set, data|
48
- provs = data.map do |cond_in, prov_in|
49
- cond = cond_in.is_a?(Proc) ? cond_in[target] : cond_in
50
- cond && (prov_in.is_a?(Proc) && prov_in[self, target] || prov_in) || []
51
- end.flatten
66
+ def target_sets rules, target, sets_in
67
+ sets = sets_in && [sets_in].flatten || rules.keys
52
68
 
53
- [ set, provs ]
54
- end.to_h
69
+ rules.slice(*sets).transform_values do |data|
70
+ data.map {|condition, value| dynamic_value(condition, target) && dynamic_value(value, self, target) || [] }
71
+ .tap(&:flatten!)
72
+ end
55
73
  end
56
74
 
57
- def target_reqs target, sets_in = nil
58
- sets = sets_in && [ sets_in ].flatten || REQS.keys
59
-
60
- #require 'pry'; binding.pry
61
- REQS.select { |set, _| sets.include?(set) }.map do |set, data|
62
- reqs = data.map do |cond_in, req_in|
63
- cond = cond_in.is_a?(Proc) ? cond_in[target] : cond_in
64
- cond && (req_in.is_a?(Proc) && req_in[self, target] || req_in) || []
65
- end.flatten
75
+ def dynamic_value value, *args
76
+ value.is_a?(Proc) ? value[*args] : value
77
+ end
66
78
 
67
- [ set, reqs.uniq ]
68
- end.to_h
79
+ def target_reqs target, sets_in = nil
80
+ target_sets(REQS, target, sets_in).transform_values(&:uniq)
69
81
  end
70
82
 
71
83
  ## deps
72
84
  def deps_gem_dsl dsl, set = 'lib'
73
- deps =
74
- case set
75
- when 'bin'
76
- dsl.runtime_deps(:gemfile)
77
- when 'devel'
78
- dsl.development_deps(:gemspec)
79
- else
80
- dsl.runtime_deps(:gemspec)
85
+ list =
86
+ gem_dsl_dependencies(dsl, set).map do |dependency|
87
+ (["#{prefix}(#{dependency.name})"] | self.class.lower_to_rpm(dependency.requirement)).join(' ')
81
88
  end
82
89
 
83
- list = []
90
+ return list unless /lib|bin/.match?(set)
84
91
 
85
- deps.each do |dep|
86
- list << (["#{prefix}(#{dep.name})"] | self.class.lower_to_rpm(dep.requirement)).join(" ")
87
- end
92
+ list |= interpreter_dependencies(dsl)
88
93
 
89
- if /lib|bin/ =~ set
90
- list |=
91
- dsl.required_ruby_version.requirements.map do |(cond, ver)|
92
- self.class.lower_to_rpm(Gem::Requirement.new("#{cond} #{ver}"))
93
- end.reject {|x| x.blank? }.map do |req|
94
- [dsl.required_ruby] | req
95
- end.map {|x| x.join(" ") }
96
- list << "rubygems #{dsl.required_rubygems_version}"
94
+ list << "rubygems #{dsl.required_rubygems_version}"
95
+ end
96
+
97
+ def gem_dsl_dependencies dsl, set
98
+ case set
99
+ when 'bin' then dsl.runtime_deps(:gemfile)
100
+ when 'devel' then dsl.development_deps(:gemspec)
101
+ else dsl.runtime_deps(:gemspec)
97
102
  end
103
+ end
104
+
105
+ def interpreter_dependencies dsl
106
+ dsl.required_ruby_version.requirements.filter_map do |condition, version|
107
+ requirement = self.class.lower_to_rpm(Gem::Requirement.new("#{condition} #{version}"))
98
108
 
99
- list
109
+ ([dsl.required_ruby] | requirement).join(' ') unless requirement.blank?
110
+ end
100
111
  end
101
112
 
102
113
  def deps_ruby_version
103
- # TODO enable when fix for new version ruby rebuld
104
- #"ruby(#{RbConfig::CONFIG['ruby_version']})"
105
- ""
114
+ # TODO: enable when fix for new version ruby rebuld
115
+ # "ruby(#{RbConfig::CONFIG['ruby_version']})"
116
+ ''
106
117
  end
107
118
 
108
119
  def deps_gem source
@@ -110,41 +121,22 @@ class Baltix::Deps
110
121
  end
111
122
 
112
123
  def deps_gem_ext source
113
- %w(gem).map do |kind|
124
+ %w[gem].map do |kind|
114
125
  "#{kind}(#{source.name}) = #{source.version}"
115
126
  end
116
127
  end
117
128
 
118
129
  def deps_dyno source, set, kind = nil
119
- root = project.config.dep_sources[set]
130
+ root = space.config.dep_sources[set]
120
131
  name = (root[source.name] || root[nil]).first
121
- if name == 'auto'
122
- kind == :dsl && deps_gem_dsl(source.dsl, set) || deps_gem(source)
123
- else
124
- project.select_source(name).map do |source|
125
- deps_gem_dsl(source.dsl)
126
- end
127
- end
132
+
133
+ return automatic_dependencies(source, set, kind) if name == 'auto'
134
+
135
+ space.select_source(name).map {|selected| deps_gem_dsl(selected.dsl) }
128
136
  end
129
137
 
130
- def deps_ruby_exec target
131
- target.public_executables.map do |file|
132
- File.join(target.root, file)
133
- end.map do |file|
134
- if File.symlink?(file)
135
- realfile = File.readlink(file)
136
- IO.read(File.join(target.root, realfile), mode: 'rb').split("\n").first
137
- elsif File.exist?(file)
138
- IO.read(file, mode: 'rb').split("\n").first
139
- end
140
- end.compact.uniq.map do |line|
141
- if match = /#!\s*(?<exec>\S+)/.match(line)
142
- match[:exec]
143
- else
144
- $stderr.puts "Invalid shebang line '#{line}'"
145
- nil
146
- end
147
- end.uniq
138
+ def automatic_dependencies source, set, kind
139
+ kind == :dsl ? deps_gem_dsl(source.dsl, set) : deps_gem(source)
148
140
  end
149
141
 
150
142
  def deps_execs target
@@ -153,128 +145,45 @@ class Baltix::Deps
153
145
 
154
146
  # common
155
147
  def deps type, set = nil
156
- $stderr.puts "* #{type} ->"
148
+ warn("* #{type} ->")
157
149
 
158
- method = method("target_#{type}")
150
+ reader = method("target_#{type}")
159
151
 
160
- deps = targets.map do |target|
161
- $stderr.puts " - [#{target.source.name}]"
152
+ targets.to_h do |target|
153
+ warn(" - [#{target.source.name}]")
162
154
 
163
- target_deps = method[target, set].each do |set, deps|
164
- if !deps.empty?
165
- $stderr.puts " [#{set}]:"
166
- deps.each do |dep|
167
- $stderr.puts " #{dep}"
168
- end
169
- end
170
- end
155
+ dependencies = reader[target, set]
171
156
 
172
- [ target.source.name, target_deps ]
173
- end.to_h
174
- end
175
-
176
- def reqs
177
- deps 'reqs', project.config.current_set
178
- end
179
-
180
- def provs
181
- deps 'provs', project.config.current_set
182
- end
157
+ dependencies.each {|group, values| log_dependency_group(group, values) }
183
158
 
184
- class << self
185
- def lower_to_rpm req
186
- req.requirements.reduce([]) do |res, r|
187
- merge(res, debound(r))
188
- end
159
+ [target.source.name, dependencies]
189
160
  end
161
+ end
190
162
 
191
- def upper_negate_to_rpm req
192
- req.requirements.reduce([]) do |res, r|
193
- merge(res, negate(r))
194
- end
195
- end
163
+ def log_dependency_group group, dependencies
164
+ return if dependencies.empty?
196
165
 
197
- # TODO for requirement
198
- # +debound+ crop upper limitation bound from the requirement rule
199
- #
200
- def debound req
201
- ver = Gem::Version.new("#{req[1]}".gsub(/x/, '0'))
202
-
203
- case req[0]
204
- when "~>"
205
- ['>=', ver.release]
206
- when ">=", ">", "="
207
- [req[0], ver.release]
208
- when "!="
209
- ['>', ver.release]
210
- else
211
- nil
212
- end
213
- end
166
+ warn(" [#{group}]:")
214
167
 
215
- # TODO for requirement
216
- # +negate+ megates requirement rule
217
- #
218
- def negate req
219
- ver = Gem::Version.new("#{req[1]}".gsub(/x/, '0'))
220
-
221
- case req[0]
222
- when "~>"
223
- ['>=', ver.bump]
224
- when "<"
225
- ['>=', ver.release]
226
- when "<="
227
- ['>', ver.release]
228
- else
229
- nil
230
- end
231
- end
168
+ dependencies.each {|dependency| warn(" #{dependency}") }
169
+ end
232
170
 
233
- # TODO for requirement
234
- # +merge+ enstricts requirement
235
- # >= 4 & >= 5 => >= 5
236
- # > 5 ^ > 4 => > 5
237
- #
238
- # > 5 & >= 4 => > 5
239
- # > 4 & >= 4 => > 4
240
- # > 4 & >= 4.x => >= 4.x
241
- #
242
- # >= 4 & > 4 => > 4
243
- # >= 4 & > 5 => > 5
244
- # >= 5 & > 4 => >= 5
245
- #
246
- MERGE_CONDS = {
247
- ">=" => {
248
- code: -1,
249
- }
250
- }
171
+ def reqs
172
+ deps('reqs', space.config.current_set)
173
+ end
251
174
 
252
- def merge req1, req2
253
- return req1 if req2.blank?
254
- return req2 if req1.blank?
255
-
256
- m = [req1[1], req2[1]].max
257
-
258
- if req1[0] == req2[0]
259
- [req1[0], m]
260
- elsif req1[0] == ">="
261
- req1[1] <= req2[1] ? [">", m] : [">=", m]
262
- elsif req1[0] == ">"
263
- req1[1] >= req2[1] ? [">", m] : [">=", m]
264
- elsif %w(= < <=).include?(req1[0])
265
- # unsupported
266
- req2
267
- else
268
- # unsupported
269
- req1
270
- end
271
- end
175
+ def provs
176
+ deps('provs', space.config.current_set)
272
177
  end
273
178
 
274
179
  protected
275
180
 
276
- def initialize project: raise, options: {}
277
- @project = project
181
+ def initialize space: raise, options: {}
182
+ @space = space
278
183
  @options = options
279
184
  end
280
185
  end
186
+
187
+ require 'baltix/spec/rpm/deps'
188
+
189
+ require 'baltix/deps/executables'
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Selects dependencies by their original metadata groups and supported package phases.
4
+ class Baltix::DSL
5
+ # Selects original dependencies for the requested package kinds.
6
+ # @param kinds_in [Symbol, Array<Symbol>, nil] runtime, development or other kinds
7
+ # @return [Array<Bundler::Dependency>] matching dependencies on supported platforms
8
+ # Custom groups use the default development/test mapping.
9
+ def original_deps_for kinds_in = nil
10
+ original_deps.select do |dep|
11
+ self.class.match_kind_dep(dep, kinds_in) &&
12
+ (dep.platforms.blank? || dep.platforms.any? {|p| PLATFORMS[p] })
13
+ end
14
+ end
15
+
16
+ # Selects merged dependencies by included and excluded package kinds.
17
+ # @param kinds_in [Symbol, Array<Symbol>] kinds to include
18
+ # @param kinds_out [Symbol, Array<Symbol>] kinds whose dependencies are excluded
19
+ # @return [Array<Bundler::Dependency>] matching dependencies on supported platforms
20
+ # Custom groups use the default development/test mapping; exclusions take priority.
21
+ def all_dependencies_for kinds_in: [], kinds_out: []
22
+ all_dependencies.select do |dep|
23
+ self.class.match_kind_dep(dep, kinds_in) && !self.class.match_kind_dep(dep, kinds_out) &&
24
+ (dep.platforms.blank? || dep.platforms.any? {|p| PLATFORMS[p] })
25
+ end
26
+ end
27
+
28
+ def original_deps
29
+ @original_deps ||=
30
+ all_dependencies.filter_map do |dep|
31
+ type = dep.groups.filter_map {|g| GROUP_MAPPING[g] }.flatten.tap(&:uniq!).min || dep.type
32
+
33
+ dep.instance_variable_set(:@type, type)
34
+
35
+ valid = !dep.source.is_a?(Bundler::Source::Path)
36
+
37
+ valid && dep || nil
38
+ end
39
+ end
40
+
41
+ def runtime_deps kind = :gemspec
42
+ if kind == :gemspec
43
+ deps_but(extracted_gemspec_runtime_deps)
44
+ else
45
+ deps_but(original_deps_for(:runtime))
46
+ end
47
+ end
48
+
49
+ def development_deps _kind = :gemspec
50
+ deps_but(original_deps_for(:devel))
51
+ end
52
+
53
+ def dependencies type = nil
54
+ if type
55
+ self.class.merge_dependencies(*self.class.filter_dependencies(type, definition.dependencies,
56
+ spec&.dependencies))
57
+ else
58
+ self.class.merge_dependencies(definition.dependencies, spec&.dependencies)
59
+ end
60
+ end
61
+
62
+ def deps
63
+ deps_but(original_deps) | gemspec_deps
64
+ end
65
+
66
+ def gemspec_deps
67
+ gemspecs.map do |gs|
68
+ version = gs.version || Gem::Version.new(0)
69
+
70
+ Gem::Dependency.new(gs.name, Gem::Requirement.new(["= #{version}"]), :devel)
71
+ end
72
+ end
73
+
74
+ def deps_for kinds_in = nil
75
+ deps_but(original_deps_for(kinds_in)) | gemspec_deps
76
+ end
77
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Combines source declarations after excluding unsupported platform variants.
4
+ class Baltix::DSL
5
+ def external_dependencies
6
+ return [] unless source_file
7
+
8
+ dir = File.dirname(source_file)
9
+
10
+ (Gem::DependencyInstaller.instance_variable_get(:@deps) || []).filter_map do |(path, dep)|
11
+ Bundler::Dependency.new(dep.name, dep.requirement, 'group' => :development) if path[0...dir.size] == dir
12
+ end
13
+ end
14
+
15
+ def spec_dependencies
16
+ gemspecs.flat_map(&:dependencies).map do |dep|
17
+ group_in = :test
18
+ options = {
19
+ 'group' => dep.type == :development ? [group_in] : [:runtime, group_in],
20
+ 'platforms' => dep.respond_to?(:platforms) ? dep.platforms : []
21
+ }
22
+
23
+ Bundler::Dependency.new(dep.name, dep.requirement, options)
24
+ end
25
+ end
26
+
27
+ # Merges dependencies after excluding unsupported platform declarations.
28
+ # Takes no parameters.
29
+ # @return [Array<Bundler::Dependency>] constraints from supported platforms
30
+ # Platform filtering precedes merging: a repeated JRuby-only declaration must
31
+ # not become an unrestricted dependency when its groups and bounds are merged.
32
+ def all_dependencies
33
+ lists =
34
+ [additional_dependencies, external_dependencies, gemfile_dependencies,
35
+ spec_dependencies].map do |dependencies|
36
+ Array(dependencies).select {|dependency| self.class.platform_allowed?(dependency) }
37
+ end
38
+
39
+ Baltix::DSL.merge_dependencies(*lists)
40
+ end
41
+
42
+ # Returns Gemfile dependencies with groups appropriate to the project type.
43
+ # Takes no parameters and returns an Array of Bundler::Dependency objects.
44
+ # If a gemspec is present, default Gemfile dependencies are copied into the
45
+ # gemfile group for development, binaries and tests; explicit groups are
46
+ # preserved. If there is no gemspec,
47
+ # returns the original dependencies so application runtime groups are kept.
48
+ # If every inferred platform of a dependency is ignored by skip_platforms,
49
+ # that Gemfile dependency is omitted before dependencies are merged.
50
+ def gemfile_dependencies
51
+ return dsl.dependencies if gemspecs.empty?
52
+
53
+ dsl.dependencies.filter_map do |dependency|
54
+ gemfile_dependency(dependency) unless inferred_platforms_ignored?(dependency.name)
55
+ end
56
+ end
57
+
58
+ def inferred_platforms_ignored? name
59
+ platforms = @dependency_platforms[name]
60
+
61
+ platforms && !platforms.empty? && platforms.all? {|platform| ignored_dependency_platform?(platform) }
62
+ end
63
+
64
+ def gemfile_dependency dependency
65
+ dependency.dup.tap do |copy|
66
+ copy.groups = dependency.groups.map {|group| group == :default ? :gemfile : group }.tap(&:uniq!)
67
+ end
68
+ end
69
+
70
+ # Checks an inferred gemspec platform against the configured ignore list.
71
+ # @param platform [Gem::Platform] a platform declared by a gemspec variant
72
+ # @return [Boolean] true when the platform matches an ignored OS or platform
73
+ # If an entry is jruby, it matches the Java OS. Other entries match an OS
74
+ # prefix (mingw includes mingw32) or the complete platform string.
75
+ def ignored_dependency_platform? platform
76
+ @skip_platforms.any? do |ignored|
77
+ name = ignored.to_s
78
+
79
+ if name == 'jruby'
80
+ platform.os == 'java'
81
+ else
82
+ platform.os.to_s.start_with?(name) || platform.to_s == name
83
+ end
84
+ end
85
+ end
86
+
87
+ def gemspecs
88
+ spec ? [spec] : dsl.gemspecs
89
+ end
90
+
91
+ def extracted_gemspec_deps
92
+ gemspecs.map(&:dependencies).tap(&:flatten!).tap(&:uniq!)
93
+ end
94
+
95
+ def extracted_gemspec_runtime_deps
96
+ gemspecs.map do |gs|
97
+ gs.dependencies.select(&:runtime?)
98
+ end.tap(&:flatten!).tap(&:uniq!)
99
+ end
100
+ end