def _capture_scm_auto_fields(conanfile, conanfile_dir, package_layout, output, ignore_dirty, scm_to_conandata): """Deduce the values for the scm auto fields or functions assigned to 'url' or 'revision' and replace the conanfile.py contents. Returns a tuple with (scm_data, path_to_scm_local_directory)""" scm_data = get_scm_data(conanfile) if not scm_data: return None, None # Resolve SCMData in the user workspace (someone may want to access CVS or import some py) scm = SCM(scm_data, conanfile_dir, output) captured = scm_data.capture_origin or scm_data.capture_revision if not captured: # We replace not only "auto" values, also evaluated functions (e.g from a python_require) _replace_scm_data_in_recipe(package_layout, scm_data, scm_to_conandata) return scm_data, None if not scm.is_pristine() and not ignore_dirty: output.warn( "There are uncommitted changes, skipping the replacement of 'scm.url' and " "'scm.revision' auto fields. Use --ignore-dirty to force it. The 'conan " "upload' command will prevent uploading recipes with 'auto' values in these " "fields.") origin = scm.get_qualified_remote_url(remove_credentials=True) local_src_path = scm.get_local_path_to_url(origin) return scm_data, local_src_path if scm_data.url == "auto": origin = scm.get_qualified_remote_url(remove_credentials=True) if not origin: output.warn( "Repo origin cannot be deduced, 'auto' fields won't be replaced." " 'conan upload' command will prevent uploading recipes with 'auto'" " values in these fields.") local_src_path = scm.get_local_path_to_url(origin) return scm_data, local_src_path if scm.is_local_repository(): output.warn("Repo origin looks like a local path: %s" % origin) output.success("Repo origin deduced by 'auto': %s" % origin) scm_data.url = origin if scm_data.revision == "auto": # If it is pristine by default we don't replace the "auto" unless forcing # This prevents the recipe to get uploaded pointing to an invalid commit scm_data.revision = scm.get_revision() output.success("Revision deduced by 'auto': %s" % scm_data.revision) local_src_path = scm.get_local_path_to_url(scm_data.url) _replace_scm_data_in_recipe(package_layout, scm_data, scm_to_conandata) return scm_data, local_src_path
def _run_local_scm(conanfile, conanfile_folder, src_folder, output): """ Only called when 'conan source' in user space :param conanfile: recipe :param src_folder: specified src_folder :param conanfile_folder: Folder containing the local conanfile :param output: Output :return: """ scm_data = get_scm_data(conanfile) if not scm_data: return dest_dir = os.path.normpath( os.path.join(src_folder, scm_data.subfolder or "")) # In user space, if revision="auto", then copy if scm_data.capture_origin or scm_data.capture_revision: # FIXME: or clause? scm = SCM(scm_data, conanfile_folder, output) scm_url = scm_data.url if scm_data.url != "auto" else \ scm.get_qualified_remote_url(remove_credentials=True) src_path = scm.get_local_path_to_url(url=scm_url) if src_path and src_path != dest_dir: excluded = SCM(scm_data, src_path, output).excluded_files output.info("SCM: Getting sources from folder: %s" % src_path) merge_directories(src_path, dest_dir, excluded=excluded) return output.info("SCM: Getting sources from url: '%s'" % scm_data.url) scm = SCM(scm_data, dest_dir, output) scm.checkout()
def _run_scm(conanfile, src_folder, local_sources_path, output, cache): scm_data = get_scm_data(conanfile) if not scm_data: return dest_dir = os.path.normpath(os.path.join(src_folder, scm_data.subfolder)) if cache: # When in cache, capturing the sources from user space is done only if exists if not local_sources_path or not os.path.exists(local_sources_path): local_sources_path = None else: # In user space, if revision="auto", then copy if scm_data.capture_origin or scm_data.capture_revision: # FIXME: or clause? scm = SCM(scm_data, local_sources_path, output) scm_url = scm_data.url if scm_data.url != "auto" else \ scm.get_qualified_remote_url(remove_credentials=True) src_path = scm.get_local_path_to_url(url=scm_url) if src_path: local_sources_path = src_path else: local_sources_path = None if local_sources_path and conanfile.develop: excluded = SCM(scm_data, local_sources_path, output).excluded_files output.info("Getting sources from folder: %s" % local_sources_path) merge_directories(local_sources_path, dest_dir, excluded=excluded) else: output.info("Getting sources from url: '%s'" % scm_data.url) scm = SCM(scm_data, dest_dir, output) scm.checkout() if cache: # This is a bit weird. Why after a SCM should we remove files. Maybe check conan 2.0 _clean_source_folder(dest_dir)
def _capture_export_scm_data(conanfile, conanfile_dir, destination_folder, output, scm_src_file): if os.path.exists(scm_src_file): os.unlink(scm_src_file) scm_data = get_scm_data(conanfile) if not scm_data: return # Resolve SCMData in the user workspace (someone may want to access CVS or import some py) scm = SCM(scm_data, conanfile_dir, output) captured = scm_data.capture_origin or scm_data.capture_revision if scm_data.url == "auto": origin = scm.get_qualified_remote_url(remove_credentials=True) if not origin: raise ConanException("Repo origin cannot be deduced") if scm.is_local_repository(): output.warn("Repo origin looks like a local path: %s" % origin) output.success("Repo origin deduced by 'auto': %s" % origin) scm_data.url = origin if scm_data.revision == "auto": if not scm.is_pristine(): output.warn( "Repo status is not pristine: there might be modified files") scm_data.revision = scm.get_revision() output.success("Revision deduced by 'auto': %s" % scm_data.revision) _replace_scm_data_in_conanfile( os.path.join(destination_folder, "conanfile.py"), scm_data) if captured: # Generate the scm_folder.txt file pointing to the src_path src_path = scm.get_local_path_to_url(scm_data.url) if src_path: save(scm_src_file, os.path.normpath(src_path).replace("\\", "/")) return scm_data