mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 05:25:34 +02:00
[rubygems/rubygems] Set SOURCE_DATE_EPOCH env var if not provided.
Fixes #2290.
1. `Gem::Specification.date` returns SOURCE_DATE_EPOCH when defined,
2. this commit makes RubyGems set it _persistently_ when not provided.
This combination means that you can build a gem, check the build time,
and use that value to generate a new build -- and then verify they're
the same.
d830d53f59
This commit is contained in:
parent
8436b2717c
commit
508afe2c26
6 changed files with 82 additions and 6 deletions
|
@ -457,4 +457,36 @@ class TestGemCommandsBuildCommand < Gem::TestCase
|
|||
assert_match(/INFO: Your expired cert will be located at: .+\Wgem-public_cert\.pem\.expired\.[0-9]+/, output.shift)
|
||||
end
|
||||
|
||||
def test_build_is_reproducible
|
||||
epoch = ENV["SOURCE_DATE_EPOCH"]
|
||||
new_epoch = Time.now.to_i.to_s
|
||||
ENV["SOURCE_DATE_EPOCH"] = new_epoch
|
||||
|
||||
gem_file = File.basename(@gem.cache_file)
|
||||
|
||||
gemspec_file = File.join(@tempdir, @gem.spec_name)
|
||||
File.write(gemspec_file, @gem.to_ruby)
|
||||
@cmd.options[:args] = [gemspec_file]
|
||||
|
||||
util_test_build_gem @gem
|
||||
|
||||
build1_contents = File.read(gem_file)
|
||||
|
||||
# Guarantee the time has changed.
|
||||
sleep 1 if Time.now.to_i == new_epoch
|
||||
|
||||
ENV["SOURCE_DATE_EPOCH"] = new_epoch
|
||||
|
||||
@ui = Gem::MockGemUi.new
|
||||
@cmd.options[:args] = [gemspec_file]
|
||||
|
||||
util_test_build_gem @gem
|
||||
|
||||
build2_contents = File.read(gem_file)
|
||||
|
||||
assert_equal build1_contents, build2_contents
|
||||
ensure
|
||||
ENV["SOURCE_DATE_EPOCH"] = epoch
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue