Ejemplo n.º 1
0
    def test_reuse(self):
        self._create("Hello0", "0.1")
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"])
        self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False)

        for lang, id0, id1 in [(0, "2e38bbc2c3ef1425197c8e2ffa8532894c347d26",
                                   "44671ecdd9c606eb7166f2197ab50be8d36a3c3b"),
                               (1, "8b964e421a5b7e48b7bc19b94782672be126be8b",
                                   "3eeab577a3134fa3afdcd82881751789ec48e08f")]:

            self.client.run("install . -o language=%d %s --build missing" % (lang, self.settings))
            self.assertIn("Configuration:[settings]", "".join(str(self.client.out).splitlines()))
            info_path = os.path.join(self.client.current_folder, CONANINFO)
            conan_info = ConanInfo.load_file(info_path)
            self.assertEqual("arch=x86\n"
                             "compiler=Visual Studio\n"
                             "compiler.runtime=MD\n"
                             "compiler.version=12\n"
                             "os=Windows",
                             conan_info.settings.dumps())
            self.assertEqual("language=%s\nstatic=True" % lang, conan_info.options.dumps())
            ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

            hello0 = self.client.cache.package_layout(ref).package(PackageReference(ref, id0))
            hello0_info = os.path.join(hello0, CONANINFO)
            hello0_conan_info = ConanInfo.load_file(hello0_info)
            self.assertEqual(lang, hello0_conan_info.options.language)

            pref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"), id1)
            hello1 = self.client.cache.package_layout(pref1.ref).package(pref1)
            hello1_info = os.path.join(hello1, CONANINFO)
            hello1_conan_info = ConanInfo.load_file(hello1_info)
            self.assertEqual(lang, hello1_conan_info.options.language)
Ejemplo n.º 2
0
    def test_upper_option_txt(self):
        self._create("Hello0", "0.1", no_config=True)
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True)

        files = cpp_hello_conan_files("Hello2", "0.1", ["Hello1/0.1@lasote/stable"])
        files.pop(CONANFILE)
        files[CONANFILE_TXT] = """[requires]
        Hello1/0.1@lasote/stable

        [options]
        Hello0:language=1
        Hello1:language=0
        """
        self.client.save(files, clean_first=True)

        self.client.run("install . %s --build missing" % self.settings)
        info_path = os.path.join(self.client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
        pref = PackageReference(ref, "8b964e421a5b7e48b7bc19b94782672be126be8b")
        hello0 = self.client.cache.package_layout(ref).package(pref)
        hello0_info = os.path.join(hello0, CONANINFO)
        hello0_conan_info = ConanInfo.load_file(hello0_info)
        self.assertEqual(1, hello0_conan_info.options.language)

        pref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"),
                                 "44671ecdd9c606eb7166f2197ab50be8d36a3c3b")
        hello1 = self.client.cache.package_layout(pref1.ref).package(pref1)
        hello1_info = os.path.join(hello1, CONANINFO)
        hello1_conan_info = ConanInfo.load_file(hello1_info)
        self.assertEqual(0, hello1_conan_info.options.language)
Ejemplo n.º 3
0
    def test_inverse_upper_option(self):
        self._create("Hello0", "0.1", no_config=True)
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True)
        self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False, no_config=True)

        self.client.run("install . -o language=0 -o Hello1:language=1 -o Hello0:language=0 %s "
                        "--build missing" % self.settings)
        info_path = os.path.join(self.client.current_folder, CONANINFO)

        conan_info = ConanInfo.load_file(info_path)

        self.assertEqual("language=0\nstatic=True", conan_info.options.dumps())
        ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
        pref = PackageReference(ref, "2e38bbc2c3ef1425197c8e2ffa8532894c347d26")
        hello0 = self.client.cache.package_layout(ref).package(pref)

        hello0_info = os.path.join(hello0, CONANINFO)
        hello0_conan_info = ConanInfo.load_file(hello0_info)
        self.assertEqual("language=0\nstatic=True", hello0_conan_info.options.dumps())

        pref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"),
                                 "3eeab577a3134fa3afdcd82881751789ec48e08f")
        hello1 = self.client.cache.package_layout(pref1.ref).package(pref1)
        hello1_info = os.path.join(hello1, CONANINFO)
        hello1_conan_info = ConanInfo.load_file(hello1_info)
        self.assertEqual("language=1\nstatic=True", hello1_conan_info.options.dumps())
Ejemplo n.º 4
0
    def change_option_txt_test(self):
        self._create("Hello0", "0.1")

        client = TestClient(base_folder=self.client.base_folder)
        files = {CONANFILE_TXT: """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=1
        """}
        client.save(files)

        client.run("install %s --build missing" % self.settings)
        info_path = os.path.join(client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        self.assertIn("Hello0:language=1", conan_info.full_options.dumps())
        self.assertIn("Hello0/0.1@lasote/stable:8b964e421a5b7e48b7bc19b94782672be126be8b",
                      conan_info.full_requires.dumps())

        files = {CONANFILE_TXT: """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=0
        """}
        client.save(files)
        client.run("install %s --build missing" % self.settings)

        info_path = os.path.join(client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        self.assertIn("Hello0:language=0", conan_info.full_options.dumps())
        self.assertIn("Hello0/0.1@lasote/stable:2e38bbc2c3ef1425197c8e2ffa8532894c347d26",
                      conan_info.full_requires.dumps())
Ejemplo n.º 5
0
    def reuse_test(self):
        self._create("Hello0", "0.1")
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"])
        self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False)

        for lang, id0, id1 in [(0, "2e38bbc2c3ef1425197c8e2ffa8532894c347d26",
                                   "44671ecdd9c606eb7166f2197ab50be8d36a3c3b"),
                               (1, "8b964e421a5b7e48b7bc19b94782672be126be8b",
                                   "3eeab577a3134fa3afdcd82881751789ec48e08f")]:

            self.client.run("install -o language=%d %s --build missing" % (lang, self.settings))
            info_path = os.path.join(self.client.current_folder, CONANINFO)
            conan_info = ConanInfo.load_file(info_path)
            self.assertEqual("arch=x86\n"
                             "compiler=Visual Studio\n"
                             "compiler.runtime=MD\n"
                             "compiler.version=12\n"
                             "os=Windows",
                             conan_info.settings.dumps())
            self.assertEqual("language=%s\nstatic=True" % lang, conan_info.options.dumps())
            conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

            hello0 = self.client.paths.package(PackageReference(conan_ref, id0))
            hello0_info = os.path.join(hello0, CONANINFO)
            hello0_conan_info = ConanInfo.load_file(hello0_info)
            self.assertEqual(lang, hello0_conan_info.options.language)

            package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"),
                                            id1)
            hello1 = self.client.paths.package(package_ref1)
            hello1_info = os.path.join(hello1, CONANINFO)
            hello1_conan_info = ConanInfo.load_file(hello1_info)
            self.assertEqual(lang, hello1_conan_info.options.language)
Ejemplo n.º 6
0
    def inverse_upper_option_test(self):
        self._create("Hello0", "0.1", no_config=True)
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True)
        self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False, no_config=True)

        self.client.run("install -o language=0 -o Hello1:language=1 -o Hello0:language=0 %s "
                        "--build missing" % self.settings)
        info_path = os.path.join(self.client.current_folder, CONANINFO)

        conan_info = ConanInfo.load_file(info_path)

        self.assertEqual("language=0\nstatic=True", conan_info.options.dumps())
        conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

        hello0 = self.client.paths.package(PackageReference(conan_ref,
                                           "2e38bbc2c3ef1425197c8e2ffa8532894c347d26"))
        hello0_info = os.path.join(hello0, CONANINFO)
        hello0_conan_info = ConanInfo.load_file(hello0_info)
        self.assertEqual("language=0\nstatic=True", hello0_conan_info.options.dumps())

        package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"),
                                        "3eeab577a3134fa3afdcd82881751789ec48e08f")
        hello1 = self.client.paths.package(package_ref1)
        hello1_info = os.path.join(hello1, CONANINFO)
        hello1_conan_info = ConanInfo.load_file(hello1_info)
        self.assertEqual("language=1\nstatic=True", hello1_conan_info.options.dumps())
Ejemplo n.º 7
0
    def upper_option_txt_test(self):
        self._create("Hello0", "0.1", no_config=True)
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True)

        files = cpp_hello_conan_files("Hello2", "0.1", ["Hello1/0.1@lasote/stable"])
        files.pop(CONANFILE)
        files[CONANFILE_TXT] = """[requires]
        Hello1/0.1@lasote/stable

        [options]
        Hello0:language=1
        Hello1:language=0
        """
        self.client.save(files, clean_first=True)

        self.client.run("install %s --build missing" % self.settings)
        info_path = os.path.join(self.client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

        hello0 = self.client.paths.package(PackageReference(conan_ref,
                                           "8b964e421a5b7e48b7bc19b94782672be126be8b"))
        hello0_info = os.path.join(hello0, CONANINFO)
        hello0_conan_info = ConanInfo.load_file(hello0_info)
        self.assertEqual(1, hello0_conan_info.options.language)

        package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"),
                                        "44671ecdd9c606eb7166f2197ab50be8d36a3c3b")
        hello1 = self.client.paths.package(package_ref1)
        hello1_info = os.path.join(hello1, CONANINFO)
        hello1_conan_info = ConanInfo.load_file(hello1_info)
        self.assertEqual(0, hello1_conan_info.options.language)
def test_reuse(client):
    for lang, id0, id1 in [(0, "3475bd55b91ae904ac96fde0f106a136ab951a5e",
                            "5faecfb46fd09e49f1812d732d6360bc1663e3ab"),
                           (1, "f43bd822487baa4ed2426c279c27b2811870499a",
                            "b96337c5fcdafd6533298017c2ba94812654f8ec")]:

        client.run("install . -o *:language=%d --build missing" % lang)
        assert "Configuration:[settings]", "".join(
            str(client.out).splitlines())
        info_path = os.path.join(client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        assert "os=Windows" == conan_info.settings.dumps()
        assert "language=%s" % lang, conan_info.options.dumps()
        ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

        hello0 = client.cache.package_layout(ref).package(
            PackageReference(ref, id0))
        hello0_info = os.path.join(hello0, CONANINFO)
        hello0_conan_info = ConanInfo.load_file(hello0_info)
        assert lang == hello0_conan_info.options.language

        pref1 = PackageReference(
            ConanFileReference.loads("Hello1/0.1@lasote/stable"), id1)
        hello1 = client.cache.package_layout(pref1.ref).package(pref1)
        hello1_info = os.path.join(hello1, CONANINFO)
        hello1_conan_info = ConanInfo.load_file(hello1_info)
        assert lang == hello1_conan_info.options.language
def test_upper_option(client):
    client.run(
        "install conanfile.py -o Hello2:language=1 -o Hello1:language=0 "
        "-o Hello0:language=1 --build missing")
    package_id = re.search(r"Hello0/0.1@lasote/stable:(\S+)",
                           str(client.out)).group(1)
    package_id2 = re.search(r"Hello1/0.1@lasote/stable:(\S+)",
                            str(client.out)).group(1)
    info_path = os.path.join(client.current_folder, CONANINFO)
    conan_info = ConanInfo.load_file(info_path)
    assert "language=1" == conan_info.options.dumps()
    ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

    pref = PackageReference(ref, package_id)
    hello0 = client.cache.package_layout(ref).package(pref)

    hello0_info = os.path.join(hello0, CONANINFO)
    hello0_conan_info = ConanInfo.load_file(hello0_info)
    assert 1 == hello0_conan_info.options.language

    pref1 = PackageReference(
        ConanFileReference.loads("Hello1/0.1@lasote/stable"), package_id2)
    hello1 = client.cache.package_layout(pref1.ref).package(pref1)
    hello1_info = os.path.join(hello1, CONANINFO)
    hello1_conan_info = ConanInfo.load_file(hello1_info)
    assert 0 == hello1_conan_info.options.language
def test_upper_option_txt(client):
    files = {
        CONANFILE_TXT:
        """[requires]
        Hello1/0.1@lasote/stable

        [options]
        Hello0:language=1
        Hello1:language=0
        """
    }
    client.save(files, clean_first=True)

    client.run("install . --build missing")
    package_id = re.search(r"Hello0/0.1@lasote/stable:(\S+)",
                           str(client.out)).group(1)
    package_id2 = re.search(r"Hello1/0.1@lasote/stable:(\S+)",
                            str(client.out)).group(1)
    info_path = os.path.join(client.current_folder, CONANINFO)
    conan_info = ConanInfo.load_file(info_path)
    assert "" == conan_info.options.dumps()
    ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
    pref = PackageReference(ref, package_id)
    hello0 = client.cache.package_layout(ref).package(pref)
    hello0_info = os.path.join(hello0, CONANINFO)
    hello0_conan_info = ConanInfo.load_file(hello0_info)
    assert 1 == hello0_conan_info.options.language

    pref1 = PackageReference(
        ConanFileReference.loads("Hello1/0.1@lasote/stable"), package_id2)
    hello1 = client.cache.package_layout(pref1.ref).package(pref1)
    hello1_info = os.path.join(hello1, CONANINFO)
    hello1_conan_info = ConanInfo.load_file(hello1_info)
    assert 0 == hello1_conan_info.options.language
Ejemplo n.º 11
0
    def upper_option_test(self):
        self._create("Hello0", "0.1", no_config=True)
        self._create("Hello1",
                     "0.1", ["Hello0/0.1@lasote/stable"],
                     no_config=True)
        self._create("Hello2",
                     "0.1", ["Hello1/0.1@lasote/stable"],
                     export=False,
                     no_config=True)

        self.client.run(
            "install conanfile.py -o Hello2:language=1 -o Hello1:language=0 "
            "-o Hello0:language=1 %s --build missing" % self.settings)
        info_path = os.path.join(self.client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("language=1\nstatic=True", conan_info.options.dumps())
        conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

        hello0 = self.client.client_cache.package(
            PackageReference(conan_ref,
                             "8b964e421a5b7e48b7bc19b94782672be126be8b"))
        hello0_info = os.path.join(hello0, CONANINFO)
        hello0_conan_info = ConanInfo.load_file(hello0_info)
        self.assertEqual(1, hello0_conan_info.options.language)

        package_ref1 = PackageReference(
            ConanFileReference.loads("Hello1/0.1@lasote/stable"),
            "44671ecdd9c606eb7166f2197ab50be8d36a3c3b")
        hello1 = self.client.client_cache.package(package_ref1)
        hello1_info = os.path.join(hello1, CONANINFO)
        hello1_conan_info = ConanInfo.load_file(hello1_info)
        self.assertEqual(0, hello1_conan_info.options.language)
Ejemplo n.º 12
0
def test_upper_option_txt(client):
    files = {
        CONANFILE_TXT:
        """[requires]
        Hello1/0.1@lasote/stable

        [options]
        Hello0:language=1
        Hello1:language=0
        """
    }
    client.save(files, clean_first=True)

    client.run("install . --build missing")
    info_path = os.path.join(client.current_folder, CONANINFO)
    conan_info = ConanInfo.load_file(info_path)
    assert "" == conan_info.options.dumps()
    ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
    pref = PackageReference(ref, "f43bd822487baa4ed2426c279c27b2811870499a")
    hello0 = client.cache.package_layout(ref).package(pref)
    hello0_info = os.path.join(hello0, CONANINFO)
    hello0_conan_info = ConanInfo.load_file(hello0_info)
    assert 1 == hello0_conan_info.options.language

    pref1 = PackageReference(
        ConanFileReference.loads("Hello1/0.1@lasote/stable"),
        "5faecfb46fd09e49f1812d732d6360bc1663e3ab")
    hello1 = client.cache.package_layout(pref1.ref).package(pref1)
    hello1_info = os.path.join(hello1, CONANINFO)
    hello1_conan_info = ConanInfo.load_file(hello1_info)
    assert 0 == hello1_conan_info.options.language
Ejemplo n.º 13
0
    def change_option_txt_test(self):
        self._create("Hello0", "0.1")

        # Do not adjust cpu_count, it is reusing a cache
        client = TestClient(base_folder=self.client.base_folder,
                            cpu_count=False)
        files = {
            CONANFILE_TXT:
            """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=1
        """
        }
        client.save(files)

        client.run("install conanfile.txt %s --build missing" % self.settings)
        info_path = os.path.join(client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        self.assertIn("Hello0:language=1", conan_info.full_options.dumps())
        self.assertIn(
            "Hello0/0.1@lasote/stable:8b964e421a5b7e48b7bc19b94782672be126be8b",
            conan_info.full_requires.dumps())

        files = {
            CONANFILE_TXT:
            """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=0
        """
        }
        client.save(files)
        client.run("install . %s --build missing" % self.settings)

        info_path = os.path.join(client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        # For conan install options are not cached anymore
        self.assertIn("Hello0:language=0", conan_info.full_options.dumps())

        # it is necessary to clean the cached conaninfo
        client.save(files, clean_first=True)
        client.run("install ./conanfile.txt %s --build missing" %
                   self.settings)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        self.assertIn("Hello0:language=0", conan_info.full_options.dumps())
        self.assertIn(
            "Hello0/0.1@lasote/stable:2e38bbc2c3ef1425197c8e2ffa8532894c347d26",
            conan_info.full_requires.dumps())
def test_change_option_txt(client):
    # Do not adjust cpu_count, it is reusing a cache
    client = TestClient(cache_folder=client.cache_folder, cpu_count=False)
    files = {
        CONANFILE_TXT:
        """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=1
        """
    }
    client.save(files)

    client.run("install conanfile.txt --build missing")
    info_path = os.path.join(client.current_folder, CONANINFO)
    conan_info = ConanInfo.load_file(info_path)
    assert "" == conan_info.options.dumps()
    assert "Hello0:language=1" == conan_info.full_options.dumps()
    assert "Hello0/0.1@lasote/stable:f43bd822487baa4ed2426c279c27b2811870499a" ==\
           conan_info.full_requires.dumps()

    files = {
        CONANFILE_TXT:
        """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=0
        """
    }
    client.save(files)
    client.run("install . --build missing")

    info_path = os.path.join(client.current_folder, CONANINFO)
    conan_info = ConanInfo.load_file(info_path)
    assert "" == conan_info.options.dumps()
    # For conan install options are not cached anymore
    assert "Hello0:language=0" == conan_info.full_options.dumps()

    # it is necessary to clean the cached conaninfo
    client.save(files, clean_first=True)
    client.run("install ./conanfile.txt --build missing")
    conan_info = ConanInfo.load_file(info_path)
    assert "" == conan_info.options.dumps()
    assert "Hello0:language=0" == conan_info.full_options.dumps()
    assert "Hello0/0.1@lasote/stable:3475bd55b91ae904ac96fde0f106a136ab951a5e" \
           == conan_info.full_requires.dumps()
Ejemplo n.º 15
0
    def _loader(self, conan_info_path=None, profile=None):
        # The disk settings definition, already including the default disk values
        settings = self._client_cache.settings
        mixed_profile = Profile()
        if profile is None:
            if conan_info_path and os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                mixed_profile.options = existing_info.full_options
                mixed_profile.scopes = existing_info.scope
                mixed_profile.env_values = existing_info.env_values
        else:
            mixed_profile.env_values.update(profile.env_values)
            settings.values = profile.settings_values
            if profile.scopes:
                mixed_profile.scopes.update_scope(profile.scopes)
            mixed_profile.options.update(profile.options)
            for pkg, pkg_settings in profile.package_settings.items():
                mixed_profile.package_settings[pkg].update(pkg_settings)

        self._current_scopes = mixed_profile.scopes
        return ConanFileLoader(
            self._runner,
            settings=settings,
            package_settings=mixed_profile.package_settings_values,
            options=mixed_profile.options,
            scopes=mixed_profile.scopes,
            env_values=mixed_profile.env_values)
Ejemplo n.º 16
0
    def _loader(self,
                current_path=None,
                user_settings_values=None,
                user_options_values=None):
        # The disk settings definition, already including the default disk values
        settings = self._paths.settings
        options = OptionsValues()

        if current_path:
            conan_info_path = os.path.join(current_path, CONANINFO)
            if os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                options = existing_info.full_options  # Take existing options from conaninfo.txt

        if user_settings_values:
            aux_values = Values.from_list(user_settings_values)
            settings.values = aux_values

        if user_options_values is not None:  # Install will pass an empty list []
            # Install OVERWRITES options, existing options in CONANINFO are not taken
            # into account, just those from CONANFILE + user command line
            options = OptionsValues.from_list(user_options_values)

        return ConanFileLoader(self._runner, settings, options=options)
Ejemplo n.º 17
0
    def _loader(self, current_path=None, user_settings_values=None, package_settings=None,
                user_options_values=None, scopes=None, env_values=None, use_conaninfo=True):

        # The disk settings definition, already including the default disk values
        settings = self._client_cache.settings

        conaninfo_scopes = Scopes()
        user_options = OptionsValues(user_options_values)
        mixed_env_values = EnvValues()
        mixed_env_values.update(env_values)

        if current_path:
            conan_info_path = os.path.join(current_path, CONANINFO)
            if use_conaninfo and os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                options = existing_info.full_options  # Take existing options from conaninfo.txt
                options.update(user_options)
                user_options = options
                conaninfo_scopes = existing_info.scope
                # Update with info (prioritize user input)
                mixed_env_values.update(existing_info.env_values)

        if user_settings_values:
            aux_values = Values.from_list(user_settings_values)
            settings.values = aux_values

        if scopes:
            conaninfo_scopes.update_scope(scopes)

        self._current_scopes = conaninfo_scopes
        return ConanFileLoader(self._runner, settings, package_settings=package_settings,
                               options=user_options, scopes=conaninfo_scopes,
                               env_values=mixed_env_values)
Ejemplo n.º 18
0
    def _loader(self, current_path=None, user_settings_values=None, user_options_values=None,
                scopes=None):
        # The disk settings definition, already including the default disk values
        settings = self._paths.settings
        options = OptionsValues()
        conaninfo_scopes = Scopes()

        if current_path:
            conan_info_path = os.path.join(current_path, CONANINFO)
            if os.path.exists(conan_info_path):
                existing_info = ConanInfo.load_file(conan_info_path)
                settings.values = existing_info.full_settings
                options = existing_info.full_options  # Take existing options from conaninfo.txt
                conaninfo_scopes = existing_info.scope

        if user_settings_values:
            aux_values = Values.from_list(user_settings_values)
            settings.values = aux_values

        if user_options_values is not None:  # Install will pass an empty list []
            # Install OVERWRITES options, existing options in CONANINFO are not taken
            # into account, just those from CONANFILE + user command line
            options = OptionsValues.from_list(user_options_values)

        if scopes:
            conaninfo_scopes.update_scope(scopes)

        self._current_scopes = conaninfo_scopes
        return ConanFileLoader(self._runner, settings, options=options, scopes=conaninfo_scopes)
Ejemplo n.º 19
0
    def package_available(self, package_ref, package_folder, check_outdated):
        """
        Returns True if there is a local or remote package available (and up to date if check_outdated).
        It wont download the package, just check its hash
        """

        output = ScopedOutput(str(package_ref.conan), self._out)
        remote_info = None
        # No package in local cache
        if not os.path.exists(package_folder):
            try:
                # NOTE This call can associate a recently exported recipe, with anything
                # to a remote containing the recipe reference
                remote_info = self._get_package_info(package_ref)
            except (NotFoundException, NoRemoteAvailable):  # 404 or no remote
                return False

        # Maybe we have the package (locally or in remote) but it's outdated
        if check_outdated:
            if remote_info:
                package_hash = remote_info.recipe_hash
            else:
                package_hash = ConanInfo.load_file(os.path.join(package_folder, CONANINFO)).recipe_hash
            local_recipe_hash = self._client_cache.load_manifest(package_ref.conan).summary_hash
            up_to_date = local_recipe_hash == package_hash
            if not up_to_date:
                output.info("Outdated package!")
            else:
                output.info("Package is up to date")
            return up_to_date

        return True
Ejemplo n.º 20
0
def read_conaninfo_profile(current_path):
    conan_info_path = os.path.join(current_path, CONANINFO)
    if not os.path.exists(conan_info_path):
        return None
    existing_info = ConanInfo.load_file(conan_info_path)
    profile = Profile()
    profile.settings = OrderedDict(existing_info.full_settings.as_list())
    profile.options = existing_info.full_options
    profile.env_values = existing_info.env_values
    return profile
Ejemplo n.º 21
0
def read_conaninfo_profile(current_path):
    conan_info_path = os.path.join(current_path, CONANINFO)
    if not os.path.exists(conan_info_path):
        return None
    existing_info = ConanInfo.load_file(conan_info_path)
    profile = Profile()
    profile.settings = OrderedDict(existing_info.full_settings.as_list())
    profile.options = existing_info.full_options
    profile.env_values = existing_info.env_values
    return profile
Ejemplo n.º 22
0
    def change_option_txt_test(self):
        self._create("Hello0", "0.1")

        client = TestClient(base_folder=self.client.base_folder)
        files = {
            CONANFILE_TXT:
            """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=1
        """
        }
        client.save(files)

        client.run("install %s --build missing" % self.settings)
        info_path = os.path.join(client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        self.assertIn("Hello0:language=1", conan_info.full_options.dumps())
        self.assertIn(
            "Hello0/0.1@lasote/stable:8b964e421a5b7e48b7bc19b94782672be126be8b",
            conan_info.full_requires.dumps())

        files = {
            CONANFILE_TXT:
            """[requires]
        Hello0/0.1@lasote/stable

        [options]
        Hello0:language=0
        """
        }
        client.save(files)
        client.run("install %s --build missing" % self.settings)

        info_path = os.path.join(client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("", conan_info.options.dumps())
        self.assertIn("Hello0:language=0", conan_info.full_options.dumps())
        self.assertIn(
            "Hello0/0.1@lasote/stable:2e38bbc2c3ef1425197c8e2ffa8532894c347d26",
            conan_info.full_requires.dumps())
Ejemplo n.º 23
0
    def reuse_test(self):
        self._create("Hello0", "0.1")
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"])
        self._create("Hello2",
                     "0.1", ["Hello1/0.1@lasote/stable"],
                     export=False)

        current_folder = self.client.current_folder
        h00 = "2e38bbc2c3ef1425197c8e2ffa8532894c347d26"
        h10 = "44671ecdd9c606eb7166f2197ab50be8d36a3c3b"
        h01 = "8b964e421a5b7e48b7bc19b94782672be126be8b"
        h11 = "3eeab577a3134fa3afdcd82881751789ec48e08f"
        for lang, id0, id1, id2, id3 in [(0, h00, h10, h01, h11),
                                         (1, h01, h11, h00, h10)]:
            self.client.current_folder = os.path.join(current_folder,
                                                      "lang%dbuild" % lang)
            mkdir(self.client.current_folder)
            self.client.run("install .. -o language=%d %s --build missing" %
                            (lang, self.settings))
            info_path = os.path.join(self.client.current_folder, CONANINFO)
            conan_info = ConanInfo.load_file(info_path)
            self.assertEqual(
                "arch=x86\n"
                "compiler=Visual Studio\n"
                "compiler.runtime=MD\n"
                "compiler.version=12\n"
                "os=Windows", conan_info.settings.dumps())
            conan_info_text = load(info_path)
            self.assertIn(id0, conan_info_text)
            self.assertIn(id1, conan_info_text)
            self.assertNotIn(id2, conan_info_text)
            self.assertNotIn(id3, conan_info_text)
            self.assertEqual("language=%s\nstatic=True" % lang,
                             conan_info.options.dumps())
            build_cmake = os.path.join(self.client.current_folder,
                                       BUILD_INFO_CMAKE)
            build_cmake_text = load(build_cmake)
            self.assertIn(id0, build_cmake_text)
            self.assertIn(id1, build_cmake_text)
            self.assertNotIn(id2, build_cmake_text)
            self.assertNotIn(id3, build_cmake_text)

        # Now test "build" command in subfolders
        for lang, id0, id1, id2, id3 in [(0, h00, h10, h01, h11),
                                         (1, h01, h11, h00, h10)]:
            self.client.current_folder = os.path.join(current_folder,
                                                      "lang%dbuild" % lang)
            self.client.run("build ..")
            self.assertIn("compiler=Visual Studio", self.client.user_io.out)
            self.assertIn("language=%d" % lang, self.client.user_io.out)
            self.assertNotIn("language=%d" % (not lang),
                             self.client.user_io.out)
Ejemplo n.º 24
0
    def reuse_test(self):
        self._create("Hello0", "0.1")
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"])
        self._create("Hello2",
                     "0.1", ["Hello1/0.1@lasote/stable"],
                     export=False)

        for lang, id0, id1 in [(0, "2e38bbc2c3ef1425197c8e2ffa8532894c347d26",
                                "44671ecdd9c606eb7166f2197ab50be8d36a3c3b"),
                               (1, "2e38bbc2c3ef1425197c8e2ffa8532894c347d26",
                                "44671ecdd9c606eb7166f2197ab50be8d36a3c3b")]:

            self.client.run("install -o language=%d %s --build missing" %
                            (lang, self.settings))
            info_path = os.path.join(self.client.current_folder, CONANINFO)
            conan_info = ConanInfo.load_file(info_path)
            self.assertEqual(
                "arch=x86\n"
                "compiler=Visual Studio\n"
                "compiler.runtime=MD\n"
                "compiler.version=12\n"
                "os=Windows", conan_info.settings.dumps())
            self.assertEqual("language=%s\nstatic=True" % lang,
                             conan_info.options.dumps())
            conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

            hello0 = self.client.paths.package(PackageReference(
                conan_ref, id0))
            hello0_info = os.path.join(hello0, CONANINFO)
            hello0_conan_info = ConanInfo.load_file(hello0_info)
            self.assertEqual(0, hello0_conan_info.options.language)

            package_ref1 = PackageReference(
                ConanFileReference.loads("Hello1/0.1@lasote/stable"), id1)
            hello1 = self.client.paths.package(package_ref1)
            hello1_info = os.path.join(hello1, CONANINFO)
            hello1_conan_info = ConanInfo.load_file(hello1_info)
            self.assertEqual(0, hello1_conan_info.options.language)
Ejemplo n.º 25
0
def test_upper_option(client):
    client.run(
        "install conanfile.py -o Hello2:language=1 -o Hello1:language=0 "
        "-o Hello0:language=1 --build missing")
    info_path = os.path.join(client.current_folder, CONANINFO)
    conan_info = ConanInfo.load_file(info_path)
    assert "language=1" == conan_info.options.dumps()
    ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

    pref = PackageReference(ref, "f43bd822487baa4ed2426c279c27b2811870499a")
    hello0 = client.cache.package_layout(ref).package(pref)

    hello0_info = os.path.join(hello0, CONANINFO)
    hello0_conan_info = ConanInfo.load_file(hello0_info)
    assert 1 == hello0_conan_info.options.language

    pref1 = PackageReference(
        ConanFileReference.loads("Hello1/0.1@lasote/stable"),
        "5faecfb46fd09e49f1812d732d6360bc1663e3ab")
    hello1 = client.cache.package_layout(pref1.ref).package(pref1)
    hello1_info = os.path.join(hello1, CONANINFO)
    hello1_conan_info = ConanInfo.load_file(hello1_info)
    assert 0 == hello1_conan_info.options.language
Ejemplo n.º 26
0
def test_inverse_upper_option(client):
    client.run(
        "install . -o language=0 -o Hello1:language=1 -o Hello0:language=0 --build missing"
    )
    info_path = os.path.join(client.current_folder, CONANINFO)

    conan_info = ConanInfo.load_file(info_path)

    assert "language=0" == conan_info.options.dumps()
    ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")
    pref = PackageReference(ref, "3475bd55b91ae904ac96fde0f106a136ab951a5e")
    hello0 = client.cache.package_layout(ref).package(pref)

    hello0_info = os.path.join(hello0, CONANINFO)
    hello0_conan_info = ConanInfo.load_file(hello0_info)
    assert "language=0" == hello0_conan_info.options.dumps()

    pref1 = PackageReference(
        ConanFileReference.loads("Hello1/0.1@lasote/stable"),
        "b96337c5fcdafd6533298017c2ba94812654f8ec")
    hello1 = client.cache.package_layout(pref1.ref).package(pref1)
    hello1_info = os.path.join(hello1, CONANINFO)
    hello1_conan_info = ConanInfo.load_file(hello1_info)
    assert "language=1" == hello1_conan_info.options.dumps()
Ejemplo n.º 27
0
    def upper_option_test(self):
        self._create("Hello0", "0.1", no_config=True)
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"], no_config=True)
        self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False, no_config=True)

        self.client.run("install -o language=1 -o Hello1:language=0 -o Hello0:language=1 %s "
                        "--build missing" % self.settings)
        info_path = os.path.join(self.client.current_folder, CONANINFO)
        conan_info = ConanInfo.load_file(info_path)
        self.assertEqual("language=1\nstatic=True", conan_info.options.dumps())
        conan_ref = ConanFileReference.loads("Hello0/0.1@lasote/stable")

        hello0 = self.client.paths.package(PackageReference(conan_ref,
                                           "8b964e421a5b7e48b7bc19b94782672be126be8b"))
        hello0_info = os.path.join(hello0, CONANINFO)
        hello0_conan_info = ConanInfo.load_file(hello0_info)
        self.assertEqual(1, hello0_conan_info.options.language)

        package_ref1 = PackageReference(ConanFileReference.loads("Hello1/0.1@lasote/stable"),
                                        "44671ecdd9c606eb7166f2197ab50be8d36a3c3b")
        hello1 = self.client.paths.package(package_ref1)
        hello1_info = os.path.join(hello1, CONANINFO)
        hello1_conan_info = ConanInfo.load_file(hello1_info)
        self.assertEqual(0, hello1_conan_info.options.language)
Ejemplo n.º 28
0
    def reuse_test(self):
        self._create("Hello0", "0.1")
        self._create("Hello1", "0.1", ["Hello0/0.1@lasote/stable"])
        self._create("Hello2", "0.1", ["Hello1/0.1@lasote/stable"], export=False)

        current_folder = self.client.current_folder
        h00 = "2e38bbc2c3ef1425197c8e2ffa8532894c347d26"
        h10 = "44671ecdd9c606eb7166f2197ab50be8d36a3c3b"
        h01 = "8b964e421a5b7e48b7bc19b94782672be126be8b"
        h11 = "3eeab577a3134fa3afdcd82881751789ec48e08f"
        for lang, id0, id1, id2, id3 in [(0, h00, h10, h01, h11),
                                         (1, h01, h11, h00, h10)]:
            self.client.current_folder = os.path.join(current_folder, "lang%dbuild" % lang)
            mkdir(self.client.current_folder)
            self.client.run("install .. -o language=%d %s --build missing" % (lang, self.settings))
            info_path = os.path.join(self.client.current_folder, CONANINFO)
            conan_info = ConanInfo.load_file(info_path)
            self.assertEqual("arch=x86\n"
                             "compiler=Visual Studio\n"
                             "compiler.runtime=MD\n"
                             "compiler.version=12\n"
                             "os=Windows",
                             conan_info.settings.dumps())
            conan_info_text = load(info_path)
            self.assertIn(id0, conan_info_text)
            self.assertIn(id1, conan_info_text)
            self.assertNotIn(id2, conan_info_text)
            self.assertNotIn(id3, conan_info_text)
            self.assertEqual("language=%s\nstatic=True" % lang, conan_info.options.dumps())
            build_cmake = os.path.join(self.client.current_folder, BUILD_INFO_CMAKE)
            build_cmake_text = load(build_cmake)
            self.assertIn(id0, build_cmake_text)
            self.assertIn(id1, build_cmake_text)
            self.assertNotIn(id2, build_cmake_text)
            self.assertNotIn(id3, build_cmake_text)

        # Now test "build" command in subfolders
        for lang, id0, id1, id2, id3 in [(0, h00, h10, h01, h11),
                                         (1, h01, h11, h00, h10)]:
            self.client.current_folder = os.path.join(current_folder, "lang%dbuild" % lang)
            self.client.run("build ..")
            self.assertIn("compiler=Visual Studio", self.client.user_io.out)
            self.assertIn("language=%d" % lang, self.client.user_io.out)
            self.assertNotIn("language=%d" % (not lang), self.client.user_io.out)
Ejemplo n.º 29
0
    def _evaluate_node(self, node, build_mode, update, evaluated_references,
                       remote_name):
        assert node.binary is None

        conan_ref, conanfile = node.conan_ref, node.conanfile
        package_id = conanfile.info.package_id()
        package_ref = PackageReference(conan_ref, package_id)
        # Check that this same reference hasn't already been checked
        previous_node = evaluated_references.get(package_ref)
        if previous_node:
            node.binary = previous_node.binary
            node.binary_remote = previous_node.binary_remote
            return
        evaluated_references[package_ref] = node

        output = ScopedOutput(str(conan_ref), self._out)
        if build_mode.forced(conanfile, conan_ref):
            output.warn('Forced build from source')
            node.binary = BINARY_BUILD
            return

        package_folder = self._client_cache.package(
            package_ref, short_paths=conanfile.short_paths)

        # Check if dirty, to remove it
        local_project = self._workspace[conan_ref] if self._workspace else None
        if local_project:
            node.binary = BINARY_WORKSPACE
            return

        with self._client_cache.package_lock(package_ref):
            if is_dirty(package_folder):
                output.warn("Package is corrupted, removing folder: %s" %
                            package_folder)
                rmdir(package_folder)

        if remote_name:
            remote = self._registry.remote(remote_name)
        else:
            remote = self._registry.get_ref(conan_ref)
        remotes = self._registry.remotes

        if os.path.exists(package_folder):
            if update:
                if remote:
                    if self._check_update(package_folder, package_ref, remote,
                                          output):
                        node.binary = BINARY_UPDATE
                        if build_mode.outdated:
                            package_hash = self._get_package_info(
                                package_ref, remote).recipe_hash
                elif remotes:
                    pass
                else:
                    output.warn("Can't update, no remote defined")
            if not node.binary:
                node.binary = BINARY_CACHE
                package_hash = ConanInfo.load_file(
                    os.path.join(package_folder, CONANINFO)).recipe_hash
        else:  # Binary does NOT exist locally
            remote_info = None
            if remote:
                remote_info = self._get_package_info(package_ref, remote)
            elif remotes:  # Iterate all remotes to get this binary
                for r in remotes:
                    remote_info = self._get_package_info(package_ref, r)
                    if remote_info:
                        remote = r
                        break
            if remote_info:
                node.binary = BINARY_DOWNLOAD
                package_hash = remote_info.recipe_hash
            else:
                if build_mode.allowed(conanfile, conan_ref):
                    node.binary = BINARY_BUILD
                else:
                    node.binary = BINARY_MISSING

        if build_mode.outdated:
            if node.binary in (BINARY_CACHE, BINARY_DOWNLOAD, BINARY_UPDATE):
                local_recipe_hash = self._client_cache.load_manifest(
                    package_ref.conan).summary_hash
                if local_recipe_hash != package_hash:
                    output.info("Outdated package!")
                    node.binary = BINARY_BUILD
                else:
                    output.info("Package is up to date")

        node.binary_remote = remote