Preprocessor Timestamp

前端 未结 3 915
时光说笑
时光说笑 2021-01-25 09:17

Is it possible to generate an embedded Unix timestamp via a preprocessor macro?

For instance: #define VERSION_EXPIRE __TIMESTAMP__

The reason for th

3条回答
  •  星月不相逢
    2021-01-25 09:28

    If you'd use versioning software like svn or git you may have automatic replacement of strings like $Id: $ or $Date: $ by the id or date of the particular version of the file (svn) or of the "HEAD" release (git).

    Edit: For git you can extract the sources

    git archive --format=zip -9 -o project.zip HEAD file1 file2...
    

    To replace certain strings during that process you have to tell git in .gitattributes that you want to have things substituted:

    file*   export-subst
    

    For the syntax of what and how terms between "$...$", please refer to the formats in the man page of git-log. Just as examples I have in my code

    #define P99_VERSION_DATE "$Format:%cd$"
    #define P99_VERSION_ID "$Format:%H$"
    

    Which in the distribution version of the file is

    #define P99_VERSION_DATE "Thu Oct 7 23:38:43 2010 +0200"
    #define P99_VERSION_ID "6f9740a6808ff50f42d24bb7b5234a904f84e6fe"
    

提交回复
热议问题