Build identification strings #1054

pull sipa wants to merge 1 commits into bitcoin:master from sipa:buildinfo changing 20 files +193 −31
  1. sipa commented at 1:15 AM on April 7, 2012: member

    All client version information is moved to version.cpp, which optionally (-DHAVE_BUILD_INFO) includes build.h. build.h is automatically generated on supporting platforms via contrib/genbuild.sh, using git describe.

    The git export-subst attribute is used to put the commit id statically in version.cpp inside generated archives, and this value is used if no build.h is present.

    The gitian descriptors are modified to use git archive instead of a copy, to create the src/ directory in the output. This way, src/src/version.cpp will contain the static commit id.

  2. in bitcoin-qt.pro:None in 7adea81d45 outdated
     154 | @@ -149,7 +155,8 @@ HEADERS += src/qt/bitcoingui.h \
     155 |      src/qt/notificator.h \
     156 |      src/qt/qtipcserver.h \
     157 |      src/allocators.h \
     158 | -    src/ui_interface.h
     159 | +    src/ui_interface.h \
     160 | +    src/build.h
    


    luke-jr commented at 1:24 AM on April 7, 2012:

    Shouldn't this be conditional on !windows?


    sipa commented at 2:20 AM on April 7, 2012:

    Oh yes, indeed. Fixed.

  3. in src/makefile.linux-mingw:None in 7adea81d45 outdated
      64 | @@ -64,6 +65,10 @@ OBJS= \
      65 |  
      66 |  all: bitcoind.exe
      67 |  
      68 | +build.h: FORCE
      69 | +	cd ..; contrib/genbuild.sh; cd src
    


    luke-jr commented at 1:25 AM on April 7, 2012:

    How about having genbuild.sh write to stdout, and pipe it to build.h here?


    sipa commented at 2:20 AM on April 7, 2012:

    That's probably more flexible. Done.

  4. jgarzik commented at 8:24 AM on April 7, 2012: contributor
    1. why do you "cd .." in cd ..; contrib/genbuild.sh >src/build.h; cd src ?

    it seems like one command would suffice: ../contrib/genbuild.sh > build.h

    1. do we want to update 'clean' targets?
  5. sipa commented at 11:02 AM on April 7, 2012: member

    @jgarzik

    1. genbuild.sh depends on being run from the project's root directory, which may include a commit id

    2. no idea what you mean

  6. laanwj commented at 2:15 PM on April 7, 2012: member

    Looks like useful functionality. However, as I understand it (I'm not a makefile guru though), build.h is force-written on every build.

    Won't this cause the dependent compilation unit (version.cpp) to be built every time, and a subsequent link?

    Ideally, to prevent this, build.h should be left untouched if it still matches the current version info.

  7. sipa commented at 2:35 PM on April 7, 2012: member

    @laanwj yes, indeed; version.cpp is built every time, and linking is done every time. These are small, and won't take much time to build. However, preventing such a rebuild every time would be nice indeed. No idea how to pull that off via a makefile, though.

  8. luke-jr commented at 2:38 PM on April 7, 2012: member

    Write a .new file, use diff to compare, then mv over the real file if different?

  9. laanwj commented at 2:42 PM on April 7, 2012: member

    Could certainly be done in sh script. Something like:

    BUILD_H=src/build.h
    if [ -e "$BUILD_H" ] ; then
        CURRENT_BUILD_VERSION=`cat $BUILD_H`
    else
        CURRENT_BUILD_VERSION=
    fi
    # expected to be run in the project's root directory
    if [ -d .git -a -e "$(which git)" ]; then
        NEW_BUILD_VERSION="#define BUILD_DESC \"$(git describe)\""
    elif echo $PWD | grep '/[a-z]\+-[a-z]\+-[0-9a-f]\{7,\}$'; then
        NEW_BUILD_VERSION="#define BUILD_COMMIT \"$(echo "$PWD" | cut -d '-' -f 3)\""
    else
        NEW_BUILD_VERSION=""
    fi
    if [ "$CURRENT_BUILD_VERSION" -ne "$NEW_BUILD_VERSION" ]; then
        echo "$NEW_BUILD_VERSION" > $BUILD_H
    fi
    

    Note: untested

  10. laanwj commented at 2:47 PM on April 7, 2012: member

    Luke's suggestion is easier.

  11. sipa commented at 2:49 PM on April 7, 2012: member

    Right, of course. That won't prevent rebuilding build.h, but it will prevent its dependencies from being rebuilt.

  12. sipa commented at 3:14 PM on April 7, 2012: member

    New version, mostly following @laanwj's idea, but generalized genbuild.sh a bit.

  13. laanwj commented at 3:28 PM on April 7, 2012: member

    I just realized: I think we don't handle the case in which an empty build.h file needs to be created (as an empty file is handled in the same way as no file).

    Maybe set NEWINFO to a C++ comment i.s.o. completely empty when no version info can be found...

  14. sipa commented at 7:43 PM on April 7, 2012: member

    Ok, fairly large rewrite: by using the export-subst git attribute in a somewhat hacky way, the commit id is now included statically in version.cpp in exported source trees (github tar/zip bundles, output of the git-archive command, gitian build src/ directories, ...). contrib/build.sh is only used for running a git-describe where possible anyway, and does not require cd'ing to a root anymore.

    Thanks to @makomk and @luke-jr for the idea.

  15. luke-jr commented at 9:23 PM on April 7, 2012: member

    I don't think this will put the correct file in the Win32-setup source?

  16. sipa commented at 11:02 PM on April 7, 2012: member

    @luke-jr now it does.

  17. jgarzik commented at 12:18 AM on April 8, 2012: contributor
    1. there should be no need to run from project's root dir. git certainly works in sub-directories (where ".git" is in .. etc.)

    2. 'clean' is a makefile target. one types "make clean" (or sometimes "make distclean") to remove build generated objects. Your change fails to update the 'clean' makefile target. The general rationale is that you want your build to be able to clean up after itself.

  18. sipa commented at 12:31 AM on April 8, 2012: member
    1. there was; this was for handling cases where we worked in a gitless environnement. the script looked at the directory name to find the commit id (since github's tarballs contain a directory [projname]-[reponame]-[commitid]). The script used some pattern matching on the last component of $PWD to find this. I've now switched to using the export-subst method, which is far more robust.

    2. oh sure

  19. in src/version.cpp:None in 275ae22571 outdated
      40 | +    "v" STRINGIFY(maj) "." STRINGIFY(min) "." STRINGIFY(rev) "." STRINGIFY(build) "-unk"
      41 | +
      42 | +#define BUILD_STRING_FROM_DESC(desc) \
      43 | +    desc
      44 | +
      45 | +#ifndef BUILD_STRING
    


    gavinandresen commented at 2:08 PM on April 9, 2012:

    Can you put a big comment either before or in this complicated nested #ifdef explaining what is going on? I'm lost.

    Something like: "If you're building from an un-tarred git-produced tarball, then blah, if you're building from a checked out git directory then blah or blah depending on blah...."

  20. sipa commented at 4:40 PM on April 9, 2012: member

    Ok, updated, simplified and added some comments. I've also changed it to use git describe --dirty, which will result in nice version strings like 0.6.0-66-g4f364be-dirty-beta. The problem is that the gitian scripts modify the source directory before building, so they too result in the dirty marker being added. It could be avoided by setting some env variable to disable the dirty marker entirely, but I'd prefer the builds just being done on a clean directory altogether. Anyone feel like looking into that?

  21. luke-jr commented at 1:52 PM on April 10, 2012: member

    version.cpp:43:23: fatal error: build.h: No such file or directory

  22. Build identification strings
    All client version information is moved to version.cpp, which optionally
    (-DHAVE_BUILD_INFO) includes build.h. build.h is automatically generated
    on supporting platforms via contrib/genbuild.sh, using git describe.
    
    The git export-subst attribute is used to put the commit id statically
    in version.cpp inside generated archives, and this value is used if no
    build.h is present.
    
    The gitian descriptors are modified to use git archive instead of a
    copy, to create the src/ directory in the output. This way,
    src/src/version.cpp will contain the static commit id. To prevent
    gitian builds from getting the "-dirty" marker in their git-describe
    generated identifiers, no touching of files or running sed on the
    makefile is performed anymore. This does not seem to influence
    determinism.
    a20c0d0f67
  23. sipa commented at 4:51 PM on April 10, 2012: member

    Ok, again some changes: the "dirty" flag added in the gitian builds was a result of a bug in git that was fixed in 1.7.7. For now I've worked around it. Gitian builds are now done from a clean repository, and seem to be deterministic.

    I also added a CLIENT_DATE next to CLIENT_BUILD, with either the time of the last commit, or the build time. It's written to debug.log at startup. If someone wants to add it to Bitcoin-Qt's about box, feel free.

  24. jgarzik commented at 6:49 PM on April 10, 2012: contributor

    ACK

    Would prefer that genbuild.sh output to stdout, rather than overwrote a file, but that's not a big deal.

  25. sipa commented at 6:53 PM on April 10, 2012: member

    @jgarzik reason is that we want to prevent build.h being updated unnecessarily, as that would cause a rebuild of version.cpp and linking every time.

  26. jgarzik commented at 6:55 PM on April 10, 2012: contributor

    I know the reason the logic exists. It is only a question of taste, where that logic should go. Did not mean to suggest the logic should be deleted.

  27. gavinandresen commented at 8:25 PM on April 10, 2012: contributor

    ACK

  28. sipa referenced this in commit 702764f53b on Apr 10, 2012
  29. sipa merged this on Apr 10, 2012
  30. sipa closed this on Apr 10, 2012

  31. coblee referenced this in commit 93439752ca on Jul 17, 2012
  32. suprnurd referenced this in commit 1eb399cf34 on Dec 5, 2017
  33. ptschip referenced this in commit 7c2b132b08 on May 1, 2018
  34. lateminer referenced this in commit 7c2cd32d6e on Oct 30, 2019
  35. Bushstar referenced this in commit afa3c81aa1 on Jan 5, 2020
  36. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me