[Misc #22206] Sync dependency files from default gems

Keep complete dependency rules in upstream gems while storing only source
mappings in the Ruby repository.
This commit is contained in:
Nobuyoshi Nakada authored and Nobuyoshi Nakada committed 2026-08-28 10:49:39 +09:00
1 parent 888a9fe269
commit b414f2825d
2 files changed
+47 -2
Notes: git 2026-08-28 01:50:28 +00:00

No files matched your search

+20 -2
View File
@@ -6,6 +6,7 @@ require 'fileutils'
require "rbconfig"
require "find"
require "tempfile"
require_relative "../lib/mkmf/depend"
module SyncDefaultGems
include FileUtils
@@ -46,7 +47,6 @@ module SyncDefaultGems
def repo((upstream, branch), mappings, exclude: [])
branch ||= CLASSICAL_DEFAULT_BRANCH
exclude += ["ext/**/depend"]
Repository.new(upstream:, branch:, mappings:, exclude:)
end
@@ -194,7 +194,6 @@ module SyncDefaultGems
["History.md", "ext/openssl/History.md"],
], exclude: [
"test/openssl/envutil.rb",
"ext/openssl/depend",
]),
optparse: lib("ruby/optparse", gemspec_in_subdir: true).tap {
it.mappings << ["doc/optparse", "doc/optparse"]
@@ -395,6 +394,23 @@ module SyncDefaultGems
end
end
def minimize_dependencies(gem)
files = REPOSITORIES[gem].mappings.flat_map do |_src, dst|
if File.file?(dst)
File.basename(dst) == "depend" ? [dst] : []
elsif File.directory?(dst)
Dir.glob("#{dst}/**/depend")
else
[]
end
end.uniq
return if files.empty?
MakeMakefile::Depend.new(root: Dir.pwd).run(
files, mode: :inplace, sources: true,
)
end
# We usually don't use this. Please consider using #sync_default_gems_with_commits instead.
def sync_default_gems(gem)
config = REPOSITORIES[gem]
@@ -438,6 +454,7 @@ module SyncDefaultGems
if gem == "rubygems"
rubygems_do_fixup
end
minimize_dependencies(gem)
check_prerelease_version(gem)
@@ -653,6 +670,7 @@ module SyncDefaultGems
if gem == "rubygems"
rubygems_do_fixup
end
minimize_dependencies(gem)
replace_rdoc_ref_all_full
end
+27
View File
@@ -225,6 +225,33 @@ module Test_SyncDefaultGems
assert_operator(top_commit(@target), :start_with?, log.last[/\h+$/], out)
end
def test_minimize_dependencies
SyncDefaultGems::REPOSITORIES[@target].mappings <<
["ext/example", "ext/example"]
Dir.mkdir("#@target/ext")
Dir.mkdir("#@target/ext/example")
File.write("#@target/ext/example/example.c", <<~C)
#include "example.h"
C
File.write("#@target/ext/example/example.h", "")
File.write("#@target/ext/example/depend", <<~MAKE)
# AUTOGENERATED DEPENDENCIES START
example.o: example.c
example.o: example.h
# AUTOGENERATED DEPENDENCIES END
MAKE
git(*%W"add ext/example", chdir: @target)
git(*%W"commit -q -m", "Add extension", chdir: @target)
out = assert_sync()
assert_equal(<<~MAKE, File.read("src/ext/example/depend"), out)
# AUTOGENERATED DEPENDENCIES START
example.o: example.c
# AUTOGENERATED DEPENDENCIES END
MAKE
end
def test_unknown_repository
assert_raise_with_message(RuntimeError, /unknown/) do
SyncDefaultGems::REPOSITORIES["not-exist"]