This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Allow embedded timestamps by C/C++ macros to be set externally (3)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Dhole <dhole at openmailbox dot org>
- Cc: Bernd Schmidt <bschmidt at redhat dot com>, Matthias Klose <doko at ubuntu dot com>, gcc-patches at gcc dot gnu dot org
- Date: Fri, 29 Apr 2016 09:17:44 +0200
- Subject: Re: Allow embedded timestamps by C/C++ macros to be set externally (3)
- Authentication-results: sourceware.org; auth=none
- References: <20160426212803 dot GB11894 at panther> <571FFADB dot 3080209 at redhat dot com> <20160427155633 dot GA21574 at panther> <5721D5DC dot 7060004 at ubuntu dot com> <20160428100815 dot GL26501 at tucnak dot zalov dot cz> <5721E68C dot 20208 at redhat dot com> <20160428103506 dot GM26501 at tucnak dot zalov dot cz> <57220BC2 dot 7080901 at redhat dot com> <20160428131420 dot GO26501 at tucnak dot zalov dot cz> <20160428182956 dot GG21574 at panther>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Apr 28, 2016 at 08:29:56PM +0200, Dhole wrote:
> There is the Wdate-time flag, that warns on using __DATE__, __TIME__ and
> __TIMESTAMP__. Although that alone will not make the compilation fail
> unless it's used with Werror.
>
> The reason behind using fatal_error (rather than a warning) when
> SOURCE_DATE_EPOCH contains an invalid value is due to the
> SOURCE_DATE_EPOCH specification [1]:
>
> SOURCE_DATE_EPOCH
> (...)
> If the value is malformed, the build process SHOULD exit with a non-zero error code.
First of all, using error instead of fatal_error achieves just that too,
except that it allows also detecting other errors in the source.
fatal_error is meant for cases where there is no way to go forward with the
compilation, while here exists a perfectly reasonable way to go forward (assume
the env var is not set, use a hardcoded timestamp, ...).
> And the reason for reading and parsing the env var in gcc/ rather than
> when the macro is expanded for the first time (in libcpp/) is from a
> comment by Joseph Myers made the first time I submited this patch [2].
> The most clean way to read the env var from gcc/ I found was to do it
> during the initialization. But if you think this should be done
> different I'm open to change the implementation.
Doing this on the gcc/ side is of course reasonable, but can be done through
callbacks, libcpp already has lots of other callbacks into the gcc/ code,
look for e.g. cpp_get_callbacks in gcc/c-family/* and in libcpp/ for
corresponding code.
> Bernd: I'll see if I can prepare a testcase; first I need to get
> familiar with the testing framework and learn how to set environment
> variables in tests. Any tips on that will be really welcome!
grep for dg-set-target-env-var in various tests.
Jakub