summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authordoko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-28 09:12:05 +0000
committerdoko <doko@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-28 09:12:05 +0000
commite3e8c48c4a494d9da741c1c8ea6c4c0b7c4ff934 (patch)
treea72db5c4b6147a63f588b215e341061ba7b18de5 /libcpp
parentf0307fcb54df45f94a262c3ce5af1cb97b0b4a6d (diff)
downloadgcc-e3e8c48c4a494d9da741c1c8ea6c4c0b7c4ff934.tar.gz
gcc/c-family/ChangeLog:
2016-04-28 Eduard Sanou <dhole@openmailbox.org> Matthias Klose <doko@debian.org> * c-common.c (get_source_date_epoch): New function, gets the environment variable SOURCE_DATE_EPOCH and parses it as long long with error handling. * c-common.h (get_source_date_epoch): Prototype. * c-lex.c (c_lex_with_flags): set parse_in->source_date_epoch. gcc/ChangeLog: 2016-04-28 Eduard Sanou <dhole@openmailbox.org> Matthias Klose <doko@debian.org> * doc/cppenv.texi: Document SOURCE_DATE_EPOCH environment variable. libcpp/ChangeLog: 2016-04-28 Eduard Sanou <dhole@openmailbox.org> Matthias Klose <doko@debian.org> * include/cpplib.h (cpp_init_source_date_epoch): Prototype. * init.c (cpp_init_source_date_epoch): New function. * internal.h: Added source_date_epoch variable to struct cpp_reader to store a reproducible date. * macro.c (_cpp_builtin_macro_text): Set pfile->date timestamp from pfile->source_date_epoch instead of localtime if source_date_epoch is set, to be used for __DATE__ and __TIME__ macros to help reproducible builds. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@235550 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog12
-rw-r--r--libcpp/include/cpplib.h3
-rw-r--r--libcpp/init.c9
-rw-r--r--libcpp/internal.h4
-rw-r--r--libcpp/macro.c21
5 files changed, 41 insertions, 8 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index acb8d75dccf..1dc1c73bff2 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,15 @@
+2016-04-28 Eduard Sanou <dhole@openmailbox.org>
+ Matthias Klose <doko@debian.org>
+
+ * include/cpplib.h (cpp_init_source_date_epoch): Prototype.
+ * init.c (cpp_init_source_date_epoch): New function.
+ * internal.h: Added source_date_epoch variable to struct
+ cpp_reader to store a reproducible date.
+ * macro.c (_cpp_builtin_macro_text): Set pfile->date timestamp from
+ pfile->source_date_epoch instead of localtime if source_date_epoch is
+ set, to be used for __DATE__ and __TIME__ macros to help reproducible
+ builds.
+
2016-04-13 Bernd Schmidt <bschmidt@redhat.com>
Patch from Roger Orr <rogero@howzatt.demon.co.uk>
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 35b0375c09c..4998b3a8ab8 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -784,6 +784,9 @@ extern void cpp_init_special_builtins (cpp_reader *);
/* Set up built-ins like __FILE__. */
extern void cpp_init_builtins (cpp_reader *, int);
+/* Initialize the source_date_epoch value. */
+extern void cpp_init_source_date_epoch (cpp_reader *, time_t);
+
/* This is called after options have been parsed, and partially
processed. */
extern void cpp_post_options (cpp_reader *);
diff --git a/libcpp/init.c b/libcpp/init.c
index 4343075ba85..f5ff85b3bae 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -533,8 +533,15 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
_cpp_define_builtin (pfile, "__OBJC__ 1");
}
+/* Initialize the source_date_epoch value. */
+void
+cpp_init_source_date_epoch (cpp_reader *pfile, time_t source_date_epoch)
+{
+ pfile->source_date_epoch = source_date_epoch;
+}
+
/* Sanity-checks are dependent on command-line options, so it is
- called as a subroutine of cpp_read_main_file (). */
+ called as a subroutine of cpp_read_main_file. */
#if CHECKING_P
static void sanity_checks (cpp_reader *);
static void sanity_checks (cpp_reader *pfile)
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 9ce870738cc..e3eb26b1f27 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -502,6 +502,10 @@ struct cpp_reader
const unsigned char *date;
const unsigned char *time;
+ /* Externally set timestamp to replace current date and time useful for
+ reproducibility. */
+ time_t source_date_epoch;
+
/* EOF token, and a token forcing paste avoidance. */
cpp_token avoid_paste;
cpp_token eof;
diff --git a/libcpp/macro.c b/libcpp/macro.c
index c2515534504..c2a83764660 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -357,13 +357,20 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node,
time_t tt;
struct tm *tb = NULL;
- /* (time_t) -1 is a legitimate value for "number of seconds
- since the Epoch", so we have to do a little dance to
- distinguish that from a genuine error. */
- errno = 0;
- tt = time(NULL);
- if (tt != (time_t)-1 || errno == 0)
- tb = localtime (&tt);
+ /* Set a reproducible timestamp for __DATE__ and __TIME__ macro
+ usage if SOURCE_DATE_EPOCH is defined. */
+ if (pfile->source_date_epoch != (time_t) -1)
+ tb = gmtime (&pfile->source_date_epoch);
+ else
+ {
+ /* (time_t) -1 is a legitimate value for "number of seconds
+ since the Epoch", so we have to do a little dance to
+ distinguish that from a genuine error. */
+ errno = 0;
+ tt = time (NULL);
+ if (tt != (time_t)-1 || errno == 0)
+ tb = localtime (&tt);
+ }
if (tb)
{