def cmd_export(conanfile_path, name, version, user, channel, keep_source, output, search_manager, client_cache): """ Export the recipe param conanfile_path: the original source directory of the user containing a conanfile.py param user: user under this package will be exported param channel: string (stable, testing,...) """ logger.debug("Exporting %s" % conanfile_path) conan_linter(conanfile_path, output) conanfile = _load_export_conanfile(conanfile_path, output, name, version) conan_ref = ConanFileReference(conanfile.name, conanfile.version, user, channel) conan_ref_str = str(conan_ref) # Maybe a platform check could be added, but depends on disk partition refs = search_manager.search(conan_ref_str, ignorecase=True) if refs and conan_ref not in refs: raise ConanException( "Cannot export package with same name but different case\n" "You exported '%s' but already existing '%s'" % (conan_ref_str, " ".join(str(s) for s in refs))) output = ScopedOutput(str(conan_ref), output) with client_cache.conanfile_write_lock(conan_ref): _export_conanfile(conanfile_path, output, client_cache, conanfile, conan_ref, keep_source)
def cmd_export(conanfile_path, conanfile, reference, keep_source, output, client_cache, plugin_manager): """ Export the recipe param conanfile_path: the original source directory of the user containing a conanfile.py """ plugin_manager.execute("pre_export", conanfile=conanfile, conanfile_path=conanfile_path, reference=reference) logger.debug("Exporting %s" % conanfile_path) output.highlight("Exporting package recipe") conan_linter(conanfile_path, output) # Maybe a platform check could be added, but depends on disk partition conan_ref_str = str(reference) refs = search_recipes(client_cache, conan_ref_str, ignorecase=True) if refs and reference not in refs: raise ConanException( "Cannot export package with same name but different case\n" "You exported '%s' but already existing '%s'" % (conan_ref_str, " ".join(str(s) for s in refs))) with client_cache.conanfile_write_lock(reference): _export_conanfile(conanfile_path, conanfile.output, client_cache, conanfile, reference, keep_source) conanfile_cache_path = client_cache.conanfile(reference) plugin_manager.execute("post_export", conanfile=conanfile, conanfile_path=conanfile_cache_path, reference=reference)
def cmd_export(conanfile_path, conanfile, reference, keep_source, output, client_cache): """ Export the recipe param conanfile_path: the original source directory of the user containing a conanfile.py """ logger.debug("Exporting %s" % conanfile_path) output.highlight("Exporting package recipe") conan_linter(conanfile_path, output) for field in ["url", "license", "description"]: field_value = getattr(conanfile, field, None) if not field_value: output.warn("Conanfile doesn't have '%s'.\n" "It is recommended to add it as attribute" % field) conan_ref_str = str(reference) # Maybe a platform check could be added, but depends on disk partition refs = search_recipes(client_cache, conan_ref_str, ignorecase=True) if refs and reference not in refs: raise ConanException( "Cannot export package with same name but different case\n" "You exported '%s' but already existing '%s'" % (conan_ref_str, " ".join(str(s) for s in refs))) with client_cache.conanfile_write_lock(reference): _export_conanfile(conanfile_path, conanfile.output, client_cache, conanfile, reference, keep_source)
def cmd_export(user, channel, conan_file_path, output, search_manager, client_cache, keep_source=False, filename=None, name=None, version=None): """ Export the recipe param conanfile_path: the original source directory of the user containing a conanfile.py param user: user under this package will be exported param channel: string (stable, testing,...) """ assert conan_file_path logger.debug("Exporting %s" % conan_file_path) src_folder = conan_file_path conanfile_name = filename or CONANFILE conan_file_path = os.path.join(conan_file_path, conanfile_name) if ((os.path.exists(conan_file_path) and conanfile_name not in os.listdir(src_folder)) or (conanfile_name != "conanfile.py" and conanfile_name.lower() == "conanfile.py")): raise ConanException("Wrong '%s' case" % conanfile_name) conan_linter(conan_file_path, output) conanfile = _load_export_conanfile(conan_file_path, output, name, version) conan_ref = ConanFileReference(conanfile.name, conanfile.version, user, channel) conan_ref_str = str(conan_ref) # Maybe a platform check could be added, but depends on disk partition refs = search_manager.search(conan_ref_str, ignorecase=True) if refs and conan_ref not in refs: raise ConanException( "Cannot export package with same name but different case\n" "You exported '%s' but already existing '%s'" % (conan_ref_str, " ".join(str(s) for s in refs))) output = ScopedOutput(str(conan_ref), output) with client_cache.conanfile_write_lock(conan_ref): _export_conanfile(output, client_cache, conanfile, src_folder, conan_ref, keep_source, filename)
def cmd_export(app, conanfile_path, name, version, user, channel, keep_source, export=True, graph_lock=None): """ Export the recipe param conanfile_path: the original source directory of the user containing a conanfile.py """ loader, cache, hook_manager, output = app.loader, app.cache, app.hook_manager, app.out revisions_enabled = app.config.revisions_enabled conanfile = loader.load_export(conanfile_path, name, version, user, channel) # FIXME: Conan 2.0, deprecate CONAN_USER AND CONAN_CHANNEL and remove this try excepts # Take the default from the env vars if they exist to not break behavior try: user = conanfile.user except ConanException: user = None try: channel = conanfile.channel except ConanException: channel = None ref = ConanFileReference(conanfile.name, conanfile.version, user, channel) # If we receive lock information, python_requires could have been locked if graph_lock: node_id = graph_lock.get_node(ref) python_requires = graph_lock.python_requires(node_id) # TODO: check that the locked python_requires are different from the loaded ones # FIXME: private access, will be improved when api collaborators are improved loader._python_requires._range_resolver.output # invalidate previous version range output conanfile = loader.load_export(conanfile_path, conanfile.name, conanfile.version, conanfile.user, conanfile.channel, python_requires) check_casing_conflict(cache=cache, ref=ref) package_layout = cache.package_layout(ref, short_paths=conanfile.short_paths) if not export: metadata = package_layout.load_metadata() recipe_revision = metadata.recipe.revision ref = ref.copy_with_rev(recipe_revision) if graph_lock: graph_lock.update_exported_ref(node_id, ref) return ref hook_manager.execute("pre_export", conanfile=conanfile, conanfile_path=conanfile_path, reference=package_layout.ref) logger.debug("EXPORT: %s" % conanfile_path) output.highlight("Exporting package recipe") conan_linter(conanfile_path, output) output = conanfile.output # Get previous digest try: previous_manifest = FileTreeManifest.load(package_layout.export()) except IOError: previous_manifest = None finally: _recreate_folders(package_layout.export(), package_layout.export_sources()) # Copy sources to target folders with package_layout.conanfile_write_lock(output=output): origin_folder = os.path.dirname(conanfile_path) export_recipe(conanfile, origin_folder, package_layout.export()) export_source(conanfile, origin_folder, package_layout.export_sources()) shutil.copy2(conanfile_path, package_layout.conanfile()) _capture_export_scm_data(conanfile, os.path.dirname(conanfile_path), package_layout.export(), output, scm_src_file=package_layout.scm_folder()) # Execute post-export hook before computing the digest hook_manager.execute("post_export", conanfile=conanfile, reference=package_layout.ref, conanfile_path=package_layout.conanfile()) # Compute the new digest manifest = FileTreeManifest.create(package_layout.export(), package_layout.export_sources()) modified_recipe = not previous_manifest or previous_manifest != manifest if modified_recipe: output.success('A new %s version was exported' % CONANFILE) output.info('Folder: %s' % package_layout.export()) else: output.info("The stored package has not changed") manifest = previous_manifest # Use the old one, keep old timestamp manifest.save(package_layout.export()) # Compute the revision for the recipe revision = _update_revision_in_metadata( package_layout=package_layout, revisions_enabled=revisions_enabled, output=output, path=os.path.dirname(conanfile_path), manifest=manifest, revision_mode=conanfile.revision_mode) # FIXME: Conan 2.0 Clear the registry entry if the recipe has changed source_folder = package_layout.source() if os.path.exists(source_folder): try: if is_dirty(source_folder): output.info("Source folder is corrupted, forcing removal") rmdir(source_folder) elif modified_recipe and not keep_source: output.info( "Package recipe modified in export, forcing source folder removal" ) output.info("Use the --keep-source, -k option to skip it") rmdir(source_folder) except BaseException as e: output.error( "Unable to delete source folder. Will be marked as corrupted for deletion" ) output.warn(str(e)) set_dirty(source_folder) # When revisions enabled, remove the packages not matching the revision if revisions_enabled: packages = search_packages(package_layout, query=None) metadata = package_layout.load_metadata() recipe_revision = metadata.recipe.revision to_remove = [ pid for pid in packages if metadata.packages.get(pid) and metadata.packages.get(pid).recipe_revision != recipe_revision ] if to_remove: output.info( "Removing the local binary packages from different recipe revisions" ) remover = DiskRemover() remover.remove_packages(package_layout, ids_filter=to_remove) ref = ref.copy_with_rev(revision) output.info("Exported revision: %s" % revision) if graph_lock: graph_lock.update_exported_ref(node_id, ref) return ref
def cmd_export(conanfile_path, name, version, user, channel, keep_source, revisions_enabled, output, hook_manager, loader, cache, export=True): """ Export the recipe param conanfile_path: the original source directory of the user containing a conanfile.py """ conanfile = loader.load_export(conanfile_path, name, version, user, channel) ref = ConanFileReference(conanfile.name, conanfile.version, conanfile.user, conanfile.channel) check_casing_conflict(cache=cache, ref=ref) package_layout = cache.package_layout(ref, short_paths=conanfile.short_paths) if not export: metadata = package_layout.load_metadata() recipe_revision = metadata.recipe.revision ref = ref.copy_with_rev(recipe_revision) return ref hook_manager.execute("pre_export", conanfile=conanfile, conanfile_path=conanfile_path, reference=package_layout.ref) logger.debug("EXPORT: %s" % conanfile_path) output.highlight("Exporting package recipe") conan_linter(conanfile_path, output) output = conanfile.output # Get previous digest try: previous_digest = FileTreeManifest.load(package_layout.export()) except IOError: previous_digest = None finally: _recreate_folders(package_layout.export(), package_layout.export_sources()) # Copy sources to target folders with package_layout.conanfile_write_lock(output=output): origin_folder = os.path.dirname(conanfile_path) export_recipe(conanfile, origin_folder, package_layout.export()) export_source(conanfile, origin_folder, package_layout.export_sources()) shutil.copy2(conanfile_path, package_layout.conanfile()) _capture_export_scm_data(conanfile, os.path.dirname(conanfile_path), package_layout.export(), output, scm_src_file=package_layout.scm_folder()) # Execute post-export hook before computing the digest hook_manager.execute("post_export", conanfile=conanfile, reference=package_layout.ref, conanfile_path=package_layout.conanfile()) # Compute the new digest digest = FileTreeManifest.create(package_layout.export(), package_layout.export_sources()) modified_recipe = not previous_digest or previous_digest != digest if modified_recipe: output.success('A new %s version was exported' % CONANFILE) output.info('Folder: %s' % package_layout.export()) else: output.info("The stored package has not changed") digest = previous_digest # Use the old one, keep old timestamp digest.save(package_layout.export()) # Compute the revision for the recipe revision = _update_revision_in_metadata( package_layout=package_layout, revisions_enabled=revisions_enabled, output=output, path=os.path.dirname(conanfile_path), digest=digest, revision_mode=conanfile.revision_mode) # FIXME: Conan 2.0 Clear the registry entry if the recipe has changed source_folder = package_layout.source() if os.path.exists(source_folder): try: if is_dirty(source_folder): output.info("Source folder is corrupted, forcing removal") rmdir(source_folder) elif modified_recipe and not keep_source: output.info( "Package recipe modified in export, forcing source folder removal" ) output.info("Use the --keep-source, -k option to skip it") rmdir(source_folder) except BaseException as e: output.error( "Unable to delete source folder. Will be marked as corrupted for deletion" ) output.warn(str(e)) set_dirty(source_folder) # When revisions enabled, remove the packages not matching the revision if revisions_enabled: packages = search_packages(package_layout, query=None) metadata = package_layout.load_metadata() recipe_revision = metadata.recipe.revision to_remove = [ pid for pid in packages if metadata.packages.get(pid) and metadata.packages.get(pid).recipe_revision != recipe_revision ] if to_remove: output.info( "Removing the local binary packages from different recipe revisions" ) remover = DiskRemover() remover.remove_packages(package_layout, ids_filter=to_remove) ref = ref.copy_with_rev(revision) return ref