Skip to content

Do not store current timestamps in gz headers #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/rdoc/generator/json_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ def generate

JSON.dump data, io, 0
end
unless ENV['SOURCE_DATE_EPOCH'].nil?
index_file.utime index_file.atime, Time.at(ENV['SOURCE_DATE_EPOCH'].to_i).gmtime
end

Dir.chdir @template_dir do
Dir['**/*.js'].each do |source|
dest = File.join out_dir, source

FileUtils.install source, dest, :mode => 0644, :verbose => $DEBUG_RDOC
FileUtils.install source, dest, :mode => 0644, :preserve => true, :verbose => $DEBUG_RDOC
end
end
end
Expand Down
29 changes: 28 additions & 1 deletion test/test_rdoc_generator_json_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
def setup
super

@tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_darkfish_#{$$}"
@tmpdir = Dir.mktmpdir "test_rdoc_generator_darkfish_#{$$}_"
FileUtils.mkdir_p @tmpdir

@options = RDoc::Options.new
Expand Down Expand Up @@ -89,12 +89,25 @@ def test_file_dir
end

def test_generate
now = Time.now
@g.generate

assert_file 'js/searcher.js'
assert_file 'js/navigation.js'
assert_file 'js/search_index.js'

orig_file = Pathname(File.join @pwd, 'lib/rdoc/generator/template/json_index/js/navigation.js')
generated_file = Pathname(File.join @tmpdir, 'js/navigation.js')

# This is dirty hack on JRuby for MiniTest 4
assert orig_file.mtime.inspect == generated_file.mtime.inspect,
'.js files should be tha same timestamp of original'

assert generated_file.mtime < now, '.js files should be the same timestamp'

generated_search_index = Pathname(File.join @tmpdir, 'js/search_index.js')
assert generated_search_index.mtime > (now - 1), 'search_index.js should be generated timestamp'

json = File.read 'js/search_index.js'

json =~ /\Avar search_data = /
Expand Down Expand Up @@ -137,6 +150,20 @@ def test_generate
assert_equal expected, index
end

def test_generate_search_index_with_reproducible_builds
backup_epoch = ENV['SOURCE_DATE_EPOCH']
ruby_birthday = Time.parse 'Wed, 24 Feb 1993 21:00:00 +0900'
ENV['SOURCE_DATE_EPOCH'] = ruby_birthday.to_i.to_s

@g.generate

assert_file 'js/search_index.js'
generated_search_index = Pathname(File.join @tmpdir, 'js/search_index.js')
assert_equal ruby_birthday, generated_search_index.mtime

ENV['SOURCE_DATE_EPOCH'] = backup_epoch
end

def test_generate_gzipped
begin
require 'zlib'
Expand Down