conan: Cannot retrieve git SHA when using `exports_sources`

I am using a conanfile inside of the source repository, and the build system uses git commands to find out the current SHA to tag the library with it, so we know for sure which version we are dealing with.

However, this does not work even if I manually specify “.git” in my exports attribute, because conans/client/file_copier.py has a check to prevent copying “.git” and “.svn” folders.

This prevents me from retrieving the SHA if I use the conanfile in-source, and forces me to use a source() method that does a git clone.

Is there a way I could work around this copy restriction ?

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

Ok, here it goes. 😃

def get_git_sha():
    os.system("git log --pretty=format:%H -1 > sha.txt")

get_git_sha()

class GitshaConan(ConanFile):
    name = "GitSha"
    version = "0.1"
    exports_sources = "src/*", "sha.txt"

    def source(self):
        sha = load("sha.txt")
        print "Source: MySHA is", sha

    def build(self):
        sha = load("sha.txt")
        print "Build: MySHA is", sha

It seems to work here. What do you think?