def _run_source(conanfile, conanfile_path, hook_manager, reference, cache, get_sources_from_exports): """Execute the source core functionality, both for local cache and user space, in order: - Calling pre_source hook - Getting sources from SCM - Getting sources from exported folders in the local cache - Clean potential TGZ and other files in the local cache - Executing the recipe source() method - Calling post_source hook """ src_folder = conanfile.source_folder if hasattr(conanfile, "layout") \ else conanfile.folders.base_source mkdir(src_folder) with tools.chdir(src_folder): try: with get_env_context_manager(conanfile): hook_manager.execute("pre_source", conanfile=conanfile, conanfile_path=conanfile_path, reference=reference) output = conanfile.output output.info('Configuring sources in %s' % src_folder) get_sources_from_exports() if cache: # Clear the conanfile.py to avoid errors cloning git repositories. _clean_source_folder(src_folder) with conanfile_exception_formatter(conanfile.display_name, "source"): with conan_v2_property( conanfile, 'settings', "'self.settings' access in source() method is deprecated" ): with conan_v2_property( conanfile, 'options', "'self.options' access in source() method is deprecated" ): conanfile.source() hook_manager.execute("post_source", conanfile=conanfile, conanfile_path=conanfile_path, reference=reference) except ConanExceptionInUserConanfileMethod: raise except Exception as e: raise ConanException(e)
def _run_source(conanfile, conanfile_path, src_folder, hook_manager, reference, cache, get_sources_from_exports): """Execute the source core functionality, both for local cache and user space, in order: - Calling pre_source hook - Getting sources from SCM - Getting sources from exported folders in the local cache - Clean potential TGZ and other files in the local cache - Executing the recipe source() method - Calling post_source hook """ conanfile.source_folder = src_folder conanfile.build_folder = None conanfile.package_folder = None with tools.chdir(src_folder): try: with get_env_context_manager(conanfile): hook_manager.execute("pre_source", conanfile=conanfile, conanfile_path=conanfile_path, reference=reference) output = conanfile.output output.info('Configuring sources in %s' % src_folder) get_sources_from_exports() if cache: _clean_source_folder( src_folder) # TODO: Why is it needed in cache? with conanfile_exception_formatter(conanfile.display_name, "source"): with conan_v2_property( conanfile, 'settings', "'self.settings' access in source() method is deprecated" ): with conan_v2_property( conanfile, 'options', "'self.options' access in source() method is deprecated" ): conanfile.source() hook_manager.execute("post_source", conanfile=conanfile, conanfile_path=conanfile_path, reference=reference) except ConanExceptionInUserConanfileMethod: raise except Exception as e: raise ConanException(e)
def _call_package(conanfile, package_id, source_folder, build_folder, package_folder, install_folder, hook_manager, conanfile_path, ref, copy_info): output = conanfile.output hook_manager.execute("pre_package", conanfile=conanfile, conanfile_path=conanfile_path, reference=ref, package_id=package_id) output.highlight("Calling package()") folders = [source_folder, build_folder] if source_folder != build_folder else [build_folder] conanfile.copy = FileCopier(folders, package_folder) with conanfile_exception_formatter(str(conanfile), "package"): with chdir(build_folder): with conan_v2_property(conanfile, 'info', "'self.info' access in package() method is deprecated"): conanfile.package() hook_manager.execute("post_package", conanfile=conanfile, conanfile_path=conanfile_path, reference=ref, package_id=package_id) manifest = _create_aux_files(install_folder, package_folder, conanfile, copy_info) package_output = ScopedOutput("%s package()" % output.scope, output) report_files_from_manifest(package_output, manifest) package_id = package_id or os.path.basename(package_folder) output.success("Package '%s' created" % package_id) prev = manifest.summary_hash output.info("Created package revision %s" % prev) return prev
def _compute_package_id(self, node, default_package_id_mode, default_python_requires_id_mode): """ Compute the binary package ID of this node :param node: the node to compute the package-ID :param default_package_id_mode: configuration of the package-ID mode """ # TODO Conan 2.0. To separate the propagation of the graph (options) of the package-ID # A bit risky to be done now conanfile = node.conanfile neighbors = node.neighbors() direct_reqs, indirect_reqs = self.package_id_transitive_reqs(node) # FIXME: Conan v2.0 This is introducing a bug for backwards compatibility, it will add # only the requirements available in the 'neighbour.info' object, not all the closure if not self._fixed_package_id: old_indirect = set() for neighbor in neighbors: old_indirect.update( (p.ref, p.id) for p in neighbor.conanfile.info.requires.refs()) indirect_reqs = set(p for p in indirect_reqs if (p.ref, p.id) in old_indirect) indirect_reqs.difference_update(direct_reqs) python_requires = getattr(conanfile, "python_requires", None) if python_requires: if isinstance(python_requires, dict): python_requires = None # Legacy python-requires do not change package-ID else: python_requires = python_requires.all_refs() conanfile.info = ConanInfo.create( conanfile.settings.values, conanfile.options.values, direct_reqs, indirect_reqs, default_package_id_mode=default_package_id_mode, python_requires=python_requires, default_python_requires_id_mode=default_python_requires_id_mode) # Once we are done, call package_id() to narrow and change possible values with conanfile_exception_formatter(str(conanfile), "package_id"): with conan_v2_property( conanfile, 'cpp_info', "'self.cpp_info' access in package_id() method is deprecated" ): conanfile.package_id() if hasattr(conanfile, "validate") and callable(conanfile.validate): with conanfile_exception_formatter(str(conanfile), "validate"): try: conanfile.validate() except ConanInvalidConfiguration as e: conanfile.info.invalid = str(e) info = conanfile.info node.package_id = info.package_id()
def _compute_package_id(self, node, default_package_id_mode, default_python_requires_id_mode): """ Compute the binary package ID of this node :param node: the node to compute the package-ID :param default_package_id_mode: configuration of the package-ID mode """ # TODO Conan 2.0. To separate the propagation of the graph (options) of the package-ID # A bit risky to be done now conanfile = node.conanfile neighbors = node.neighbors() if not self._fixed_package_id: direct_reqs = [] # of PackageReference indirect_reqs = set() # of PackageReference, avoid duplicates for neighbor in neighbors: ref, nconan = neighbor.ref, neighbor.conanfile direct_reqs.append(neighbor.pref) indirect_reqs.update(nconan.info.requires.refs()) # Make sure not duplicated indirect_reqs.difference_update(direct_reqs) else: node.id_direct_prefs = set() # of PackageReference node.id_indirect_prefs = set( ) # of PackageReference, avoid duplicates for neighbor in neighbors: node.id_direct_prefs.add(neighbor.pref) node.id_indirect_prefs.update(neighbor.id_direct_prefs) node.id_indirect_prefs.update(neighbor.id_indirect_prefs) # Make sure not duplicated, totally necessary node.id_indirect_prefs.difference_update(node.id_direct_prefs) direct_reqs = node.id_direct_prefs indirect_reqs = node.id_indirect_prefs python_requires = getattr(conanfile, "python_requires", None) if python_requires: if isinstance(python_requires, dict): python_requires = None # Legacy python-requires do not change package-ID else: python_requires = python_requires.all_refs() conanfile.info = ConanInfo.create( conanfile.settings.values, conanfile.options.values, direct_reqs, indirect_reqs, default_package_id_mode=default_package_id_mode, python_requires=python_requires, default_python_requires_id_mode=default_python_requires_id_mode) # Once we are done, call package_id() to narrow and change possible values with conanfile_exception_formatter(str(conanfile), "package_id"): with conan_v2_property( conanfile, 'cpp_info', "'self.cpp_info' access in package_id() method is deprecated" ): conanfile.package_id() info = conanfile.info node.package_id = info.package_id()
def _call_package(conanfile, package_id, source_folder, build_folder, package_folder, install_folder, hook_manager, conanfile_path, ref, local, copy_info): output = conanfile.output try: hook_manager.execute("pre_package", conanfile=conanfile, conanfile_path=conanfile_path, reference=ref, package_id=package_id) output.highlight("Calling package()") folders = [source_folder, build_folder ] if source_folder != build_folder else [build_folder] conanfile.copy = FileCopier(folders, package_folder) with conanfile_exception_formatter(str(conanfile), "package"): with chdir(build_folder): with conan_v2_property( conanfile, 'info', "'self.info' access in package() method is deprecated" ): conanfile.package() except Exception as e: if not local: os.chdir(build_folder) try: rmdir(package_folder) except Exception as e_rm: output.error("Unable to remove package folder %s\n%s" % (package_folder, str(e_rm))) output.warn("**** Please delete it manually ****") if isinstance(e, ConanExceptionInUserConanfileMethod): raise raise ConanException(e) hook_manager.execute("post_package", conanfile=conanfile, conanfile_path=conanfile_path, reference=ref, package_id=package_id) manifest = _create_aux_files(install_folder, package_folder, conanfile, copy_info) package_output = ScopedOutput("%s package()" % output.scope, output) _report_files_from_manifest(package_output, manifest) package_id = package_id or os.path.basename(package_folder) output.success("Package '%s' created" % package_id) prev = manifest.summary_hash output.info("Created package revision %s" % prev) return prev