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.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/README.md +136 -10
- data/Rakefile +8 -3
- data/baltix.gemspec +47 -29
- data/bin/console +4 -3
- data/data/alt-licenses/README.md +26 -0
- data/data/alt-licenses/licenses.json +2991 -0
- data/data/alt-rpm/README.md +21 -0
- data/data/alt-rpm/architectures.json +613 -0
- data/data/spdx/README.md +22 -0
- data/data/spdx/licenses.json +9287 -0
- data/docs/action-flow.md +42 -0
- data/docs/actor-integration.md +71 -0
- data/docs/alt-architectures.md +27 -0
- data/docs/cleanup-actors.md +14 -0
- data/docs/dependency-actions.md +22 -0
- data/docs/installation-actors.md +35 -0
- data/docs/pkglist.md +56 -0
- data/docs/plans/revision-003.md +328 -0
- data/docs/plans/revision-004.md +416 -0
- data/docs/plans/revision-005.md +431 -0
- data/docs/plans/revision-006.md +439 -0
- data/docs/plans/revision-007.md +441 -0
- data/docs/plans/revision-008.md +445 -0
- data/docs/plans/revision-009.md +450 -0
- data/docs/plans/revision-010.md +486 -0
- data/docs/plans/revision-011.md +500 -0
- data/docs/plans/revision-012.md +501 -0
- data/docs/plans/revision-013.md +501 -0
- data/docs/plans/revision-014.md +501 -0
- data/docs/plans/revision-015.md +502 -0
- data/docs/plans/revision-016.md +503 -0
- data/docs/plans/revision-017.md +504 -0
- data/docs/plans/revision-018.md +505 -0
- data/docs/plans/revision-019.md +510 -0
- data/docs/plans/revision-020.md +524 -0
- data/docs/plans/revision-021.md +542 -0
- data/docs/plans/revision-022.md +542 -0
- data/docs/plans/revision-023.md +545 -0
- data/docs/plans/revision-024.md +567 -0
- data/docs/plans/revision-025.md +583 -0
- data/docs/plans/revision-026.md +241 -0
- data/docs/plans/revision-027.md +305 -0
- data/docs/plans/revision-028.md +298 -0
- data/docs/plans/revision-029.md +288 -0
- data/docs/rpm-action-macros.md +52 -0
- data/docs/rpm-parts.md +53 -0
- data/docs/ruby-dependencies.md +217 -0
- data/docs/ruby-policy-2.1.md +28 -0
- data/docs/ruby-versioning.md +61 -0
- data/docs/space-format.md +58 -0
- data/exe/baltix +1 -0
- data/lib/baltix/action_flow/files.rb +49 -0
- data/lib/baltix/action_flow/inputs.rb +60 -0
- data/lib/baltix/action_flow/journal.rb +60 -0
- data/lib/baltix/action_flow/options.rb +60 -0
- data/lib/baltix/action_flow.rb +65 -0
- data/lib/baltix/actor/build/collect.rb +72 -0
- data/lib/baltix/actor/build/compile.rb +25 -0
- data/lib/baltix/actor/build/extconf.rb +14 -0
- data/lib/baltix/actor/build/make.rb +18 -0
- data/lib/baltix/actor/build/postprocess.rb +14 -0
- data/lib/baltix/actor/build/rake.rb +18 -0
- data/lib/baltix/actor/build/ronn.rb +55 -0
- data/lib/baltix/actor/build.rb +87 -0
- data/lib/baltix/actor/clean/remove.rb +45 -0
- data/lib/baltix/actor/clean.rb +37 -0
- data/lib/baltix/actor/config.rb +12 -0
- data/lib/baltix/actor/copy.rb +22 -7
- data/lib/baltix/actor/distclean.rb +20 -0
- data/lib/baltix/actor/doc/collect.rb +39 -0
- data/lib/baltix/actor/doc/generate.rb +47 -0
- data/lib/baltix/actor/doc/inputs.rb +25 -0
- data/lib/baltix/actor/doc.rb +70 -0
- data/lib/baltix/actor/gen.rb +19 -0
- data/lib/baltix/actor/install/data.rb +18 -0
- data/lib/baltix/actor/install/documentation.rb +48 -0
- data/lib/baltix/actor/install/executable.rb +27 -0
- data/lib/baltix/actor/install/extension.rb +44 -0
- data/lib/baltix/actor/install/headers.rb +10 -0
- data/lib/baltix/actor/install/library.rb +13 -0
- data/lib/baltix/actor/install/metadata.rb +21 -0
- data/lib/baltix/actor/install/paths.rb +73 -0
- data/lib/baltix/actor/install/plugin.rb +25 -0
- data/lib/baltix/actor/install/record.rb +48 -0
- data/lib/baltix/actor/install/shebang.rb +29 -0
- data/lib/baltix/actor/install/transfer.rb +64 -0
- data/lib/baltix/actor/install/trees.rb +34 -0
- data/lib/baltix/actor/install.rb +71 -0
- data/lib/baltix/actor/link.rb +15 -6
- data/lib/baltix/actor/make.rb +14 -0
- data/lib/baltix/actor/predeps/write.rb +51 -0
- data/lib/baltix/actor/predeps.rb +41 -0
- data/lib/baltix/actor/provides.rb +12 -0
- data/lib/baltix/actor/requires.rb +12 -0
- data/lib/baltix/actor/show.rb +26 -0
- data/lib/baltix/actor/spec.rb +6 -3
- data/lib/baltix/actor/test/record.rb +8 -0
- data/lib/baltix/actor/test/run.rb +30 -0
- data/lib/baltix/actor/test/select.rb +16 -0
- data/lib/baltix/actor/test.rb +41 -0
- data/lib/baltix/actor/touch.rb +14 -5
- data/lib/baltix/actor.rb +43 -26
- data/lib/baltix/cli/dependency_options.rb +63 -0
- data/lib/baltix/cli/options/action.rb +32 -0
- data/lib/baltix/cli/options.rb +280 -0
- data/lib/baltix/cli/output_options.rb +56 -0
- data/lib/baltix/cli/rake_tasks.rb +59 -0
- data/lib/baltix/cli/source_options.rb +52 -0
- data/lib/baltix/cli.rb +130 -116
- data/lib/baltix/concerns/command.rb +52 -0
- data/lib/baltix/concerns/configuration.rb +39 -0
- data/lib/baltix/concerns/dependency_output.rb +21 -0
- data/lib/baltix/concerns/extension_metadata.rb +44 -0
- data/lib/baltix/concerns/file_destination.rb +14 -0
- data/lib/baltix/concerns/inspection.rb +27 -0
- data/lib/baltix/concerns/parts.rb +16 -0
- data/lib/baltix/concerns/target_paths.rb +57 -0
- data/lib/baltix/concerns.rb +11 -0
- data/lib/baltix/core_extensions/gem_dependency.rb +24 -0
- data/lib/baltix/core_extensions/gem_requirement.rb +45 -0
- data/lib/baltix/core_extensions/open_struct_merge.rb +62 -0
- data/lib/baltix/deps/executables.rb +30 -0
- data/lib/baltix/deps/packages.rb +32 -0
- data/lib/baltix/deps.rb +103 -194
- data/lib/baltix/dsl/dependency_groups.rb +77 -0
- data/lib/baltix/dsl/dependency_sources.rb +100 -0
- data/lib/baltix/dsl/filtering.rb +26 -0
- data/lib/baltix/dsl/loading.rb +72 -0
- data/lib/baltix/dsl/merging.rb +74 -0
- data/lib/baltix/dsl/rendering.rb +54 -0
- data/lib/baltix/dsl/requirements.rb +77 -0
- data/lib/baltix/dsl/temporary_files.rb +36 -0
- data/lib/baltix/dsl.rb +66 -273
- data/lib/baltix/executable_dependencies/features.rb +53 -0
- data/lib/baltix/executable_dependencies/library.rb +21 -0
- data/lib/baltix/executable_dependencies/library_features.rb +34 -0
- data/lib/baltix/executable_dependencies/syntax.rb +102 -0
- data/lib/baltix/executable_dependencies.rb +102 -0
- data/lib/baltix/extensions/bones.rb +173 -0
- data/lib/baltix/extensions/echoe.rb +143 -0
- data/lib/baltix/extensions/hoe/metadata.rb +89 -0
- data/lib/baltix/extensions/hoe/options.rb +84 -0
- data/lib/baltix/extensions/hoe/readme.rb +29 -0
- data/lib/baltix/extensions/hoe.rb +146 -0
- data/lib/baltix/extensions/jeweler.rb +95 -0
- data/lib/baltix/extensions/levitate.rb +74 -0
- data/lib/baltix/extensions/olddoc.rb +42 -0
- data/lib/baltix/extensions.rb +340 -419
- data/lib/baltix/i18n.rb +22 -19
- data/lib/baltix/license/catalog/capture.rb +58 -0
- data/lib/baltix/license/catalog.rb +75 -0
- data/lib/baltix/license.rb +76 -0
- data/lib/baltix/loader/capture.rb +91 -0
- data/lib/baltix/loader/cmake.rb +6 -3
- data/lib/baltix/loader/evaluation.rb +49 -0
- data/lib/baltix/loader/extconf.rb +27 -0
- data/lib/baltix/loader/feature_loading.rb +54 -0
- data/lib/baltix/loader/git-version-gen.rb +36 -21
- data/lib/baltix/loader/mast/properties.rb +58 -0
- data/lib/baltix/loader/mast.rb +97 -109
- data/lib/baltix/loader/object_capture.rb +27 -0
- data/lib/baltix/loader/olddoc.gemspec.erb +31 -0
- data/lib/baltix/loader/pom.rb +36 -16
- data/lib/baltix/loader/rookbook.rb +19 -14
- data/lib/baltix/loader/yaml.rb +9 -5
- data/lib/baltix/loader.rb +85 -132
- data/lib/baltix/log.rb +26 -27
- data/lib/baltix/rake/metadata_adapter.rb +30 -0
- data/lib/baltix/rake/task_context.rb +59 -0
- data/lib/baltix/rake/task_libraries.rb +73 -0
- data/lib/baltix/rake.rb +62 -12
- data/lib/baltix/source/base/dependencies.rb +81 -0
- data/lib/baltix/source/base/file_queries.rb +67 -0
- data/lib/baltix/source/base/file_tree.rb +70 -0
- data/lib/baltix/source/base/metadata.rb +140 -0
- data/lib/baltix/source/base/options.rb +71 -0
- data/lib/baltix/source/base/roots.rb +53 -0
- data/lib/baltix/source/base.rb +95 -377
- data/lib/baltix/source/fake.rb +89 -5
- data/lib/baltix/source/gem/delegation.rb +32 -0
- data/lib/baltix/source/gem/dependencies.rb +69 -0
- data/lib/baltix/source/gem/discovery.rb +72 -0
- data/lib/baltix/source/gem/file_trees.rb +114 -0
- data/lib/baltix/source/gem/forwarding.rb +12 -0
- data/lib/baltix/source/gem/metadata.rb +104 -0
- data/lib/baltix/source/gem/specification.rb +65 -0
- data/lib/baltix/source/gem.rb +65 -312
- data/lib/baltix/source/gemfile.rb +55 -5
- data/lib/baltix/source/rakefile.rb +12 -5
- data/lib/baltix/source.rb +36 -24
- data/lib/baltix/space/configuration.rb +54 -0
- data/lib/baltix/space/data/collections.rb +33 -0
- data/lib/baltix/space/data/gem_metadata.rb +79 -0
- data/lib/baltix/space/data/models.rb +20 -0
- data/lib/baltix/space/data/values.rb +72 -0
- data/lib/baltix/space/data.rb +53 -0
- data/lib/baltix/space/dependencies.rb +53 -0
- data/lib/baltix/space/filters.rb +96 -0
- data/lib/baltix/space/initialization.rb +124 -0
- data/lib/baltix/space/metadata.rb +130 -0
- data/lib/baltix/space/source_order.rb +43 -0
- data/lib/baltix/space/source_selection.rb +136 -0
- data/lib/baltix/space/source_status.rb +114 -0
- data/lib/baltix/space/spec.rb +3 -0
- data/lib/baltix/space.rb +87 -367
- data/lib/baltix/spec/rpm/aliases.rb +79 -0
- data/lib/baltix/spec/rpm/arch.rb +119 -0
- data/lib/baltix/spec/rpm/available_overrides.rb +106 -0
- data/lib/baltix/spec/rpm/build_dependencies.rb +132 -0
- data/lib/baltix/spec/rpm/build_queries.rb +61 -0
- data/lib/baltix/spec/rpm/changelog.rb +115 -0
- data/lib/baltix/spec/rpm/dependency_overrides.rb +83 -0
- data/lib/baltix/spec/rpm/dependency_policy.rb +69 -0
- data/lib/baltix/spec/rpm/deps.rb +113 -0
- data/lib/baltix/spec/rpm/env/requirements.rb +20 -0
- data/lib/baltix/spec/rpm/env.rb +76 -0
- data/lib/baltix/spec/rpm/executable_packages.rb +49 -0
- data/lib/baltix/spec/rpm/file_manifest.rb +72 -0
- data/lib/baltix/spec/rpm/guard_compilation.rb +95 -0
- data/lib/baltix/spec/rpm/imported_secondaries.rb +26 -0
- data/lib/baltix/spec/rpm/layout.rb +14 -0
- data/lib/baltix/spec/rpm/manpages.rb +71 -0
- data/lib/baltix/spec/rpm/metadata.rb +78 -0
- data/lib/baltix/spec/rpm/name/equality.rb +68 -0
- data/lib/baltix/spec/rpm/name/formatting.rb +33 -0
- data/lib/baltix/spec/rpm/name/parsing.rb +58 -0
- data/lib/baltix/spec/rpm/name.rb +77 -108
- data/lib/baltix/spec/rpm/packaged_versions.rb +107 -0
- data/lib/baltix/spec/rpm/parser/comments.rb +35 -0
- data/lib/baltix/spec/rpm/parser/context.rb +50 -0
- data/lib/baltix/spec/rpm/parser/dependencies.rb +91 -0
- data/lib/baltix/spec/rpm/parser/file_sections.rb +68 -0
- data/lib/baltix/spec/rpm/parser/flow.rb +84 -0
- data/lib/baltix/spec/rpm/parser/header_dependencies.rb +36 -0
- data/lib/baltix/spec/rpm/parser/macros.rb +43 -0
- data/lib/baltix/spec/rpm/parser/metadata.rb +106 -0
- data/lib/baltix/spec/rpm/parser/sections.rb +88 -0
- data/lib/baltix/spec/rpm/parser/values.rb +85 -0
- data/lib/baltix/spec/rpm/parser.rb +124 -269
- data/lib/baltix/spec/rpm/part_files.rb +64 -0
- data/lib/baltix/spec/rpm/part_prelude.rb +43 -0
- data/lib/baltix/spec/rpm/part_scripts.rb +52 -0
- data/lib/baltix/spec/rpm/part_switches.rb +65 -0
- data/lib/baltix/spec/rpm/pkglist/header.rb +73 -0
- data/lib/baltix/spec/rpm/pkglist/provides.rb +57 -0
- data/lib/baltix/spec/rpm/pkglist.rb +116 -0
- data/lib/baltix/spec/rpm/preparation.rb +73 -0
- data/lib/baltix/spec/rpm/rendering.rb +66 -0
- data/lib/baltix/spec/rpm/repository_application.rb +33 -0
- data/lib/baltix/spec/rpm/revision.rb +58 -0
- data/lib/baltix/spec/rpm/root_source.rb +48 -0
- data/lib/baltix/spec/rpm/scripts.rb +85 -0
- data/lib/baltix/spec/rpm/secondaries.rb +82 -0
- data/lib/baltix/spec/rpm/secondary.rb +117 -64
- data/lib/baltix/spec/rpm/secondary_parts.rb +84 -0
- data/lib/baltix/spec/rpm/section_document.rb +84 -0
- data/lib/baltix/spec/rpm/section_guards.rb +116 -0
- data/lib/baltix/spec/rpm/source_selection.rb +82 -0
- data/lib/baltix/spec/rpm/spec_core/architecture.rb +28 -0
- data/lib/baltix/spec/rpm/spec_core/attributes.rb +89 -0
- data/lib/baltix/spec/rpm/spec_core/availability.rb +60 -0
- data/lib/baltix/spec/rpm/spec_core/dependency_rendering.rb +83 -0
- data/lib/baltix/spec/rpm/spec_core/descriptions.rb +77 -0
- data/lib/baltix/spec/rpm/spec_core/documentation.rb +48 -0
- data/lib/baltix/spec/rpm/spec_core/executable_names.rb +37 -0
- data/lib/baltix/spec/rpm/spec_core/host_names.rb +60 -0
- data/lib/baltix/spec/rpm/spec_core/interpreters.rb +103 -0
- data/lib/baltix/spec/rpm/spec_core/names.rb +80 -0
- data/lib/baltix/spec/rpm/spec_core/obsoletes.rb +38 -0
- data/lib/baltix/spec/rpm/spec_core/package_dependencies.rb +74 -0
- data/lib/baltix/spec/rpm/spec_core/plain_dependencies.rb +60 -0
- data/lib/baltix/spec/rpm/spec_core/pre_name.rb +23 -0
- data/lib/baltix/spec/rpm/spec_core/provides.rb +104 -0
- data/lib/baltix/spec/rpm/spec_core/readme.rb +78 -0
- data/lib/baltix/spec/rpm/spec_core/registration.rb +18 -0
- data/lib/baltix/spec/rpm/spec_core/runtime_dependencies.rb +81 -0
- data/lib/baltix/spec/rpm/spec_core/summaries.rb +64 -0
- data/lib/baltix/spec/rpm/spec_core/text_wrapping.rb +36 -0
- data/lib/baltix/spec/rpm/spec_core/versioning.rb +75 -0
- data/lib/baltix/spec/rpm/spec_core/versions.rb +94 -0
- data/lib/baltix/spec/rpm/spec_core.rb +75 -527
- data/lib/baltix/spec/{rpm.erb → rpm/template.erb} +131 -31
- data/lib/baltix/spec/rpm.rb +253 -644
- data/lib/baltix/spec.rb +16 -14
- data/lib/baltix/target/gem.rb +61 -0
- data/lib/baltix/target/site.rb +40 -0
- data/lib/baltix/target.rb +16 -0
- data/lib/baltix/version.rb +3 -1
- data/lib/baltix.rb +77 -5
- data/locale/en_US.UTF-8.yaml +4 -1
- data/locale/ru_RU.UTF-8.yaml +7 -1
- data/rpm/baltix.env +4 -0
- data/rpm/baltix.prov +8 -0
- data/rpm/baltix.prov.files +6 -0
- data/rpm/baltix.req +8 -0
- data/rpm/baltix.req.files +6 -0
- data/rpm/macros.baltix +24 -0
- data/utils/rubocop/compact_block_braces.rb +39 -0
- data/utils/rubocop/spacing.rb +96 -0
- data/utils/update_alt_architectures.rb +57 -0
- data/utils/update_alt_licenses.rb +19 -0
- data/utils/update_spdx_licenses.rb +21 -0
- metadata +526 -17
- data/.github/workflows/ci.yml +0 -44
- data/.gitignore +0 -10
- data/TODO +0 -84
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Decodes bounded RPM header fields for plain and compressed package indexes.
|
|
4
|
+
class Baltix::Pkglist::Reader
|
|
5
|
+
private
|
|
6
|
+
|
|
7
|
+
def decode_header intro, input
|
|
8
|
+
count, length = header_limits(intro)
|
|
9
|
+
indexes = read_exact(input, count * 16)
|
|
10
|
+
data = read_exact(input, length)
|
|
11
|
+
entries = indexes.unpack('N*').each_slice(4).to_h {|tag, type, offset, size| [tag, [type, offset, size]] }
|
|
12
|
+
|
|
13
|
+
[entries, data]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def header_limits intro
|
|
17
|
+
fail_index('truncated RPM header introduction') unless intro.bytesize == 16
|
|
18
|
+
fail_index('invalid RPM header magic') unless intro.start_with?(MAGIC)
|
|
19
|
+
|
|
20
|
+
count, length = intro.byteslice(8, 8).unpack('N2')
|
|
21
|
+
|
|
22
|
+
fail_index('RPM header exceeds format limits') if count > 65_535 || 8 + count * 16 + length > MAX_HEADER_BYTES
|
|
23
|
+
|
|
24
|
+
[count, length]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def read_exact input, size
|
|
28
|
+
bytes = input.read(size)
|
|
29
|
+
|
|
30
|
+
fail_index('truncated RPM header data') unless bytes && bytes.bytesize == size
|
|
31
|
+
|
|
32
|
+
bytes
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def strings entry, data
|
|
36
|
+
type, offset, count = entry
|
|
37
|
+
|
|
38
|
+
fail_index('expected RPM string array') unless type == 8
|
|
39
|
+
fail_index('string array outside RPM header data') if offset > data.bytesize || count > data.bytesize - offset
|
|
40
|
+
|
|
41
|
+
Array.new(count) do
|
|
42
|
+
ending = data.index("\0", offset)
|
|
43
|
+
|
|
44
|
+
fail_index('unterminated RPM string') unless ending
|
|
45
|
+
|
|
46
|
+
value = data.byteslice(offset, ending - offset)
|
|
47
|
+
offset = ending + 1
|
|
48
|
+
|
|
49
|
+
value
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def integers entry, data
|
|
54
|
+
type, offset, count = entry
|
|
55
|
+
|
|
56
|
+
fail_index('expected RPM int32 array') unless type == 4
|
|
57
|
+
fail_index('integer array outside RPM header data') if offset + count * 4 > data.bytesize
|
|
58
|
+
|
|
59
|
+
data.byteslice(offset, count * 4).unpack('N*')
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def utf8 value
|
|
63
|
+
value = value.dup.force_encoding(Encoding::UTF_8)
|
|
64
|
+
|
|
65
|
+
fail_index('invalid UTF-8 in gem capability') unless value.valid_encoding?
|
|
66
|
+
|
|
67
|
+
value
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def fail_index message
|
|
71
|
+
raise(Baltix::Pkglist::Error, "#{@path}: RPM header #{@record}: #{message}")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Selects exact RubyGems capabilities while retaining index diagnostics.
|
|
4
|
+
class Baltix::Pkglist::Reader
|
|
5
|
+
private
|
|
6
|
+
|
|
7
|
+
def sorted_versions result
|
|
8
|
+
result.keys.sort.to_h do |name|
|
|
9
|
+
versions = result[name].uniq.sort_by {|version| [Gem::Version.new(version), version] }
|
|
10
|
+
|
|
11
|
+
[name, versions]
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def read_provides entries, data, result
|
|
16
|
+
names = strings(entries[PROVIDES], data)
|
|
17
|
+
versions = entries[PROVIDE_VERSIONS] && strings(entries[PROVIDE_VERSIONS], data)
|
|
18
|
+
flags = entries[PROVIDE_FLAGS] && integers(entries[PROVIDE_FLAGS], data)
|
|
19
|
+
|
|
20
|
+
validate_provide_arrays(names, versions, flags)
|
|
21
|
+
|
|
22
|
+
names.each_with_index.sum {|capability, index| append_capability(capability, index, versions, flags, result) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def validate_provide_arrays names, versions, flags
|
|
26
|
+
return unless (versions && versions.size != names.size) || (flags && flags.size != names.size)
|
|
27
|
+
|
|
28
|
+
fail_index('unaligned Provides arrays')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def append_capability capability, index, versions, flags, result
|
|
32
|
+
match = /\Agem\(([^)]+)\)\z/n.match(capability)
|
|
33
|
+
|
|
34
|
+
return 0 unless match
|
|
35
|
+
|
|
36
|
+
version = versions && versions[index]
|
|
37
|
+
|
|
38
|
+
return 1 unless exact_capability?(version, flags, index)
|
|
39
|
+
|
|
40
|
+
append_gem_version(utf8(match[1]), utf8(version), result)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def exact_capability? version, flags, index
|
|
44
|
+
version && !version.empty? && flags && flags[index] & 14 == 8
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def append_gem_version name, version, result
|
|
48
|
+
Gem::Version.new(version)
|
|
49
|
+
result[name] << version
|
|
50
|
+
|
|
51
|
+
0
|
|
52
|
+
rescue ArgumentError
|
|
53
|
+
@warnings << "#{@path}: RPM header #{@record}: ignored non-RubyGems capability gem(#{name}) = #{version.inspect}"
|
|
54
|
+
|
|
55
|
+
0
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
require 'baltix/version'
|
|
5
|
+
require 'rubygems/version'
|
|
6
|
+
|
|
7
|
+
# Reads ALT RPM package indexes and extracts gem capabilities.
|
|
8
|
+
module Baltix::Pkglist
|
|
9
|
+
class Error < StandardError; end
|
|
10
|
+
|
|
11
|
+
# Reads apt-rpm's concatenated RPM headers without consulting an installed RPM DB.
|
|
12
|
+
# @param paths [Array<String>] plain or XZ-compressed package indexes
|
|
13
|
+
# @return [Hash<String, Array<String>>] exact gem capability versions by literal name
|
|
14
|
+
def self.read paths
|
|
15
|
+
Reader.new.read(paths)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Decodes RPM headers from an ALT package index stream.
|
|
19
|
+
class Reader
|
|
20
|
+
MAGIC = "\x8e\xad\xe8\x01".b.freeze
|
|
21
|
+
XZ_MAGIC = "\xfd7zXZ\x00".b.freeze
|
|
22
|
+
MAX_HEADER_BYTES = 32 * 1024 * 1024
|
|
23
|
+
PROVIDES = 1047
|
|
24
|
+
PROVIDE_FLAGS = 1112
|
|
25
|
+
PROVIDE_VERSIONS = 1113
|
|
26
|
+
|
|
27
|
+
attr_reader :warnings
|
|
28
|
+
|
|
29
|
+
def initialize
|
|
30
|
+
@warnings = []
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Combines indexes while retaining every distinct exact version of a gem.
|
|
34
|
+
# Unversioned/ranged gem Provides are reported rather than assigned an RPM EVR.
|
|
35
|
+
def read paths
|
|
36
|
+
@warnings.clear
|
|
37
|
+
raise(Error, 'No pkglist paths supplied') if paths.empty?
|
|
38
|
+
|
|
39
|
+
result = Hash.new {|hash, name| hash[name] = [] }
|
|
40
|
+
|
|
41
|
+
paths.each {|path| read_file(path.to_s, result) }
|
|
42
|
+
|
|
43
|
+
sorted_versions(result)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def read_file path, result
|
|
49
|
+
@path = path
|
|
50
|
+
@record = 0
|
|
51
|
+
skipped = File.open(path, 'rb') {|file| read_index_stream(file, path, result) }
|
|
52
|
+
|
|
53
|
+
fail_index('empty package index') if @record.zero?
|
|
54
|
+
@warnings << "#{path}: ignored #{skipped} unversioned or non-exact gem Provides" if skipped.positive?
|
|
55
|
+
rescue SystemCallError => error
|
|
56
|
+
raise(Error, "#{path}: #{error.message}")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def read_index_stream file, path, result
|
|
60
|
+
magic = file.read(6)
|
|
61
|
+
|
|
62
|
+
file.rewind
|
|
63
|
+
|
|
64
|
+
magic == XZ_MAGIC ? read_xz(path, result) : read_headers(file, result)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def read_xz path, result
|
|
68
|
+
Open3.popen3('xz', '--decompress', '--stdout', '--', path) do |input, output, errors, process|
|
|
69
|
+
input.close
|
|
70
|
+
|
|
71
|
+
error_reader = Thread.new { decompression_errors(errors) }
|
|
72
|
+
|
|
73
|
+
begin
|
|
74
|
+
skipped = read_headers(output, result)
|
|
75
|
+
|
|
76
|
+
check_decompression(process.value, error_reader)
|
|
77
|
+
skipped
|
|
78
|
+
ensure
|
|
79
|
+
output.close unless output.closed?
|
|
80
|
+
error_reader.join
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def decompression_errors errors
|
|
86
|
+
message = +''
|
|
87
|
+
|
|
88
|
+
while (chunk = errors.read(2048))
|
|
89
|
+
message << chunk if message.bytesize < 2048
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
message
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def check_decompression status, error_reader
|
|
96
|
+
fail_index("XZ decompression failed: #{error_reader.value.strip}") unless status.success?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def read_headers input, result
|
|
100
|
+
skipped = 0
|
|
101
|
+
|
|
102
|
+
while (intro = input.read(16)) && !intro.empty?
|
|
103
|
+
@record += 1
|
|
104
|
+
entries, data = decode_header(intro, input)
|
|
105
|
+
|
|
106
|
+
skipped += read_provides(entries, data, result) if entries.key?(PROVIDES)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
skipped
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
require 'baltix/spec/rpm/pkglist/header'
|
|
115
|
+
|
|
116
|
+
require 'baltix/spec/rpm/pkglist/provides'
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Recognizes only conventional generated preparation, version exports and RI cleanup commands.
|
|
4
|
+
class Baltix::Spec::Rpm
|
|
5
|
+
def migrated_prep_command command, arguments, line
|
|
6
|
+
case command
|
|
7
|
+
when '%setup'
|
|
8
|
+
standard_setup_arguments?(arguments) ? self.class::STATE[:prep][:default] : line
|
|
9
|
+
when 'rm'
|
|
10
|
+
obsolete_gemspec_removal?(arguments) ? nil : line
|
|
11
|
+
when 'cp'
|
|
12
|
+
obsolete_gemspec_copy?(arguments) ? nil : line
|
|
13
|
+
else
|
|
14
|
+
line
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def standard_setup_arguments? arguments
|
|
19
|
+
arguments.delete('-q')
|
|
20
|
+
|
|
21
|
+
arguments.empty? || (arguments.size == 2 && arguments.first == '-n' && generated_gem_filename?(arguments.last))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def obsolete_gemspec_removal? arguments
|
|
25
|
+
return false unless arguments.first&.match?(/\A-(?:r*f|fr*)\z/)
|
|
26
|
+
|
|
27
|
+
files = arguments.drop(1)
|
|
28
|
+
|
|
29
|
+
files.any? && files.all? do |file|
|
|
30
|
+
GENERATED_GEM_FILES.include?(file) || generated_gem_filename?(file, '.gemspec')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def obsolete_gemspec_copy? arguments
|
|
35
|
+
arguments.size == 2 && arguments.first.match?(/\A%(?:SOURCE\d+|\{SOURCE\d+\})\z/) &&
|
|
36
|
+
generated_gem_filename?(arguments.last, '.gemspec')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def obsolete_version_export? command, arguments
|
|
40
|
+
command == 'export' && arguments.size == 1 && arguments.first.match?(/\AVERSION=%(?:version|\{version\})\z/)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Recognizes conventional generated gem paths without expanding RPM macros.
|
|
44
|
+
# @param filename [String] candidate setup directory or generated gemspec path
|
|
45
|
+
# @param suffix [String] required file suffix, empty for a setup directory
|
|
46
|
+
# @return [Boolean] whether the path is a conventional gem-name/version template
|
|
47
|
+
# Known package-name macros and actual source gem names are accepted; literal
|
|
48
|
+
# custom directories, other versions and unrelated file names are not matched.
|
|
49
|
+
def generated_gem_filename? filename, suffix = +''
|
|
50
|
+
names = sources.grep(Baltix::Source::Gem).map {|item| Regexp.escape(item.name) }
|
|
51
|
+
name = "(?:%(?:pkgname|gemname|name|\\{(?:pkgname|gemname|name)\\})|#{names.join('|')})"
|
|
52
|
+
|
|
53
|
+
filename.match?(/\A#{name}-%(?:version|\{version\})#{Regexp.escape(suffix)}\z/)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Recognizes obsolete generated cleanup of the old shared Ruby RI caches.
|
|
57
|
+
# @param line [String] shell command inspected without execution or expansion
|
|
58
|
+
# @return [Boolean] whether every removal target is a known obsolete RI cache
|
|
59
|
+
# Only standalone forced rm commands with known literal cache paths qualify.
|
|
60
|
+
# Mixed targets, shell operators, custom paths and malformed quoting return false.
|
|
61
|
+
def obsolete_ri_cleanup? line
|
|
62
|
+
command, flag, *files = Shellwords.shellsplit(line)
|
|
63
|
+
|
|
64
|
+
return false unless command == 'rm' && %w[-f -rf -fr].include?(flag) && !files.empty?
|
|
65
|
+
|
|
66
|
+
files.all? do |file|
|
|
67
|
+
file.match?(%r{\A%(?:buildroot|\{buildroot\})%(?:ruby_ri_sitedir|\{ruby_ri_sitedir\})/
|
|
68
|
+
(?:Object/cdesc-Object\.ri|cache\.ri|created\.rid|\{Object/cdesc-Object\.ri,cache\.ri,created\.rid\})\z}x)
|
|
69
|
+
end
|
|
70
|
+
rescue ArgumentError
|
|
71
|
+
false
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Renders RPM templates and canonical macro values without obsolete package-name scaffolding.
|
|
4
|
+
class Baltix::Spec::Rpm
|
|
5
|
+
# Renders the spec and accounts for changes confined to the spec file.
|
|
6
|
+
# @param spec [String, nil] optional replacement ERB template
|
|
7
|
+
# @return [String] generated RPM spec without surrounding whitespace
|
|
8
|
+
# Existing packages with an unchanged module version receive a spec revision
|
|
9
|
+
# when the rendered content changes. Identical refreshes retain their revision.
|
|
10
|
+
def render spec = nil
|
|
11
|
+
template = spec || spec_template
|
|
12
|
+
|
|
13
|
+
unless @revision_prepared
|
|
14
|
+
prepare_spec_revision(template)
|
|
15
|
+
|
|
16
|
+
@revision_prepared = true
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
render_template(template)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Evaluates an RPM template against the current package properties.
|
|
23
|
+
# @param template [String] ERB source
|
|
24
|
+
# @return [String] generated spec without surrounding whitespace
|
|
25
|
+
def render_template template
|
|
26
|
+
b = binding
|
|
27
|
+
|
|
28
|
+
omit_obsolete_pkgname(ERB.new(template, trim_mode: '<>-', eoutvar: '@spec').result(b)).strip
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Omits unused legacy package-name definitions from a generated gem RPM spec.
|
|
32
|
+
# @param spec [String] rendered spec, inspected without expanding RPM macros
|
|
33
|
+
# @return [String] spec with unused pkgname definitions removed
|
|
34
|
+
# Only gem-* packages are migrated. If literal pkgname and gemname values are
|
|
35
|
+
# identical, direct and braced references use gemname. Definitions using def*
|
|
36
|
+
# or global are obsolete; other definitions remain unchanged. If the remaining
|
|
37
|
+
# spec still mentions pkgname, its definitions remain for compatibility.
|
|
38
|
+
# Different or unresolved aliases and non-gem specs are left unchanged.
|
|
39
|
+
def omit_obsolete_pkgname spec
|
|
40
|
+
return spec unless spec[/^Name:[ \t]+(\S+)/, 1].to_s.start_with?('gem-')
|
|
41
|
+
|
|
42
|
+
body = spec.gsub(/^[ \t]*%(?:def\S*|global)[ \t]+pkgname(?:[ \t]+[^\r\n]*)?(?:\r?\n|\z)/, '')
|
|
43
|
+
legacy = spec.scan(/^%(?:define|global)[ \t]+pkgname[ \t]+([^\r\n]+)/).flatten.last
|
|
44
|
+
current = spec.scan(/^%(?:define|global)[ \t]+gemname[ \t]+([^\r\n]+)/).flatten.last
|
|
45
|
+
|
|
46
|
+
if legacy && legacy == current && legacy.match?(/\A[\w.+-]+\z/)
|
|
47
|
+
body = body.gsub(/%pkgname\b/, '%gemname').gsub(/(%\{[!?]*)pkgname\b/, '\1gemname')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
body.match?(/\bpkgname\b/) ? spec : body
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def macros name
|
|
54
|
+
[context.__macros[name]].flatten(1).map! {|x| "%#{name} #{x}" }.join("\n")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Formats explicit path tokens for an RPM macro and the directory-token CLI.
|
|
58
|
+
# @param tokens [Array<String, Regexp>] configured source path tokens
|
|
59
|
+
# @return [String] comma-separated tokens retaining their matching behavior
|
|
60
|
+
# If a token is a regexp, partial-directory wildcards and embedded regexp
|
|
61
|
+
# flags retain its semantics when the macro is read back as string tokens.
|
|
62
|
+
# String tokens are emitted unchanged.
|
|
63
|
+
def path_tokens_for_macro tokens
|
|
64
|
+
tokens.map {|token| token.is_a?(Regexp) ? "[^/]*#{token}[^/]*" : token }.join(',')
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Keeps repository package identity when a nested Gemfile supplies its application metadata.
|
|
4
|
+
class Baltix::Spec::Rpm
|
|
5
|
+
protected
|
|
6
|
+
|
|
7
|
+
def global_application_name value
|
|
8
|
+
value = repository_application_name(value)
|
|
9
|
+
|
|
10
|
+
value.class.parse(value, prefix: nil, kind: 'app', name: value.original_fullname)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def repository_application_name value
|
|
14
|
+
return value unless nested_repository_application?
|
|
15
|
+
return value if preserved_application_name?
|
|
16
|
+
|
|
17
|
+
value.class.parse(value, prefix: nil, kind: 'app', name: space.default_fake_source.name)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def nested_repository_application?
|
|
21
|
+
source.is_a?(Baltix::Source::Gemfile) && space &&
|
|
22
|
+
File.expand_path(source.rootdir) != File.expand_path(space.rootdir) &&
|
|
23
|
+
space.repository_root_source.is_a?(Baltix::Source::Fake)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def preserved_application_name?
|
|
27
|
+
return true if options.name
|
|
28
|
+
|
|
29
|
+
stated = of_state(:name)
|
|
30
|
+
|
|
31
|
+
stated && stated != source.name && stated.to_s != space.default_fake_source.name
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Selects spec-only revisions and invalidates derived package metadata before final rendering.
|
|
4
|
+
class Baltix::Spec::Rpm
|
|
5
|
+
# Selects a spec-only revision by comparing a preview with the original spec.
|
|
6
|
+
# @param template [String] ERB source used for both preview and final output
|
|
7
|
+
# @return [void]
|
|
8
|
+
# New packages and changed module versions keep the normal version flow.
|
|
9
|
+
# An unchanged preview retains the input release and changelog. Any other
|
|
10
|
+
# change increments the spec component, unless a different release is explicitly
|
|
11
|
+
# configured. Derived package caches are cleared before the final render so
|
|
12
|
+
# subpackage revisions and changelog entries agree.
|
|
13
|
+
def prepare_spec_revision template
|
|
14
|
+
original = of_state(:original_spec)
|
|
15
|
+
|
|
16
|
+
return unless original && of_state(:version) == version
|
|
17
|
+
|
|
18
|
+
@checking_revision = true
|
|
19
|
+
preview = render_template(template)
|
|
20
|
+
@checking_revision = false
|
|
21
|
+
|
|
22
|
+
select_spec_revision(original, preview)
|
|
23
|
+
reset_revision_cache
|
|
24
|
+
change(:fix) unless @unchanged_spec
|
|
25
|
+
ensure
|
|
26
|
+
@checking_revision = false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def select_spec_revision original, preview
|
|
30
|
+
previous = of_state(:release)
|
|
31
|
+
configured = of_options(:release)
|
|
32
|
+
@unchanged_spec = original.strip == preview.strip && (!configured || configured == previous)
|
|
33
|
+
@spec_revision_release =
|
|
34
|
+
if @unchanged_spec
|
|
35
|
+
previous
|
|
36
|
+
else
|
|
37
|
+
configured && configured != previous ? configured : next_spec_revision(previous)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def reset_revision_cache
|
|
42
|
+
self.class::STATE.to_h.each_key {|key| instance_variable_set(:"@#{key}", nil) }
|
|
43
|
+
|
|
44
|
+
@valid_secondaries = @autoaliases = nil
|
|
45
|
+
@change_list = []
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Increments the final spec component of an ALT packaging release.
|
|
49
|
+
# @param release [String] previous release, such as alt1.2 or alt0.1.2
|
|
50
|
+
# @return [String] next spec revision, such as alt1.3 or alt0.1.3
|
|
51
|
+
# A release without a spec component gains .1. Unrecognized release formats
|
|
52
|
+
# retain their existing components and gain .1 rather than losing information.
|
|
53
|
+
def next_spec_revision release
|
|
54
|
+
match = /\Aalt(?<base>0\.\d+|\d+)(?:\.(?<spec>\d+))?\z/.match(release.to_s)
|
|
55
|
+
|
|
56
|
+
match ? "alt#{match[:base]}.#{match[:spec].to_i + 1}" : "#{release}.1"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Resolves root source metadata and retains application packages with explicit files.
|
|
4
|
+
class Baltix::Spec::Rpm
|
|
5
|
+
def source
|
|
6
|
+
return @source ||= distinct_root_source if distinct_root_package?
|
|
7
|
+
|
|
8
|
+
@source ||= selected_root_source
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def selected_root_source
|
|
12
|
+
space&.main_source || sources.find {|source_in| pre_name == source_in.name } || fallback_root_source
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def distinct_root_source
|
|
16
|
+
Baltix::Source::Fake.new(source_file: File.join(space.rootdir, '.baltix-root'),
|
|
17
|
+
name: state.name.original_fullname, version: state.version, valid: true)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def fallback_root_source
|
|
21
|
+
Baltix::Source::Fake.new({
|
|
22
|
+
'name' => state.name&.fullname,
|
|
23
|
+
'version' => state.version,
|
|
24
|
+
'kind' => state.kind || state.name&.kind,
|
|
25
|
+
'valid' => true
|
|
26
|
+
})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# +sources+ infers sources from the space if any. filtered out by the ignore names filter
|
|
30
|
+
def sources
|
|
31
|
+
@sources ||=
|
|
32
|
+
space&.valid_sources&.reject do |source_in|
|
|
33
|
+
ignored_name?(source_in.name)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def valid_secondaries
|
|
38
|
+
@valid_secondaries ||=
|
|
39
|
+
secondaries.select do |secondary|
|
|
40
|
+
secondary.source&.source_file || retained_application_secondary?(secondary)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def retained_application_secondary? secondary
|
|
45
|
+
secondary.source.is_a?(Baltix::Source::Fake) && APPLICATION_SECONDARY_KINDS.include?(secondary.kind) &&
|
|
46
|
+
has_custom_packaging_files?(secondary.state.name)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Preserves custom shell commands while migrating recognized obsolete Ruby scaffolding.
|
|
4
|
+
class Baltix::Spec::Rpm
|
|
5
|
+
# Renders custom script commands while regenerating standard Ruby packaging code.
|
|
6
|
+
# @param section [Symbol] :prep, :build, :install or :check
|
|
7
|
+
# @return [String] section commands, preserving custom arguments and ordering
|
|
8
|
+
# Obsolete wrappers and lines mentioning bundler/setup or ruby-tool-setup are
|
|
9
|
+
# removed. With a source gemspec, standard setup commands are normalized and
|
|
10
|
+
# obsolete gemspec copying, VERSION exports and commented test wrappers are
|
|
11
|
+
# omitted. Custom commands, arguments and ordering survive.
|
|
12
|
+
# Legacy ruby_build selection and rake flags move to their generated macros.
|
|
13
|
+
# Standard RI cleanup and its preceding generated comment are removed together.
|
|
14
|
+
# If migration empties a section, its current default is used.
|
|
15
|
+
def preserved_script section
|
|
16
|
+
lines =
|
|
17
|
+
public_send(section).to_s.lines.each_with_object([]) do |line, retained|
|
|
18
|
+
migrated = migrate_script_line(section, line.chomp)
|
|
19
|
+
|
|
20
|
+
append_preserved_script_line(retained, migrated, section, line)
|
|
21
|
+
end
|
|
22
|
+
result = lines.join("\n").strip
|
|
23
|
+
|
|
24
|
+
result.empty? ? self.class::STATE[section][:default] : result
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def append_preserved_script_line retained, migrated, section, original
|
|
28
|
+
if migrated
|
|
29
|
+
retained << migrated
|
|
30
|
+
elsif section == :install && obsolete_ri_cleanup?(original) &&
|
|
31
|
+
retained.last&.strip == '# Remove unnecessary files'
|
|
32
|
+
retained.pop
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Classifies a script line using its section and the available source metadata.
|
|
37
|
+
# @param section [Symbol] :prep, :build, :install or :check
|
|
38
|
+
# @param line [String] original command, never evaluated
|
|
39
|
+
# @return [String, nil] retained/rebuilt command, or nil for obsolete generated code
|
|
40
|
+
# Standard preparation is rebuilt in place so following custom commands still
|
|
41
|
+
# run after setup. Gem metadata cleanup/copying and a package VERSION export are
|
|
42
|
+
# redundant only when a native gemspec is available. Unknown commands, custom
|
|
43
|
+
# arguments and malformed shell quoting remain unchanged; no shell is executed.
|
|
44
|
+
# Standard RI cache cleanup is omitted from installation with a native gemspec.
|
|
45
|
+
# Lines matching bundler/setup or ruby-tool-setup are omitted in every section,
|
|
46
|
+
# with or without source metadata; dependency declarations are handled separately.
|
|
47
|
+
def migrate_script_line section, line
|
|
48
|
+
return if line.match?(/^\s*%(?:update_setup_rb|ruby_config|rdoc)(?:\s|$)/)
|
|
49
|
+
return if line.match?(%r{bundler/setup|ruby-tool-setup})
|
|
50
|
+
|
|
51
|
+
line = line.sub(/^\s*%gem_build\b/, '%ruby_build').sub(/^\s*%gem_install\b/, '%ruby_install')
|
|
52
|
+
|
|
53
|
+
line = line.gsub(/\s+--(?:pre|use|alias|ignore)=\S+/, '') if line.match?(/^\s*%ruby_build\b/)
|
|
54
|
+
|
|
55
|
+
return line unless source_gemspec_available?
|
|
56
|
+
|
|
57
|
+
migrate_gemspec_script_line(section, line)
|
|
58
|
+
rescue ArgumentError
|
|
59
|
+
line
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def source_gemspec_available?
|
|
63
|
+
space && sources.any? {|item| item.source_file.to_s.end_with?('.gemspec') }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def migrate_gemspec_script_line section, line
|
|
67
|
+
return if obsolete_native_script_line?(section, line)
|
|
68
|
+
|
|
69
|
+
command, *arguments = Shellwords.shellsplit(line)
|
|
70
|
+
|
|
71
|
+
case section
|
|
72
|
+
when :prep
|
|
73
|
+
migrated_prep_command(command, arguments, line)
|
|
74
|
+
when :build, :install
|
|
75
|
+
line unless obsolete_version_export?(command, arguments)
|
|
76
|
+
else
|
|
77
|
+
line
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def obsolete_native_script_line? section, line
|
|
82
|
+
(section == :check && line.match?(/^\s*#+\s*%*ruby_test(?:_unit)?(?:\s|$)/)) ||
|
|
83
|
+
(section == :install && obsolete_ri_cleanup?(line))
|
|
84
|
+
end
|
|
85
|
+
end
|