Source: ruby-prawn
Version: 1.3.0
Severity: wishlist
Tags: patch
User: reproducible-builds@lists.alioth.debian.org
Usertags: timestamps
Control: block -1 by 782890

Hi!

While working on the “reproducible builds” effort [1], we have noticed
that ruby-prawn could not be built reproducibly.

The attached patch will set the manual last update date to the latest
debian/changelog entry.

Applied together with the patch submitted for #782890, ruby-prawn can
then be built reproducibly in our current experimental framework.

 [1]: https://wiki.debian.org/ReproducibleBuilds

-- 
Lunar                                .''`. 
lu...@debian.org                    : :Ⓐ  :  # apt-get install anarchism
                                    `. `'` 
                                      `-   
From 27cfd53708b0133278723dee307e812e4f74a33e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Bobbio?= <lu...@debian.org>
Date: Sun, 19 Apr 2015 16:06:50 +0200
Subject: [PATCH 2/2] Make the package build reproducibly

Add 0800_enable_manual_to_be_built_reproducibly.patch
to allow the manual last update to be set using an environment
variable and set it in debian/rules.
---
 debian/changelog                                   |  5 ++
 ...00_enable_manual_to_be_built_reproducibly.patch | 56 ++++++++++++++++++++++
 debian/patches/series                              |  1 +
 debian/rules                                       |  4 ++
 4 files changed, 66 insertions(+)
 create mode 100644 debian/patches/0800_enable_manual_to_be_built_reproducibly.patch

diff --git a/debian/changelog b/debian/changelog
index eef987e..0fc542b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,11 @@ ruby-prawn (1.3.0+dfsg-1.0~reproducible1) UNRELEASED; urgency=low
 
   * Add 0700_use_deterministic_keys_for_gradients.patch to make
     Prawn build PDF in a deterministic manner when they use gradients.
+  * Make the package build reproducibly:
+    - Add 0800_enable_manual_to_be_built_reproducibly.patch
+      to allow the manual last update to be set using an environment
+      variable.
+    - Set the build date in debian/rules.
 
  -- Jérémy Bobbio <lu...@debian.org>  Sun, 19 Apr 2015 14:25:51 +0200
 
diff --git a/debian/patches/0800_enable_manual_to_be_built_reproducibly.patch b/debian/patches/0800_enable_manual_to_be_built_reproducibly.patch
new file mode 100644
index 0000000..e6fc7e1
--- /dev/null
+++ b/debian/patches/0800_enable_manual_to_be_built_reproducibly.patch
@@ -0,0 +1,56 @@
+Description: Enable manual to be built reproducibly
+ In order to make the manual build reproducibly, we need a way to stop
+ writing the current build time in it.
+ .
+ The following patch will allow this in two ways: if BUILD_DATE is set
+ in the environment, the date will be taken from there; otherwise, if
+ the Git index is available, the date of the last commit will be used.
+Author: Jérémy Bobbio <lu...@debian.org>
+
+Index: git/manual/cover.rb
+===================================================================
+--- git.orig/manual/cover.rb	2015-04-19 14:21:50.000000000 +0200
++++ git/manual/cover.rb	2015-04-19 14:52:37.936507292 +0200
+@@ -23,17 +23,20 @@
+                         :size => 60}
+                      ], :at => [170, cursor - 160])
+ 
++  last_update = Time.at(ENV['BUILD_EPOCH'].to_i) if ENV['BUILD_EPOCH']
+   if Dir.exist?("#{Prawn::BASEDIR}/.git")
+     #long git commit hash
+     #commit = `git show --pretty=%H`
+     #short git commit hash
+     commit = `git show --pretty=%h`
+     git_commit = "git commit: #{commit}"
++    last_update ||= Time.at(`git log -1 --pretty='%ct'`.to_i)
+   else
+     git_commit = ""
++    last_update ||= Time.now
+   end
+ 
+-  formatted_text_box([  {:text => "Last Update: #{Time.now.strftime("%Y-%m-%d")}\n"+
++  formatted_text_box([  {:text => "Last Update: #{last_update.utc.strftime('%Y-%m-%d')}\n"+
+                                   "Prawn Version: #{Prawn::VERSION}\n"+
+                                   git_commit,
+                          :size => 12}
+Index: git/manual/document_and_page_options/metadata.rb
+===================================================================
+--- git.orig/manual/document_and_page_options/metadata.rb	2015-04-19 14:12:16.182219653 +0200
++++ git/manual/document_and_page_options/metadata.rb	2015-04-19 14:52:46.300625712 +0200
+@@ -7,6 +7,7 @@
+ require File.expand_path(File.join(File.dirname(__FILE__),
+                                    %w[.. example_helper]))
+ 
++creation_date = ENV['BUILD_EPOCH'] ? Time.at(ENV['BUILD_EPOCH'].to_i) : Time.now
+ Prawn::Document.generate("metadata.pdf",
+   :info => {
+     :Title        => "My title",
+@@ -15,7 +16,7 @@
+     :Keywords     => "test metadata ruby pdf dry",
+     :Creator      => "ACME Soft App",
+     :Producer     => "Prawn",
+-    :CreationDate => Time.now
++    :CreationDate => creation_date.utc
+   }) do
+ 
+   text "This is a test of setting metadata properties via the info option."
diff --git a/debian/patches/series b/debian/patches/series
index 3ddcfe4..6aca906 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -6,3 +6,4 @@
 0500_disable_tests_using_removed_files.patch
 0600_replace_require_relative_manual.patch
 0700_use_deterministic_keys_for_gradients.patch
+0800_enable_manual_to_be_built_reproducibly.patch
diff --git a/debian/rules b/debian/rules
index f98f768..5a0b525 100755
--- a/debian/rules
+++ b/debian/rules
@@ -11,6 +11,10 @@
 # If you need to specify the .gemspec (eg there is more than one)
 #export DH_RUBY_GEMSPEC=gem.gemspec
 
+LAST_CHANGE = $(shell dpkg-parsechangelog -S Date)
+BUILD_EPOCH = $(shell date -u +"%s" --date="$(LAST_CHANGE)")
+export BUILD_EPOCH
+
 %:
 	dh $@ --buildsystem=ruby --with ruby
 
-- 
1.9.1

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to