def _export_scm(scm_data, origin_folder, scm_sources_folder, output): """ Copy the local folder to the scm_sources folder in the cache, this enables to work with local sources without committing and pushing changes to the scm remote. https://github.com/conan-io/conan/issues/5195""" excluded = SCM(scm_data, origin_folder, output).excluded_files excluded.append("conanfile.py") output.info("SCM: Getting sources from folder: %s" % origin_folder) merge_directories(origin_folder, scm_sources_folder, excluded=excluded)
def _fetch_scm(scm_data, dest_dir, local_sources_path, output): if local_sources_path: excluded = SCM(scm_data, local_sources_path).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) scm.checkout() _clean_source_folder(dest_dir)
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_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 get_scm(conanfile, src_folder): data = getattr(conanfile, "scm", None) if data is not None and isinstance(data, dict): return SCM(data, src_folder) else: # not an instance of dict or None, skip SCM feature. pass
def _capture_export_scm_data(conanfile, conanfile_dir, destination_folder, output, paths, conan_ref): scm_src_file = paths.scm_folder(conan_ref) if os.path.exists(scm_src_file): os.unlink(scm_src_file) scm_data = get_scm_data(conanfile) if not scm_data or not (scm_data.capture_origin or scm_data.capture_revision): return scm = SCM(scm_data, conanfile_dir) if scm_data.url == "auto": origin = scm.get_qualified_remote_url() if not origin: raise ConanException("Repo origin cannot be deduced by 'auto'") 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) # Generate the scm_folder.txt file pointing to the src_path src_path = scm.get_repo_root() save(scm_src_file, src_path.replace("\\", "/")) _replace_scm_data_in_conanfile( os.path.join(destination_folder, "conanfile.py"), scm_data)
def _detect_scm_revision(path): if not path: raise ConanException("Not path supplied") repo_type = SCM.detect_scm(path) if not repo_type: raise ConanException("'{}' repository not detected".format(repo_type)) repo_obj = SCM.availables.get(repo_type)(path) return repo_obj.get_revision(), repo_type, repo_obj.is_pristine()
def _detect_scm_revision(path): if not path: return None, None repo_type = SCM.detect_scm(path) if not repo_type: return None, None repo_obj = SCM.availables.get(repo_type)(path) return repo_obj.get_revision(), repo_type
def scm_serialization_test(self): data = { "url": "myurl", "revision": "myrevision", "username": "******", "password": "******", "type": "git", "verify_ssl": True, "subfolder": "mysubfolder" } scm = SCM(data, temp_folder()) the_json = str(scm) data2 = json.loads(the_json) self.assertEquals(data, data2)
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
def get_scm(conanfile, src_folder): data = getattr(conanfile, "scm", None) if data is not None: return SCM(data, src_folder)
def test_none(self): r = SCM.detect_scm(folder=tempfile.gettempdir()) self.assertEqual(r, None)
def test_git(self): with mock.patch("conans.client.tools.scm.Git.check_repo", return_value=None): r = SCM.detect_scm(folder=tempfile.gettempdir()) self.assertEqual(r, "git")
def test_none(self): r = SCM.detect_scm(folder=self.folder) self.assertEqual(r, None)
def test_svn(self): with mock.patch("conans.client.tools.scm.SVN.check_repo", return_value=None): r = SCM.detect_scm(folder=self.folder) self.assertEqual(r, "svn")