From MAILER-DAEMON Thu Jul 28 22:29:13 2016 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1bSxY1-0004nx-LO for mharc-groff-commit@gnu.org; Thu, 28 Jul 2016 22:29:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSxXy-0004mJ-9p for groff-commit@gnu.org; Thu, 28 Jul 2016 22:29:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSxXw-0002Gs-B0 for groff-commit@gnu.org; Thu, 28 Jul 2016 22:29:10 -0400 Received: from vcs.savannah.gnu.org ([208.118.235.72]:50726) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSxXw-0002Go-5r for groff-commit@gnu.org; Thu, 28 Jul 2016 22:29:08 -0400 Received: by vcs.savannah.gnu.org (Postfix, from userid 67502) id 03B5422016B; Fri, 29 Jul 2016 02:29:07 +0000 (UTC) To: groff-commit@gnu.org Subject: [groff] 01/01: Implement `SOURCE_DATE_EPOCH' for reproducible builds. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Reply-To: Colin Watson In-Reply-To: groff@gnu.org References: <20160729022907.12547.93141@vcs.savannah.gnu.org> X-Git-Repo: groff X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: e4290210f2c1db5292d97678197a986d6822d044 Auto-Submitted: auto-generated Message-Id: <20160729022908.03B5422016B@vcs.savannah.gnu.org> Date: Fri, 29 Jul 2016 02:29:07 +0000 (UTC) From: cjwatson@debian.org (Colin Watson) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.72 X-BeenThere: groff-commit@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2016 02:29:12 -0000 cjwatson pushed a commit to branch master in repository groff. commit e4290210f2c1db5292d97678197a986d6822d044 Author: Colin Watson Date: Fri Jul 29 03:25:26 2016 +0100 Implement `SOURCE_DATE_EPOCH' for reproducible builds. =20 * src/include/curtime.h: New file. * src/libs/libgroff/curtime.cpp: New file. * src/libs/libgroff/libgroff.am (libgroff_a_SOURCES): Add src/libs/libgroff/curtime.cpp. =20 * src/roff/troff/input.cpp (init_registers): Use `current_time' instead of `time(0)'. * src/devices/grohtml/post-html.cpp (html_printer::do_file_components): Likewise. (html_printer::~html_printer): Likewise. * src/devices/grops/ps.cpp (ps_printer::~ps_printer): Likewise. * src/devices/gropdf/gropdf.pl: Use `$ENV{SOURCE_DATE_EPOCH}` if available in preference to `time`. =20 * doc/groff.texi (Environment): Document `SOURCE_DATE_EPOCH'. * src/devices/grohtml/grohtml.1.man (ENVIRONMENT): Likewise. * src/devices/gropdf/gropdf.1.man (ENVIRONMENT): Likewise. * src/devices/grops/grops.1.man (ENVIRONMENT): Likewise. --- ChangeLog | 23 +++++++++++++++++ doc/groff.texi | 6 +++++ src/devices/grohtml/grohtml.1.man | 7 +++++ src/devices/grohtml/post-html.cpp | 5 ++-- src/devices/gropdf/gropdf.1.man | 7 +++++ src/devices/gropdf/gropdf.pl | 3 ++- src/devices/grops/grops.1.man | 7 +++++ src/devices/grops/ps.cpp | 3 ++- src/include/curtime.h | 23 +++++++++++++++++ src/libs/libgroff/curtime.cpp | 51 +++++++++++++++++++++++++++++++= ++++++ src/libs/libgroff/libgroff.am | 1 + src/roff/troff/input.cpp | 3 ++- 12 files changed, 134 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66961cc..156d23a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2016-07-29 Colin Watson + + Implement `SOURCE_DATE_EPOCH' for reproducible builds. + + * src/include/curtime.h: New file. + * src/libs/libgroff/curtime.cpp: New file. + * src/libs/libgroff/libgroff.am (libgroff_a_SOURCES): Add + src/libs/libgroff/curtime.cpp. + + * src/roff/troff/input.cpp (init_registers): Use `current_time' + instead of `time(0)'. + * src/devices/grohtml/post-html.cpp + (html_printer::do_file_components): Likewise. + (html_printer::~html_printer): Likewise. + * src/devices/grops/ps.cpp (ps_printer::~ps_printer): Likewise. + * src/devices/gropdf/gropdf.pl: Use `$ENV{SOURCE_DATE_EPOCH}` if + available in preference to `time`. + + * doc/groff.texi (Environment): Document `SOURCE_DATE_EPOCH'. + * src/devices/grohtml/grohtml.1.man (ENVIRONMENT): Likewise. + * src/devices/gropdf/gropdf.1.man (ENVIRONMENT): Likewise. + * src/devices/grops/grops.1.man (ENVIRONMENT): Likewise. + 2016-04-19 Carsten Kunze =20 eqn: Fix problem with explicite spacing before unary operator diff --git a/doc/groff.texi b/doc/groff.texi index 8db136e..7610fef 100644 --- a/doc/groff.texi +++ b/doc/groff.texi @@ -1453,6 +1453,12 @@ default directory (on Unix and GNU/Linux systems, = this is usually @item GROFF_TYPESETTER @tindex GROFF_TYPESETTER@r{, environment variable} The default output device. + +@item SOURCE_DATE_EPOCH +@tindex SOURCE_DATE_EPOCH@r{, environment variable} +A timestamp (expressed as seconds since the Unix epoch) to use in place = of +the current time when initializing time-based built-in registers such as +@code{\n[seconds]}. @end table =20 Note that MS-DOS and MS-Windows ports of @code{groff} use semi-colons, diff --git a/src/devices/grohtml/grohtml.1.man b/src/devices/grohtml/groh= tml.1.man index 2efdd81..f8c45dd 100644 --- a/src/devices/grohtml/grohtml.1.man +++ b/src/devices/grohtml/grohtml.1.man @@ -419,6 +419,13 @@ and for more details. . . +.TP +.SM +.B SOURCE_DATE_EPOCH +A timestamp (expressed as seconds since the Unix epoch) to use as the +creation timestamp in place of the current time. +. +. .\" -------------------------------------------------------------------- .SH BUGS .\" -------------------------------------------------------------------- diff --git a/src/devices/grohtml/post-html.cpp b/src/devices/grohtml/post= -html.cpp index fefbf01..b5fc516 100644 --- a/src/devices/grohtml/post-html.cpp +++ b/src/devices/grohtml/post-html.cpp @@ -28,6 +28,7 @@ along with this program. If not, see . */ #include "html.h" #include "html-text.h" #include "html-table.h" +#include "curtime.h" =20 #include =20 @@ -5013,7 +5014,7 @@ void html_printer::do_file_components (void) .put_string(Version_string) .end_comment(); =20 - t =3D time(0); + t =3D current_time(); html.begin_comment("CreationDate: ") .put_string(ctime(&t), strlen(ctime(&t))-1) .end_comment(); @@ -5126,7 +5127,7 @@ html_printer::~html_printer() .put_string(Version_string) .end_comment(); =20 - t =3D time(0); + t =3D current_time(); html.begin_comment("CreationDate: ") .put_string(ctime(&t), strlen(ctime(&t))-1) .end_comment(); diff --git a/src/devices/gropdf/gropdf.1.man b/src/devices/gropdf/gropdf.= 1.man index 25287a6..4a06c0f 100644 --- a/src/devices/gropdf/gropdf.1.man +++ b/src/devices/gropdf/gropdf.1.man @@ -1024,6 +1024,13 @@ and for more details. . . +.TP +.SM +.B SOURCE_DATE_EPOCH +A timestamp (expressed as seconds since the Unix epoch) to use as the +creation timestamp in place of the current time. +. +. .\" -------------------------------------------------------------------- .SH FILES .\" -------------------------------------------------------------------- diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl index 0744378..b95169e 100644 --- a/src/devices/gropdf/gropdf.pl +++ b/src/devices/gropdf/gropdf.pl @@ -259,13 +259,14 @@ elsif (exists($ppsz{$papersz})) @defaultmb=3D@mediabox=3D(0,0,$ppsz{$papersz}->[0],$ppsz{$papersz}->= [1]); } =20 -my (@dt)=3Dlocaltime(time); +my (@dt)=3Dlocaltime($ENV{SOURCE_DATE_EPOCH} || time); my $dt=3DPDFDate(\@dt); =20 my %info=3D('Creator' =3D> "(groff version $cfg{GROFF_VERSION})", 'Producer' =3D> "(gropdf version $cfg{GROFF_VERSION})", 'ModDate' =3D> "($dt)", 'CreationDate' =3D> "($dt)"); + while (<>) { chomp; diff --git a/src/devices/grops/grops.1.man b/src/devices/grops/grops.1.ma= n index e7064d2..55b26f7 100644 --- a/src/devices/grops/grops.1.man +++ b/src/devices/grops/grops.1.man @@ -1423,6 +1423,13 @@ and for more details. . . +.TP +.SM +.B SOURCE_DATE_EPOCH +A timestamp (expressed as seconds since the Unix epoch) to use as the +creation timestamp in place of the current time. +. +. .\" -------------------------------------------------------------------- .SH FILES .\" -------------------------------------------------------------------- diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp index 1215100..86b2b9d 100644 --- a/src/devices/grops/ps.cpp +++ b/src/devices/grops/ps.cpp @@ -28,6 +28,7 @@ along with this program. If not, see . */ #include "cset.h" #include "nonposix.h" #include "paper.h" +#include "curtime.h" =20 #include "ps.h" #include @@ -1390,7 +1391,7 @@ ps_printer::~ps_printer() #else time_t #endif - t =3D time(0); + t =3D current_time(); fputs(ctime(&t), out.get_file()); } for (font_pointer_list *f =3D font_list; f; f =3D f->next) { diff --git a/src/include/curtime.h b/src/include/curtime.h new file mode 100644 index 0000000..a410519 --- /dev/null +++ b/src/include/curtime.h @@ -0,0 +1,23 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + +This file is part of groff. + +groff is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation, either version 2 of the License, or +(at your option) any later version. + +groff is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +The GNU General Public License version 2 (GPL2) is available in the +internet at . */ + +#ifdef LONG_FOR_TIME_T +long +#else +time_t +#endif +current_time(); diff --git a/src/libs/libgroff/curtime.cpp b/src/libs/libgroff/curtime.cp= p new file mode 100644 index 0000000..00821b7 --- /dev/null +++ b/src/libs/libgroff/curtime.cpp @@ -0,0 +1,51 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + +This file is part of groff. + +groff is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation, either version 2 of the License, or +(at your option) any later version. + +groff is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +The GNU General Public License version 2 (GPL2) is available in the +internet at . */ + +#include +#include +#include +#include +#include + +#include "errarg.h" +#include "error.h" + +#ifdef LONG_FOR_TIME_T +long +#else +time_t +#endif +current_time() +{ + char *source_date_epoch =3D getenv("SOURCE_DATE_EPOCH"); + + if (source_date_epoch) { + errno =3D 0; + char *endptr; + long epoch =3D strtol(source_date_epoch, &endptr, 10); + + if ((errno =3D=3D ERANGE && (epoch =3D=3D LONG_MAX || epoch =3D=3D L= ONG_MIN)) || + (errno !=3D 0 && epoch =3D=3D 0)) + fatal("$SOURCE_DATE_EPOCH: strtol: %1", strerror(errno)); + if (endptr =3D=3D source_date_epoch) + fatal("$SOURCE_DATE_EPOCH: no digits found: %1", endptr); + if (*endptr !=3D '\0') + fatal("$SOURCE_DATE_EPOCH: trailing garbage: %1", endptr); + return epoch; + } else + return time(0); +} diff --git a/src/libs/libgroff/libgroff.am b/src/libs/libgroff/libgroff.a= m index 78e3394..e215f2e 100644 --- a/src/libs/libgroff/libgroff.am +++ b/src/libs/libgroff/libgroff.am @@ -33,6 +33,7 @@ libgroff_a_SOURCES =3D \ src/libs/libgroff/cmap.cpp \ src/libs/libgroff/color.cpp \ src/libs/libgroff/cset.cpp\ + src/libs/libgroff/curtime.cpp \ src/libs/libgroff/device.cpp \ src/libs/libgroff/errarg.cpp \ src/libs/libgroff/error.cpp \ diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp index 2d346d7..7cc2d91 100644 --- a/src/roff/troff/input.cpp +++ b/src/roff/troff/input.cpp @@ -36,6 +36,7 @@ along with this program. If not, see . */ #include "input.h" #include "defs.h" #include "unicode.h" +#include "curtime.h" =20 // Needed for getpid() and isatty() #include "posix.h" @@ -8080,7 +8081,7 @@ static void init_registers() #else /* not LONG_FOR_TIME_T */ time_t #endif /* not LONG_FOR_TIME_T */ - t =3D time(0); + t =3D current_time(); // Use struct here to work around misfeature in old versions of g++. struct tm *tt =3D localtime(&t); set_number_reg("seconds", int(tt->tm_sec));