diff --git a/conanfile.py b/conanfile.py index 121da49..172a558 100644 --- a/conanfile.py +++ b/conanfile.py @@ -2,7 +2,7 @@ from conan import ConanFile from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain -from conan.tools.files import copy +from conan.tools.files import copy,save,load from conan.tools.scm import Git required_conan_version = ">=2.12.2" @@ -38,7 +38,16 @@ class ForestdbConan(ConanFile): "build_tests": False } - exports_sources = "CMakeLists.txt", "src/*", "include/*", "cmake/*", "tools/*", "LICENSE" + exports_sources = "CMakeLists.txt", "src/*", "include/*", "cmake/*", "tools/*", "option/*", "utils/*", "LICENSE" + + def set_version(self): + if self.version: + return + + git = Git(self, folder=self.recipe_folder) + self.version = git.run(cmd="describe --tags --long") + if self.version.startswith("v"): + self.version = self.version[1:] def requirements(self): if self.options.with_snappy: @@ -47,12 +56,27 @@ def requirements(self): if self.options.with_jemalloc: self.requires("jemalloc/[*]") + def _computeCommitHash(self): + hash_file = os.path.join(self.recipe_folder, "COMMIT_HASH") + if (os.path.exists(hash_file)): + hash = load(self,path=hash_file) + self.output.info(f"Fetched commit hash from {hash_file}") + else: # we are building from local source, i.e. in editable mode + git = Git(self, folder=self.recipe_folder) + hash = git.get_commit() + diff = git.run(cmd="diff --stat") + if diff: + hash +="-dirty" + self.output.info(f"Fetched commit hash {hash} from local Git in {self.recipe_folder}") + return hash + + def export(self): + save(self, path=os.path.join(self.export_folder, "COMMIT_HASH"), content=self._computeCommitHash()) + def layout(self): cmake_layout(self, generator="CMakeDeps") self.cpp.package.libs = [f"lib{self.name}.so" if self.options.shared else f"lib{self.name}.a"] - - hash = Git(self).get_commit() - self.cpp.package.defines = self.cpp.build.defines = ["_FDB_COMMIT_HASH=%s" % hash] + self.cpp.package.defines = self.cpp.build.defines = ["_FDB_COMMIT_HASH=%s" % self._computeCommitHash()] def generate(self): tc = CMakeToolchain(self) @@ -79,7 +103,3 @@ def package(self): cmake.install() assert copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")), "Copy failed" - def package_info(self): - self.cpp_info.system_libs.extend(["pthread", "m", "dl"]) - if self.settings.os == "Linux": - self.cpp_info.system_libs.extend(["rt"]) \ No newline at end of file