#!/usr/bin/env python3 """ This is a master conanfile.py which can be symlinked into a root directory and automatically discover conanfile.txt from child packages from nerdcruft. (ie, from the glob cruft/*/conanfile.txt). It also looks for a file _conanfile.txt in the same directory as this script. This config is loaded at the end and so its [options] section will override any other options present in the defaults, or child packages., """ from conans.client.loader_txt import ConanFileTextLoader from conans.model.options import Options from conan import ConanFile from conan.tools.files import copy import os import glob def slurp(path: str) -> str: with open(path, 'rt') as f: return f.read() # Load all the conanfile.txt of submodules dirname = os.path.abspath(os.path.dirname(__file__)) print(dirname) subpackages = [ ConanFileTextLoader(slurp(i)) for i in glob.glob( os.path.join( dirname, 'cruft', "*", 'conanfile.txt') ) ] # Attempt to load a conanfile.txt in the root directory too. try: subpackages.append( ConanFileTextLoader( slurp(os.path.join(dirname, '_conanfile.txt')) ) ) except FileNotFoundError: pass # Combine all the options and requirements _opt = Options() for i in subpackages: _opt.update_options(Options.loads(i.options)) _opt = _opt.serialize() _requirements = tuple(j for i in subpackages for j in i.requirements) class RootConan(ConanFile): name = 'cruft-root' version = '0.1' settings = "os", "compiler", "build_type", "arch" requires = _requirements tool_requires = ( 'cmake/[>=3.23]' ) generators = 'CMakeDeps', 'CMakeToolchain' default_options = {'*:shared': True} | _opt LIB_PATTERNS = ( "*.dylib", "*.dll", "*.dll.a", "*.so", "*.so.*", ) # Conan2 doesn't have a "deploy" function. # # For the time being use this post-processing step to emulate it. def generate(self): for dep in self.dependencies.values(): deps_dir = f"{self.build_folder}/deps" for src_dir in dep.cpp_info.libdirs + dep.cpp_info.bindirs: for pattern in self.LIB_PATTERNS: copy(self, pattern, src_dir, deps_dir)