示例#1
0
    def _check_conaninfo(self, client):
        # Check that conaninfo is correct
        ref_debug = PackageReference.loads("Pkg/0.1@user/channel:"
                                           "f3989dcba0ab50dc5ed9b40ede202bdd7b421f09")
        conaninfo = load(os.path.join(client.client_cache.package(ref_debug), "conaninfo.txt"))
        self.assertIn("os=Windows", conaninfo)
        self.assertIn("build_type=Debug", conaninfo)
        self.assertNotIn("Release", conaninfo)

        ref_release = PackageReference.loads("Pkg/0.1@user/channel:"
                                             "ab2e9f86b4109980930cdc685f4a320b359e7bb4")
        conaninfo = load(os.path.join(client.client_cache.package(ref_release), "conaninfo.txt"))
        self.assertIn("os=Windows", conaninfo)
        self.assertIn("build_type=Release", conaninfo)
        self.assertNotIn("Debug", conaninfo)

        ref_debug = PackageReference.loads("Pkg/0.1@user/channel:"
                                           "322de4b4a41f905f6b18f454ab5f498690b39c2a")
        conaninfo = load(os.path.join(client.client_cache.package(ref_debug), "conaninfo.txt"))
        self.assertIn("os=Linux", conaninfo)
        self.assertIn("build_type=Debug", conaninfo)
        self.assertNotIn("Release", conaninfo)

        ref_release = PackageReference.loads("Pkg/0.1@user/channel:"
                                             "24c3aa2d6c5929d53bd86b31e020c55d96b265c7")
        conaninfo = load(os.path.join(client.client_cache.package(ref_release), "conaninfo.txt"))
        self.assertIn("os=Linux", conaninfo)
        self.assertIn("build_type=Release", conaninfo)
        self.assertNotIn("Debug", conaninfo)
示例#2
0
    def _check_conaninfo(self, client):
        # Check that conaninfo is correct
        ref_debug = PackageReference.loads("Pkg/0.1@user/channel:"
                                           "5a67a79dbc25fd0fa149a0eb7a20715189a0d988")
        conaninfo = load(os.path.join(client.client_cache.package(ref_debug), "conaninfo.txt"))
        self.assertIn("build_type=Debug", conaninfo)
        self.assertNotIn("Release", conaninfo)

        ref_release = PackageReference.loads("Pkg/0.1@user/channel:"
                                             "4024617540c4f240a6a5e8911b0de9ef38a11a72")
        conaninfo = load(os.path.join(client.client_cache.package(ref_release), "conaninfo.txt"))
        self.assertIn("build_type=Release", conaninfo)
        self.assertNotIn("Debug", conaninfo)
示例#3
0
    def custom_settings_test(self):
        settings = """os:
    None:
    Windows:
        subsystem: [None, cygwin]
    Linux:
compiler: [gcc, visual]
"""
        client = TestClient()
        save(client.paths.settings_path, settings)
        save(client.paths.default_profile_path, "")
        conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    settings = "os", "compiler"
"""
        client.save({"conanfile.py": conanfile})
        client.run("create . Pkg/0.1@lasote/testing -s compiler=gcc")
        self.assertIn("544c1d8c53e9d269737e68e00ec66716171d2704", client.out)
        client.run("search Pkg/0.1@lasote/testing")
        self.assertNotIn("os: None", client.out)
        package_reference = PackageReference.loads("Pkg/0.1@lasote/testing:544c1d8c53e9d269737e68e00ec66716171d2704")
        info_path = os.path.join(client.paths.package(package_reference), CONANINFO)
        info = load(info_path)
        self.assertNotIn("os", info)
        # Explicitly specifying None, put it in the conaninfo.txt, but does not affect the hash
        client.run("create . Pkg/0.1@lasote/testing -s compiler=gcc -s os=None")
        self.assertIn("544c1d8c53e9d269737e68e00ec66716171d2704", client.out)
        client.run("search Pkg/0.1@lasote/testing")
        self.assertIn("os: None", client.out)
        info = load(info_path)
        self.assertIn("os", info)
示例#4
0
    def package_files_test(self):
        if platform.system() == "Windows":
            return

        client = TestClient()
        conanfile = """
from conans import ConanFile
class TestConan(ConanFile):
    name = "Hello"
    version = "0.1"

    def package(self):
        self.copy("*", symlinks=True)
    """
        client.save({"recipe/conanfile.py": conanfile})
        file1 = os.path.join(client.current_folder, "file1.txt")
        file2 = os.path.join(client.current_folder, "version1/file2.txt")
        file11 = os.path.join(client.current_folder, "file1.txt.1")
        latest = os.path.join(client.current_folder, "latest")
        save(file1, "Hello1")
        os.symlink("file1.txt", file11)
        save(file2, "Hello2")
        os.symlink("version1", latest)
        client.run("export-pkg ./recipe Hello/0.1@lasote/stable")
        ref = PackageReference.loads("Hello/0.1@lasote/stable:"
                                     "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")

        self._check(client, ref, build=False)
示例#5
0
    def basic_disabled_test(self):
        client = TestClient()
        base = '''
from conans import ConanFile

class ConanLib(ConanFile):
    short_paths = True
'''
        client.save({"conanfile.py": base})

        client.run("create . lib/0.1@user/channel")
        package_ref = PackageReference.loads("lib/0.1@user/channel:"
                                             "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        client.run("search")
        self.assertIn("lib/0.1@user/channel", client.user_io.out)
        client.run("search lib/0.1@user/channel")
        self.assertIn("Package_ID: 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9", client.user_io.out)

        if platform.system() == "Windows":
            conan_ref = ConanFileReference.loads("lib/0.1@user/channel")
            source_folder = client.client_cache.source(conan_ref)
            build_folder = client.client_cache.build(package_ref)
            package_folder = client.client_cache.package(package_ref)
            link_source = os.path.join(source_folder, ".conan_link")
            link_build = os.path.join(build_folder, ".conan_link")
            link_package = os.path.join(package_folder, ".conan_link")

            self.assertTrue(os.path.exists(link_source))
            self.assertTrue(os.path.exists(link_build))
            self.assertTrue(os.path.exists(link_package))
示例#6
0
    def upload_test(self):
        test_server = TestServer([],  # write permissions
                                 users={"lasote": "mypass"})  # exported users and passwords
        servers = {"default": test_server}
        client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]})
        files = {"conanfile.py": base}
        client.save(files)
        client.run("export . lasote/channel")
        client.run("install lib/0.1@lasote/channel --build")
        client.run("upload lib/0.1@lasote/channel --all")
        client.run("remove lib/0.1@lasote/channel -f")
        client.run("search")
        self.assertIn("There are no packages", client.user_io.out)

        for command in ("install", "download"):
            client2 = TestClient(servers=servers, users={"default": [("lasote", "mypass")]})
            client2.run("%s lib/0.1@lasote/channel" % command)
            reference = ConanFileReference.loads("lib/0.1@lasote/channel")
            export_folder = client2.client_cache.export(reference)
            export_files = os.listdir(export_folder)
            self.assertNotIn('conan_export.tgz', export_files)
            package_ref = PackageReference.loads("lib/0.1@lasote/channel:"
                                                 "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
            package_folder = client2.client_cache.package(package_ref, short_paths=None)
            if platform.system() == "Windows":
                original_folder = client2.client_cache.package(package_ref)
                link = load(os.path.join(original_folder, ".conan_link"))
                self.assertEqual(link, package_folder)

            files = os.listdir(package_folder)
            self.assertIn("myfile.txt", files)
            self.assertIn("myfile2.txt", files)
            self.assertNotIn("conan_package.tgz", files)
示例#7
0
    def _capture_verify_manifest(self, reference, remote="local cache", folder=""):
        self.client.run("install %s --build missing --manifests %s" % (str(reference), folder))
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        real_folder = folder or ".conan_manifests"
        output_folder = os.path.join(self.client.current_folder, real_folder)
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))

        # again should do nothing
        self.client.run("install %s --build missing --manifests %s"
                        % (str(self.reference), folder))
        self.assertNotIn("manifest", self.client.user_io.out)

        # now verify
        self.client.run("install %s --build missing --verify %s" % (str(self.reference), folder))
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
示例#8
0
    def fail_test_package_test(self):
        client = TestClient()
        conanfile = """
from conans import ConanFile

class HelloConan(ConanFile):
    name = "Hello"
    version = "0.1"
    exports = "*"

    def package(self):
        self.copy("*")
"""
        test_conanfile = """
from conans import ConanFile, CMake
import os

class HelloReuseConan(ConanFile):
    requires = "Hello/0.1@lasote/stable"

    def test(self):
        self.conanfile_directory
"""
        client.save({"conanfile.py": conanfile,
                     "FindXXX.cmake": "Hello FindCmake",
                     "test/conanfile.py": test_conanfile})
        client.run("test_package")
        ref = PackageReference.loads("Hello/0.1@lasote/stable:"
                                     "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertEqual("Hello FindCmake",
                         load(os.path.join(client.paths.package(ref), "FindXXX.cmake")))
        client.save({"FindXXX.cmake": "Bye FindCmake"})
        client.run("test_package")
        self.assertEqual("Bye FindCmake",
                         load(os.path.join(client.paths.package(ref), "FindXXX.cmake")))
示例#9
0
    def failure_test(self):

        base = '''
from conans import ConanFile
from conans.util.files import load, save
import os

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    short_paths = True
    exports = "*"
    generators = "cmake"

    def build(self):
        self.output.info("%s/%s" % (self.conanfile_directory, self.name))
        # print os.listdir(self.conanfile_directory)
        path = os.path.join(self.conanfile_directory, self.name)
        # print "PATH EXISTS ", os.path.exists(path)
        # print os.listdir(path)
        path = os.path.join(path, "myfile.txt")
        # print "PATH EXISTS ", os.path.exists(path)

    def package(self):
        self.copy("*.txt", keep_path=False)
'''

        client = TestClient()
        files = {"conanfile.py": base,
                 "lib/myfile.txt": "Hello world!"}
        client.save(files)
        client.run("export user/channel")
        client.run("install lib/0.1@user/channel --build")
        # print client.paths.store
        package_ref = PackageReference.loads("lib/0.1@user/channel:"
                                             "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        package_folder = client.client_cache.package(package_ref, short_paths=None)
        file1 = load(os.path.join(package_folder, "myfile.txt"))
        self.assertEqual("Hello world!", file1)

        client.run("install lib/0.1@user/channel --build")
        package_ref = PackageReference.loads("lib/0.1@user/channel:"
                                             "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        package_folder = client.client_cache.package(package_ref, short_paths=None)
        file1 = load(os.path.join(package_folder, "myfile.txt"))
        self.assertEqual("Hello world!", file1)
示例#10
0
    def basic_test(self):
        client = TestClient()
        base = '''
from conans import ConanFile
from conans.util.files import load, save
import os

class ConanLib(ConanFile):
    name = "lib"
    version = "0.1"
    short_paths = True

    def source(self):
        extra_path = "1/" * 108
        os.makedirs(extra_path)
        myfile = os.path.join(extra_path, "myfile.txt")
        # print("File length ", len(myfile))
        save(myfile, "Hello extra path length")

    def build(self):
        extra_path = "1/" * 108
        myfile = os.path.join(extra_path, "myfile2.txt")
        # print("File length ", len(myfile))
        save(myfile, "Hello2 extra path length")

    def package(self):
        self.copy("*.txt", keep_path=False)
'''

        files = {"conanfile.py": base}
        client.save(files)
        client.run("export user/channel")
        client.run("install lib/0.1@user/channel --build")
        package_ref = PackageReference.loads("lib/0.1@user/channel:"
                                             "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        package_folder = client.client_cache.package(package_ref)
        file1 = load(os.path.join(package_folder, "myfile.txt"))
        self.assertEqual("Hello extra path length", file1)
        file2 = load(os.path.join(package_folder, "myfile2.txt"))
        self.assertEqual("Hello2 extra path length", file2)

        if platform.system() == "Windows":
            conan_ref = ConanFileReference.loads("lib/0.1@user/channel")
            source_folder = client.client_cache.source(conan_ref)
            link_source = load(os.path.join(source_folder, ".conan_link"))
            self.assertTrue(os.path.exists(link_source))

            build_folder = client.client_cache.build(package_ref)
            link_build = load(os.path.join(build_folder, ".conan_link"))
            self.assertTrue(os.path.exists(link_build))

            client.run("remove lib* -f")
            self.assertFalse(os.path.exists(link_source))
            self.assertFalse(os.path.exists(link_build))
示例#11
0
    def test_corrupted_package(self):
        self.client.run("install %s --build missing" % str(self.reference))
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        package_path = self.client.paths.package(package_reference)
        file_path = os.path.join(package_path, "conaninfo.txt")
        save(file_path, load(file_path) + "RANDOM STRING")

        self.client.run("install %s --build missing --manifests" % str(self.reference),
                        ignore_error=True)
        self.assertIn("%s local cache package is corrupted" % str(package_reference),
                      self.client.user_io.out)
示例#12
0
    def conanfile_capture_verify_manifest_folder_test(self):
        files = {"conanfile.txt": "[requires]\nHello/0.1@lasote/stable"}
        self.client.save(files, clean_first=True)
        folder = "mymanifests"
        self._capture_verify_manifest(".", folder=folder)

        conanfile = """from conans import ConanFile
class ConanFileTest(ConanFile):
    name = "Hello2"
    version = "0.1"
"""
        client = TestClient(base_folder=self.client.base_folder)
        client.save({CONANFILE: conanfile})
        client.run("export lasote/stable")

        files = {"conanfile.txt": "[requires]\nHello2/0.1@lasote/stable\nHello/0.1@lasote/stable"}
        self.client.save(files)

        self.client.run("install . --build missing --manifests %s" % folder)

        remote = "local cache"
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello2/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder, folder)
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))
        package_reference = PackageReference.loads("Hello2/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))
示例#13
0
文件: info.py 项目: 19317362/conan
    def __init__(self, value_str, indirect=False):
        """ parse the input into fields name, version...
        """
        ref = PackageReference.loads(value_str)
        self.package = ref
        self.full_name = ref.conan.name
        self.full_version = ref.conan.version
        self.full_user = ref.conan.user
        self.full_channel = ref.conan.channel
        self.full_package_id = ref.package_id

        # sha values
        if indirect:
            self.unrelated_mode()
        else:
            self.semver()
示例#14
0
    def basic_test(self):
        if platform.system() == "Windows":
            return

        client = TestClient()
        client.save({"conanfile.py": conanfile,
                     "conanfile.txt": test_conanfile})
        client.run("export lasote/stable")
        client.run("install --build -f=conanfile.txt")
        ref = PackageReference.loads("Hello/0.1@lasote/stable:"
                                     "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")

        self._check(client, ref)

        client.run("install --build -f=conanfile.txt")
        self._check(client, ref)
示例#15
0
    def build_test(self):
        """ Try to reuse variables loaded from txt generator => deps_cpp_info
        """
        client = TestClient()
        client.save({CONANFILE: conanfile_dep})
        client.run("export lasote/testing")

        client.save({CONANFILE: conanfile_scope_env}, clean_first=True)
        client.run("install --build=missing")

        client.run("build")
        ref = PackageReference.loads("Hello/0.1@lasote/testing:"
                                     "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        package_folder = client.paths.package(ref).replace("\\", "/")
        self.assertIn("Project: INCLUDE PATH: %s/include" % package_folder, client.user_io.out)
        self.assertIn("Project: HELLO ROOT PATH: %s" % package_folder, client.user_io.out)
        self.assertIn("Project: HELLO INCLUDE PATHS: %s/include"
                      % package_folder, client.user_io.out)
示例#16
0
    def test_package_test(self, use_abs_folder):
        self.client.run("install Hello/0.1@lasote/stable --build missing")
        conanfile = """from conans import ConanFile

class ConsumerFileTest(ConanFile):
    name = "Chat"
    version = "0.1"
    requires = "Hello/0.1@lasote/stable"
"""
        test_conanfile = """from conans import ConanFile

class ConsumerFileTest(ConanFile):
    requires = "Chat/0.1@lasote/stable"
    def test(self):
        self.output.info("TEST OK")
"""
        if use_abs_folder:
            output_folder = temp_folder()
            dest = '="%s"' % output_folder
        else:
            dest = ""
            output_folder = os.path.join(self.client.current_folder, ".conan_manifests")

        self.client.save({"conanfile.py": conanfile,
                          "test_package/conanfile.py": test_conanfile}, clean_first=True)

        self.client.run("create . lasote/stable --manifests%s" % dest)
        self.assertIn("Chat/0.1@lasote/stable (test package): TEST OK", self.client.user_io.out)
        self.assertIn("Installed manifest for 'Chat/0.1@lasote/stable' from local cache",
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from local cache",
                      self.client.user_io.out)

        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))
        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))
        # now verify
        self.client.run("create . lasote/stable --verify%s" % dest)
        self.assertIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
示例#17
0
    def upload_test(self):
        if platform.system() == "Windows":
            return

        test_server = TestServer()
        servers = {"default": test_server}
        client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]})

        client.save({"conanfile.py": conanfile,
                     "conanfile.txt": test_conanfile})
        client.run("export lasote/stable")
        client.run("install --build -f=conanfile.txt")
        ref = PackageReference.loads("Hello/0.1@lasote/stable:"
                                     "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")

        client.run("upload Hello/0.1@lasote/stable --all")
        client.run('remove "*" -f')
        client.save({"conanfile.txt": test_conanfile}, clean_first=True)
        client.run("install")
        self._check(client, ref, build=False)
示例#18
0
    def _failed_package_verify(self, reference, remote="local cache"):
        self.client.run("install %s --build missing --manifests" % str(reference))
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder, ".conan_manifests")
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))

        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))

        client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})

        client.save(self.files)
        client.run("export lasote/stable")
        client.run("install Hello/0.1@lasote/stable --build=missing")
        info = os.path.join(client.paths.package(package_reference), "conaninfo.txt")
        info_content = load(info)
        info_content += "# Dummy string"
        save(info, info_content)
        manifest = client.paths.load_package_manifest(package_reference)
        manifest.file_sums["conaninfo.txt"] = md5(info_content)
        save(client.paths.digestfile_package(package_reference), str(manifest))

        manifest = client.paths.load_package_manifest(package_reference)
        client.run("upload %s --all" % str(self.reference))

        # now verify, with update
        self.client.run("remove Hello/0.1@lasote/stable -f")
        self.client.run("install %s --build missing --verify"
                        % str(self.reference),
                        ignore_error=True)
        self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
        self.assertIn("Modified or new manifest '%s' detected" % str(package_reference),
                      self.client.user_io.out)
示例#19
0
 def export_source_test(self):
     client = TestClient()
     files = {"conanfile.py": base,
              "path/"*20 + "file0.txt": "file0 content"}
     client.save(files)
     client.run("export . user/channel")
     conan_ref = ConanFileReference.loads("lib/0.1@user/channel")
     source_folder = client.client_cache.export_sources(conan_ref)
     if platform.system() == "Windows":
         source_folder = load(os.path.join(source_folder, ".conan_link"))
     self.assertTrue(os.path.exists(source_folder))
     self.assertEqual(load(os.path.join(source_folder + "/path"*20 + "/file0.txt")),
                      "file0 content")
     client.run("install lib/0.1@user/channel --build=missing")
     package_ref = PackageReference.loads("lib/0.1@user/channel:"
                                          "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
     package_folder = client.client_cache.package(package_ref)
     if platform.system() == "Windows":
         package_folder = load(os.path.join(package_folder, ".conan_link"))
     self.assertTrue(os.path.exists(package_folder))
     self.assertEqual(load(os.path.join(package_folder + "/file0.txt")), "file0 content")
示例#20
0
    def _failed_verify(self, reference, remote="local cache"):
        self.client.run("install %s --build missing --manifests" % str(reference))
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable' from %s" % remote,
                      self.client.user_io.out)
        self.assertIn("Installed manifest for 'Hello/0.1@lasote/stable:"
                      "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9' from %s" % remote,
                      self.client.user_io.out)

        output_folder = os.path.join(self.client.current_folder, ".conan_manifests")
        paths = SimplePaths(output_folder)
        self.assertTrue(os.path.exists(paths.digestfile_conanfile(self.reference)))

        package_reference = PackageReference.loads("Hello/0.1@lasote/stable:"
                                                   "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        self.assertTrue(os.path.exists(paths.digestfile_package(package_reference)))

        client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})
        conanfile = """from conans import ConanFile
class ConanFileTest(ConanFile):
    name = "Hello"
    version = "0.1"
    exports = "*"
"""
        files = {CONANFILE: conanfile, "data.txt": "MyDataHacked"}
        # Export and upload the conanfile
        client.save(files)
        client.run("export lasote/stable")
        client.run("upload %s --all" % str(self.reference))

        # now verify, with update
        self.client.run("remove Hello/0.1@lasote/stable -f")
        self.client.run("install %s --build missing --verify"
                        % str(self.reference),
                        ignore_error=True)
        self.assertNotIn("Manifest for 'Hello/0.1@lasote/stable': OK", self.client.user_io.out)
        self.assertNotIn("Manifest for '%s': OK" % str(package_reference), self.client.user_io.out)
        self.assertIn("Modified or new manifest 'Hello/0.1@lasote/stable' detected",
                      self.client.user_io.out)
示例#21
0
    def basic_test(self):
        client = TestClient()
        files = {"conanfile.py": base}
        client.save(files)
        client.run("export user/channel")
        client.run("install lib/0.1@user/channel --build")
        package_ref = PackageReference.loads("lib/0.1@user/channel:"
                                             "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")
        client.run("search")
        self.assertIn("lib/0.1@user/channel", client.user_io.out)
        client.run("search lib/0.1@user/channel")
        self.assertIn("Package_ID: 5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9", client.user_io.out)

        package_folder = client.client_cache.package(package_ref, short_paths=None)
        file1 = load(os.path.join(package_folder, "myfile.txt"))
        self.assertEqual("Hello extra path length", file1)
        file2 = load(os.path.join(package_folder, "myfile2.txt"))
        self.assertEqual("Hello2 extra path length", file2)

        if platform.system() == "Windows":
            conan_ref = ConanFileReference.loads("lib/0.1@user/channel")
            source_folder = client.client_cache.source(conan_ref)
            link_source = load(os.path.join(source_folder, ".conan_link"))
            self.assertTrue(os.path.exists(link_source))

            build_folder = client.client_cache.build(package_ref)
            link_build = load(os.path.join(build_folder, ".conan_link"))
            self.assertTrue(os.path.exists(link_build))

            package_folder = client.client_cache.package(package_ref)
            link_package = load(os.path.join(package_folder, ".conan_link"))
            self.assertTrue(os.path.exists(link_package))

            client.run("remove lib* -f")
            self.assertFalse(os.path.exists(link_source))
            self.assertFalse(os.path.exists(link_build))
            self.assertFalse(os.path.exists(link_package))
示例#22
0
 def add_pref_remote(pkg_ref, remotes_, remote_name_):
     pref_ = PackageReference.loads(pkg_ref, validate=True)
     remote = remotes_.get(remote_name_)
     if remote:
         with cache.package_layout(pref_.ref).update_metadata() as metadata:
             metadata.packages[pref_.id].remote = remote.name
示例#23
0
    def test_copy(self):
        output = TestBufferConanOutput()
        userio = MockedBooleanUserIO(True, out=output)
        paths = ClientCache(temp_folder(), output)

        # Create some packages to copy
        ref = ConanFileReference.loads("Hello/0.1@lasote/testing")
        self._create_conanfile(ref, paths)
        self._create_package(ref, "0101001", paths)
        self._create_package(ref, "2222222", paths)

        # Copy all to destination
        package_copy(ref,
                     "lasote/stable", ["0101001", "2222222"],
                     paths,
                     user_io=userio,
                     force=False)
        new_ref = ConanFileReference.loads("Hello/0.1@lasote/stable")
        self._assert_conanfile_exists(new_ref, paths)
        self._assert_package_exists(new_ref, "0101001", paths)
        self._assert_package_exists(new_ref, "2222222", paths)
        self.assertIn(
            "Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable",
            output)
        self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output)
        self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output)

        # Copy again, without force and answering yes
        output._stream.truncate(0)  # Reset output
        package_copy(ref,
                     "lasote/stable", ["0101001", "2222222"],
                     paths,
                     user_io=userio,
                     force=False)
        self.assertIn(
            "Copied Hello/0.1@lasote/testing to Hello/0.1@lasote/stable",
            output)
        self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output)
        self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output)
        self.assertIn("'Hello/0.1@lasote/stable' already exist. Override?",
                      output)
        self.assertIn("Package '2222222' already exist. Override?", output)
        self.assertIn("Package '0101001' already exist. Override?", output)

        # Now alter the origin and copy again to same destination and confirm the copy
        self._create_conanfile(ref, paths, "new content")
        self._create_package(ref, "0101001", paths, "new lib content")
        self._create_package(ref, "2222222", paths, "new lib content")
        output._stream.truncate(0)  # Reset output
        package_copy(ref,
                     "lasote/stable", ["0101001", "2222222"],
                     paths,
                     user_io=userio,
                     force=False)
        conanfile_content = load(paths.package_layout(new_ref).conanfile())
        self.assertEqual(conanfile_content, "new content")
        pref = PackageReference(new_ref, "0101001")
        package_content = load(
            os.path.join(
                paths.package_layout(new_ref).package(pref), "package.lib"))
        self.assertEqual(package_content, "new lib content")

        # Now we are going to answer always NO to override
        output._stream.truncate(0)  # Reset output
        userio = MockedBooleanUserIO(False, out=output)

        self._create_conanfile(ref, paths, "content22")
        self._create_package(ref, "0101001", paths, "newlib22")
        self._create_package(ref, "2222222", paths, "newlib22")
        package_copy(ref,
                     "lasote/stable", ["0101001", "2222222"],
                     paths,
                     user_io=userio,
                     force=False)
        conanfile_content = load(paths.package_layout(new_ref).conanfile())
        self.assertEqual(conanfile_content, "new content")  # Not content22
        pref = PackageReference(new_ref, "0101001")
        package_content = load(
            os.path.join(
                paths.package_layout(new_ref).package(pref), "package.lib"))
        self.assertEqual(package_content, "new lib content")  # Not newlib22
        # If conanfile is not override it exist
        self.assertNotIn("Package '2222222' already exist. Override?", output)
        self.assertNotIn("Package '0101001' already exist. Override?", output)
        self.assertNotIn("Copied 0101001 to Hello/0.1@lasote/stable", output)
        self.assertNotIn("Copied 2222222 to Hello/0.1@lasote/stable", output)

        # Now override
        output._stream.truncate(0)  # Reset output
        package_copy(ref,
                     "lasote/stable", ["0101001", "2222222"],
                     paths,
                     user_io=userio,
                     force=True)
        self.assertIn("Copied 0101001 to Hello/0.1@lasote/stable", output)
        self.assertIn("Copied 2222222 to Hello/0.1@lasote/stable", output)

        # Now copy just one package to another user/channel
        output._stream.truncate(0)  # Reset output
        package_copy(ref,
                     "pepe/mychannel", ["0101001"],
                     paths,
                     user_io=userio,
                     force=True)
        self.assertIn("Copied 0101001 to Hello/0.1@pepe/mychannel", output)
        self.assertNotIn("Copied 2222222 to Hello/0.1@pepe/mychannel", output)
        new_ref = ConanFileReference.loads("Hello/0.1@pepe/mychannel")
        self._assert_package_exists(new_ref, "0101001", paths)
        self._assert_package_doesnt_exists(new_ref, "2222222", paths)
示例#24
0
    def setUp(self):
        self.client = self._get_client()
        self.ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable#%s" %
                                            DEFAULT_REVISION_V1)
        self.pref = PackageReference(self.ref, "myfakeid", DEFAULT_REVISION_V1)
        reg_folder = self.client.cache.package_layout(self.ref).export()

        self.client.run('upload %s' % str(self.ref), assert_error=True)
        self.assertIn("ERROR: Recipe not found: '%s'" % str(self.ref),
                      self.client.out)

        files = cpp_hello_source_files(0)

        fake_metadata = PackageMetadata()
        fake_metadata.recipe.revision = DEFAULT_REVISION_V1
        fake_metadata.packages[self.pref.id].revision = DEFAULT_REVISION_V1
        self.client.save({"metadata.json": fake_metadata.dumps()},
                         path=self.client.cache.package_layout(
                             self.ref).base_folder())
        self.client.save(files, path=reg_folder)
        self.client.save(
            {
                CONANFILE:
                GenConanfile().with_name("Hello").with_version("1.2.1"),
                "include/math/lib1.h": "//copy",
                "my_lib/debug/libd.a": "//copy",
                "my_data/readme.txt": "//copy",
                "my_bin/executable": "//copy"
            },
            path=reg_folder)
        mkdir(self.client.cache.package_layout(self.ref).export_sources())
        manifest = FileTreeManifest.create(reg_folder)
        manifest.time = '123123123'
        manifest.save(reg_folder)
        self.test_server.server_store.update_last_revision(self.ref)

        self.server_pack_folder = self.test_server.server_store.package(
            self.pref)

        package_folder = self.client.cache.package_layout(self.ref).package(
            self.pref)
        save(os.path.join(package_folder, "include", "lib1.h"), "//header")
        save(os.path.join(package_folder, "lib", "my_lib", "libd.a"), "//lib")
        save(os.path.join(package_folder, "res", "shares", "readme.txt"),
             "//res")
        save(os.path.join(package_folder, "bin", "my_bin", "executable"),
             "//bin")
        save(os.path.join(package_folder, CONANINFO),
             """[recipe_hash]\n%s""" % manifest.summary_hash)
        FileTreeManifest.create(package_folder).save(package_folder)
        self.test_server.server_store.update_last_package_revision(self.pref)

        os.chmod(
            os.path.join(package_folder, "bin", "my_bin", "executable"),
            os.stat(os.path.join(package_folder, "bin", "my_bin",
                                 "executable")).st_mode | stat.S_IRWXU)

        expected_manifest = FileTreeManifest.create(package_folder)
        expected_manifest.save(package_folder)

        self.server_reg_folder = self.test_server.server_store.export(self.ref)
        self.assertFalse(os.path.exists(self.server_reg_folder))
        self.assertFalse(os.path.exists(self.server_pack_folder))
示例#25
0
 def deserialize(data):
     ret = RequirementsInfo({}, None)
     for ref, requinfo in data.items():
         ref = PackageReference.loads(ref)
         ret._data[ref] = RequirementInfo.deserialize(requinfo)
     return ret
示例#26
0
文件: info.py 项目: 19317362/conan
 def deserialize(data):
     ret = RequirementsInfo({}, None)
     for ref, requinfo in data.items():
         ref = PackageReference.loads(ref)
         ret._data[ref] = RequirementInfo.deserialize(requinfo)
     return ret
示例#27
0
    def complete_test(self):
        """ basic installation of a new conans
        """
        servers = {}
        # All can write (for avoid authentication until we mock user_io)
        test_server = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")])
        servers["default"] = test_server

        conan_digest = FileTreeManifest(123123123, {})

        client = TestClient(servers=servers)
        client.init_dynamic_vars()
        conan_ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable")
        reg_folder = client.paths.export(conan_ref)

        files = hello_source_files()
        client.save(files, path=reg_folder)
        client.save(
            {
                CONANFILE: myconan1,
                CONAN_MANIFEST: str(conan_digest),
                "include/math/lib1.h": "//copy",
                "my_lib/debug/libd.a": "//copy",
                "my_data/readme.txt": "//copy"
            },
            path=reg_folder)

        package_ref = PackageReference(conan_ref, "fakeid")
        package_folder = client.paths.package(package_ref)
        save(os.path.join(package_folder, CONANINFO), "info")
        save(os.path.join(package_folder, CONAN_MANIFEST), "manifest")
        save(os.path.join(package_folder, "include", "lib1.h"), "//header")
        save(os.path.join(package_folder, "lib", "my_lib", "libd.a"), "//lib")
        save(os.path.join(package_folder, "res", "shares", "readme.txt"),
             "//res")

        digest_path = client.client_cache.digestfile_package(package_ref)
        expected_manifest = FileTreeManifest.create(
            os.path.dirname(digest_path))
        save(os.path.join(package_folder, CONAN_MANIFEST),
             str(expected_manifest))

        client.run("upload %s" % str(conan_ref))
        client.run("upload %s -p %s" %
                   (str(conan_ref), package_ref.package_id))

        client2 = TestClient(servers=servers)
        client2.init_dynamic_vars()

        installer = ConanProxy(client2.paths, client2.user_io,
                               client2.remote_manager, "default")

        installer.get_recipe(conan_ref)
        installer.get_package(package_ref, force_build=False)
        # Check that the output is done in order
        lines = [
            line.strip() for line in str(client2.user_io.out).splitlines()
            if line.startswith("Downloading")
        ]
        self.assertEqual(lines, [
            "Downloading conanmanifest.txt", "Downloading conanfile.py",
            "Downloading conan_export.tgz", "Downloading conanmanifest.txt",
            "Downloading conaninfo.txt", "Downloading conan_package.tgz"
        ])

        reg_path = client2.paths.export(
            ConanFileReference.loads("Hello/1.2.1/frodo/stable"))
        pack_folder = client2.paths.package(package_ref)

        # Test the file in the downloaded conans
        files = [
            'CMakeLists.txt', 'my_lib/debug/libd.a', 'hello.cpp', 'hello0.h',
            CONANFILE, CONAN_MANIFEST, 'main.cpp', 'include/math/lib1.h',
            'my_data/readme.txt'
        ]

        for _file in files:
            self.assertTrue(os.path.exists(os.path.join(reg_path, _file)))
        self.assertTrue(os.path.exists(pack_folder))

        # Test the file in the downloaded package
        self.assertTrue(os.path.exists(pack_folder))
        self.assertTrue(
            os.path.exists(os.path.join(pack_folder, "include", "lib1.h")))
        self.assertTrue(
            os.path.exists(os.path.join(pack_folder, "lib", "my_lib/libd.a")))
        self.assertTrue(
            os.path.exists(
                os.path.join(pack_folder, "res", "shares/readme.txt")))
示例#28
0
    def reuse_test(self):
        test_server = TestServer()
        self.servers = {"default": test_server}
        self.client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})

        ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
        files = cpp_hello_conan_files("Hello0", "0.1", need_patch=True)
        self.client.save(files)
        self.client.run("create . lasote/stable")
        self.assertIn("Hello0/0.1@lasote/stable package(): Packaged 1 '.h' file: helloHello0.h",
                      self.client.out)
        # Check compilation ok
        package_ids = self.client.cache.package_layout(ref).conan_packages()
        self.assertEqual(len(package_ids), 1)
        pref = PackageReference(ref, package_ids[0])
        self._assert_library_exists(pref, self.client.cache)

        # Upload package
        self.client.run("upload %s" % str(ref))
        self.assertIn("Compressing recipe", str(self.client.out))

        # Not needed to tgz again
        self.client.run("upload %s" % str(ref))
        self.assertNotIn("Compressing exported", str(self.client.out))

        # Check that recipe exists on server
        server_paths = self.servers["default"].server_store
        rev = server_paths.get_last_revision(ref).revision
        conan_path = server_paths.export(ref.copy_with_rev(rev))
        self.assertTrue(os.path.exists(conan_path))

        # Upload package
        self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0])))
        self.assertIn("Compressing package", str(self.client.out))

        # Not needed to tgz again
        self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0])))
        self.assertNotIn("Compressing package", str(self.client.out))

        # If we install the package again will be removed and re tgz
        self.client.run("install %s" % str(ref))
        # Upload package
        self.client.run("upload %s -p %s" % (str(ref), str(package_ids[0])))
        self.assertNotIn("Compressing package", str(self.client.out))

        # Check library on server
        self._assert_library_exists_in_server(pref, server_paths)

        # Now from other "computer" install the uploaded conans with same options (nothing)
        other_conan = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})
        other_conan.run("install %s" % str(ref))
        # Build should be empty
        build_path = other_conan.cache.package_layout(pref.ref).build(pref)
        self.assertFalse(os.path.exists(build_path))
        # Lib should exist
        self._assert_library_exists(pref, other_conan.cache)

        # Now install it but with other options
        other_conan.run('install %s -o language=1 --build missing' % (str(ref)))
        # Should have two packages
        package_ids = other_conan.cache.package_layout(ref).conan_packages()
        self.assertEqual(len(package_ids), 2)
        for package_id in package_ids:
            pref = PackageReference(ref, package_id)
            self._assert_library_exists(pref, other_conan.cache)

        client3 = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})
        files3 = cpp_hello_conan_files("Hello1", "0.1", ["Hello0/0.1@lasote/stable"])
        client3.save(files3)
        client3.run('install .')
        client3.run('build .')
        command = os.sep.join([".", "bin", "say_hello"])
        client3.run_command(command)
        self.assertIn("Hello Hello1", client3.out)
        self.assertIn("Hello Hello0", client3.out)

        client3.run('install . -o language=1 --build missing')
        time.sleep(1)
        client3.run('build .')

        command = os.sep.join([".", "bin", "say_hello"])
        client3.run_command(command)
        self.assertIn("Hola Hello1", client3.out)
        self.assertIn("Hola Hello0", client3.out)
示例#29
0
    def test_version_ranges(self):
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                {requires}
                exports_sources = "myfile.txt"
                keep_imports = True
                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                def package_info(self):
                    self.output.info("SELF FILE: %s"
                        % load(os.path.join(self.package_folder, "myfile.txt")))
                    for d in os.listdir(self.package_folder):
                        p = os.path.join(self.package_folder, d, "myfile.txt")
                        if os.path.isfile(p):
                            self.output.info("DEP FILE %s: %s" % (d, load(p)))
                """)
        client = TestClient()
        client.run(
            "config set general.default_package_id_mode=full_package_mode")
        client.save({
            "conanfile.py": conanfile.format(requires=""),
            "myfile.txt": "HelloA"
        })
        client.run("create . PkgA/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgA/[*]@user/channel"'),
            "myfile.txt":
            "HelloB"
        })
        client.run("create . PkgB/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgB/[*]@user/channel"'),
            "myfile.txt":
            "HelloC"
        })
        client.run("create . PkgC/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgC/[*]@user/channel"'),
            "myfile.txt":
            "HelloD"
        })
        client.run("create . PkgD/0.1@user/channel")
        self.assertIn("PkgD/0.1@user/channel: SELF FILE: HelloD", client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgA: HelloA",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgC: HelloC",
                      client.out)

        client.run("graph lock PkgD/0.1@user/channel")
        lock_file = client.load(LOCKFILE)
        initial_lock_file = lock_file
        self.assertIn(
            "PkgA/0.1@user/channel#189390ce059842ce984e0502c52cf736:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9#5ba7f606729949527141beef73c72bc8",
            lock_file)
        self.assertIn(
            "PkgB/0.1@user/channel#fa97c46bf83849a5db4564327b3cfada:"
            "096f747d204735584fa0115bcbd7482d424094bc#aedbc184c721dd1d93896e0494392108",
            lock_file)
        self.assertIn(
            "PkgC/0.1@user/channel#c6f95948619d28d9d96b0ae86c46a482:"
            "f6d5dbb6f309dbf8519278bae8d07d3b739b3dec#de5dabc761668d5b97157dbf3eb40ca1",
            lock_file)
        self.assertIn(
            "PkgD/0.1@user/channel#fce78c934bc0de73eeb05eb4060fc2b7:"
            "de4467a3fa6ef01b09b7464e85553fb4be2d2096#a4ff125f400ac721e935976b4a2b1880",
            lock_file)

        # Do a change in B
        clientb = TestClient(cache_folder=client.cache_folder)
        clientb.run(
            "config set general.default_package_id_mode=full_package_mode")
        clientb.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgA/[*]@user/channel"'),
            "myfile.txt":
            "ByeB World!!",
            LOCKFILE:
            lock_file
        })
        clientb.run("create . PkgB/0.2@user/channel --lockfile")
        lock_fileb = clientb.load(LOCKFILE)
        lock_file_json = json.loads(lock_fileb)
        # ONLY PkgB changes
        self.assertIn(
            "PkgA/0.1@user/channel#189390ce059842ce984e0502c52cf736:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9#5ba7f606729949527141beef73c72bc8",
            lock_fileb)
        self.assertIn(
            "PkgB/0.2@user/channel#5db9f1469df844f4c2be22114d19f1cb:"
            "096f747d204735584fa0115bcbd7482d424094bc#b679ab3ac3bb090ea157d884b252eb30",
            lock_fileb)
        self.assertIn(
            "PkgC/0.1@user/channel#c6f95948619d28d9d96b0ae86c46a482:"
            "f6d5dbb6f309dbf8519278bae8d07d3b739b3dec#de5dabc761668d5b97157dbf3eb40ca1",
            lock_fileb)
        self.assertIn(
            "PkgD/0.1@user/channel#fce78c934bc0de73eeb05eb4060fc2b7:"
            "de4467a3fa6ef01b09b7464e85553fb4be2d2096#a4ff125f400ac721e935976b4a2b1880",
            lock_fileb)
        self.assertEqual(
            "built", lock_file_json["graph_lock"]["nodes"]["3"]["modified"])

        # Go back to main orchestrator
        client.save({"new_lock/%s" % LOCKFILE: lock_fileb})
        client.run("graph update-lock . new_lock")
        client.run(
            "graph build-order . --json=build_order.json --build=missing")
        lock_fileb = client.load(LOCKFILE)

        self.assertIn(
            "PkgA/0.1@user/channel#189390ce059842ce984e0502c52cf736:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9#5ba7f606729949527141beef73c72bc8",
            lock_fileb)
        self.assertIn(
            "PkgB/0.2@user/channel#5db9f1469df844f4c2be22114d19f1cb:"
            "096f747d204735584fa0115bcbd7482d424094bc#b679ab3ac3bb090ea157d884b252eb30",
            lock_fileb)
        self.assertIn(
            "PkgC/0.1@user/channel#c6f95948619d28d9d96b0ae86c46a482:"
            "44aada014946a7c029f860c7fa9db2eaaee37b52", lock_fileb)
        self.assertIn(
            "PkgD/0.1@user/channel#fce78c934bc0de73eeb05eb4060fc2b7:"
            "a52124975839b320fa6027273ae5ed11a232a66e", lock_fileb)
        json_file = client.load("build_order.json")
        to_build = json.loads(json_file)
        lock_fileaux = lock_fileb
        while to_build:
            for _, pkg_ref in to_build[0]:
                pkg_ref = PackageReference.loads(pkg_ref)
                client_aux = TestClient(cache_folder=client.cache_folder)
                client_aux.run(
                    "config set general.default_package_id_mode=full_package_mode"
                )
                client_aux.save({LOCKFILE: lock_fileaux})
                client_aux.run("install %s --build=%s --lockfile" %
                               (pkg_ref.ref, pkg_ref.ref.name))
                lock_fileaux = client_aux.load(LOCKFILE)
                client.save({"new_lock/%s" % LOCKFILE: lock_fileaux})
                client.run("graph update-lock . new_lock")

            client.run("graph build-order . --build=missing")
            lock_fileaux = client.load(LOCKFILE)
            output = str(client.out).splitlines()[-1]
            to_build = eval(output)

        new_lockfile = client.load(LOCKFILE)
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)

        client.save({LOCKFILE: initial_lock_file})
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)

        client.save({LOCKFILE: new_lockfile})
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)

        dirty_lockfile = client.load(LOCKFILE)
        self.assertIn('"modified": "%s"' % GraphLockNode.MODIFIED_BUILT,
                      dirty_lockfile)
        client.run("graph clean-modified .")
        clean_lockfile = client.load(LOCKFILE)
        self.assertNotIn('modified', clean_lockfile)
示例#30
0
    def setUp(self):
        hello_files = cpp_hello_conan_files("Hello")
        test_conanfile_contents = hello_files[CONANFILE]

        self.server_folder = temp_folder()
        test_server = TestServer(users={"myuser": "******"},
                                 base_path=self.server_folder)  # exported users and passwords
        self.server = test_server
        servers = {"default": test_server}
        client = TestClient(servers=servers, users={"default": [("myuser", "mypass")]})

        # Conans with and without packages created
        self.root_folder = {"H1": 'Hello/1.4.10@myuser/testing',
                            "H2": 'Hello/2.4.11@myuser/testing',
                            "B": 'Bye/0.14@myuser/testing',
                            "O": 'Other/1.2@myuser/testing'}

        files = {}
        prefs = []
        for key, folder in self.root_folder.items():
            ref = ConanFileReference.loads(folder)
            folder = folder.replace("@", "/")
            fake_metadata = PackageMetadata()
            fake_metadata.recipe.revision = DEFAULT_REVISION_V1
            files["%s/%s/conanfile.py" % (folder, EXPORT_FOLDER)] = test_conanfile_contents
            files["%s/%s/conanmanifest.txt" % (folder, EXPORT_FOLDER)] = "%s\nconanfile.py: 234234234" % fake_recipe_hash
            files["%s/%s/conans.txt" % (folder, SRC_FOLDER)] = ""
            for pack_id in (1, 2):
                i = pack_id
                pack_id = "%s_%s" % (pack_id, key)
                fake_metadata.packages[pack_id].revision = DEFAULT_REVISION_V1
                prefs.append(PackageReference(ref, str(pack_id)))
                files["%s/%s/%s/conans.txt" % (folder, BUILD_FOLDER, pack_id)] = ""
                files["%s/%s/%s/conans.txt" % (folder, PACKAGES_FOLDER, pack_id)] = ""
                files["%s/%s/%s/%s" % (folder, PACKAGES_FOLDER, pack_id, CONANINFO)] = conaninfo % str(i) + "905eefe3570dd09a8453b30b9272bb44"
                files["%s/%s/%s/%s" % (folder, PACKAGES_FOLDER, pack_id, CONAN_MANIFEST)] = ""
            files["%s/metadata.json" % folder] = fake_metadata.dumps()
            exports_sources_dir = client.cache.package_layout(ref).export_sources()
            os.makedirs(exports_sources_dir)

        client.save(files, client.cache.store)

        # Create the manifests to be able to upload
        for pref in prefs:
            pkg_folder = client.cache.package_layout(pref.ref).package(pref)
            expected_manifest = FileTreeManifest.create(pkg_folder)
            files["%s/%s/%s/%s" % (pref.ref.dir_repr(),
                                   PACKAGES_FOLDER,
                                   pref.id,
                                   CONAN_MANIFEST)] = repr(expected_manifest)

        client.save(files, client.cache.store)

        self.client = client

        for folder in self.root_folder.values():
            client.run("upload %s --all" % folder)

        self.assert_folders({"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                            {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                            {"H1": [1, 2], "H2": [1, 2], "B": [1, 2], "O": [1, 2]},
                            {"H1": True, "H2": True, "B": True, "O": True})
示例#31
0
    def _build(self, nodes_by_level, skip_private_nodes, build_mode):
        """ The build assumes an input of conans ordered by degree, first level
        should be independent from each other, the next-second level should have
        dependencies only to first level conans.
        param nodes_by_level: list of lists [[nodeA, nodeB], [nodeC], [nodeD, ...], ...]

        build_mode => ["*"] if user wrote "--build"
                   => ["hello*", "bye*"] if user wrote "--build hello --build bye"
                   => False if user wrote "never"
                   => True if user wrote "missing"
                   => "outdated" if user wrote "--build outdated"

        """

        inverse = self._deps_graph.inverse_levels()
        flat = []

        for level in inverse:
            level = sorted(level, key=lambda x: x.conan_ref)
            flat.extend(level)

        # Get the nodes in order and if we have to build them
        nodes_to_process = self._get_nodes(nodes_by_level, skip_private_nodes, build_mode)

        for conan_ref, package_id, conan_file, build_needed in nodes_to_process:

            if build_needed:
                build_allowed = self._build_allowed(conan_ref, build_mode, conan_file)
                if not build_allowed:
                    self._raise_package_not_found_error(conan_ref, conan_file)

                output = ScopedOutput(str(conan_ref), self._out)
                package_ref = PackageReference(conan_ref, package_id)
                package_folder = self._client_cache.package(package_ref, conan_file.short_paths)
                if build_mode is True:
                    output.info("Building package from source as defined by build_policy='missing'")
                elif self._build_forced(conan_ref, build_mode, conan_file):
                    output.warn('Forced build from source')

                t1 = time.time()
                # Assign to node the propagated info
                self._propagate_info(conan_ref, conan_file, flat)

                self._remote_proxy.get_recipe_sources(conan_ref)
                # Call the conanfile's build method
                build_folder = self._build_conanfile(conan_ref, conan_file, package_ref,
                                                     package_folder, output)

                # Call the conanfile's package method
                self._package_conanfile(conan_ref, conan_file, package_ref, build_folder,
                                        package_folder, output)

                # Call the info method
                self._package_info_conanfile(conan_ref, conan_file)

                duration = time.time() - t1
                log_file = os.path.join(build_folder, RUN_LOG_NAME)
                log_file = log_file if os.path.exists(log_file) else None
                log_package_built(package_ref, duration, log_file)
            else:
                # Get the package, we have a not outdated remote package
                if conan_ref:
                    self._get_package(conan_ref, conan_file)

                # Assign to the node the propagated info
                # (conan_ref could be None if user project, but of course assign the info
                self._propagate_info(conan_ref, conan_file, flat)

                # Call the info method
                self._package_info_conanfile(conan_ref, conan_file)
示例#32
0
文件: tools.py 项目: swipswaps/conan
def inc_package_manifest_timestamp(cache, package_reference, inc_time):
    pref = PackageReference.loads(package_reference)
    path = cache.package_layout(pref.ref).package(pref)
    manifest = FileTreeManifest.load(path)
    manifest.time += inc_time
    manifest.save(path)
示例#33
0
 def remote_pref_list(self, package_references):
     for package_reference, remote_name in package_references.items():
         pref = PackageReference.loads(package_reference)
         self._output.info("%s: %s" % (pref.full_str(), remote_name))
示例#34
0
    def _grab_info_data(self, deps_graph, grab_paths):
        """ Convert 'deps_graph' into consumible information for json and cli """
        compact_nodes = OrderedDict()
        for node in sorted(deps_graph.nodes):
            compact_nodes.setdefault((node.ref, node.package_id),
                                     []).append(node)

        remotes = self._cache.registry.load_remotes()
        ret = []
        for (ref, package_id), list_nodes in compact_nodes.items():
            node = list_nodes[0]
            if node.recipe == RECIPE_VIRTUAL:
                continue

            item_data = {}
            conanfile = node.conanfile
            if node.recipe == RECIPE_CONSUMER:
                ref = str(conanfile)
            else:
                item_data["revision"] = ref.revision

            item_data["reference"] = str(ref)
            item_data["is_ref"] = isinstance(ref, ConanFileReference)
            item_data["display_name"] = conanfile.display_name
            item_data["id"] = package_id
            item_data["build_id"] = build_id(conanfile)

            # Paths
            if isinstance(ref, ConanFileReference) and grab_paths:
                package_layout = self._cache.package_layout(
                    ref, conanfile.short_paths)
                item_data["export_folder"] = package_layout.export()
                item_data["source_folder"] = package_layout.source()
                # @todo: check if this is correct or if it must always be package_id
                package_id = build_id(conanfile) or package_id
                pref = PackageReference(ref, package_id)
                item_data["build_folder"] = package_layout.build(pref)

                pref = PackageReference(ref, package_id)
                item_data["package_folder"] = package_layout.package(pref)

            try:
                reg_remote = self._cache.package_layout(
                    ref).load_metadata().recipe.remote
                reg_remote = remotes.get(reg_remote)
                if reg_remote:
                    item_data["remote"] = {
                        "name": reg_remote.name,
                        "url": reg_remote.url
                    }
            except Exception:
                pass

            def _add_if_exists(attrib, as_list=False):
                value = getattr(conanfile, attrib, None)
                if value:
                    if not as_list:
                        item_data[attrib] = value
                    else:
                        item_data[attrib] = list(value) if isinstance(value, (list, tuple, set)) \
                            else [value, ]

            _add_if_exists("url")
            _add_if_exists("homepage")
            _add_if_exists("license", as_list=True)
            _add_if_exists("author")
            _add_if_exists("topics", as_list=True)

            if isinstance(ref, ConanFileReference):
                item_data["recipe"] = node.recipe

                if get_env("CONAN_CLIENT_REVISIONS_ENABLED",
                           False) and node.ref.revision:
                    item_data["revision"] = node.ref.revision

                item_data["binary"] = node.binary
                if node.binary_remote:
                    item_data["binary_remote"] = node.binary_remote.name

            node_times = self._read_dates(deps_graph)
            if node_times and node_times.get(ref, None):
                item_data["creation_date"] = node_times.get(ref, None)

            if isinstance(ref, ConanFileReference):
                dependants = [
                    n for node in list_nodes for n in node.inverse_neighbors()
                ]
                required = [
                    d.conanfile for d in dependants
                    if d.recipe != RECIPE_VIRTUAL
                ]
                if required:
                    item_data["required_by"] = [
                        d.display_name for d in required
                    ]

            depends = node.neighbors()
            requires = [d for d in depends if not d.build_require]
            build_requires = [d for d in depends if d.build_require]

            if requires:
                item_data["requires"] = [
                    repr(d.ref.copy_clear_rev()) for d in requires
                ]

            if build_requires:
                item_data["build_requires"] = [
                    repr(d.ref.copy_clear_rev()) for d in build_requires
                ]

            ret.append(item_data)

        return ret
示例#35
0
 def _assert_package_doesnt_exists(self, ref, package_id, paths):
     pref = PackageReference(ref, package_id)
     self.assertFalse(
         os.path.exists(
             os.path.join(
                 paths.package_layout(ref).package(pref), "package.lib")))
示例#36
0
    def test_version_ranges_diamond(self):
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                {requires}
                exports_sources = "myfile.txt"
                keep_imports = True
                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                def package_info(self):
                    self.output.info("SELF FILE: %s"
                        % load(os.path.join(self.package_folder, "myfile.txt")))
                    for d in os.listdir(self.package_folder):
                        p = os.path.join(self.package_folder, d, "myfile.txt")
                        if os.path.isfile(p):
                            self.output.info("DEP FILE %s: %s" % (d, load(p)))
                """)
        client = TestClient()
        client.run(
            "config set general.default_package_id_mode=full_package_mode")
        client.save({
            "conanfile.py": conanfile.format(requires=""),
            "myfile.txt": "HelloA"
        })
        client.run("create . PkgA/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgA/[*]@user/channel"'),
            "myfile.txt":
            "HelloB"
        })
        client.run("create . PkgB/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgA/[*]@user/channel"'),
            "myfile.txt":
            "HelloC"
        })
        client.run("create . PkgC/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgB/[*]@user/channel",'
                             ' "PkgC/[*]@user/channel"'),
            "myfile.txt":
            "HelloD"
        })
        client.run("create . PkgD/0.1@user/channel")
        self.assertIn("PkgD/0.1@user/channel: SELF FILE: HelloD", client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgA: HelloA",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgC: HelloC",
                      client.out)

        client.run("graph lock PkgD/0.1@user/channel")
        lock_file = client.load(LOCKFILE)
        initial_lock_file = lock_file
        self.assertIn("PkgB/0.1@user/channel", lock_file)
        self.assertIn("PkgA/0.1@user/channel", lock_file)
        self.assertIn("PkgC/0.1@user/channel", lock_file)
        self.assertIn("PkgD/0.1@user/channel", lock_file)

        # Do a change in A
        clientb = TestClient(cache_folder=client.cache_folder)
        clientb.run(
            "config set general.default_package_id_mode=full_package_mode")
        clientb.save({
            "conanfile.py": conanfile.format(requires=''),
            "myfile.txt": "ByeA World!!",
            LOCKFILE: lock_file
        })
        clientb.run("create . PkgA/0.2@user/channel --lockfile")
        lock_fileb = load(os.path.join(clientb.current_folder, LOCKFILE))
        self.assertIn("PkgB/0.1@user/channel", lock_fileb)
        self.assertIn("PkgA/0.2@user/channel", lock_fileb)
        self.assertIn("PkgC/0.1@user/channel", lock_fileb)
        self.assertIn("PkgD/0.1@user/channel", lock_fileb)

        # Go back to main orchestrator
        client.save({"new_lock/%s" % LOCKFILE: lock_fileb})
        client.run("graph update-lock . new_lock")
        client.run(
            "graph build-order . --json=build_order.json --build=missing")
        lock_fileb = client.load(LOCKFILE)
        json_file = os.path.join(client.current_folder, "build_order.json")
        to_build = json.loads(load(json_file))
        lock_fileaux = lock_fileb
        while to_build:
            _, pkg_ref = to_build[0].pop(0)
            pkg_ref = PackageReference.loads(pkg_ref)
            self.assertIsNotNone(pkg_ref.ref.revision)
            self.assertIsNone(pkg_ref.revision)
            client_aux = TestClient(cache_folder=client.cache_folder)
            client_aux.run(
                "config set general.default_package_id_mode=full_package_mode")
            client_aux.save({LOCKFILE: lock_fileaux})
            client_aux.run("install %s --build=%s --lockfile" %
                           (pkg_ref.ref, pkg_ref.ref.name))
            lock_fileaux = load(
                os.path.join(client_aux.current_folder, LOCKFILE))
            client.save({"new_lock/%s" % LOCKFILE: lock_fileaux})
            client.run("graph update-lock . new_lock")

            client.run("graph build-order . --build=missing")
            lock_fileaux = client.load(LOCKFILE)
            output = str(client.out).splitlines()[-1]
            to_build = eval(output)

        new_lockfile = client.load(LOCKFILE)
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgB/0.1@user/channel: DEP FILE PkgA: ByeA World!!",
                      client.out)
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgA: ByeA World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgA: ByeA World!!",
                      client.out)

        client.save({LOCKFILE: initial_lock_file})
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgB/0.1@user/channel: DEP FILE PkgA: HelloA",
                      client.out)
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgA: HelloA",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgA: HelloA",
                      client.out)

        client.save({LOCKFILE: new_lockfile})
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgB/0.1@user/channel: DEP FILE PkgA: ByeA World!!",
                      client.out)
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgA: ByeA World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgA: ByeA World!!",
                      client.out)
示例#37
0
    def package_info_components_complete_test(self):
        dep = textwrap.dedent("""
            import os
            from conans import ConanFile
            class Dep(ConanFile):
                exports_sources = "*"
                def package(self):
                    self.copy("*")
                def package_info(self):
                    self.cpp_info.name = "Galaxy"
                    self.cpp_info.components["Starlight"].includedirs = [os.path.join("galaxy", "starlight")]
                    self.cpp_info.components["Starlight"].libs = ["libstarlight"]
                    self.cpp_info.components["Planet"].includedirs = [os.path.join("galaxy", "planet")]
                    self.cpp_info.components["Planet"].libs = ["libplanet"]
                    self.cpp_info.components["Planet"].requires = ["Starlight"]
                    self.cpp_info.components["Launcher"].system_libs = ["ground"]
                    self.cpp_info.components["ISS"].includedirs = [os.path.join("galaxy", "iss")]
                    self.cpp_info.components["ISS"].libs = ["libiss"]
                    self.cpp_info.components["ISS"].libdirs = ["iss_libs"]
                    self.cpp_info.components["ISS"].system_libs = ["solar", "magnetism"]
                    self.cpp_info.components["ISS"].requires = ["Starlight", "Launcher"]
        """)
        consumer = textwrap.dedent("""
        from conans import ConanFile
        class Consumer(ConanFile):
            requires = "dep/1.0@us/ch"
            def build(self):
                # Global values
                self.output.info("GLOBAL Include paths: %s" % self.deps_cpp_info.include_paths)
                self.output.info("GLOBAL Library paths: %s" % self.deps_cpp_info.lib_paths)
                self.output.info("GLOBAL Binary paths: %s" % self.deps_cpp_info.bin_paths)
                self.output.info("GLOBAL Libs: %s" % self.deps_cpp_info.libs)
                self.output.info("GLOBAL Exes: %s" % self.deps_cpp_info.exes)
                self.output.info("GLOBAL System libs: %s" % self.deps_cpp_info.system_libs)
                # Deps values
                for dep_key, dep_value in self.deps_cpp_info.dependencies:
                    self.output.info("DEPS name: %s" % dep_value.name)
                    self.output.info("DEPS Include paths: %s" % dep_value.include_paths)
                    self.output.info("DEPS Library paths: %s" % dep_value.lib_paths)
                    self.output.info("DEPS Binary paths: %s" % dep_value.bin_paths)
                    self.output.info("DEPS Libs: %s" % dep_value.libs)
                    self.output.info("DEPS System libs: %s" % dep_value.system_libs)
                # Components values
                for dep_key, dep_value in self.deps_cpp_info.dependencies:
                    for comp_name, comp_value in dep_value.components.items():
                        self.output.info("COMP %s Include paths: %s" % (comp_name,
                        comp_value.include_paths))
                        self.output.info("COMP %s Library paths: %s" % (comp_name, comp_value.lib_paths))
                        self.output.info("COMP %s Binary paths: %s" % (comp_name, comp_value.bin_paths))
                        self.output.info("COMP %s Libs: %s" % (comp_name, comp_value.libs))
                        self.output.info("COMP %s Requires: %s" % (comp_name, comp_value.requires))
                        self.output.info("COMP %s System libs: %s" % (comp_name, comp_value.system_libs))
        """)

        client = TestClient()
        client.save({
            "conanfile_dep.py": dep,
            "conanfile_consumer.py": consumer,
            "galaxy/starlight/starlight.h": "",
            "lib/libstarlight": "",
            "galaxy/planet/planet.h": "",
            "lib/libplanet": "",
            "galaxy/iss/iss.h": "",
            "iss_libs/libiss": "",
            "bin/exelauncher": ""
        })
        dep_ref = ConanFileReference("dep", "1.0", "us", "ch")
        dep_pref = PackageReference(dep_ref, NO_SETTINGS_PACKAGE_ID)
        client.run("create conanfile_dep.py dep/1.0@us/ch")
        client.run("create conanfile_consumer.py consumer/1.0@us/ch")
        package_folder = client.cache.package_layout(dep_ref).package(dep_pref)

        expected_comp_starlight_include_paths = [
            os.path.join(package_folder, "galaxy", "starlight")
        ]
        expected_comp_planet_include_paths = [
            os.path.join(package_folder, "galaxy", "planet")
        ]
        expected_comp_launcher_include_paths = []
        expected_comp_iss_include_paths = [
            os.path.join(package_folder, "galaxy", "iss")
        ]
        expected_comp_starlight_library_paths = [
            os.path.join(package_folder, "lib")
        ]
        expected_comp_launcher_library_paths = [
            os.path.join(package_folder, "lib")
        ]
        expected_comp_planet_library_paths = [
            os.path.join(package_folder, "lib")
        ]
        expected_comp_iss_library_paths = [
            os.path.join(package_folder, "iss_libs")
        ]
        expected_comp_starlight_binary_paths = [
            os.path.join(package_folder, "bin")
        ]
        expected_comp_launcher_binary_paths = [
            os.path.join(package_folder, "bin")
        ]
        expected_comp_planet_binary_paths = [
            os.path.join(package_folder, "bin")
        ]
        expected_comp_iss_binary_paths = [os.path.join(package_folder, "bin")]

        expected_global_include_paths = expected_comp_planet_include_paths + \
            expected_comp_iss_include_paths + expected_comp_starlight_include_paths
        expected_global_library_paths = expected_comp_starlight_library_paths + \
            expected_comp_iss_library_paths
        expected_global_binary_paths = expected_comp_starlight_binary_paths

        self.assertIn(
            "GLOBAL Include paths: %s" % expected_global_include_paths,
            client.out)
        self.assertIn(
            "GLOBAL Library paths: %s" % expected_global_library_paths,
            client.out)
        self.assertIn("GLOBAL Binary paths: %s" % expected_global_binary_paths,
                      client.out)
        self.assertIn("GLOBAL Libs: ['libplanet', 'libiss', 'libstarlight']",
                      client.out)
        self.assertIn("GLOBAL System libs: ['solar', 'magnetism', 'ground']",
                      client.out)

        self.assertIn("DEPS name: Galaxy", client.out)
        self.assertIn("DEPS Include paths: %s" % expected_global_include_paths,
                      client.out)
        self.assertIn("DEPS Library paths: %s" % expected_global_library_paths,
                      client.out)
        self.assertIn("DEPS Binary paths: %s" % expected_global_binary_paths,
                      client.out)
        self.assertIn("DEPS Libs: ['libplanet', 'libiss', 'libstarlight']",
                      client.out)
        self.assertIn("DEPS System libs: ['solar', 'magnetism', 'ground']",
                      client.out)

        self.assertIn(
            "COMP Starlight Include paths: %s" %
            expected_comp_starlight_include_paths, client.out)
        self.assertIn(
            "COMP Planet Include paths: %s" %
            expected_comp_planet_include_paths, client.out)
        self.assertIn(
            "COMP Launcher Include paths: %s" %
            expected_comp_launcher_include_paths, client.out)
        self.assertIn(
            "COMP ISS Include paths: %s" % expected_comp_iss_include_paths,
            client.out)
        self.assertIn(
            "COMP Starlight Library paths: %s" %
            expected_comp_starlight_library_paths, client.out)
        self.assertIn(
            "COMP Planet Library paths: %s" %
            expected_comp_planet_library_paths, client.out)
        self.assertIn(
            "COMP Launcher Library paths: %s" %
            expected_comp_launcher_library_paths, client.out)
        self.assertIn(
            "COMP ISS Library paths: %s" % expected_comp_iss_library_paths,
            client.out)
        self.assertIn(
            "COMP Starlight Binary paths: %s" % expected_comp_iss_binary_paths,
            client.out)
        self.assertIn(
            "COMP Planet Binary paths: %s" % expected_comp_planet_binary_paths,
            client.out)
        self.assertIn(
            "COMP Launcher Binary paths: %s" %
            expected_comp_launcher_binary_paths, client.out)
        self.assertIn(
            "COMP ISS Binary paths: %s" % expected_comp_iss_binary_paths,
            client.out)
        self.assertIn("COMP Starlight Libs: ['libstarlight']", client.out)
        self.assertIn("COMP Planet Libs: ['libplanet']", client.out)
        self.assertIn("COMP Launcher Libs: []", client.out)
        self.assertIn("COMP ISS Libs: ['libiss']", client.out)
        self.assertIn("COMP Starlight System libs: []", client.out)
        self.assertIn("COMP Planet System libs: []", client.out)
        self.assertIn("COMP Launcher System libs: ['ground']", client.out)
        self.assertIn("COMP ISS System libs: ['solar', 'magnetism']",
                      client.out)
        self.assertIn("COMP Starlight Requires: []", client.out)
        self.assertIn("COMP Launcher Requires: []", client.out)
        self.assertIn("COMP Planet Requires: ['Starlight']", client.out)
        self.assertIn("COMP ISS Requires: ['Starlight', 'Launcher']",
                      client.out)
示例#38
0
 def deserialize(data):
     return RequirementsList([PackageReference.loads(line) for line in data])
示例#39
0
    def test_package_revision_mode(self):
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                {requires}
                exports_sources = "myfile.txt"
                keep_imports = True
                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                def package_info(self):
                    self.output.info("SELF FILE: %s"
                        % load(os.path.join(self.package_folder, "myfile.txt")))
                    for d in os.listdir(self.package_folder):
                        p = os.path.join(self.package_folder, d, "myfile.txt")
                        if os.path.isfile(p):
                            self.output.info("DEP FILE %s: %s" % (d, load(p)))
                """)
        test_server = TestServer(users={"user": "******"})
        client = TestClient(servers={"default": test_server},
                            users={"default": [("user", "mypass")]})
        client.run(
            "config set general.default_package_id_mode=package_revision_mode")
        client.save({
            "conanfile.py": conanfile.format(requires=""),
            "myfile.txt": "HelloA"
        })
        client.run("create . PkgA/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires = "PkgA/0.1@user/channel"'),
            "myfile.txt":
            "HelloB"
        })
        client.run("create . PkgB/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires = "PkgB/0.1@user/channel"'),
            "myfile.txt":
            "HelloC"
        })
        client.run("create . PkgC/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires = "PkgC/0.1@user/channel"'),
            "myfile.txt":
            "HelloD"
        })
        client.run("create . PkgD/0.1@user/channel")
        self.assertIn("PkgD/0.1@user/channel: SELF FILE: HelloD", client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgA: HelloA",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgC: HelloC",
                      client.out)

        client.run("upload * --all --confirm")

        client.run("graph lock PkgD/0.1@user/channel")
        lock_file = client.load(LOCKFILE)
        initial_lock_file = lock_file
        self.assertIn(
            "PkgB/0.1@user/channel#c51f99a8622d6c837cd9dcd2595e43e4:"
            "6e9742c2106791c1c777da8ccfb12a1408385d8d#f25c123185dcbd2fe326cecb0d73edaa",
            lock_file)
        self.assertIn(
            "PkgA/0.1@user/channel#189390ce059842ce984e0502c52cf736:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9#5ba7f606729949527141beef73c72bc8",
            lock_file)
        self.assertIn(
            "PkgC/0.1@user/channel#1c63e932e9392857cdada81f34bf4690:"
            "d27e81082fa545d364f19bd07bdf7975acd9e1ac#667a94f8b740b0f35519116997eabeff",
            lock_file)
        self.assertIn(
            "PkgD/0.1@user/channel#d3d184611fb757faa65e4d4203198579:"
            "d80dd9662f447164906643ab88a1ed4e7b12925b#50246cbe82411551e5ebc5bcc75f1a9a",
            lock_file)

        # Do a change in B
        clientb = TestClient(cache_folder=client.cache_folder,
                             servers={"default": test_server})
        clientb.run(
            "config set general.default_package_id_mode=package_revision_mode")
        clientb.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgA/0.1@user/channel"'),
            "myfile.txt":
            "ByeB World!!",
            LOCKFILE:
            lock_file
        })
        clientb.run("create . PkgB/0.1@user/channel --lockfile")
        lock_fileb = load(os.path.join(clientb.current_folder, LOCKFILE))
        self.assertIn(
            "PkgB/0.1@user/channel#569839e7b741ee474406de1db69d19c2:"
            "6e9742c2106791c1c777da8ccfb12a1408385d8d#2711a0a3b580e72544af8f36d0a87424",
            lock_fileb)
        self.assertIn(
            "PkgA/0.1@user/channel#189390ce059842ce984e0502c52cf736:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9#5ba7f606729949527141beef73c72bc8",
            lock_fileb)
        self.assertIn(
            "PkgC/0.1@user/channel#1c63e932e9392857cdada81f34bf4690:"
            "d27e81082fa545d364f19bd07bdf7975acd9e1ac#667a94f8b740b0f35519116997eabeff",
            lock_fileb)
        self.assertIn(
            "PkgD/0.1@user/channel#d3d184611fb757faa65e4d4203198579:"
            "d80dd9662f447164906643ab88a1ed4e7b12925b#50246cbe82411551e5ebc5bcc75f1a9a",
            lock_fileb)
        self.assertIn('"modified": "%s"' % GraphLockNode.MODIFIED_BUILT,
                      lock_fileb)
        # Go back to main orchestrator
        client.save({"new_lock/%s" % LOCKFILE: lock_fileb})
        client.run("graph update-lock . new_lock")
        client.run(
            "graph build-order . --json=build_order.json --build=cascade")
        lock_file_order = load(os.path.join(clientb.current_folder, LOCKFILE))
        json_file = os.path.join(client.current_folder, "build_order.json")
        to_build = json.loads(load(json_file))
        lock_fileaux = lock_file_order
        while to_build:
            for _, pkg_ref in to_build[0]:
                pkg_ref = PackageReference.loads(pkg_ref)
                client_aux = TestClient(cache_folder=client.cache_folder,
                                        servers={"default": test_server})
                client_aux.save({LOCKFILE: lock_fileaux})
                client_aux.run("install %s --build=%s --lockfile" %
                               (pkg_ref.ref, pkg_ref.ref.name))
                lock_fileaux = client_aux.load(LOCKFILE)
                client.save({"new_lock/%s" % LOCKFILE: lock_fileaux})
                client.run("graph update-lock . new_lock")

            client.run("graph build-order . --build=cascade")
            lock_fileaux = client.load(LOCKFILE)
            output = str(client.out).splitlines()[-1]
            to_build = eval(output)

        new_lockfile = client.load(LOCKFILE)
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        client.run("upload * --all --confirm")

        client.save({LOCKFILE: initial_lock_file})
        client.run("remove * -f")
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)

        client.save({LOCKFILE: new_lockfile})
        client.run("remove * -f")
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
示例#40
0
    def test_search(self):
        """ check the dict is returned by get_packages_info service
        """
        # Creating and saving conans, packages, and conans.vars
        ref2 = ConanFileReference("openssl", "3.0", "lasote", "stable",
                                  DEFAULT_REVISION_V1)
        ref3 = ConanFileReference("Assimp", "1.10", "fenix", "stable",
                                  DEFAULT_REVISION_V1)
        ref4 = ConanFileReference("assimpFake", "0.1", "phil", "stable",
                                  DEFAULT_REVISION_V1)

        pref2 = PackageReference(ref2, "12345587754", DEFAULT_REVISION_V1)
        pref3 = PackageReference(ref3, "77777777777", DEFAULT_REVISION_V1)

        conan_vars = """
[options]
    use_Qt=%s
"""
        conan_vars1 = conan_vars % "True"
        conan_vars2 = conan_vars % "False"
        conan_vars3 = conan_vars % "True"

        save_files(self.server_store.package(self.pref),
                   {CONANINFO: conan_vars1})
        self.server_store.update_last_package_revision(self.pref)
        save_files(self.server_store.package(pref2), {CONANINFO: conan_vars2})
        self.server_store.update_last_package_revision(pref2)
        save_files(self.server_store.package(pref3), {CONANINFO: conan_vars3})
        self.server_store.update_last_package_revision(pref3)

        save_files(self.server_store.export(ref4), {"dummy.txt": "//"})

        info = self.search_service.search()
        expected = [r.copy_clear_rev() for r in [ref3, ref4, self.ref, ref2]]
        self.assertEqual(expected, info)

        info = self.search_service.search(pattern="Assimp*", ignorecase=False)
        self.assertEqual(info, [ref3.copy_clear_rev()])

        info = self.search_service.search_packages(ref2, None)
        self.assertEqual(
            info, {
                '12345587754': {
                    'full_requires': [],
                    'options': {
                        'use_Qt': 'False'
                    },
                    'settings': {},
                    'recipe_hash': None
                }
            })

        info = self.search_service.search_packages(ref3, None)
        self.assertEqual(
            info, {
                '77777777777': {
                    'full_requires': [],
                    'options': {
                        'use_Qt': 'True'
                    },
                    'settings': {},
                    'recipe_hash': None
                }
            })
示例#41
0
    def test_revisions(self):
        conanfile = textwrap.dedent("""
            from conans import ConanFile, load
            import os
            class Pkg(ConanFile):
                {requires}
                exports_sources = "myfile.txt"
                keep_imports = True
                def imports(self):
                    self.copy("myfile.txt", folder=True)
                def package(self):
                    self.copy("*myfile.txt")
                def package_info(self):
                    self.output.info("SELF FILE: %s"
                        % load(os.path.join(self.package_folder, "myfile.txt")))
                    for d in os.listdir(self.package_folder):
                        p = os.path.join(self.package_folder, d, "myfile.txt")
                        if os.path.isfile(p):
                            self.output.info("DEP FILE %s: %s" % (d, load(p)))
                """)
        test_server = TestServer(users={"user": "******"})
        client = TestClient(servers={"default": test_server},
                            users={"default": [("user", "mypass")]})
        client.save({
            "conanfile.py": conanfile.format(requires=""),
            "myfile.txt": "HelloA"
        })
        client.run("create . PkgA/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires = "PkgA/0.1@user/channel"'),
            "myfile.txt":
            "HelloB"
        })
        client.run("create . PkgB/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires = "PkgB/0.1@user/channel"'),
            "myfile.txt":
            "HelloC"
        })
        client.run("create . PkgC/0.1@user/channel")
        client.save({
            "conanfile.py":
            conanfile.format(requires='requires = "PkgC/0.1@user/channel"'),
            "myfile.txt":
            "HelloD"
        })
        client.run("create . PkgD/0.1@user/channel")
        self.assertIn("PkgD/0.1@user/channel: SELF FILE: HelloD", client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgA: HelloA",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgC: HelloC",
                      client.out)

        client.run("upload * --all --confirm")

        client.run("graph lock PkgD/0.1@user/channel")
        lock_file = client.load(LOCKFILE)
        initial_lock_file = lock_file
        self.assertIn(
            "PkgB/0.1@user/channel#c51f99a8622d6c837cd9dcd2595e43e4:"
            "5bf1ba84b5ec8663764a406f08a7f9ae5d3d5fb5#e7f906f2f693abccb3dc3419c4270413",
            lock_file)
        self.assertIn(
            "PkgA/0.1@user/channel#189390ce059842ce984e0502c52cf736:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9#5ba7f606729949527141beef73c72bc8",
            lock_file)
        self.assertIn(
            "PkgC/0.1@user/channel#1c63e932e9392857cdada81f34bf4690:"
            "8f97510bcea8206c1c046cc8d71cc395d4146547#7ae97bd9488da55592ab7d94a1885282",
            lock_file)
        self.assertIn(
            "PkgD/0.1@user/channel#d3d184611fb757faa65e4d4203198579:"
            "7e4312d9a6d3726436d62a6b508f361d13e65354#55f822331b182e54b5144e578ba9135b",
            lock_file)

        # Do a change in B
        clientb = TestClient(cache_folder=client.cache_folder,
                             servers={"default": test_server})
        clientb.save({
            "conanfile.py":
            conanfile.format(requires='requires="PkgA/0.1@user/channel"'),
            "myfile.txt":
            "ByeB World!!",
            LOCKFILE:
            lock_file
        })
        clientb.run("create . PkgB/0.1@user/channel --lockfile")
        lock_fileb = load(os.path.join(clientb.current_folder, LOCKFILE))
        self.assertIn(
            "PkgB/0.1@user/channel#569839e7b741ee474406de1db69d19c2:"
            "5bf1ba84b5ec8663764a406f08a7f9ae5d3d5fb5#d1974c85c53dfaa549478a9ead361fe2",
            lock_fileb)
        self.assertIn(
            "PkgA/0.1@user/channel#189390ce059842ce984e0502c52cf736:"
            "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9#5ba7f606729949527141beef73c72bc8",
            lock_fileb)
        self.assertIn(
            "PkgC/0.1@user/channel#1c63e932e9392857cdada81f34bf4690:"
            "8f97510bcea8206c1c046cc8d71cc395d4146547#7ae97bd9488da55592ab7d94a1885282",
            lock_fileb)
        self.assertIn(
            "PkgD/0.1@user/channel#d3d184611fb757faa65e4d4203198579:"
            "7e4312d9a6d3726436d62a6b508f361d13e65354#55f822331b182e54b5144e578ba9135b",
            lock_fileb)
        self.assertIn('"modified": "%s"' % GraphLockNode.MODIFIED_BUILT,
                      lock_fileb)
        # Go back to main orchestrator
        client.save({"new_lock/%s" % LOCKFILE: lock_fileb})
        client.run("graph update-lock . new_lock")
        client.run(
            "graph build-order . --json=build_order.json --build=cascade")
        lock_file_order = load(os.path.join(clientb.current_folder, LOCKFILE))
        json_file = os.path.join(client.current_folder, "build_order.json")
        to_build = json.loads(load(json_file))
        lock_fileaux = lock_file_order
        while to_build:
            for _, pkg_ref in to_build[0]:
                pkg_ref = PackageReference.loads(pkg_ref)
                client_aux = TestClient(cache_folder=client.cache_folder,
                                        servers={"default": test_server})
                client_aux.save({LOCKFILE: lock_fileaux})
                client_aux.run("install %s --build=%s --lockfile" %
                               (pkg_ref.ref, pkg_ref.ref.name))
                lock_fileaux = load(
                    os.path.join(client_aux.current_folder, LOCKFILE))
                client.save({"new_lock/%s" % LOCKFILE: lock_fileaux})
                client.run("graph update-lock . new_lock")

            client.run("graph build-order . --build=cascade")
            lock_fileaux = client.load(LOCKFILE)
            output = str(client.out).splitlines()[-1]
            to_build = eval(output)

        new_lockfile = client.load(LOCKFILE)
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        client.run("upload * --all --confirm")

        client.save({LOCKFILE: initial_lock_file})
        client.run("remove * -f")
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: HelloB",
                      client.out)

        client.save({LOCKFILE: new_lockfile})
        client.run("remove * -f")
        client.run("install PkgD/0.1@user/channel --lockfile")
        self.assertIn("PkgC/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
        self.assertIn("PkgD/0.1@user/channel: DEP FILE PkgB: ByeB World!!",
                      client.out)
示例#42
0
def inc_package_manifest_timestamp(client_cache, package_ref, inc_time):
    pkg_ref = PackageReference.loads(str(package_ref))
    path = client_cache.package(pkg_ref)
    manifest = FileTreeManifest.load(path)
    manifest.time += inc_time
    manifest.save(path)
示例#43
0
    def test_build_modules(self):
        conanfile = textwrap.dedent("""
            import os
            from conans import ConanFile, CMake

            class Conan(ConanFile):
                name = "test"
                version = "1.0"
                exports_sources = ["my-module.cmake", "FindFindModule.cmake"]

                def package(self):
                    self.copy("*.cmake", dst="share/cmake")

                def package_info(self):
                    # Only first module is defined
                    # (the other one should be found by CMAKE_MODULE_PATH in builddirs)
                    builddir = os.path.join("share", "cmake")
                    module = os.path.join(builddir, "my-module.cmake")
                    self.cpp_info.build_modules.append(module)
                    self.cpp_info.builddirs = [builddir]
        """)
        # This is a module that has other find_package() calls
        my_module = textwrap.dedent("""
            find_package(FindModule REQUIRED)
            """)
        # This is a module that defines some functionality
        find_module = textwrap.dedent("""
            function(conan_message MESSAGE_OUTPUT)
                message(${ARGV${0}})
            endfunction()
            """)
        client = TestClient()
        client.save({
            "conanfile.py": conanfile,
            "my-module.cmake": my_module,
            "FindFindModule.cmake": find_module
        })
        client.run("create .")
        ref = ConanFileReference("test", "1.0", None, None)
        pref = PackageReference(ref, NO_SETTINGS_PACKAGE_ID, None)
        package_path = client.cache.package_layout(ref).package(pref)
        modules_path = os.path.join(package_path, "share", "cmake")
        self.assertEqual(set(os.listdir(modules_path)),
                         {"FindFindModule.cmake", "my-module.cmake"})

        consumer = textwrap.dedent("""
            from conans import ConanFile, CMake

            class Conan(ConanFile):
                name = "consumer"
                version = "1.0"
                settings = "os", "compiler", "build_type", "arch"
                exports_sources = ["CMakeLists.txt"]
                generators = "cmake_find_package"
                requires = "test/1.0"

                def build(self):
                    cmake = CMake(self)
                    cmake.configure()
                    cmake.build()
            """)
        cmakelists = textwrap.dedent("""
            cmake_minimum_required(VERSION 3.0)
            project(test)
            find_package(test)
            conan_message("Printing using a external module!")
            """)
        client.save({"conanfile.py": consumer, "CMakeLists.txt": cmakelists})
        client.run("create .")
        self.assertIn("Printing using a external module!", client.out)
示例#44
0
    def check_conaninfo_completion_test(self):
        """
        consumer -> B -> C
                      -> D (conditional)

        The overwritten environment variables caused by the consumer have to be reflected in B's conaninfo.txt
        """
        client = TestClient()
        conanfile = """
from conans import ConanFile
class LibConan(ConanFile):
    name = "libC"
    version = "1.0"

    def package_info(self):
        self.env_info.MYVAR = "ValueByLibC"
"""
        client.save({"conanfile.py": conanfile})
        client.run("export . foo/bar")

        conanfile = """
from conans import ConanFile
class LibConan(ConanFile):
    name = "libD"
    version = "1.0"

    def package_info(self):
        self.env_info.MYVAR = "ValueByLibD"
"""
        client.save({"conanfile.py": conanfile})
        client.run("export . foo/bar")

        conanfile = """
import os
from conans import ConanFile
class LibConan(ConanFile):
    name = "libB"
    version = "1.0"

    def requirements(self):
        if os.environ.get("DEP", None) == "C":
            self.requires.add("libC/1.0@foo/bar")
        else:
            self.requires.add("libD/1.0@foo/bar")

    def build_info(self):
        self.output.warn("Value of MYVAR: %s" % os.environ["MYVAR"])
"""
        client.save({"conanfile.py": conanfile})
        client.run("export . foo/bar")

        refb = PackageReference.loads("libB/1.0@foo/bar:5fecb9aaf431791c8c06ab146f3451823f982bb8")

        # With no overrides, B takes dependency D and the value should be ValueByLibD
        client.run("install libB/1.0@foo/bar --build")
        self.assertTrue("Value of MYVAR: ValueByLibD")
        conaninfo = load(os.path.join(client.client_cache.package(refb), CONANINFO))
        self.assertTrue(conaninfo.endswith("[env]\n\n"))  # Not user input env

        # B takes dependency C and the value should be ValueByLibC
        client.run("install libB/1.0@foo/bar --build -e DEP=C")
        self.assertTrue("Value of MYVAR: ValueByLibC")
        conaninfo = load(os.path.join(client.client_cache.package(refb), CONANINFO))
        self.assertTrue(conaninfo.endswith("[env]\n\n"))  # Not user input env

        # Consumer overrides MYVAR, so his conaninfo should have it
        client.run("install libB/1.0@foo/bar --build -e MYVAR=ValueByConsumer")
        self.assertTrue("Value of MYVAR: ValueByConsumer")
        conaninfo = load(os.path.join(client.client_cache.package(refb), CONANINFO))
        self.assertTrue(conaninfo.endswith("[env]\n    MYVAR=ValueByConsumer\n"))

        # Consumer overrides MYVAR, so his conaninfo should have it, but not the libC, because
        # is not a dependency
        client.run("install libB/1.0@foo/bar --build -e libB:MYVAR=ValueByConsumer "
                   "-e libC:MYVAR=OtherValue")
        self.assertTrue("Value of MYVAR: ValueByConsumer")
        conaninfo = load(os.path.join(client.client_cache.package(refb), CONANINFO))
        self.assertTrue(conaninfo.endswith("[env]\n    libB:MYVAR=ValueByConsumer\n"))

        # Consumer overrides MYVAR, so his conaninfo should have it, both libB and libD
        client.run("install libB/1.0@foo/bar --build -e libB:MYVAR=ValueByConsumer "
                   "-e libD:MYVAR=OtherValue")
        self.assertTrue("Value of MYVAR: ValueByConsumer")
        conaninfo = load(os.path.join(client.client_cache.package(refb), CONANINFO))
        self.assertTrue(conaninfo.endswith("[env]\n    libB:MYVAR=ValueByConsumer\n"
                                           "    libD:MYVAR=OtherValue\n"))  # Not user input env
示例#45
0
    def test_basic(self, short_paths):
        client = TestClient()
        conanfile = """
from conans import ConanFile
class TestConan(ConanFile):
    name = "Hello"
    version = "0.1"
    settings = "os"

    def package(self):
        self.copy("*")
"""
        if short_paths:
            conanfile += "    short_paths = True"
        client.save({CONANFILE: conanfile})
        client.run("export . lasote/stable")
        client.save({"include/header.h": "//Windows header"})
        client.run("export-pkg . Hello/0.1@lasote/stable -s os=Windows")
        ref = ConanFileReference.loads("Hello/0.1@lasote/stable")
        win_pref = PackageReference(
            ref, "3475bd55b91ae904ac96fde0f106a136ab951a5e")
        package_folder = client.cache.package(win_pref,
                                              short_paths=short_paths)
        if short_paths and platform.system() == "Windows":
            self.assertEqual(
                load(
                    os.path.join(client.cache.package(win_pref),
                                 ".conan_link")), package_folder)
        else:
            self.assertEqual(client.cache.package(win_pref), package_folder)
        self.assertEqual(
            load(os.path.join(package_folder, "include/header.h")),
            "//Windows header")
        self._consume(client, ". -s os=Windows")
        self.assertIn(
            "Hello/0.1@lasote/stable:3475bd55b91ae904ac96fde0f106a136ab951a5e",
            client.user_io.out)

        # Now repeat
        client.save(
            {
                CONANFILE: conanfile,
                "include/header.h": "//Windows header2"
            },
            clean_first=True)
        # Without force it fails
        err = client.run("export-pkg . Hello/0.1@lasote/stable -s os=Windows",
                         assert_error=True)
        self.assertIn(
            "Package already exists. Please use --force, -f to overwrite it",
            client.user_io.out)
        self.assertTrue(err)
        # With force works
        client.run("export-pkg . Hello/0.1@lasote/stable -s os=Windows -f")
        self.assertEqual(
            load(os.path.join(package_folder, "include/header.h")),
            "//Windows header2")

        # Now use --install-folder
        client.save(
            {
                CONANFILE: conanfile,
                "include/header.h": "//Windows header3"
            },
            clean_first=True)
        # Without force it fails
        client.run("install . --install-folder=inst -s os=Windows")
        err = client.run("export-pkg . Hello/0.1@lasote/stable -if inst",
                         assert_error=True)
        self.assertTrue(err)
        self.assertIn(
            "Package already exists. Please use --force, -f to overwrite it",
            client.user_io.out)
        # With force works
        client.run("export-pkg . Hello/0.1@lasote/stable -if inst -f")
        self.assertIn(
            "Hello/0.1@lasote/stable: Package '3475bd55b91ae904ac96fde0f106a136ab951a5e'"
            " created", client.out)
        self.assertEqual(
            load(os.path.join(package_folder, "include/header.h")),
            "//Windows header3")

        # we can specify settings too
        client.save({"include/header.h": "//Windows header4"})
        client.run(
            "export-pkg . Hello/0.1@lasote/stable -if inst -f -s os=Windows")
        self.assertIn(
            "Hello/0.1@lasote/stable: Package '3475bd55b91ae904ac96fde0f106a136ab951a5e'"
            " created", client.out)
        self.assertEqual(
            load(os.path.join(package_folder, "include/header.h")),
            "//Windows header4")

        # Try to specify a install folder with no files
        client.run("export-pkg . Hello/0.1@lasote/stable -if fake",
                   assert_error=True)
        self.assertIn("ERROR: Failed to load graphinfo file in install-folder",
                      client.out)
示例#46
0
    def reuse_test(self):
        conan_reference = ConanFileReference.loads(
            "stringutil/0.1@lasote/stable")
        files = {
            'conanfile.py': stringutil_conanfile,
            'reverse.go': reverse,
            'reverse_test.go': reverse_test,
            'reverse.txt': reverse,
            'hello/helloreverse.txt': reverse
        }
        self.client.save(files)
        self.client.run("export lasote/stable")
        self.client.run("install %s --build missing" % str(conan_reference))
        # Check compilation ok
        package_ids = self.client.paths.conan_packages(conan_reference)
        self.assertEquals(len(package_ids), 1)
        package_ref = PackageReference(conan_reference, package_ids[0])
        self._assert_package_exists(package_ref, self.client.paths,
                                    list(files.keys()))

        # Upload conans
        self.client.run("upload %s" % str(conan_reference))

        # Check that conans exists on server
        server_paths = self.servers["default"].paths
        conan_path = server_paths.export(conan_reference)
        self.assertTrue(os.path.exists(conan_path))

        # Upload package
        self.client.run("upload %s -p %s" %
                        (str(conan_reference), str(package_ids[0])))

        # Check library on server
        self._assert_package_exists_in_server(package_ref, server_paths,
                                              list(files.keys()))

        # Now from other "computer" install the uploaded conans with same options (nothing)
        other_conan = TestClient(servers=self.servers,
                                 users={"default": [("lasote", "mypass")]})
        other_conan.run("install %s --build missing" % str(conan_reference))
        # Build should be empty
        build_path = other_conan.paths.build(package_ref)
        self.assertFalse(os.path.exists(build_path))
        # Lib should exist
        self._assert_package_exists(package_ref, other_conan.paths,
                                    list(files.keys()))

        reuse_conan = TestClient(servers=self.servers,
                                 users={"default": [("lasote", "mypass")]})
        files = {'conanfile.py': reuse_conanfile, 'src/hello/main.go': main}
        reuse_conan.save(files)
        reuse_conan.run("install --build missing")

        with CustomEnvPath(paths_to_add=['$GOPATH/bin'],
                           var_to_add=[
                               ('GOPATH', reuse_conan.current_folder),
                           ]):

            if platform.system() == "Windows":
                command = "hello"
            else:
                command = './hello'
            reuse_conan.runner('go install hello',
                               cwd=reuse_conan.current_folder)
            reuse_conan.runner(command,
                               cwd=os.path.join(reuse_conan.current_folder,
                                                'bin'))
        self.assertIn("Hello, Go!", reuse_conan.user_io.out)
示例#47
0
    def _collect_packages_to_upload(self, refs, confirm, remotes, all_packages,
                                    query, package_id):
        """ compute the references with revisions and the package_ids to be uploaded
        """
        # Group recipes by remote
        refs_by_remote = defaultdict(list)

        for ref in refs:
            metadata = self._cache.package_layout(ref).load_metadata()
            if ref.revision and ref.revision != metadata.recipe.revision:
                raise ConanException(
                    "Recipe revision {} does not match the one stored in the "
                    "cache {}".format(ref.revision, metadata.recipe.revision))
            ref = ref.copy_with_rev(metadata.recipe.revision)
            remote = remotes.selected
            if remote:
                ref_remote = remote
            else:
                ref_remote = metadata.recipe.remote
                ref_remote = remotes.get_remote(ref_remote)

            upload = True
            if not confirm:
                msg = "Are you sure you want to upload '%s' to '%s'?" % (
                    str(ref), ref_remote.name)
                upload = self._user_io.request_boolean(msg)
            if upload:
                try:
                    conanfile_path = self._cache.package_layout(
                        ref).conanfile()
                    conanfile = self._loader.load_basic(conanfile_path)
                except NotFoundException:
                    raise NotFoundException(
                        ("There is no local conanfile exported as %s" %
                         str(ref)))

                # TODO: This search of binary packages has to be improved, more robust
                # So only real packages are retrieved
                if all_packages or query:
                    if all_packages:
                        query = None
                    # better to do a search, that will retrieve real packages with ConanInfo
                    # Not only "package_id" folders that could be empty
                    package_layout = self._cache.package_layout(
                        ref.copy_clear_rev())
                    packages = search_packages(package_layout, query)
                    packages_ids = list(packages.keys())
                elif package_id:
                    packages_ids = [
                        package_id,
                    ]
                else:
                    packages_ids = []
                if packages_ids:
                    if conanfile.build_policy == "always":
                        raise ConanException(
                            "Conanfile '%s' has build_policy='always', "
                            "no packages can be uploaded" % str(ref))
                prefs = []
                # Gather all the complete PREFS with PREV
                for package in packages_ids:
                    package_id, prev = package.split(
                        "#") if "#" in package else (package, None)
                    if package_id not in metadata.packages:
                        raise ConanException("Binary package %s:%s not found" %
                                             (str(ref), package_id))
                    if prev and prev != metadata.packages[package_id].revision:
                        raise ConanException(
                            "Binary package %s:%s#%s not found" %
                            (str(ref), package_id, prev))
                    # Filter packages that don't match the recipe revision
                    if self._cache.config.revisions_enabled and ref.revision:
                        rec_rev = metadata.packages[package_id].recipe_revision
                        if ref.revision != rec_rev:
                            self._output.warn(
                                "Skipping package '%s', it doesn't belong to the"
                                " current recipe revision" % package_id)
                            continue
                    package_revision = metadata.packages[package_id].revision
                    assert package_revision is not None, "PREV cannot be None to upload"
                    prefs.append(
                        PackageReference(ref, package_id, package_revision))
                refs_by_remote[ref_remote].append((ref, conanfile, prefs))

        return refs_by_remote
示例#48
0
 def deserialize(data):
     return RequirementsList(
         [PackageReference.loads(line) for line in data])
示例#49
0
文件: installer.py 项目: niosHD/conan
    def _build(self, nodes_by_level, skip_private_nodes, deps_graph,
               profile_build_requires):
        """ The build assumes an input of conans ordered by degree, first level
        should be independent from each other, the next-second level should have
        dependencies only to first level conans.
        param nodes_by_level: list of lists [[nodeA, nodeB], [nodeC], [nodeD, ...], ...]

        build_mode => ["*"] if user wrote "--build"
                   => ["hello*", "bye*"] if user wrote "--build hello --build bye"
                   => False if user wrote "never"
                   => True if user wrote "missing"
                   => "outdated" if user wrote "--build outdated"

        """

        inverse = deps_graph.inverse_levels()
        flat = []

        for level in inverse:
            level = sorted(level, key=lambda x: x.conan_ref)
            flat.extend(n for n in level if n not in skip_private_nodes)

        # Get the nodes in order and if we have to build them
        nodes_to_process = self._get_nodes(nodes_by_level, skip_private_nodes)

        for conan_ref, package_id, conan_file, build_needed in nodes_to_process:
            output = ScopedOutput(str(conan_ref), self._out)

            if build_needed and (conan_ref,
                                 package_id) not in self._built_packages:
                package_ref = PackageReference(conan_ref, package_id)
                build_allowed = self._build_mode.allowed(conan_file, conan_ref)
                if not build_allowed:
                    _raise_package_not_found_error(conan_file, conan_ref,
                                                   output)

                if conan_file.build_policy_missing:
                    output.info(
                        "Building package from source as defined by build_policy='missing'"
                    )
                elif self._build_mode.forced(conan_file, conan_ref):
                    output.warn('Forced build from source')

                self._build_requires.install(conan_ref, conan_file, self,
                                             profile_build_requires)

                t1 = time.time()
                # Assign to node the propagated info
                self._propagate_info(conan_file, conan_ref, flat, deps_graph)
                builder = _ConanPackageBuilder(conan_file, package_ref,
                                               self._client_cache, output)
                with self._client_cache.conanfile_write_lock(conan_ref):
                    self._remote_proxy.get_recipe_sources(
                        conan_ref, conan_file.short_paths)
                    builder.prepare_build()

                with self._client_cache.conanfile_read_lock(conan_ref):
                    with self._client_cache.package_lock(
                            builder.build_reference):
                        builder.build()
                        builder.package()

                        self._remote_proxy.handle_package_manifest(
                            package_ref, installed=True)
                        package_folder = self._client_cache.package(
                            package_ref, conan_file.short_paths)
                        # Call the info method
                        call_package_info(conan_file, package_folder)

                        # Log build
                        self._log_built_package(conan_file, package_ref,
                                                time.time() - t1)
                        self._built_packages.add((conan_ref, package_id))
            else:
                # Get the package, we have a not outdated remote package
                package_ref = None
                if conan_ref:
                    package_ref = PackageReference(conan_ref, package_id)
                    with self._client_cache.package_lock(package_ref):
                        self._get_remote_package(conan_file, package_ref,
                                                 output)

                # Assign to the node the propagated info
                # (conan_ref could be None if user project, but of course assign the info
                self._propagate_info(conan_file, conan_ref, flat, deps_graph)

                if package_ref:
                    # Call the info method
                    package_folder = self._client_cache.package(
                        package_ref, conan_file.short_paths)
                    call_package_info(conan_file, package_folder)
示例#50
0
class UploadTest(unittest.TestCase):
    def _get_client(self, requester=None):
        servers = {}
        # All can write (for avoid authentication until we mock user_io)
        self.test_server = TestServer([("*/*@*/*", "*")], [("*/*@*/*", "*")],
                                      users={"lasote": "mypass"})
        servers["default"] = self.test_server
        return TestClient(servers=servers,
                          users={"default": [("lasote", "mypass")]},
                          requester_class=requester)

    def setUp(self):
        self.client = self._get_client()
        self.ref = ConanFileReference.loads("Hello/1.2.1@frodo/stable#%s" %
                                            DEFAULT_REVISION_V1)
        self.pref = PackageReference(self.ref, "myfakeid", DEFAULT_REVISION_V1)
        reg_folder = self.client.cache.package_layout(self.ref).export()

        self.client.run('upload %s' % str(self.ref), assert_error=True)
        self.assertIn("ERROR: Recipe not found: '%s'" % str(self.ref),
                      self.client.out)

        files = cpp_hello_source_files(0)

        fake_metadata = PackageMetadata()
        fake_metadata.recipe.revision = DEFAULT_REVISION_V1
        fake_metadata.packages[self.pref.id].revision = DEFAULT_REVISION_V1
        self.client.save({"metadata.json": fake_metadata.dumps()},
                         path=self.client.cache.package_layout(
                             self.ref).base_folder())
        self.client.save(files, path=reg_folder)
        self.client.save(
            {
                CONANFILE:
                GenConanfile().with_name("Hello").with_version("1.2.1"),
                "include/math/lib1.h": "//copy",
                "my_lib/debug/libd.a": "//copy",
                "my_data/readme.txt": "//copy",
                "my_bin/executable": "//copy"
            },
            path=reg_folder)
        mkdir(self.client.cache.package_layout(self.ref).export_sources())
        manifest = FileTreeManifest.create(reg_folder)
        manifest.time = '123123123'
        manifest.save(reg_folder)
        self.test_server.server_store.update_last_revision(self.ref)

        self.server_pack_folder = self.test_server.server_store.package(
            self.pref)

        package_folder = self.client.cache.package_layout(self.ref).package(
            self.pref)
        save(os.path.join(package_folder, "include", "lib1.h"), "//header")
        save(os.path.join(package_folder, "lib", "my_lib", "libd.a"), "//lib")
        save(os.path.join(package_folder, "res", "shares", "readme.txt"),
             "//res")
        save(os.path.join(package_folder, "bin", "my_bin", "executable"),
             "//bin")
        save(os.path.join(package_folder, CONANINFO),
             """[recipe_hash]\n%s""" % manifest.summary_hash)
        FileTreeManifest.create(package_folder).save(package_folder)
        self.test_server.server_store.update_last_package_revision(self.pref)

        os.chmod(
            os.path.join(package_folder, "bin", "my_bin", "executable"),
            os.stat(os.path.join(package_folder, "bin", "my_bin",
                                 "executable")).st_mode | stat.S_IRWXU)

        expected_manifest = FileTreeManifest.create(package_folder)
        expected_manifest.save(package_folder)

        self.server_reg_folder = self.test_server.server_store.export(self.ref)
        self.assertFalse(os.path.exists(self.server_reg_folder))
        self.assertFalse(os.path.exists(self.server_pack_folder))

    def test_try_upload_bad_recipe(self):
        files = cpp_hello_conan_files("Hello0", "1.2.1")
        self.client.save(files)
        self.client.run("export . frodo/stable")
        ref = ConanFileReference.loads("Hello0/1.2.1@frodo/stable")
        os.unlink(
            os.path.join(
                self.client.cache.package_layout(ref).export(),
                CONAN_MANIFEST))
        with six.assertRaisesRegex(self, Exception, "Command failed"):
            self.client.run("upload %s" % str(ref))

        self.assertIn("Cannot upload corrupted recipe", self.client.out)

    def test_upload_with_pattern(self):
        for num in range(5):
            files = cpp_hello_conan_files("Hello%s" % num, "1.2.1")
            self.client.save(files)
            self.client.run("export . frodo/stable")

        self.client.run("upload Hello* --confirm")
        for num in range(5):
            self.assertIn("Uploading Hello%s/1.2.1@frodo/stable" % num,
                          self.client.out)

        self.client.run("upload Hello0* --confirm")
        self.assertIn("Uploading Hello0/1.2.1@frodo/stable", self.client.out)
        self.assertIn("Recipe is up to date, upload skipped", self.client.out)
        self.assertNotIn("Hello1", self.client.out)
        self.assertNotIn("Hello2", self.client.out)
        self.assertNotIn("Hello3", self.client.out)

    def test_upload_error(self):
        """Cause an error in the transfer and see some message"""

        # Check for the default behaviour
        client = self._get_client(BadConnectionUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run("upload Hello* --confirm")
        self.assertIn("Can't connect because of the evil mock", client.out)
        self.assertIn("Waiting 5 seconds to retry...", client.out)

        # This will fail in the first put file, so, as we need to
        # upload 3 files (conanmanifest, conanfile and tgz) will do it with 2 retries
        client = self._get_client(BadConnectionUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run("upload Hello* --confirm --retry-wait=0")
        self.assertIn("Can't connect because of the evil mock", client.out)
        self.assertIn("Waiting 0 seconds to retry...", client.out)

        # but not with 0
        client = self._get_client(BadConnectionUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run("upload Hello* --confirm --retry 0 --retry-wait=1",
                   assert_error=True)
        self.assertNotIn("Waiting 1 seconds to retry...", client.out)
        self.assertIn(
            "ERROR: Hello0/1.2.1@frodo/stable: Upload recipe to 'default' failed: "
            "Execute upload again to retry upload the failed files: "
            "conan_export.tgz. [Remote: default]", client.out)

        # Try with broken connection even with 10 retries
        client = self._get_client(TerribleConnectionUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run("upload Hello* --confirm --retry 10 --retry-wait=0",
                   assert_error=True)
        self.assertIn("Waiting 0 seconds to retry...", client.out)
        self.assertIn(
            "ERROR: Hello0/1.2.1@frodo/stable: Upload recipe to 'default' failed: "
            "Execute upload again to retry upload the failed files",
            client.out)

        # For each file will fail the first time and will success in the second one
        client = self._get_client(FailPairFilesUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run("install Hello0/1.2.1@frodo/stable --build")
        client.run("upload Hello* --confirm --retry 3 --retry-wait=0 --all")
        self.assertEqual(str(client.out).count("ERROR: Pair file, error!"), 6)

    def test_upload_error_with_config(self):
        """Cause an error in the transfer and see some message"""

        # This will fail in the first put file, so, as we need to
        # upload 3 files (conanmanifest, conanfile and tgz) will do it with 2 retries
        client = self._get_client(BadConnectionUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run('config set general.retry_wait=0')
        client.run("upload Hello* --confirm")
        self.assertIn("Can't connect because of the evil mock", client.out)
        self.assertIn("Waiting 0 seconds to retry...", client.out)

        # but not with 0
        client = self._get_client(BadConnectionUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run('config set general.retry=0')
        client.run('config set general.retry_wait=1')
        client.run("upload Hello* --confirm", assert_error=True)
        self.assertNotIn("Waiting 1 seconds to retry...", client.out)
        self.assertIn(
            "ERROR: Hello0/1.2.1@frodo/stable: Upload recipe to 'default' failed: "
            "Execute upload again to retry upload the failed files: "
            "conan_export.tgz. [Remote: default]", client.out)

        # Try with broken connection even with 10 retries
        client = self._get_client(TerribleConnectionUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run('config set general.retry=10')
        client.run('config set general.retry_wait=0')
        client.run("upload Hello* --confirm", assert_error=True)
        self.assertIn("Waiting 0 seconds to retry...", client.out)
        self.assertIn(
            "ERROR: Hello0/1.2.1@frodo/stable: Upload recipe to 'default' failed: "
            "Execute upload again to retry upload the failed files",
            client.out)

        # For each file will fail the first time and will success in the second one
        client = self._get_client(FailPairFilesUploader)
        files = cpp_hello_conan_files("Hello0", "1.2.1", build=False)
        client.save(files)
        client.run("export . frodo/stable")
        client.run("install Hello0/1.2.1@frodo/stable --build")
        client.run('config set general.retry=3')
        client.run('config set general.retry_wait=0')
        client.run("upload Hello* --confirm --all")
        self.assertEqual(str(client.out).count("ERROR: Pair file, error!"), 6)

    def test_upload_parallel_error(self):
        """Cause an error in the parallel transfer and see some message"""
        client = TestClient(requester_class=FailOnReferencesUploader,
                            default_server_user=True)
        client.save({"conanfile.py": GenConanfile()})
        client.run('user -p password -r default user')
        for index in range(4):
            client.run('create . lib{}/1.0@user/channel'.format(index))
        client.run('upload lib* --parallel -c --all -r default',
                   assert_error=True)
        self.assertIn("Connection fails with lib2 and lib4 references!",
                      client.out)
        self.assertIn("Execute upload again to retry upload the failed files",
                      client.out)

    def test_upload_parallel_success(self):
        """Upload 2 packages in parallel with success"""

        client = TestClient(default_server_user=True)
        client.save({"conanfile.py": GenConanfile()})
        client.run('create . lib0/1.0@user/channel')
        self.assertIn(
            "lib0/1.0@user/channel: Package '{}' created".format(
                NO_SETTINGS_PACKAGE_ID), client.out)
        client.run('create . lib1/1.0@user/channel')
        self.assertIn(
            "lib1/1.0@user/channel: Package '{}' created".format(
                NO_SETTINGS_PACKAGE_ID), client.out)
        client.run('user -p password -r default user')
        client.run('upload lib* --parallel -c --all -r default')
        self.assertIn("Uploading lib0/1.0@user/channel to remote 'default'",
                      client.out)
        self.assertIn("Uploading lib1/1.0@user/channel to remote 'default'",
                      client.out)
        client.run('search lib0/1.0@user/channel -r default')
        self.assertIn("lib0/1.0@user/channel", client.out)
        client.run('search lib1/1.0@user/channel -r default')
        self.assertIn("lib1/1.0@user/channel", client.out)

    def test_upload_parallel_fail_on_interaction(self):
        """Upload 2 packages in parallel and fail because non_interactive forced"""

        client = TestClient(default_server_user=True)
        client.save({"conanfile.py": GenConanfile()})
        num_references = 2
        for index in range(num_references):
            client.run('create . lib{}/1.0@user/channel'.format(index))
            self.assertIn(
                "lib{}/1.0@user/channel: Package '{}' created".format(
                    index, NO_SETTINGS_PACKAGE_ID), client.out)
        client.run('user -c')
        client.run('upload lib* --parallel -c --all -r default',
                   assert_error=True)
        self.assertIn(
            "ERROR: lib0/1.0@user/channel: Upload recipe to 'default' failed: "
            "Conan interactive mode disabled. [Remote: default]", client.out)

    def test_beat_character_long_upload(self):
        client = TestClient(default_server_user=True)
        slow_conanfile = textwrap.dedent("""
            from conans import ConanFile
            class MyPkg(ConanFile):
                exports = "*"
                def package(self):
                    self.copy("*")
            """)
        client.save({"conanfile.py": slow_conanfile, "hello.cpp": ""})
        client.run("create . pkg/0.1@user/stable")
        client.run("user user --password=password")
        with patch("conans.util.progress_bar.TIMEOUT_BEAT_SECONDS", -1):
            with patch("conans.util.progress_bar.TIMEOUT_BEAT_CHARACTER",
                       "%&$"):
                client.run("upload pkg/0.1@user/stable --all")
        out = "".join(str(client.out).splitlines())
        self.assertIn(
            "Compressing package...%&$%&$Uploading conan_package.tgz -> "
            "pkg/0.1@user/stable:5ab8", out)
        self.assertIn("%&$Uploading conan_export.tgz", out)
        self.assertIn("%&$Uploading conaninfo.txt", out)

    def test_upload_with_pattern_and_package_error(self):
        files = cpp_hello_conan_files("Hello1", "1.2.1")
        self.client.save(files)
        self.client.run("export . frodo/stable")

        self.client.run("upload Hello* --confirm -p 234234234",
                        assert_error=True)
        self.assertIn(
            "-p parameter only allowed with a valid recipe reference",
            self.client.out)

    def test_check_upload_confirm_question(self):
        user_io = MockedUserIO({"default": [("lasote", "mypass")]},
                               out=TestBufferConanOutput())
        files = cpp_hello_conan_files("Hello1", "1.2.1")
        self.client.save(files)
        self.client.run("export . frodo/stable")

        user_io.request_string = lambda _: "y"
        self.client.run("upload Hello*", user_io=user_io)
        self.assertIn("Uploading Hello1/1.2.1@frodo/stable", self.client.out)

        files = cpp_hello_conan_files("Hello2", "1.2.1")
        self.client.save(files)
        self.client.run("export . frodo/stable")

        user_io.request_string = lambda _: "n"
        self.client.run("upload Hello*", user_io=user_io)
        self.assertNotIn("Uploading Hello2/1.2.1@frodo/stable",
                         self.client.out)

    def test_upload_same_package_dont_compress(self):
        # Create a manifest for the faked package
        pack_path = self.client.cache.package_layout(self.pref.ref).package(
            self.pref)
        package_path = self.client.cache.package_layout(self.pref.ref).package(
            self.pref)
        expected_manifest = FileTreeManifest.create(package_path)
        expected_manifest.save(pack_path)

        self.client.run("upload %s --all" % str(self.ref))
        self.assertIn("Compressing recipe", self.client.out)
        self.assertIn("Compressing package", str(self.client.out))

        self.client.run("upload %s --all" % str(self.ref))
        self.assertNotIn("Compressing recipe", self.client.out)
        self.assertNotIn("Compressing package", str(self.client.out))
        self.assertIn("Package is up to date", str(self.client.out))

    def test_upload_with_no_valid_settings(self):
        # Check if upload is still working even if the specified setting is not valid.
        # If this test fails, will fail in Linux/OSx
        conanfile = """
from conans import ConanFile
class TestConan(ConanFile):
    name = "Hello"
    version = "1.2"
    settings = {"os": ["Windows"]}
"""
        files = {CONANFILE: conanfile}
        self.client.save(files)
        self.client.run("export . lasote/stable")
        self.assertIn("WARN: Conanfile doesn't have 'license'",
                      self.client.out)
        self.client.run("upload Hello/1.2@lasote/stable")
        self.assertIn("Uploading conanmanifest.txt", self.client.out)

    def test_single_binary(self):
        """ basic installation of a new conans
        """
        # Try to upload an package without upload conans first
        self.client.run('upload %s -p %s' % (self.ref, str(self.pref.id)))
        self.assertIn("Uploaded conan recipe '%s'" % str(self.ref),
                      self.client.out)

    def test_simple(self):
        # Upload package
        self.client.run('upload %s' % str(self.ref))
        self.server_reg_folder = self.test_server.server_store.export(self.ref)

        self.assertTrue(os.path.exists(self.server_reg_folder))
        if not self.client.cache.config.revisions_enabled:
            self.assertFalse(os.path.exists(self.server_pack_folder))

        # Upload package
        self.client.run('upload %s -p %s' % (str(self.ref), str(self.pref.id)))

        self.server_pack_folder = self.test_server.server_store.package(
            self.pref)

        self.assertTrue(os.path.exists(self.server_reg_folder))
        self.assertTrue(os.path.exists(self.server_pack_folder))

        # Test the file in the downloaded conans
        files = [
            'CMakeLists.txt', 'my_lib/debug/libd.a', 'hello.cpp', 'hello0.h',
            CONANFILE, CONAN_MANIFEST, 'main.cpp', 'include/math/lib1.h',
            'my_data/readme.txt', 'my_bin/executable'
        ]

        self.assertTrue(
            os.path.exists(os.path.join(self.server_reg_folder, CONANFILE)))
        self.assertTrue(
            os.path.exists(
                os.path.join(self.server_reg_folder, EXPORT_TGZ_NAME)))
        tmp = temp_folder()
        untargz(os.path.join(self.server_reg_folder, EXPORT_TGZ_NAME), tmp)
        for f in files:
            if f not in (CONANFILE, CONAN_MANIFEST):
                self.assertTrue(os.path.exists(os.path.join(tmp, f)))
            else:
                self.assertFalse(os.path.exists(os.path.join(tmp, f)))

        folder = uncompress_packaged_files(self.test_server.server_store,
                                           self.pref)

        self.assertTrue(
            os.path.exists(os.path.join(folder, "include", "lib1.h")))
        self.assertTrue(
            os.path.exists(os.path.join(folder, "lib", "my_lib/libd.a")))
        self.assertTrue(
            os.path.exists(os.path.join(folder, "res", "shares/readme.txt")))

        if platform.system() != "Windows":
            self.assertEqual(
                os.stat(os.path.join(folder, "bin",
                                     "my_bin/executable")).st_mode
                & stat.S_IRWXU, stat.S_IRWXU)

    def test_upload_all(self):
        """Upload conans and package together"""
        # Try to upload all conans and packages
        self.client.run('user -p mypass -r default lasote')
        self.client.run('upload %s --all' % str(self.ref))
        lines = [
            line.strip() for line in str(self.client.out).splitlines()
            if line.startswith("Uploading")
        ]
        self.assertEqual(lines, [
            "Uploading to remote 'default':",
            "Uploading Hello/1.2.1@frodo/stable to remote 'default'",
            "Uploading conan_export.tgz -> Hello/1.2.1@frodo/stable",
            "Uploading conanfile.py -> Hello/1.2.1@frodo/stable",
            "Uploading conanmanifest.txt -> Hello/1.2.1@frodo/stable",
            "Uploading package 1/1: myfakeid to 'default'",
            "Uploading conan_package.tgz -> Hello/1.2.1@frodo/stable:myfa",
            "Uploading conaninfo.txt -> Hello/1.2.1@frodo/stable:myfa",
            "Uploading conanmanifest.txt -> Hello/1.2.1@frodo/stable:myfa",
        ])
        if self.client.cache.config.revisions_enabled:
            layout = self.client.cache.package_layout(self.ref)
            rev = layout.recipe_revision()
            self.ref = self.ref.copy_with_rev(rev)
            prev = layout.package_revision(self.pref)
            self.pref = self.pref.copy_with_revs(rev, prev)

        server_reg_folder = self.test_server.server_store.export(self.ref)
        server_pack_folder = self.test_server.server_store.package(self.pref)

        self.assertTrue(os.path.exists(server_reg_folder))
        self.assertTrue(os.path.exists(server_pack_folder))

    def test_force(self):
        # Tries to upload a package exported after than remote version.
        # Upload all recipes and packages
        self.client.run('upload %s --all' % str(self.ref))

        if self.client.cache.config.revisions_enabled:
            layout = self.client.cache.package_layout(self.ref)
            rev = layout.recipe_revision()
            self.ref = self.ref.copy_with_rev(rev)
            prev = layout.package_revision(self.pref)
            self.pref = self.pref.copy_with_revs(rev, prev)

        self.server_reg_folder = self.test_server.server_store.export(self.ref)
        self.server_pack_folder = self.test_server.server_store.package(
            self.pref)

        self.assertTrue(os.path.exists(self.server_reg_folder))
        self.assertTrue(os.path.exists(self.server_pack_folder))

        # Fake datetime from exported date and upload again

        old_digest = self.client.cache.package_layout(
            self.ref).recipe_manifest()
        old_digest.file_sums["new_file"] = "012345"
        fake_digest = FileTreeManifest(2, old_digest.file_sums)
        fake_digest.save(self.client.cache.package_layout(self.ref).export())

        self.client.run('upload %s' % str(self.ref), assert_error=True)
        self.assertIn("Remote recipe is newer than local recipe",
                      self.client.out)

        self.client.run('upload %s --force' % str(self.ref))
        self.assertIn("Uploading %s" % str(self.ref), self.client.out)

        # Repeat transfer, to make sure it is uploading again
        self.client.run('upload %s --force' % str(self.ref))
        self.assertIn("Uploading conan_export.tgz", self.client.out)
        self.assertIn("Uploading conanfile.py", self.client.out)

    def test_upload_json(self):
        conanfile = """
from conans import ConanFile

class TestConan(ConanFile):
    name = "test"
    version = "0.1"

    def package(self):
        self.copy("mylib.so", dst="lib")
"""

        client = self._get_client()
        client.save({"conanfile.py": conanfile, "mylib.so": ""})
        client.run("create . danimtb/testing")

        # Test conflict parameter error
        client.run(
            "upload test/0.1@danimtb/* --all -p ewvfw --json upload.json",
            assert_error=True)

        json_path = os.path.join(client.current_folder, "upload.json")
        self.assertTrue(os.path.exists(json_path))
        json_content = load(json_path)
        output = json.loads(json_content)
        self.assertTrue(output["error"])
        self.assertEqual(0, len(output["uploaded"]))

        # Test invalid reference error
        client.run("upload fake/0.1@danimtb/testing --all --json upload.json",
                   assert_error=True)
        json_path = os.path.join(client.current_folder, "upload.json")
        self.assertTrue(os.path.exists(json_path))
        json_content = load(json_path)
        output = json.loads(json_content)
        self.assertTrue(output["error"])
        self.assertEqual(0, len(output["uploaded"]))

        # Test normal upload
        client.run("upload test/0.1@danimtb/testing --all --json upload.json")
        self.assertTrue(os.path.exists(json_path))
        json_content = load(json_path)
        output = json.loads(json_content)
        output_expected = {
            "error":
            False,
            "uploaded": [{
                "recipe": {
                    "id": "test/0.1@danimtb/testing",
                    "remote_url": "unknown",
                    "remote_name": "default",
                    "time": "unknown"
                },
                "packages": [{
                    "id": NO_SETTINGS_PACKAGE_ID,
                    "time": "unknown"
                }]
            }]
        }
        self.assertEqual(output_expected["error"], output["error"])
        self.assertEqual(len(output_expected["uploaded"]),
                         len(output["uploaded"]))

        for i, item in enumerate(output["uploaded"]):
            self.assertEqual(output_expected["uploaded"][i]["recipe"]["id"],
                             item["recipe"]["id"])
            self.assertEqual(
                output_expected["uploaded"][i]["recipe"]["remote_name"],
                item["recipe"]["remote_name"])
            for j, subitem in enumerate(item["packages"]):
                self.assertEqual(
                    output_expected["uploaded"][i]["packages"][j]["id"],
                    subitem["id"])
示例#51
0
    def setUp(self):
        hello_files = cpp_hello_conan_files("Hello")
        test_conanfile_contents = hello_files[CONANFILE]

        self.server_folder = temp_folder()
        test_server = TestServer(
            users={"fenix": "mypass"},
            base_path=self.server_folder)  # exported users and passwords
        self.server = test_server
        servers = {"default": test_server}
        client = TestClient(servers=servers,
                            users={"default": [("fenix", "mypass")]})

        # Conans with and without packages created
        self.root_folder = {
            "H1": 'Hello/1.4.10/fenix/testing',
            "H2": 'Hello/2.4.11/fenix/testing',
            "B": 'Bye/0.14/fenix/testing',
            "O": 'Other/1.2/fenix/testing'
        }

        files = {}
        pack_refs = []
        for key, folder in self.root_folder.items():
            ref = ConanFileReference.loads(folder)
            files["%s/%s/conanfile.py" %
                  (folder, EXPORT_FOLDER)] = test_conanfile_contents
            files["%s/%s/conanmanifest.txt" % (folder, EXPORT_FOLDER)] = ""
            files["%s/%s/conans.txt" % (folder, SRC_FOLDER)] = ""
            for pack_id in (1, 2):
                i = pack_id
                pack_id = "%s_%s" % (pack_id, key)
                pack_refs.append(PackageReference(ref, str(pack_id)))
                files["%s/%s/%s/conans.txt" %
                      (folder, BUILD_FOLDER, pack_id)] = ""
                files["%s/%s/%s/conans.txt" %
                      (folder, PACKAGES_FOLDER, pack_id)] = ""
                files["%s/%s/%s/%s" % (folder, PACKAGES_FOLDER, pack_id,
                                       CONANINFO)] = conaninfo % str(i)
                files["%s/%s/%s/%s" %
                      (folder, PACKAGES_FOLDER, pack_id, CONAN_MANIFEST)] = ""

            exports_sources_dir = client.client_cache.export_sources(ref)
            os.makedirs(exports_sources_dir)

        client.save(files, client.client_cache.store)

        # Create the manifests to be able to upload
        for pack_ref in pack_refs:
            pkg_folder = client.client_cache.package(pack_ref)
            expected_manifest = FileTreeManifest.create(pkg_folder)
            files["%s/%s/%s/%s" % ("/".join(
                pack_ref.conan), PACKAGES_FOLDER, pack_ref.package_id,
                                   CONAN_MANIFEST)] = str(expected_manifest)

        client.save(files, client.client_cache.store)

        self.client = client

        for folder in self.root_folder.values():
            client.run("upload %s --all" % folder.replace("/fenix", "@fenix"))

        self.assert_folders(
            {
                "H1": [1, 2],
                "H2": [1, 2],
                "B": [1, 2],
                "O": [1, 2]
            }, {
                "H1": [1, 2],
                "H2": [1, 2],
                "B": [1, 2],
                "O": [1, 2]
            }, {
                "H1": [1, 2],
                "H2": [1, 2],
                "B": [1, 2],
                "O": [1, 2]
            }, {
                "H1": True,
                "H2": True,
                "B": True,
                "O": True
            })
示例#52
0
    def assert_folders(self, local_folders, remote_folders, build_folders, src_folders):
        for base_path, folders in [(self.client.cache, local_folders),
                                   (self.server.server_store, remote_folders)]:
            root_folder = base_path.store
            for k, shas in folders.items():
                folder = os.path.join(root_folder, self.root_folder[k].replace("@", "/"))
                ref = ConanFileReference.loads(self.root_folder[k])
                if isinstance(base_path, ServerStore):
                    if self.client.cache.config.revisions_enabled:
                        try:
                            rev = self.client.cache.package_layout(ref).recipe_revision()
                        except:
                            # This whole test is a crap, we cannot guess remote revision
                            # if the package is not in local anymore
                            continue
                    else:
                        rev = DEFAULT_REVISION_V1
                    folder += "/%s" % rev
                if shas is None:
                    self.assertFalse(os.path.exists(folder))
                else:
                    for value in (1, 2):
                        sha = "%s_%s" % (value, k)
                        package_folder = os.path.join(folder, "package", sha)
                        if isinstance(base_path, ServerStore):
                            if self.client.cache.config.revisions_enabled:
                                pref = PackageReference(ref, sha)
                                try:
                                    layout = self.client.cache.package_layout(pref.ref)
                                    prev = layout.package_revision(pref)
                                except:
                                    # This whole test is a crap, we cannot guess remote revision
                                    # if the package is not in local anymore
                                    continue
                            else:
                                prev = DEFAULT_REVISION_V1
                            package_folder += "/%s" % prev if prev else ""
                        if value in shas:
                            self.assertTrue(os.path.exists(package_folder),
                                            "%s doesn't exist " % package_folder)
                        else:
                            self.assertFalse(os.path.exists(package_folder), package_folder)

        root_folder = self.client.cache.store
        for k, shas in build_folders.items():
            folder = os.path.join(root_folder, self.root_folder[k].replace("@", "/"))
            if shas is None:
                self.assertFalse(os.path.exists(folder))
            else:
                for value in (1, 2):
                    sha = "%s_%s" % (value, k)
                    build_folder = os.path.join(folder, "build", sha)
                    if value in shas:
                        self.assertTrue(os.path.exists(build_folder))
                    else:
                        self.assertFalse(os.path.exists(build_folder))
        for k, value in src_folders.items():
            folder = os.path.join(root_folder, self.root_folder[k].replace("@", "/"), "source")
            if value:
                self.assertTrue(os.path.exists(folder))
            else:
                self.assertFalse(os.path.exists(folder))
示例#53
0
    def cmake_paths_integration_test(self):
        """First package with own findHello0.cmake file"""
        client = TestClient()
        conanfile = """from conans import ConanFile
class TestConan(ConanFile):
    name = "Hello0"
    version = "0.1"
    exports = "*"

    def package(self):
        self.copy(pattern="*", keep_path=False)

"""
        files = {
            "conanfile.py":
            conanfile,
            "FindHello0.cmake":
            """
SET(Hello0_FOUND 1)
MESSAGE("HELLO FROM THE Hello0 FIND PACKAGE!")
MESSAGE("ROOT PATH: ${CONAN_HELLO0_ROOT}")
"""
        }
        client.save(files)
        client.run("create . user/channel")

        # Directly using CMake as a consumer we can find it with the "cmake_paths" generator
        files = {
            "CMakeLists.txt":
            """
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_ABI_COMPILED 1)
project(MyHello CXX)
cmake_minimum_required(VERSION 2.8)

find_package(Hello0 REQUIRED)

"""
        }
        client.save(files, clean_first=True)
        client.run("install Hello0/0.1@user/channel -g cmake_paths")
        self.assertTrue(
            os.path.exists(
                os.path.join(client.current_folder, "conan_paths.cmake")))
        # Without the toolchain we cannot find the package
        build_dir = os.path.join(client.current_folder, "build")
        os.mkdir(build_dir)
        with client.chdir(build_dir):
            client.run_command("cmake ..", assert_error=True)
        shutil.rmtree(build_dir)

        # With the toolchain everything is ok
        os.mkdir(build_dir)
        with client.chdir(build_dir):
            client.run_command(
                "cmake .. -DCMAKE_TOOLCHAIN_FILE=../conan_paths.cmake")
        self.assertIn("HELLO FROM THE Hello0 FIND PACKAGE!", client.out)
        ref = ConanFileReference.loads("Hello0/0.1@user/channel")
        pref = PackageReference(ref, NO_SETTINGS_PACKAGE_ID)
        package_folder = client.cache.package_layout(ref).package(pref)
        # Check that the CONAN_HELLO0_ROOT has been replaced with the real abs path
        self.assertIn("ROOT PATH: %s" % package_folder.replace("\\", "/"),
                      client.out)

        # Now try without toolchain but including the file
        files = {
            "CMakeLists.txt":
            """
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_ABI_COMPILED 1)
project(MyHello CXX)
cmake_minimum_required(VERSION 2.8)
include(${CMAKE_BINARY_DIR}/../conan_paths.cmake)

find_package(Hello0 REQUIRED)

"""
        }
        client.save(files, clean_first=True)
        os.mkdir(build_dir)
        client.run("install Hello0/0.1@user/channel -g cmake_paths")
        client.run_command("cmake .. ", cwd=build_dir)
        self.assertIn("HELLO FROM THE Hello0 FIND PACKAGE!", client.out)
示例#54
0
    def build_vs_project_test(self):
        conan_build_vs = """
from conans import ConanFile, MSBuild

class HelloConan(ConanFile):
    name = "Hello"
    version = "1.2.1"
    exports = "*"
    settings = "os", "build_type", "arch", "compiler", "cppstd"

    def build(self):
        msbuild = MSBuild(self)
        msbuild.build("MyProject.sln")

    def package(self):
        self.copy(pattern="*.exe")
"""
        client = TestClient()

        # Test cpp standard stuff

        files = get_vs_project_files(std="cpp17_2015")
        files[CONANFILE] = conan_build_vs

        client.save(files)
        client.run(
            'create . Hello/1.2.1@lasote/stable -s cppstd=11 -s '
            'compiler="Visual Studio" -s compiler.version=14',
            assert_error=True)
        client.run('create . Hello/1.2.1@lasote/stable -s cppstd=17 '
                   '-s compiler="Visual Studio" -s compiler.version=14')
        self.assertIn("Copied 1 '.exe' file: MyProject.exe",
                      client.user_io.out)

        files = get_vs_project_files()
        files[CONANFILE] = conan_build_vs

        # Try to not update the project
        client.client_cache._conan_config = None  # Invalidate cached config
        tools.replace_in_file(client.client_cache.conan_conf_path, "[general]",
                              "[general]\nskip_vs_projects_upgrade = True")
        client.save(files, clean_first=True)
        client.run("create . Hello/1.2.1@lasote/stable --build")
        self.assertNotIn("devenv", client.user_io.out)
        self.assertIn("Skipped sln project upgrade", client.user_io.out)

        # Try with x86_64
        client.save(files)
        client.run("export . lasote/stable")
        client.run("install Hello/1.2.1@lasote/stable --build -s arch=x86_64")
        self.assertIn("Release|x64", client.user_io.out)
        self.assertIn("Copied 1 '.exe' file: MyProject.exe",
                      client.user_io.out)

        # Try with x86
        client.save(files, clean_first=True)
        client.run("export . lasote/stable")
        client.run("install Hello/1.2.1@lasote/stable --build -s arch=x86")
        self.assertIn("Release|x86", client.user_io.out)
        self.assertIn("Copied 1 '.exe' file: MyProject.exe",
                      client.user_io.out)

        # Try with x86 debug
        client.save(files, clean_first=True)
        client.run("export . lasote/stable")
        client.run(
            "install Hello/1.2.1@lasote/stable --build -s arch=x86 -s build_type=Debug"
        )
        self.assertIn("Debug|x86", client.user_io.out)
        self.assertIn("Copied 1 '.exe' file: MyProject.exe",
                      client.user_io.out)

        # Try with a custom property file name
        files[CONANFILE] = conan_build_vs.replace(
            'msbuild.build("MyProject.sln")', 'msbuild.build("MyProject.sln", '
            'property_file_name="myprops.props")')
        client.save(files, clean_first=True)
        client.run(
            "create . Hello/1.2.1@lasote/stable --build -s arch=x86 -s build_type=Debug"
        )
        self.assertIn("Debug|x86", client.user_io.out)
        self.assertIn("Copied 1 '.exe' file: MyProject.exe",
                      client.user_io.out)
        full_ref = "Hello/1.2.1@lasote/stable:b786e9ece960c3a76378ca4d5b0d0e922f4cedc1"
        pref = PackageReference.loads(full_ref)
        build_folder = client.client_cache.build(pref)
        self.assertTrue(
            os.path.exists(os.path.join(build_folder, "myprops.props")))