Esempio n. 1
0
 def test_double_create(self):
     # https://github.com/conan-io/conan/issues/5195#issuecomment-551848955
     self.client = TestClient(default_server_user=True)
     conanfile = str(GenConanfile().
                     with_scm({"type": "git", "revision": "auto", "url": "auto"}).
                     with_import("import os").with_import("from conans import tools").
                     with_name("lib").
                     with_version("1.0"))
     conanfile += """
 def build(self):
     contents = tools.load("bla.sh")
     self.output.warn("Bla? {}".format(contents))
     """
     self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
     create_local_git_repo(folder=self.client.current_folder)
     self.client.run_command('git remote add origin https://myrepo.com.git')
     #  modified blah.sh
     self.client.save({"bla.sh": "bla bla"})
     self.client.run("create . user/channel")
     self.assertIn("Bla? bla bla", self.client.out)
     #  modified blah.sh again
     self.client.save({"bla.sh": "bla2 bla2"})
     # Run conan create again
     self.client.run("create . user/channel")
     self.assertIn("Bla? bla2 bla2", self.client.out)
Esempio n. 2
0
 def test_upload_blocking_auto(self):
     client = TestClient(default_server_user=True)
     conanfile = base_git.format(revision="auto", url='"auto"')
     client.save({
         "conanfile.py": conanfile,
         "myfile.txt": "My file is copied"
     })
     create_local_git_repo(folder=client.current_folder)
     client.run_command('git remote add origin https://myrepo.com.git')
     # Dirty file
     client.save({"dirty": "you dirty contents"})
     client.run("create . user/channel")
     self.assertIn(
         "WARN: There are uncommitted changes, skipping the replacement "
         "of 'scm.url' and 'scm.revision' auto fields. "
         "Use --ignore-dirty to force it.", client.out)
     # The upload has to fail, no "auto" fields are allowed
     client.run("upload lib/0.1@user/channel -r default", assert_error=True)
     self.assertIn(
         "ERROR: lib/0.1@user/channel: Upload recipe to 'default' failed:"
         " The recipe contains invalid data in the 'scm' attribute (some 'auto'"
         " values or missing fields 'type', 'url' or 'revision'). Use '--force'"
         " to ignore", client.out)
     # The upload with --force should work
     client.run("upload lib/0.1@user/channel -r default --force")
     self.assertIn("Uploaded conan recipe", client.out)
Esempio n. 3
0
    def test_ignore_dirty_subfolder(self):
        # https://github.com/conan-io/conan/issues/6070
        conanfile = textwrap.dedent("""
            import os
            from conans import ConanFile, tools

            class ConanLib(ConanFile):
                name = "lib"
                version = "0.1"
                short_paths = True
                scm = {
                    "type": "git",
                    "url": "auto",
                    "revision": "auto",
                }

                def build(self):
                    path = os.path.join("base_file.txt")
                    assert os.path.exists(path)
        """)
        self.client.save({
            "test/main/conanfile.py": conanfile,
            "base_file.txt": "foo"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run_command('git remote add origin https://myrepo.com.git')

        # Introduce changes
        self.client.save({"dirty_file.txt": "foo"})
        # The build() method will verify that the files from the repository are copied ok
        self.client.run("create test/main/conanfile.py user/channel")
        self.assertIn("Package '{}' created".format(NO_SETTINGS_PACKAGE_ID),
                      self.client.out)
Esempio n. 4
0
    def test_auto_subfolder(self):
        curdir = self.client.current_folder.replace("\\", "/")
        conanfile = base_git.replace(
            '"revision": "{revision}"', '"revision": "{revision}",\n        '
            '"subfolder": "mysub"')
        conanfile = conanfile.replace("short_paths = True",
                                      "short_paths = False")
        conanfile = conanfile.format(directory="None",
                                     url=_quoted("auto"),
                                     revision="auto")
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.runner('git remote add origin https://myrepo.com.git',
                           cwd=curdir)
        self.client.run("create . user/channel")

        ref = ConanFileReference.loads("lib/0.1@user/channel")
        folder = self.client.cache.package_layout(ref).source()
        self.assertTrue(
            os.path.exists(os.path.join(folder, "mysub", "myfile.txt")))
        self.assertFalse(
            os.path.exists(os.path.join(folder, "mysub", "conanfile.py")))
Esempio n. 5
0
    def test_user_space_with_local_sources(self):
        output = TestBufferConanOutput()

        # Need a real repo to get a working SCM object
        local_sources_path = os.path.join(self.tmp_dir,
                                          'git_repo').replace('\\', '/')
        create_local_git_repo(files={'file1': "content"},
                              folder=local_sources_path)
        git = Git(local_sources_path)
        url = "https://remote.url"
        git.run("remote add origin \"{}\"".format(url))

        # Mock the conanfile (return scm_data)
        conanfile = mock.MagicMock()
        conanfile.scm = {'type': 'git', 'url': 'auto', 'revision': 'auto'}

        # Mock functions called from inside _run_scm (tests will be here)
        def merge_directories(src, dst, excluded=None):
            src = os.path.normpath(src)
            dst = os.path.normpath(dst)
            self.assertEqual(src.replace('\\', '/'), local_sources_path)
            self.assertEqual(dst, self.src_folder)

        with mock.patch("conans.client.source.merge_directories",
                        side_effect=merge_directories):
            _run_local_scm(conanfile,
                           conanfile_folder=local_sources_path,
                           src_folder=self.src_folder,
                           output=output)

        self.assertIn(
            "getting sources from folder: {}".format(
                local_sources_path).lower(),
            str(output).lower())
Esempio n. 6
0
    def test_auto_git(self):
        curdir = get_cased_path(self.client.current_folder).replace("\\", "/")
        conanfile = base_git.format(directory="None", url=_quoted("auto"), revision="auto")
        self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run("export . user/channel", assert_error=True)
        self.assertIn("Repo origin cannot be deduced", self.client.out)

        self.client.run_command('git remote add origin https://myrepo.com.git')

        # Create the package, will copy the sources from the local folder
        self.client.run("create . user/channel")
        self.assertIn("Repo origin deduced by 'auto': https://myrepo.com.git", self.client.out)
        self.assertIn("Revision deduced by 'auto'", self.client.out)
        self.assertIn("SCM: Getting sources from folder: %s" % curdir, self.client.out)
        self.assertIn("My file is copied", self.client.out)

        # check blank lines are respected in replacement
        self.client.run("get lib/0.1@user/channel")
        self.assertIn("""}

    def build(self):""", self.client.out)

        # Export again but now with absolute reference, so no sources are copied from the local dir
        git = Git(curdir)
        self.client.save({"conanfile.py": base_git.format(url=_quoted(curdir),
                                                          revision=git.get_revision())})
        self.client.run("create . user/channel")
        self.assertNotIn("Repo origin deduced by 'auto'", self.client.out)
        self.assertNotIn("Revision deduced by 'auto'", self.client.out)
        self.assertNotIn("Getting sources from folder: %s" % curdir, self.client.out)
        self.assertIn("SCM: Getting sources from url: '%s'" % curdir, self.client.out)
        self.assertIn("My file is copied", self.client.out)
Esempio n. 7
0
 def test_upload_blocking_auto(self):
     self.client = TestClient(default_server_user=True)
     conanfile = base_git.format(revision="auto", url='"auto"')
     self.client.save({
         "conanfile.py": conanfile,
         "myfile.txt": "My file is copied"
     })
     create_local_git_repo(folder=self.client.current_folder)
     self.client.run_command('git remote add origin https://myrepo.com.git')
     # Dirty file
     self.client.save({"dirty": "you dirty contents"})
     self.client.run("create . user/channel")
     self.assertIn(
         "WARN: There are uncommitted changes, skipping the replacement "
         "of 'scm.url' and 'scm.revision' auto fields. "
         "Use --ignore-dirty to force it.", self.client.out)
     # The upload has to fail, no "auto" fields are allowed
     self.client.run("upload lib/0.1@user/channel -r default",
                     assert_error=True)
     self.assertIn(
         "ERROR: The recipe has 'scm.url' or 'scm.revision' with 'auto' values. "
         "Use '--force' to ignore", self.client.out)
     # The upload with --force should work
     self.client.run("upload lib/0.1@user/channel -r default --force")
     self.assertIn("Uploaded conan recipe", self.client.out)
Esempio n. 8
0
    def test_local_source(self):
        curdir = self.client.current_folder
        conanfile = base_git.format(url="auto", revision="auto")
        conanfile += """
    def source(self):
        self.output.warn("SOURCE METHOD CALLED")
"""
        self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
        create_local_git_repo(folder=self.client.current_folder)
        self.client.save({"aditional_file.txt": "contents"})

        self.client.run("source . --source-folder=./source")
        self.assertTrue(os.path.exists(os.path.join(curdir, "source", "myfile.txt")))
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
        # Even the not commited files are copied
        self.assertTrue(os.path.exists(os.path.join(curdir, "source", "aditional_file.txt")))
        self.assertIn("Getting sources from folder: %s" % curdir, self.client.out)

        # Export again but now with absolute reference, so no pointer file is created nor kept
        git = Git(curdir.replace("\\", "/"))
        conanfile = base_git.format(url=curdir.replace("\\", "/"), revision=git.get_revision())
        conanfile += """
    def source(self):
        self.output.warn("SOURCE METHOD CALLED")
"""
        self.client.save({"conanfile.py": conanfile,
                          "myfile2.txt": "My file is copied"})
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run("source . --source-folder=./source2")
        # myfile2 is no in the specified commit
        self.assertFalse(os.path.exists(os.path.join(curdir, "source2", "myfile2.txt")))
        self.assertTrue(os.path.exists(os.path.join(curdir, "source2", "myfile.txt")))
        self.assertIn("Getting sources from url: '%s'" % curdir.replace("\\", "/"), self.client.out)
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
Esempio n. 9
0
    def test_deleted_source_folder(self):
        path, _ = create_local_git_repo({"myfile": "contents"},
                                        branch="my_release")
        conanfile = base_git.format(url=_quoted("auto"), revision="auto")
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run_command('git remote add origin "%s"' %
                                path.replace("\\", "/"))
        self.client.run_command('git push origin master')
        self.client.run("export . user/channel")

        # delete old source, but it doesn't matter because the sources are in the cache
        rmdir(self.client.current_folder)
        new_curdir = temp_folder()
        self.client.current_folder = new_curdir

        self.client.run("install lib/0.1@user/channel --build")
        self.assertNotIn(
            "Getting sources from url: '%s'" % path.replace("\\", "/"),
            self.client.out)

        # If the remove the source folder, then it is fetched from the "remote" doing an install
        self.client.run("remove lib/0.1@user/channel -f -s")
        self.client.run("install lib/0.1@user/channel --build")
        self.assertIn(
            "SCM: Getting sources from url: '%s'" % path.replace("\\", "/"),
            self.client.out)
Esempio n. 10
0
    def test_non_commited_changes_export(self):
        conanfile = base_git.format(revision="auto", url='"auto"')
        self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
        create_local_git_repo(folder=self.client.current_folder)
        self.client.run_command('git remote add origin https://myrepo.com.git')
        # Dirty file
        self.client.save({"dirty": "you dirty contents"})

        for command in ("export .", "create ."):
            self.client.run(command)
            self.assertIn("WARN: There are uncommitted changes, skipping the replacement "
                          "of 'scm.url' and 'scm.revision' auto fields. "
                          "Use --ignore-dirty to force it.", self.client.out)

            # We confirm that the replacement hasn't been done
            ref = ConanFileReference.loads("lib/0.1@")
            folder = self.client.cache.package_layout(ref).export()
            conanfile_contents = load(os.path.join(folder, "conanfile.py"))
            self.assertIn('"revision": "auto"', conanfile_contents)
            self.assertIn('"url": "auto"', conanfile_contents)

        # We repeat the export/create but now using the --ignore-dirty
        for command in ("export .", "create ."):
            self.client.run("{} --ignore-dirty".format(command))
            self.assertNotIn("WARN: There are uncommitted changes, skipping the replacement "
                             "of 'scm.url' and 'scm.revision' auto fields. "
                             "Use --ignore-dirty to force it.", self.client.out)
            # We confirm that the replacement has been done
            ref = ConanFileReference.loads("lib/0.1@")
            folder = self.client.cache.package_layout(ref).export()
            conanfile_contents = load(os.path.join(folder, "conanfile.py"))
            self.assertNotIn('"revision": "auto"', conanfile_contents)
            self.assertNotIn('"url": "auto"', conanfile_contents)
Esempio n. 11
0
    def reuse_scm_test(self):
        client = TestClient()
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            class SomeBase(object):
                scm = {"type" : "git",
                       "url" : "somerepo",
                       "revision" : "auto"}

            class MyConanfileBase(SomeBase, ConanFile):
                pass
            """)
        create_local_git_repo({"conanfile.py": conanfile},
                              branch="my_release",
                              folder=client.current_folder)
        client.run("export . base/1.1@user/testing")

        reuse = textwrap.dedent("""
            from conans import ConanFile
            class PkgTest(ConanFile):
                python_requires = "base/1.1@user/testing"
                python_requires_extend = "base.SomeBase"
            """)
        client.save({"conanfile.py": reuse})
        client.run("export . Pkg/0.1@user/testing")
        client.run("get Pkg/0.1@user/testing")
        self.assertNotIn("scm = base.scm", client.out)
        self.assertIn('scm = {"revision":', client.out)
        self.assertIn('"type": "git",', client.out)
        self.assertIn('"url": "somerepo"', client.out)
Esempio n. 12
0
    def test_clone_submodule_git(self):
        subsubmodule, _ = create_local_git_repo({"subsubmodule": "contents"})
        submodule, _ = create_local_git_repo({"submodule": "contents"},
                                             submodules=[subsubmodule])
        path, commit = create_local_git_repo({"myfile": "contents"},
                                             submodules=[submodule])

        def _create_paths():
            tmp = temp_folder()
            submodule_path = os.path.join(
                tmp, os.path.basename(os.path.normpath(submodule)))
            subsubmodule_path = os.path.join(
                submodule_path,
                os.path.basename(os.path.normpath(subsubmodule)))
            return tmp, submodule_path, subsubmodule_path

        # Check old (default) behaviour
        tmp, submodule_path, _ = _create_paths()
        git = Git(tmp)
        git.clone(path)
        self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
        self.assertFalse(
            os.path.exists(os.path.join(submodule_path, "submodule")))

        # Check invalid value
        tmp, submodule_path, _ = _create_paths()
        git = Git(tmp)
        git.clone(path)
        with six.assertRaisesRegex(
                self, ConanException,
                "Invalid 'submodule' attribute value in the 'scm'."):
            git.checkout(commit, submodule="invalid")

        # Check shallow
        tmp, submodule_path, subsubmodule_path = _create_paths()
        git = Git(tmp)
        git.clone(path)
        git.checkout(commit, submodule="shallow")
        self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
        self.assertTrue(
            os.path.exists(os.path.join(submodule_path, "submodule")))
        self.assertFalse(
            os.path.exists(os.path.join(subsubmodule_path, "subsubmodule")))

        # Check recursive
        tmp, submodule_path, subsubmodule_path = _create_paths()
        git = Git(tmp)
        git.clone(path)
        git.checkout(commit, submodule="recursive")
        self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
        self.assertTrue(
            os.path.exists(os.path.join(submodule_path, "submodule")))
        self.assertTrue(
            os.path.exists(os.path.join(subsubmodule_path, "subsubmodule")))
Esempio n. 13
0
    def reuse_scm_multiple_conandata_test(self):
        # https://github.com/conan-io/conan/issues/7236
        # This only works when using conandata.yml, conanfile.py replace is broken
        client = TestClient()
        conanfile = textwrap.dedent("""
            from conans import ConanFile
            class SomeBase(object):
                scm = {"type" : "git",
                       "url" : "remote1",
                       "revision" : "auto"}

            class MyConanfileBase(SomeBase, ConanFile):
                pass
            """)
        _, base_rev = create_local_git_repo({"conanfile.py": conanfile},
                                            branch="my_release",
                                            folder=os.path.join(
                                                client.current_folder, "base"))
        client.run("config set general.scm_to_conandata=1")
        client.run("export base base/1.1@user/testing")

        reuse = textwrap.dedent("""
            from conans import ConanFile
            class PkgTest(ConanFile):
                name = "%s"
                python_requires = "base/1.1@user/testing"
                python_requires_extend = "base.SomeBase"
            """)
        _, reuse1_rev = create_local_git_repo(
            {"conanfile.py": reuse % "reuse1"},
            branch="release",
            folder=os.path.join(client.current_folder, "reuse1"))
        _, reuse2_rev = create_local_git_repo(
            {"conanfile.py": reuse % "reuse2"},
            branch="release",
            folder=os.path.join(client.current_folder, "reuse2"))
        client.run("export reuse1 reuse1/1.1@user/testing")
        client.run("export reuse2 reuse2/1.1@user/testing")

        client.run("inspect base/1.1@user/testing -a=scm --json=base.json")
        base_json = json.loads(client.load("base.json"))
        client.run("inspect reuse1/1.1@user/testing -a=scm --json=reuse1.json")
        reuse1_json = json.loads(client.load("reuse1.json"))
        client.run("inspect reuse2/1.1@user/testing -a=scm --json=reuse2.json")
        reuse2_json = json.loads(client.load("reuse2.json"))
        self.assertEqual(base_json["scm"]["revision"], base_rev)
        self.assertEqual(reuse1_json["scm"]["revision"], reuse1_rev)
        self.assertEqual(reuse2_json["scm"]["revision"], reuse2_rev)
        self.assertNotEqual(base_rev, reuse1_rev)
        self.assertNotEqual(base_rev, reuse2_rev)
        self.assertNotEqual(reuse2_rev, reuse1_rev)
Esempio n. 14
0
    def test_deleted_source_folder(self):
        path, _ = create_local_git_repo({"myfile": "contents"}, branch="my_release")
        curdir = self.client.current_folder.replace("\\", "/")
        conanfile = base_git.format(url=_quoted("auto"), revision="auto")
        self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
        create_local_git_repo(folder=self.client.current_folder)
        self.client.runner('git remote add origin "%s"' % path.replace("\\", "/"), cwd=curdir)
        self.client.run("export . user/channel")

        new_curdir = temp_folder()
        self.client.current_folder = new_curdir
        # delete old source, so it will try to checkout the remote because of the missing local dir
        rmdir(curdir)
        self.client.run("install lib/0.1@user/channel --build", assert_error=True)
        self.assertIn("Getting sources from url: '%s'" % path.replace("\\", "/"), self.client.out)
Esempio n. 15
0
 def test_clone_git_shallow_revision(self):
     path, revision = create_local_git_repo({"myfile": "contents"},
                                            commits=3,
                                            tags=["1.0"],
                                            branch="develop")
     tmp = temp_folder()
     git = Git(tmp)
     if Git.get_version() < "2.13":
         # older Git versions have known bugs with "git fetch origin <sha>":
         # https://github.com/git/git/blob/master/Documentation/RelNotes/2.13.0.txt
         #  * "git fetch" that requests a commit by object name, when the other
         #    side does not allow such an request, failed without much
         #    explanation.
         # https://github.com/git/git/blob/master/Documentation/RelNotes/2.14.0.txt
         # * There is no good reason why "git fetch $there $sha1" should fail
         #    when the $sha1 names an object at the tip of an advertised ref,
         #    even when the other side hasn't enabled allowTipSHA1InWant.
         with self.assertRaises(subprocess.CalledProcessError):
             git.clone("file://" + path, branch=revision, shallow=True)
     else:
         git.clone("file://" + path, branch=revision, shallow=True)
         with self.assertRaises(subprocess.CalledProcessError):
             git.checkout(element="HEAD~1")
         self.assertTrue(os.path.exists(os.path.join(tmp, "myfile")))
         self.assertEqual(git.get_revision(), revision)
         self.assertEqual(git.run("rev-list --all --count"), "1")
Esempio n. 16
0
    def test_excluded_repo_fies(self):
        conanfile = base_git.format(url=_quoted("auto"), revision="auto")
        conanfile = conanfile.replace("short_paths = True", "short_paths = False")
        path, _ = create_local_git_repo({"myfile": "contents",
                                         "ignored.pyc": "bin",
                                         ".gitignore": """
*.pyc
my_excluded_folder
other_folder/excluded_subfolder
""",
                                         "myfile.txt": "My file!",
                                         "my_excluded_folder/some_file": "hey Apple!",
                                         "other_folder/excluded_subfolder/some_file": "hey Apple!",
                                         "other_folder/valid_file": "!",
                                         "conanfile.py": conanfile}, branch="my_release")
        self.client.current_folder = path
        self.client.run_command('git remote add origin "%s"' % path.replace("\\", "/"))
        self.client.run("create . user/channel")
        self.assertIn("Copying sources to build folder", self.client.out)
        pref = PackageReference(ConanFileReference.loads("lib/0.1@user/channel"),
                                NO_SETTINGS_PACKAGE_ID)
        bf = self.client.cache.package_layout(pref.ref).build(pref)
        self.assertTrue(os.path.exists(os.path.join(bf, "myfile.txt")))
        self.assertTrue(os.path.exists(os.path.join(bf, "myfile")))
        self.assertTrue(os.path.exists(os.path.join(bf, ".git")))
        self.assertFalse(os.path.exists(os.path.join(bf, "ignored.pyc")))
        self.assertFalse(os.path.exists(os.path.join(bf, "my_excluded_folder")))
        self.assertTrue(os.path.exists(os.path.join(bf, "other_folder", "valid_file")))
        self.assertFalse(os.path.exists(os.path.join(bf, "other_folder", "excluded_subfolder")))
Esempio n. 17
0
    def test_scm_bad_filename(self):
        # Fixes: #3500
        badfilename = "\xE3\x81\x82badfile.txt"
        path, _ = create_local_git_repo({"goodfile.txt": "good contents"},
                                        branch="my_release")
        save(
            to_file_bytes(os.path.join(self.client.current_folder,
                                       badfilename)), "contents")
        self.client.runner('git remote add origin "%s"' %
                           path.replace("\\", "/"),
                           cwd=path)

        conanfile = '''
import os
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    scm = {
        "type": "git",
        "url": "auto",
        "revision": "auto"
    }

    def build(self):
        pass
'''
        self.client.current_folder = path
        self.client.save({"conanfile.py": conanfile})
        self.client.run("create . user/channel")
Esempio n. 18
0
    def test_source_method_export_sources_and_scm_mixed(self):
        path, _ = create_local_git_repo({"myfile": "contents"}, branch="my_release")

        conanfile = '''
import os
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    exports_sources = "file.txt"
    scm = {
        "type": "git",
        "url": "%s",
        "revision": "my_release",
        "subfolder": "src/nested"
    }

    def source(self):
        self.output.warn("SOURCE METHOD CALLED")
        assert(os.path.exists("file.txt"))
        assert(os.path.exists(os.path.join("src", "nested", "myfile")))
        tools.save("cosa.txt", "contents")

    def build(self):
        assert(os.path.exists("file.txt"))
        assert(os.path.exists("cosa.txt"))
        self.output.warn("BUILD METHOD CALLED")
''' % path
        self.client.save({"conanfile.py": conanfile, "file.txt": "My file is copied"})
        self.client.run("create . user/channel")
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
        self.assertIn("BUILD METHOD CALLED", self.client.out)
Esempio n. 19
0
    def test_repeat_clone_changing_subfolder(self):
        tmp = '''
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    scm = {{
        "type": "git",
        "url": "{url}",
        "revision": "{revision}",
        "subfolder": "onesubfolder"
    }}
'''
        path, commit = create_local_git_repo({"myfile": "contents"},
                                             branch="my_release")
        conanfile = tmp.format(url=path, revision=commit)
        self.client.save({
            "conanfile.py": conanfile,
            "myfile.txt": "My file is copied"
        })
        self.client.run("create . user/channel")
        conanfile = conanfile.replace('"onesubfolder"', '"othersubfolder"')
        self.client.save({"conanfile.py": conanfile})
        self.client.run("create . user/channel")
        folder = self.client.cache.package_layout(self.ref).source()
        self.assertIn("othersubfolder", os.listdir(folder))
        self.assertTrue(
            os.path.exists(os.path.join(folder, "othersubfolder", "myfile")))
Esempio n. 20
0
    def test_source_removed_in_local_cache(self):
        conanfile = '''
from conans import ConanFile, tools

class ConanLib(ConanFile):
    scm = {
        "type": "git",
        "url": "auto",
        "revision": "auto",
    }

    def build(self):
        contents = tools.load("myfile")
        self.output.warn("Contents: %s" % contents)

'''
        path, _ = create_local_git_repo(
            {
                "myfile": "contents",
                "conanfile.py": conanfile
            },
            branch="my_release")
        self.client.current_folder = path
        self.client.runner('git remote add origin https://myrepo.com.git',
                           cwd=path)
        self.client.run("create . lib/1.0@user/channel")
        self.assertIn("Contents: contents", self.client.out)
        self.client.save({"myfile": "Contents 2"})
        self.client.run("create . lib/1.0@user/channel")
        self.assertIn("Contents: Contents 2", self.client.out)
        self.assertIn(
            "Detected 'scm' auto in conanfile, trying to remove source folder",
            self.client.out)
Esempio n. 21
0
    def test_shallow_clone_remote(self, remote, revision, is_tag):
        # https://github.com/conan-io/conan/issues/5570
        self.client = TestClient()

        # "remote" git
        if remote == "local":
            remote, rev = create_local_git_repo(tags=[revision] if is_tag else None,
                                                files={"conans/model/username.py": "foo"})
            if revision is None:  # Get the generated commit
                revision = rev

        # Use explicit URL to avoid local optimization (scm_folder.txt)
        conanfile = '''
import os
from conans import ConanFile, tools

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    scm = {"type": "git", "url": "%s", "revision": "%s"}

    def build(self):
        assert os.path.exists(os.path.join(self.build_folder, "conans", "model", "username.py"))
''' % (remote, revision)
        self.client.save({"conanfile.py": conanfile})
        self.client.run("create . user/channel")
Esempio n. 22
0
    def test_git_delegated_function(self):
        conanfile = """
import os
from conans import ConanFile
from conans.client.tools.scm import Git

def get_revision():
    here = os.path.dirname(__file__)
    git = Git(here)
    return git.get_commit()

def get_url():
    def nested_url():
        here = os.path.dirname(__file__)
        git = Git(here)
        return git.get_remote_url()
    return nested_url()

class MyLib(ConanFile):
    name = "issue"
    version = "3831"
    scm = {'type': 'git', 'url': get_url(), 'revision': get_revision()}

"""
        self.client.save({"conanfile.py": conanfile})
        path, commit = create_local_git_repo(folder=self.client.current_folder)
        self.client.runner('git remote add origin "%s"' %
                           path.replace("\\", "/"),
                           cwd=path)

        self.client.run("export . user/channel")
        ref = ConanFileReference.loads("issue/3831@user/channel")
        exported_conanfile = self.client.cache.package_layout(ref).conanfile()
        content = load(exported_conanfile)
        self.assertIn(commit, content)
Esempio n. 23
0
    def test_with_scm(self):
        conanfile = '''
from conans import ConanFile

class HelloConan(ConanFile):
    scm = {
        "revision": "auto",
        "url": "auto",
        "type": "git"
    }
    def build(self):
        self.output.warn("Revision 1")        
'''
        path, commit = create_local_git_repo({"myfile": "contents",
                                              "conanfile.py": conanfile}, branch="my_release")
        self.client.runner('git remote add origin https://myrepo.com.git', cwd=path)

        self.client.current_folder = path
        self.client.run("create . %s" % str(self.ref))
        self.client.run("upload %s -c --all -r remote0" % str(self.ref))
        rev_server = self.servers["remote0"].paths.get_last_revision(self.ref)
        self.assertEqual(commit, rev_server.revision)

        self.client.run("remove %s -f" % str(self.ref))
        self.client.run("install %s#%s" % (str(self.ref), rev_server.revision))
        self.assertIn("Package installed 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9", self.client.out)

        self.client.run("remove %s -f" % str(self.ref))
        self.client.run("install %s" % str(self.ref))
        self.assertIn("Package installed 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9", self.client.out)
Esempio n. 24
0
    def test_auto_is_replaced(self):
        conanfile = textwrap.dedent("""
            import os
            from conans import ConanFile

            class Recipe(ConanFile):
                scm = {"type": "git", "url": "auto", "revision": "auto"}
        """)
        t = TestClient()
        t.save({'conanfile.py': conanfile})
        _, commit = create_local_git_repo(folder=t.current_folder)
        t.run_command('git remote add origin https://myrepo.com.git')
        t.run("config set general.scm_to_conandata=1")
        t.run("export . name/version@")

        # Check exported files
        package_layout = t.cache.package_layout(self.ref)
        exported_conanfile = load(package_layout.conanfile())
        self.assertEqual(exported_conanfile, conanfile)
        exported_conandata = load(
            os.path.join(package_layout.export(), DATA_YML))
        conan_data = yaml.safe_load(exported_conandata)
        self.assertDictEqual(conan_data['.conan']['scm'], {
            "type": "git",
            "url": 'https://myrepo.com.git',
            "revision": commit
        })

        # Check the recipe gets the proper values
        t.run("inspect name/version@ -a scm")
        self.assertIn("revision: {}".format(commit), t.out)
        self.assertIn("type: git", t.out)
        self.assertIn("url: https://myrepo.com.git", t.out)
Esempio n. 25
0
    def test_excluded_repo_fies(self):
        conanfile = base_git.format(url="auto", revision="auto")
        conanfile = conanfile.replace("short_paths = True", "short_paths = False")
        path, commit = create_local_git_repo({"myfile": "contents",
                                              "ignored.pyc": "bin",
                                              ".gitignore": """
*.pyc
my_excluded_folder
other_folder/excluded_subfolder
""",
                                              "myfile.txt": "My file!",
                                              "my_excluded_folder/some_file": "hey Apple!",
                                              "other_folder/excluded_subfolder/some_file": "hey Apple!",
                                              "other_folder/valid_file": "!",
                                              "conanfile.py": conanfile}, branch="my_release")
        self.client.current_folder = path
        self._commit_contents()
        self.client.runner('git remote add origin "%s"' % path.replace("\\", "/"), cwd=path)
        self.client.run("create . user/channel")
        self.assertIn("Copying sources to build folder", self.client.out)
        pref = PackageReference(ConanFileReference.loads("lib/0.1/user/channel"),
                                "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        bf = self.client.client_cache.build(pref)
        self.assertTrue(os.path.exists(os.path.join(bf, "myfile.txt")))
        self.assertTrue(os.path.exists(os.path.join(bf, "myfile")))
        self.assertTrue(os.path.exists(os.path.join(bf, ".git")))
        self.assertFalse(os.path.exists(os.path.join(bf, "ignored.pyc")))
        self.assertFalse(os.path.exists(os.path.join(bf, "my_excluded_folder")))
        self.assertTrue(os.path.exists(os.path.join(bf, "other_folder", "valid_file")))
        self.assertFalse(os.path.exists(os.path.join(bf, "other_folder", "excluded_subfolder")))
Esempio n. 26
0
    def git_to_capture_branch_test(self):
        conanfile = """
import re
from conans import ConanFile, tools

def get_version():
    git = tools.Git()
    try:
        branch = git.get_branch()
        branch = re.sub('[^0-9a-zA-Z]+', '_', branch)
        return "%s_%s" % (branch, git.get_revision())
    except:
        return None

class HelloConan(ConanFile):
    name = "Hello"
    version = get_version()

    def build(self):
        assert("r3le_ase__" in self.version)
        assert(len(self.version) == 50)
"""
        path, _ = create_local_git_repo({"conanfile.py": conanfile},
                                        branch="r3le-ase-")
        client = TestClient()
        client.current_folder = path
        client.run("create . user/channel")
Esempio n. 27
0
    def reuse_scm_test(self):
        client = TestClient()

        conanfile = """from conans import ConanFile
scm = {"type" : "git",
       "url" : "somerepo",
       "revision" : "auto"}

class MyConanfileBase(ConanFile):
    scm = scm
"""
        create_local_git_repo({"conanfile.py": conanfile},
                              branch="my_release",
                              folder=client.current_folder)
        client.run("export . MyConanfileBase/1.1@lasote/testing")
        client.run("get MyConanfileBase/1.1@lasote/testing")
        # The global scm is left as-is
        self.assertIn(
            """scm = {"type" : "git",
       "url" : "somerepo",
       "revision" : "auto"}""", client.out)
        # but the class one is replaced
        self.assertNotIn("scm = scm", client.out)
        self.assertIn('    scm = {"revision":', client.out)
        self.assertIn('"type": "git",', client.out)
        self.assertIn('"url": "somerepo"', client.out)

        reuse = """from conans import python_requires
base = python_requires("MyConanfileBase/1.1@lasote/testing")
class PkgTest(base.MyConanfileBase):
    scm = base.scm
    other = 123
    def _my_method(self):
        pass
"""
        client.save({"conanfile.py": reuse})
        # Commit changes so it replaces and exports the scm data
        client.run_command('git add .')
        client.run_command('git commit -m "Modified conanfile"')

        client.run("export . Pkg/0.1@lasote/testing")
        client.run("get Pkg/0.1@lasote/testing")
        self.assertNotIn("scm = base.scm", client.out)
        self.assertIn('scm = {"revision":', client.out)
        self.assertIn('"type": "git",', client.out)
        self.assertIn('"url": "somerepo"', client.out)
Esempio n. 28
0
    def test_local_source_subfolder(self):
        curdir = self.client.current_folder
        conanfile = base_git.replace('"revision": "{revision}"',
                                     '"revision": "{revision}",\n        '
                                     '"subfolder": "mysub"')
        conanfile = conanfile.format(url=_quoted("auto"), revision="auto")
        conanfile += """
    def source(self):
        self.output.warn("SOURCE METHOD CALLED")
"""
        self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
        create_local_git_repo(folder=self.client.current_folder)

        self.client.run("source . --source-folder=./source")
        self.assertFalse(os.path.exists(os.path.join(curdir, "source", "myfile.txt")))
        self.assertTrue(os.path.exists(os.path.join(curdir, "source", "mysub", "myfile.txt")))
        self.assertIn("SOURCE METHOD CALLED", self.client.out)
Esempio n. 29
0
    def test_install_checked_out(self):
        test_server = TestServer()
        self.servers = {"myremote": test_server}
        self.client = TestClient(servers=self.servers, users={"myremote": [("lasote", "mypass")]})

        curdir = self.client.current_folder.replace("\\", "/")
        conanfile = base_git.format(url=_quoted("auto"), revision="auto")
        self.client.save({"conanfile.py": conanfile, "myfile.txt": "My file is copied"})
        create_local_git_repo(folder=self.client.current_folder)
        cmd = 'git remote add origin "%s"' % curdir
        self.client.run_command(cmd)
        self.client.run("export . lasote/channel")
        self.client.run("upload lib* -c")

        # Take other client, the old client folder will be used as a remote
        client2 = TestClient(servers=self.servers, users={"myremote": [("lasote", "mypass")]})
        client2.run("install lib/0.1@lasote/channel --build")
        self.assertIn("My file is copied", client2.out)
Esempio n. 30
0
    def test_revision_mode_scm(self):
        path, rev = create_local_git_repo(
            files={'conanfile.py': self.conanfile.format(revision_mode="scm")})
        t = TestClient(current_folder=path)

        ref = ConanFileReference.loads("name/version@user/channel")
        t.run("export . {}".format(ref))

        meta = t.cache.package_layout(ref, short_paths=False).load_metadata()
        self.assertEqual(meta.recipe.revision, rev)