Esempio n. 1
0
def _run_cache_scm(conanfile, scm_sources_folder, src_folder, output):
    """
    :param conanfile: recipe
    :param src_folder: sources folder in the cache, (Destination dir)
    :param scm_sources_folder: scm sources folder in the cache, where the scm sources were exported
    :param output: output
    :return:
    """
    scm_data = get_scm_data(conanfile)
    if not scm_data:
        return

    if scm_data.subfolder:
        dest_dir = os.path.normpath(
            os.path.join(src_folder, scm_data.subfolder))
    else:
        dest_dir = src_folder
    if os.path.exists(scm_sources_folder):
        output.info("Copying previously cached scm sources")
        merge_directories(scm_sources_folder, dest_dir)
    else:
        output.info("SCM: Getting sources from url: '%s'" % scm_data.url)
        try:
            scm = SCM(scm_data, dest_dir, output)
            scm.checkout()
        except Exception as e:
            raise ConanException("Couldn't checkout SCM: %s" % str(e))
        # This is a bit weird. Why after a SCM should we remove files.
        # Maybe check conan 2.0
        # TODO: Why removing in the cache? There is no danger.
        _clean_source_folder(dest_dir)
Esempio n. 2
0
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()
Esempio n. 3
0
 def get_sources_from_exports():
     # First of all get the exported scm sources (if auto) or clone (if fixed)
     _run_cache_scm(conanfile, scm_sources_folder, src_folder, output)
     # so self exported files have precedence over python_requires ones
     merge_directories(export_folder, src_folder)
     # Now move the export-sources to the right location
     merge_directories(export_source_folder, src_folder)
Esempio n. 4
0
    def get_recipe_sources(self, ref, export_folder, export_sources_folder,
                           remote):
        assert ref.revision, "get_recipe_sources requires RREV"
        t1 = time.time()

        zipped_files = self._call_remote(remote, "get_recipe_sources", ref,
                                         export_folder)
        if not zipped_files:
            mkdir(export_sources_folder
                  )  # create the folder even if no source files
            return

        duration = time.time() - t1
        log_recipe_sources_download(ref, duration, remote.name, zipped_files)

        unzip_and_get_files(zipped_files,
                            export_sources_folder,
                            EXPORT_SOURCES_TGZ_NAME,
                            output=self._output)
        # REMOVE in Conan 2.0
        c_src_path = os.path.join(export_sources_folder,
                                  EXPORT_SOURCES_DIR_OLD)
        if os.path.exists(c_src_path):
            merge_directories(c_src_path, export_sources_folder)
            rmdir(c_src_path)
        touch_folder(export_sources_folder)
Esempio n. 5
0
    def excluded_dirs_test(self):
        files = [
            "file.txt", "subdir/file2.txt", "subdir/file3.txt",
            "other_dir/somefile.txt", "other_dir/somefile2.txt"
        ]
        self._save(self.source, files, "fromsrc")

        files_dest = ["file.txt", "subdir2/file2.txt"]
        self._save(self.dest, files_dest, "fromdest")

        # Excluded one file from other_dir and the whole subdir
        merge_directories(self.source,
                          self.dest,
                          excluded=["other_dir/somefile.txt", "subdir"])
        self._assert_equals(
            self._get_paths(self.dest),
            ["file.txt", "subdir2/file2.txt", "other_dir/somefile2.txt"])

        # Excluded one from dest (no sense) and one from origin
        merge_directories(
            self.source,
            self.dest,
            excluded=["subdir2/file2.txt", "subdir", "other_dir/somefile.txt"])

        self._assert_equals(
            self._get_paths(self.dest),
            ["file.txt", "subdir2/file2.txt", "other_dir/somefile2.txt"])
Esempio n. 6
0
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)
Esempio n. 7
0
    def test_non_empty_dest_merge(self):
        files = ["file.txt", "subdir/file2.txt"]
        self._save(self.source, files, "fromsrc")

        files_dest = ["file.txt", "subdir2/file2.txt"]
        self._save(self.dest, files_dest, "fromdest")

        merge_directories(self.source, self.dest)
        self._assert_equals(self._get_paths(self.dest), files + files_dest)
        # File from src overrides file from dest
        self.assertEqual(load(join(self.dest, "file.txt")), "fromsrc")
Esempio n. 8
0
 def parent_directory_test(self):
     files_dest = ["file.txt", "subdir2/file2.txt"]
     self._save(self.dest, files_dest, "fromdest")
     self.source = join(self.dest, "source_folder")
     files = ["file.txt", "subdir/file2.txt"]
     self._save(self.source, files, "fromsrc")
     merge_directories(self.source, self.dest)
     shutil.rmtree(self.source)
     self._assert_equals(self._get_paths(self.dest), files + files_dest)
     self.assertEqual(load(join(self.dest, "file.txt")), "fromsrc")
     self.assertEqual(load(join(self.dest, "subdir2/file2.txt")),
                      "fromdest")
     self.assertEqual(load(join(self.dest, "subdir/file2.txt")), "fromsrc")
Esempio n. 9
0
    def nested_directories_test(self):
        self.dest = join(self.source, "destination_dir")
        files_dest = ["file.txt", "subdir2/file2.txt"]
        self._save(self.dest, files_dest, "fromdest")
        mkdir(join(self.dest, "empty_folder", "subempty_folder"))

        files = ["file.txt", "subdir/file2.txt"]
        self._save(self.source, files, "fromsrc")

        merge_directories(self.source, self.dest)
        self._assert_equals(
            self._get_paths(self.dest), files + files_dest + [
                'empty_folder/subempty_folder',
            ])
        self.assertEqual(load(join(self.dest, "file.txt")), "fromsrc")
        self.assertEqual(load(join(self.dest, "subdir2/file2.txt")),
                         "fromdest")
        self.assertEqual(load(join(self.dest, "subdir/file2.txt")), "fromsrc")
Esempio n. 10
0
 def same_directory_test(self):
     files = ["file.txt", "subdir/file2.txt"]
     self._save(self.source, files, "fromsrc")
     merge_directories(self.source, self.source)
     self._assert_equals(self._get_paths(self.source), files)
Esempio n. 11
0
 def test_empty_dest_merge(self):
     files = ["file.txt", "subdir/file2.txt"]
     self._save(self.source, files)
     merge_directories(self.source, self.dest)
     self._assert_equals(self._get_paths(self.dest), files)