|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from conan import ConanFile |
| 5 | +from conan.errors import ConanInvalidConfiguration |
| 6 | +from conan.tools.files import get, copy, replace_in_file |
| 7 | + |
| 8 | +required_conan_version = ">=2.7" |
| 9 | + |
| 10 | +AUTOIJECT_CMAKE = "ccache-autoinject.cmake" |
| 11 | + |
| 12 | +class CcacheConan(ConanFile): |
| 13 | + name = "ccache" |
| 14 | + package_type = "application" |
| 15 | + description = ( |
| 16 | + "Ccache (or “ccache”) is a compiler cache. It speeds up recompilation " |
| 17 | + "by caching previous compilations and detecting when the same " |
| 18 | + "compilation is being done again." |
| 19 | + ) |
| 20 | + license = "GPL-3.0-or-later" |
| 21 | + topics = ("compiler-cache", "recompilation", "cache", "compiler") |
| 22 | + homepage = "https://ccache.dev" |
| 23 | + url = "https://github.com/conan-io/conan-center-index" |
| 24 | + settings = "os", "arch" |
| 25 | + exports_sources = [AUTOIJECT_CMAKE] |
| 26 | + |
| 27 | + def validate(self): |
| 28 | + if self.settings.os != "Macos" and self.settings.arch != "x86_64": |
| 29 | + raise ConanInvalidConfiguration("ccache binaries are only provided for x86_64 architectures") |
| 30 | + |
| 31 | + def build(self): |
| 32 | + arch = str(self.settings.arch) if self.settings.os != "Macos" else "universal" |
| 33 | + get(self, **self.conan_data["sources"][self.version][str(self.settings.os)][arch], |
| 34 | + destination=self.source_folder, strip_root=True) |
| 35 | + |
| 36 | + def package_id(self): |
| 37 | + if self.info.settings.os == "Macos": |
| 38 | + del self.info.settings.arch |
| 39 | + |
| 40 | + def package(self): |
| 41 | + copy(self, "*GPL-*.txt", src=self.build_folder, dst=os.path.join(self.package_folder, "licenses")) |
| 42 | + copy(self, "LICENSE.*", src=self.build_folder, dst=os.path.join(self.package_folder, "licenses")) |
| 43 | + copy(self, "ccache", src=self.build_folder, dst=os.path.join(self.package_folder, "bin")) |
| 44 | + copy(self, AUTOIJECT_CMAKE, src=self.build_folder, dst=self.package_folder) |
| 45 | + |
| 46 | + def finalize(self): |
| 47 | + copy(self, "*", src=self.immutable_package_folder, dst=self.package_folder) |
| 48 | + # TODO: find a way of retrieving conan home without accessing private API |
| 49 | + # replace_in_file(self, os.path.join(self.package_folder, AUTOIJECT_CMAKE), "<CONAN_HOME>", self._conan_helpers.cache.store) |
| 50 | + replace_in_file(self, os.path.join(self.package_folder, AUTOIJECT_CMAKE), "<CONAN_HOME>", str(Path.home())) |
| 51 | + |
| 52 | + def package_info(self): |
| 53 | + self.cpp_info.libdirs = [] |
| 54 | + self.cpp_info.includedirs = [] |
| 55 | + if self.conf.get("user.ccache:auto_inject", default=True, check_type=bool): |
| 56 | + self.conf_info.append("tools.cmake.cmaketoolchain:user_toolchain", os.path.join(self.package_folder, AUTOIJECT_CMAKE)) |
0 commit comments