def source(self, current_path, reference, force): if not isinstance(reference, ConanFileReference): output = ScopedOutput("PROJECT", self._user_io.out) conanfile_path = os.path.join(reference, CONANFILE) conanfile = load_consumer_conanfile( conanfile_path, current_path, self._client_cache.settings, self._runner, output, default_profile=self._client_cache.default_profile, deps_cpp_info_required=None) config_source_local(current_path, conanfile, output) else: output = ScopedOutput(str(reference), self._user_io.out) conanfile_path = self._client_cache.conanfile(reference) conanfile = load_consumer_conanfile( conanfile_path, current_path, self._client_cache.settings, self._runner, output, default_profile=self._client_cache.default_profile, reference=reference, deps_cpp_info_required=None) src_folder = self._client_cache.source(reference, conanfile.short_paths) export_folder = self._client_cache.export(reference) export_src_folder = self._client_cache.export_sources( reference, conanfile.short_paths) config_source(export_folder, export_src_folder, src_folder, conanfile, output, force)
def imports(self, current_path, reference, conan_file_path, dest_folder): if not isinstance(reference, ConanFileReference): output = ScopedOutput("PROJECT", self._user_io.out) if not conan_file_path: conan_file_path = os.path.join(reference, CONANFILE) if not os.path.exists(conan_file_path): conan_file_path = os.path.join(reference, CONANFILE_TXT) reference = None else: output = ScopedOutput(str(reference), self._user_io.out) conan_file_path = self._client_cache.conanfile(reference) conanfile = load_consumer_conanfile(conan_file_path, current_path, self._client_cache.settings, self._runner, output, reference=reference, deps_cpp_info_required=True) if dest_folder: if not os.path.isabs(dest_folder): dest_folder = os.path.normpath( os.path.join(current_path, dest_folder)) mkdir(dest_folder) else: dest_folder = current_path run_imports(conanfile, dest_folder, output)
def build(self, conanfile_path, source_folder, build_folder, test=False): """ Call to build() method saved on the conanfile.py param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Building in %s" % build_folder) logger.debug("Conanfile in %s" % conanfile_path) try: # Append env_vars to execution environment and clear when block code ends output = ScopedOutput("Project", self._user_io.out) conan_file = load_consumer_conanfile(conanfile_path, build_folder, self._client_cache.settings, self._runner, output) except NotFoundException: # TODO: Auto generate conanfile from requirements file raise ConanException("'%s' file is needed for build.\n" "Create a '%s' and move manually the " "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) try: os.chdir(build_folder) conan_file._conanfile_directory = source_folder conan_file.build_folder = build_folder conan_file.source_folder = source_folder with environment_append(conan_file.env): conan_file.build() if test: conan_file.test() except ConanException: raise # Raise but not let to reach the Exception except (not print traceback) except Exception: import traceback trace = traceback.format_exc().split('\n') raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
def package(self, reference, package_id): # Package paths conan_file_path = self._client_cache.conanfile(reference) if not os.path.exists(conan_file_path): raise ConanException("Package recipe '%s' does not exist" % str(reference)) conanfile = load_conanfile_class(conan_file_path) if hasattr(conanfile, "build_id"): raise ConanException( "package command does not support recipes with 'build_id'\n" "To repackage them use 'conan install'") if not package_id: packages = [ PackageReference(reference, packid) for packid in self._client_cache.conan_builds(reference) ] if not packages: raise NotFoundException( "%s: Package recipe has not been built locally\n" "Please read the 'conan package' command help\n" "Use 'conan install' or 'conan test_package' to build and " "create binaries" % str(reference)) else: packages = [PackageReference(reference, package_id)] package_source_folder = self._client_cache.source( reference, conanfile.short_paths) for package_reference in packages: build_folder = self._client_cache.build(package_reference, short_paths=None) if not os.path.exists(build_folder): raise NotFoundException( "%s: Package binary '%s' folder doesn't exist\n" "Please read the 'conan package' command help\n" "Use 'conan install' or 'conan test_package' to build and " "create binaries" % (str(reference), package_reference.package_id)) # The package already exist, we can use short_paths if they were defined package_folder = self._client_cache.package(package_reference, short_paths=None) # Will read current conaninfo with specified options and load conanfile with them output = ScopedOutput(str(reference), self._user_io.out) output.info("Re-packaging %s" % package_reference.package_id) conanfile = load_consumer_conanfile(conan_file_path, build_folder, self._client_cache.settings, self._runner, output, reference=reference) rmdir(package_folder) if getattr(conanfile, 'no_copy_source', False): source_folder = package_source_folder else: source_folder = build_folder with environment_append(conanfile.env): packager.create_package(conanfile, source_folder, build_folder, package_folder, output)
def source(self, current_path, reference, force): if not isinstance(reference, ConanFileReference): output = ScopedOutput("PROJECT", self._user_io.out) conanfile_path = os.path.join(reference, CONANFILE) conanfile = load_consumer_conanfile(conanfile_path, current_path, self._client_cache.settings, self._runner, output, error=None) export_folder = reference config_source_local(current_path, conanfile, output) else: output = ScopedOutput(str(reference), self._user_io.out) conanfile_path = self._client_cache.conanfile(reference) conanfile = load_consumer_conanfile(conanfile_path, current_path, self._client_cache.settings, self._runner, output, reference, error=None) src_folder = self._client_cache.source(reference, conanfile.short_paths) export_folder = self._client_cache.export(reference) config_source(export_folder, src_folder, conanfile, output, force)
def local_package(self, current_path, build_folder): if current_path == build_folder: raise ConanException("Cannot 'conan package' to the build folder. " "Please move to another folder and try again") output = ScopedOutput("PROJECT", self._user_io.out) conan_file_path = os.path.join(build_folder, CONANFILE) conanfile = load_consumer_conanfile(conan_file_path, current_path, self._client_cache.settings, self._runner, output) packager.create_package(conanfile, build_folder, current_path, output, local=True)
def local_package(self, package_folder, recipe_folder, build_folder, source_folder): if package_folder == build_folder: raise ConanException("Cannot 'conan package' to the build folder. " "--build_folder and package folder can't be the same") output = ScopedOutput("PROJECT", self._user_io.out) conan_file_path = os.path.join(recipe_folder, CONANFILE) conanfile = load_consumer_conanfile(conan_file_path, build_folder, self._client_cache.settings, self._runner, output) packager.create_package(conanfile, source_folder, build_folder, package_folder, output, local=True)
def build(self, conanfile_path, source_folder, build_folder, package_folder, test=False): """ Call to build() method saved on the conanfile.py param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Building in %s" % build_folder) logger.debug("Conanfile in %s" % conanfile_path) try: # Append env_vars to execution environment and clear when block code ends output = ScopedOutput( ("%s test package" % test) if test else "Project", self._user_io.out) conan_file = load_consumer_conanfile(conanfile_path, build_folder, self._client_cache.settings, self._runner, output) except NotFoundException: # TODO: Auto generate conanfile from requirements file raise ConanException("'%s' file is needed for build.\n" "Create a '%s' and move manually the " "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) try: os.chdir(build_folder) conan_file._conanfile_directory = source_folder conan_file.build_folder = build_folder conan_file.source_folder = source_folder conan_file.package_folder = package_folder with environment_append(conan_file.env): output.highlight("Running build()") with conanfile_exception_formatter(str(conan_file), "build"): conan_file.build() if test: output.highlight("Running test()") with conanfile_exception_formatter(str(conan_file), "test"): conan_file.test() except ConanException: raise # Raise but not let to reach the Exception except (not print traceback) except Exception: import traceback trace = traceback.format_exc().split('\n') raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
def package(self, reference, package_id): # Package paths conan_file_path = self._client_cache.conanfile(reference) if not os.path.exists(conan_file_path): raise ConanException("Package recipe '%s' does not exist" % str(reference)) conanfile = load_conanfile_class(conan_file_path) if hasattr(conanfile, "build_id"): raise ConanException("package command does not support recipes with 'build_id'\n" "To repackage them use 'conan install'") if not package_id: packages = [PackageReference(reference, packid) for packid in self._client_cache.conan_builds(reference)] if not packages: raise NotFoundException("%s: Package recipe has not been built locally\n" "Please read the 'conan package' command help\n" "Use 'conan install' or 'conan test_package' to build and " "create binaries" % str(reference)) else: packages = [PackageReference(reference, package_id)] package_source_folder = self._client_cache.source(reference, conanfile.short_paths) for package_reference in packages: build_folder = self._client_cache.build(package_reference, short_paths=None) if not os.path.exists(build_folder): raise NotFoundException("%s: Package binary '%s' folder doesn't exist\n" "Please read the 'conan package' command help\n" "Use 'conan install' or 'conan test_package' to build and " "create binaries" % (str(reference), package_reference.package_id)) # The package already exist, we can use short_paths if they were defined package_folder = self._client_cache.package(package_reference, short_paths=None) # Will read current conaninfo with specified options and load conanfile with them output = ScopedOutput(str(reference), self._user_io.out) output.info("Re-packaging %s" % package_reference.package_id) conanfile = load_consumer_conanfile(conan_file_path, build_folder, self._client_cache.settings, self._runner, output, reference) rmdir(package_folder) if getattr(conanfile, 'no_copy_source', False): source_folder = package_source_folder else: source_folder = build_folder with environment_append(conanfile.env): packager.create_package(conanfile, source_folder, build_folder, package_folder, output)
def local_package(self, package_folder, recipe_folder, build_folder, source_folder): if package_folder == build_folder: raise ConanException( "Cannot 'conan package' to the build folder. " "--build_folder and package folder can't be the same") output = ScopedOutput("PROJECT", self._user_io.out) conan_file_path = os.path.join(recipe_folder, CONANFILE) conanfile = load_consumer_conanfile(conan_file_path, build_folder, self._client_cache.settings, self._runner, output) packager.create_package(conanfile, source_folder, build_folder, package_folder, output, local=True)
def build(self, conanfile_path, current_path, test=False, filename=None): """ Call to build() method saved on the conanfile.py param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Building in %s" % current_path) logger.debug("Conanfile in %s" % conanfile_path) if filename and filename.endswith(".txt"): raise ConanException("A conanfile.py is needed to call 'conan build'") conan_file_path = os.path.join(conanfile_path, filename or CONANFILE) try: # Append env_vars to execution environment and clear when block code ends output = ScopedOutput("Project", self._user_io.out) conan_file = load_consumer_conanfile(conan_file_path, current_path, self._client_cache.settings, self._runner, output) except NotFoundException: # TODO: Auto generate conanfile from requirements file raise ConanException("'%s' file is needed for build.\n" "Create a '%s' and move manually the " "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) try: os.chdir(current_path) conan_file._conanfile_directory = conanfile_path with environment_append(conan_file.env): conan_file.build() if test: conan_file.test() except ConanException: raise # Raise but not let to reach the Exception except (not print traceback) except Exception: import traceback trace = traceback.format_exc().split('\n') raise ConanException("Unable to build it successfully\n%s" % '\n'.join(trace[3:]))
def imports(self, current_path, reference, conan_file_path, dest_folder): if not isinstance(reference, ConanFileReference): output = ScopedOutput("PROJECT", self._user_io.out) if not conan_file_path: conan_file_path = os.path.join(reference, CONANFILE) if not os.path.exists(conan_file_path): conan_file_path = os.path.join(reference, CONANFILE_TXT) reference = None else: output = ScopedOutput(str(reference), self._user_io.out) conan_file_path = self._client_cache.conanfile(reference) conanfile = load_consumer_conanfile(conan_file_path, current_path, self._client_cache.settings, self._runner, output, reference, error=True) if dest_folder: if not os.path.isabs(dest_folder): dest_folder = os.path.normpath(os.path.join(current_path, dest_folder)) mkdir(dest_folder) else: dest_folder = current_path run_imports(conanfile, dest_folder, output)
def test_package(self, path=None, profile_name=None, settings=None, options=None, env=None, scope=None, test_folder=None, not_export=False, build=None, keep_source=False, verify=default_manifest_folder, manifests=default_manifest_folder, manifests_interactive=default_manifest_folder, remote=None, update=False, cwd=None): settings = settings or [] options = options or [] env = env or [] cwd = prepare_cwd(cwd) root_folder = os.path.normpath(os.path.join(cwd, path)) if test_folder: test_folder_name = test_folder test_folder = os.path.join(root_folder, test_folder_name) test_conanfile = os.path.join(test_folder, "conanfile.py") if not os.path.exists(test_conanfile): raise ConanException("test folder '%s' not available, " "or it doesn't have a conanfile.py" % test_folder) else: for name in ["test_package", "test"]: test_folder_name = name test_folder = os.path.join(root_folder, test_folder_name) test_conanfile = os.path.join(test_folder, "conanfile.py") if os.path.exists(test_conanfile): break else: raise ConanException("test folder 'test_package' not available, " "or it doesn't have a conanfile.py") options = options or [] settings = settings or [] sha = hashlib.sha1("".join(options + settings).encode()).hexdigest() build_folder = os.path.join(test_folder, "build", sha) rmdir(build_folder) # shutil.copytree(test_folder, build_folder) profile = profile_from_args(profile_name, settings, options, env, scope, cwd, self._client_cache.profiles_path) conanfile = load_consumer_conanfile(test_conanfile, "", self._client_cache.settings, self._runner, self._user_io.out) try: # convert to list from ItemViews required for python3 if hasattr(conanfile, "requirements"): conanfile.requirements() reqs = list(conanfile.requires.items()) first_dep = reqs[0][1].conan_reference except Exception: raise ConanException("Unable to retrieve first requirement of test conanfile.py") # Forcing an export! if not not_export: self._user_io.out.info("Exporting package recipe") user_channel = "%s/%s" % (first_dep.user, first_dep.channel) self._manager.export(user_channel, root_folder, keep_source=keep_source) lib_to_test = first_dep.name # Get False or a list of patterns to check if build is None and lib_to_test: # Not specified, force build the tested library build = [lib_to_test] manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, root_folder, cwd) manifest_folder, manifest_interactive, manifest_verify = manifests self._manager.install(reference=test_folder, current_path=build_folder, manifest_folder=manifest_folder, manifest_verify=manifest_verify, manifest_interactive=manifest_interactive, remote=remote, profile=profile, build_modes=build, update=update, generators=["txt"] ) test_conanfile = os.path.join(test_folder, CONANFILE) self._manager.build(test_conanfile, test_folder, build_folder, test=True)
def test_package(self, path=None, profile_name=None, settings=None, options=None, env=None, scope=None, test_folder=None, not_export=False, build=None, keep_source=False, verify=default_manifest_folder, manifests=default_manifest_folder, manifests_interactive=default_manifest_folder, remote=None, update=False, cwd=None): settings = settings or [] options = options or [] env = env or [] cwd = prepare_cwd(cwd) root_folder = os.path.normpath(os.path.join(cwd, path)) if test_folder: test_folder_name = test_folder test_folder = os.path.join(root_folder, test_folder_name) test_conanfile = os.path.join(test_folder, "conanfile.py") if not os.path.exists(test_conanfile): raise ConanException("test folder '%s' not available, " "or it doesn't have a conanfile.py" % test_folder) else: for name in ["test_package", "test"]: test_folder_name = name test_folder = os.path.join(root_folder, test_folder_name) test_conanfile = os.path.join(test_folder, "conanfile.py") if os.path.exists(test_conanfile): break else: raise ConanException( "test folder 'test_package' not available, " "or it doesn't have a conanfile.py") options = options or [] settings = settings or [] sha = hashlib.sha1("".join(options + settings).encode()).hexdigest() build_folder = os.path.join(test_folder, "build", sha) rmdir(build_folder) # shutil.copytree(test_folder, build_folder) profile = profile_from_args(profile_name, settings, options, env, scope, cwd, self._client_cache.profiles_path) conanfile = load_consumer_conanfile(test_conanfile, "", self._client_cache.settings, self._runner, self._user_io.out) try: # convert to list from ItemViews required for python3 if hasattr(conanfile, "requirements"): conanfile.requirements() reqs = list(conanfile.requires.items()) first_dep = reqs[0][1].conan_reference except Exception: raise ConanException( "Unable to retrieve first requirement of test conanfile.py") # Forcing an export! if not not_export: self._user_io.out.info("Exporting package recipe") user_channel = "%s/%s" % (first_dep.user, first_dep.channel) self._manager.export(user_channel, root_folder, keep_source=keep_source) lib_to_test = first_dep.name # Get False or a list of patterns to check if build is None and lib_to_test: # Not specified, force build the tested library build = [lib_to_test] manifests = _parse_manifests_arguments(verify, manifests, manifests_interactive, root_folder, cwd) manifest_folder, manifest_interactive, manifest_verify = manifests self._manager.install(reference=test_folder, current_path=build_folder, manifest_folder=manifest_folder, manifest_verify=manifest_verify, manifest_interactive=manifest_interactive, remote=remote, profile=profile, build_modes=build, update=update, generators=["txt"]) test_conanfile = os.path.join(test_folder, CONANFILE) self._manager.build(test_conanfile, test_folder, build_folder, test=True)