def _build_graph(self, profile_host, profile_build, install=False): path = temp_folder() path = os.path.join(path, "conanfile.txt") save(path, textwrap.dedent(""" [requires] app/testing@user/channel """)) ref = ConanFileReference(None, None, None, None, validate=False) options = OptionsValues() graph_info = GraphInfo(profile_host=profile_host, profile_build=profile_build, options=options, root_ref=ref) recorder = ActionRecorder() app = self._get_app() deps_graph = app.graph_manager.load_graph(path, create_reference=None, graph_info=graph_info, build_mode=[], check_updates=False, update=False, remotes=Remotes(), recorder=recorder) if install: build_mode = [] # Means build all binary_installer = BinaryInstaller(app, recorder) build_mode = BuildMode(build_mode, app.out) binary_installer.install(deps_graph, None, build_mode, update=False, profile_host=profile_host, profile_build=profile_build, graph_lock=None, keep_build=False) return deps_graph
def load_consumer_conanfile(self, conanfile_path, info_folder, deps_info_required=False, test=False): """loads a conanfile for local flow: source, imports, package, build """ try: graph_info = GraphInfo.load(info_folder) graph_lock_file = GraphLockFile.load( info_folder, self._cache.config.revisions_enabled) graph_lock = graph_lock_file.graph_lock self._output.info( "Using lockfile: '{}/conan.lock'".format(info_folder)) profile_host = graph_lock_file.profile_host self._output.info("Using cached profile from lockfile") except IOError: # Only if file is missing graph_lock = None # This is very dirty, should be removed for Conan 2.0 (source() method only) profile_host = self._cache.default_profile profile_host.process_settings(self._cache) name, version, user, channel = None, None, None, None else: name, version, user, channel, _ = graph_info.root profile_host.process_settings(self._cache, preprocess=False) # This is the hack of recovering the options from the graph_info profile_host.options.update(graph_info.options) if conanfile_path.endswith(".py"): lock_python_requires = None if graph_lock and not test: # Only lock python requires if it is not test_package node_id = graph_lock.get_node(graph_info.root) lock_python_requires = graph_lock.python_requires(node_id) conanfile = self._loader.load_consumer( conanfile_path, profile_host=profile_host, name=name, version=version, user=user, channel=channel, lock_python_requires=lock_python_requires) if test: conanfile.display_name = "%s (test package)" % str(test) conanfile.output.scope = conanfile.display_name with get_env_context_manager(conanfile, without_python=True): with conanfile_exception_formatter(str(conanfile), "config_options"): conanfile.config_options() with conanfile_exception_formatter(str(conanfile), "configure"): conanfile.configure() conanfile.settings.validate() # All has to be ok! conanfile.options.validate() else: conanfile = self._loader.load_conanfile_txt( conanfile_path, profile_host) load_deps_info(info_folder, conanfile, required=deps_info_required) return conanfile
def build_consumer(self, path, profile_build_requires=None, ref=None, create_ref=None, install=True): profile = Profile() if profile_build_requires: profile.build_requires = profile_build_requires profile.process_settings(self.cache) update = check_updates = False recorder = ActionRecorder() remotes = Remotes() build_mode = [] # Means build all ref = ref or ConanFileReference(None, None, None, None, validate=False) options = OptionsValues() graph_info = GraphInfo(profile, options, root_ref=ref) app = self._get_app() deps_graph = app.graph_manager.load_graph(path, create_ref, graph_info, build_mode, check_updates, update, remotes, recorder) if install: binary_installer = BinaryInstaller(app, recorder) build_mode = BuildMode(build_mode, app.out) binary_installer.install(deps_graph, None, build_mode, update, False, graph_info) return deps_graph
def build_graph(self, content, profile_build_requires=None, ref=None, create_ref=None, install=True): path = temp_folder() path = os.path.join(path, "conanfile.py") save(path, str(content)) self.loader.cached_conanfiles = {} profile = Profile() if profile_build_requires: profile.build_requires = profile_build_requires profile.process_settings(self.cache) update = check_updates = False recorder = ActionRecorder() remotes = Remotes() build_mode = [] # Means build all ref = ref or ConanFileReference(None, None, None, None, validate=False) options = OptionsValues() graph_info = GraphInfo(profile, options, root_ref=ref) deps_graph, _ = self.manager.load_graph(path, create_ref, graph_info, build_mode, check_updates, update, remotes, recorder) if install: self.binary_installer.install(deps_graph, None, False, graph_info) return deps_graph
def _handle_node_editable(self, node, graph_info): # Get source of information package_layout = self._cache.package_layout(node.ref) base_path = package_layout.base_folder() self._call_package_info(node.conanfile, package_folder=base_path, ref=node.ref) node.conanfile.cpp_info.filter_empty = False # Try with package-provided file editable_cpp_info = package_layout.editable_cpp_info() if editable_cpp_info: editable_cpp_info.apply_to(node.ref, node.conanfile.cpp_info, settings=node.conanfile.settings, options=node.conanfile.options) build_folder = editable_cpp_info.folder(node.ref, EditableLayout.BUILD_FOLDER, settings=node.conanfile.settings, options=node.conanfile.options) if build_folder is not None: build_folder = os.path.join(base_path, build_folder) output = node.conanfile.output write_generators(node.conanfile, build_folder, output) save(os.path.join(build_folder, CONANINFO), node.conanfile.info.dumps()) output.info("Generated %s" % CONANINFO) graph_info_node = GraphInfo(graph_info.profile_host, root_ref=node.ref) graph_info_node.options = node.conanfile.options.values graph_info_node.graph_lock = graph_info.graph_lock graph_info_node.save(build_folder) output.info("Generated graphinfo") save(os.path.join(build_folder, BUILD_INFO), TXTGenerator(node.conanfile).content) output.info("Generated %s" % BUILD_INFO) # Build step might need DLLs, binaries as protoc to generate source files # So execute imports() before build, storing the list of copied_files copied_files = run_imports(node.conanfile, build_folder) report_copied_files(copied_files, output)
def load_consumer_conanfile(self, conanfile_path, info_folder, deps_info_required=False, test=None): """loads a conanfile for local flow: source, imports, package, build """ try: graph_info = GraphInfo.load(info_folder) except IOError: # Only if file is missing # This is very dirty, should be removed for Conan 2.0 (source() method only) profile = self._cache.default_profile profile.process_settings(self._cache) name, version, user, channel = None, None, None, None else: name, version, user, channel, _ = graph_info.root profile = graph_info.profile profile.process_settings(self._cache, preprocess=False) # This is the hack of recovering the options from the graph_info profile.options.update(graph_info.options) processed_profile = ProcessedProfile(profile, None) if conanfile_path.endswith(".py"): conanfile = self._loader.load_consumer( conanfile_path, processed_profile=processed_profile, test=test, name=name, version=version, user=user, channel=channel) with get_env_context_manager(conanfile, without_python=True): with conanfile_exception_formatter(str(conanfile), "config_options"): conanfile.config_options() with conanfile_exception_formatter(str(conanfile), "configure"): conanfile.configure() conanfile.settings.validate() # All has to be ok! conanfile.options.validate() else: conanfile = self._loader.load_conanfile_txt( conanfile_path, processed_profile) load_deps_info(info_folder, conanfile, required=deps_info_required) return conanfile
def _handle_node_editable(self, node, profile_host, profile_build, graph_lock): # Get source of information conanfile = node.conanfile ref = node.ref package_layout = self._cache.package_layout(ref) base_path = package_layout.base_folder() if hasattr(conanfile, "layout"): conanfile.folders.set_base_folders(base_path, package_layout.output_folder) else: conanfile.folders.set_base_package(base_path) conanfile.folders.set_base_source(None) conanfile.folders.set_base_build(None) conanfile.folders.set_base_install(None) self._call_package_info(conanfile, package_folder=base_path, ref=ref, is_editable=True) # New editables mechanism based on Folders if hasattr(conanfile, "layout"): output = conanfile.output output.info("Rewriting files of editable package " "'{}' at '{}'".format(conanfile.name, conanfile.generators_folder)) self._generator_manager.write_generators( conanfile, conanfile.install_folder, conanfile.generators_folder, output) write_toolchain(conanfile, conanfile.generators_folder, output) output.info("Generated toolchain") graph_info_node = GraphInfo(profile_host, root_ref=node.ref) graph_info_node.options = node.conanfile.options.values graph_info_node.graph_lock = graph_lock graph_info_node.save(base_path) output.info("Generated conan.lock") copied_files = run_imports(conanfile) report_copied_files(copied_files, output) return node.conanfile.cpp_info.filter_empty = False # OLD EDITABLE LAYOUTS: # Try with package-provided file editable_cpp_info = package_layout.editable_cpp_info() if editable_cpp_info: editable_cpp_info.apply_to(ref, conanfile.cpp_info, settings=conanfile.settings, options=conanfile.options) build_folder = editable_cpp_info.folder( ref, EditableLayout.BUILD_FOLDER, settings=conanfile.settings, options=conanfile.options) if build_folder is not None: build_folder = os.path.join(base_path, build_folder) output = conanfile.output self._generator_manager.write_generators( conanfile, build_folder, build_folder, output) write_toolchain(conanfile, build_folder, output) save(os.path.join(build_folder, CONANINFO), conanfile.info.dumps()) output.info("Generated %s" % CONANINFO) graph_info_node = GraphInfo(profile_host, root_ref=node.ref) graph_info_node.options = node.conanfile.options.values graph_info_node.graph_lock = graph_lock graph_info_node.save(build_folder) output.info("Generated graphinfo") graph_lock_file = GraphLockFile(profile_host, profile_build, graph_lock) graph_lock_file.save(os.path.join(build_folder, "conan.lock")) save(os.path.join(build_folder, BUILD_INFO), TXTGenerator(conanfile).content) output.info("Generated %s" % BUILD_INFO) # Build step might need DLLs, binaries as protoc to generate source files # So execute imports() before build, storing the list of copied_files conanfile.folders.set_base_imports(build_folder) copied_files = run_imports(conanfile) report_copied_files(copied_files, output)
def load_consumer_conanfile(self, conanfile_path, info_folder, deps_info_required=False, test=False): """loads a conanfile for local flow: source, imports, package, build """ try: graph_info = GraphInfo.load(info_folder) lock_path = os.path.join(info_folder, "conan.lock") graph_lock_file = GraphLockFile.load( lock_path, self._cache.config.revisions_enabled) graph_lock = graph_lock_file.graph_lock self._output.info( "Using lockfile: '{}/conan.lock'".format(info_folder)) profile_host = graph_lock_file.profile_host profile_build = graph_lock_file.profile_build self._output.info("Using cached profile from lockfile") except IOError: # Only if file is missing graph_lock = None # This is very dirty, should be removed for Conan 2.0 (source() method only) profile_host = self._cache.default_profile profile_host.process_settings(self._cache) profile_build = None name, version, user, channel = None, None, None, None else: name, version, user, channel, _ = graph_info.root profile_host.process_settings(self._cache, preprocess=False) # This is the hack of recovering the options from the graph_info profile_host.options.update(graph_info.options) if profile_build: profile_build.process_settings(self._cache, preprocess=False) if conanfile_path.endswith(".py"): lock_python_requires = None if graph_lock and not test: # Only lock python requires if it is not test_package node_id = graph_lock.get_consumer(graph_info.root) lock_python_requires = graph_lock.python_requires(node_id) # The global.conf is necessary for download_cache definition profile_host.conf.rebase_conf_definition(self._cache.new_config) conanfile = self._loader.load_consumer( conanfile_path, profile_host=profile_host, name=name, version=version, user=user, channel=channel, lock_python_requires=lock_python_requires) if profile_build: conanfile.settings_build = profile_build.processed_settings.copy( ) conanfile.settings_target = None if test: conanfile.display_name = "%s (test package)" % str(test) conanfile.output.scope = conanfile.display_name conanfile.tested_reference_str = repr(test) run_configure_method(conanfile, down_options=None, down_ref=None, ref=None) else: conanfile = self._loader.load_conanfile_txt( conanfile_path, profile_host=profile_host) load_deps_info(info_folder, conanfile, required=deps_info_required) return conanfile