diff options
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 12 | ||||
-rw-r--r-- | libcpp/include/cpplib.h | 6 | ||||
-rw-r--r-- | libcpp/init.c | 10 | ||||
-rw-r--r-- | libcpp/internal.h | 3 | ||||
-rw-r--r-- | libcpp/macro.c | 10 |
5 files changed, 27 insertions, 14 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index d7a89d7..5d18c0a 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,15 @@ +2016-06-01 Eduard Sanou <dhole@openmailbox.org> + + * include/cpplib.h (cpp_callbacks): Add get_source_date_epoch + callback. + * include/cpplib.h (cpp_init_source_date_epoch): Remove prototype. + * init.c (cpp_init_source_date_epoch): Remove function. + * init.c (cpp_create_reader): Initialize pfile->source_date_epoch. + * internal.h (cpp_reader): Extend comment about source_date_epoch. + * macro.c (_cpp_builtin_macro_text): Use get_source_date_epoch + callback only once, read pfile->source_date_epoch on future passes. + Check that get_source_date_epoch callback is not NULL. + 2016-05-20 Martin Liska <mliska@suse.cz> * config.in: Regenerated. diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 4998b3a..9d70cc8 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -594,6 +594,9 @@ struct cpp_callbacks /* Callback that can change a user builtin into normal macro. */ bool (*user_builtin_macro) (cpp_reader *, cpp_hashnode *); + + /* Callback to parse SOURCE_DATE_EPOCH from environment. */ + time_t (*get_source_date_epoch) (cpp_reader *); }; #ifdef VMS @@ -784,9 +787,6 @@ 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 f5ff85b..e78b320 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -257,6 +257,9 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table, /* Do not force token locations by default. */ pfile->forced_token_location_p = NULL; + /* Initialize source_date_epoch to -2 (not yet set). */ + pfile->source_date_epoch = (time_t) -2; + /* The expression parser stack. */ _cpp_expand_op_stack (pfile); @@ -533,13 +536,6 @@ 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. */ #if CHECKING_P diff --git a/libcpp/internal.h b/libcpp/internal.h index e3eb26b..cea32ec 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -503,7 +503,8 @@ struct cpp_reader const unsigned char *time; /* Externally set timestamp to replace current date and time useful for - reproducibility. */ + reproducibility. It should be initialized to -2 (not yet set) and + set to -1 to disable it or to a non-negative value to enable it. */ time_t source_date_epoch; /* EOF token, and a token forcing paste avoidance. */ diff --git a/libcpp/macro.c b/libcpp/macro.c index c2a8376..a3b8348 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -358,9 +358,13 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node, struct tm *tb = NULL; /* 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); + if SOURCE_DATE_EPOCH is defined. */ + if (pfile->source_date_epoch == (time_t) -2 + && pfile->cb.get_source_date_epoch != NULL) + pfile->source_date_epoch = pfile->cb.get_source_date_epoch (pfile); + + if (pfile->source_date_epoch >= (time_t) 0) + tb = gmtime (&pfile->source_date_epoch); else { /* (time_t) -1 is a legitimate value for "number of seconds |