[all-commits] [llvm/llvm-project] 2c0901: [Frontend] Recognize environment variable SOURCE_D...

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Oct 12 11:55:47 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2c090162746a6b901c5639562c090e4bb2b7327e
      https://github.com/llvm/llvm-project/commit/2c090162746a6b901c5639562c090e4bb2b7327e
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-10-12 (Wed, 12 Oct 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticFrontendKinds.td
    M clang/include/clang/Lex/PreprocessorOptions.h
    M clang/lib/Frontend/CompilerInvocation.cpp
    M clang/lib/Lex/PPMacroExpansion.cpp
    A clang/test/Preprocessor/SOURCE_DATE_EPOCH.c

  Log Message:
  -----------
  [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

See https://reproducible-builds.org/docs/source-date-epoch/ . The environment
variable ``SOURCE_DATE_EPOCH`` been recognized by many compilers.

In GCC, if `SOURCE_DATE_EPOCH` is set, it specifies a UNIX timestamp to be used
in replacement of the current date and time in the `__DATE__` and `__TIME__`
macros. Note: GCC as of today does not update `__TIMESTAMP__` (the modification
time of the current source file) but
https://wiki.debian.org/ReproducibleBuilds/TimestampsFromCPPMacros expresses the
intention to update it.

This patches parses SOURCE_DATE_EPOCH and changes all the three macros.

In addition, in case gmtime/localtime returns null (e.g. on 64-bit Windows
gmtime returns null when the timestamp is larger than 32536850399
(3001-01-19T21:59:59Z)), use `??? ?? ????` as used by GCC.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D135045




More information about the All-commits mailing list