コード例 #1
0
ファイル: disk_search_test.py プロジェクト: conan-io/conan
    def case_insensitive_test(self):
        root_folder2 = "sdl/1.5/lasote/stable"
        conan_ref2 = ConanFileReference.loads("sdl/1.5@lasote/stable")
        os.makedirs("%s/%s" % (root_folder2, EXPORT_FOLDER))

        root_folder3 = "assimp/0.14/phil/testing"
        conan_ref3 = ConanFileReference.loads("assimp/0.14@phil/testing")
        os.makedirs("%s/%s" % (root_folder3, EXPORT_FOLDER))

        root_folder4 = "sdl/2.10/lasote/stable"
        conan_ref4 = ConanFileReference.loads("sdl/2.10@lasote/stable")
        os.makedirs("%s/%s" % (root_folder4, EXPORT_FOLDER))

        root_folder5 = "SDL_fake/1.10/lasote/testing"
        conan_ref5 = ConanFileReference.loads("SDL_fake/1.10@lasote/testing")
        os.makedirs("%s/%s" % (root_folder5, EXPORT_FOLDER))
        # Case insensitive searches
        search_adapter = DiskSearchAdapter()
        search_manager = DiskSearchManager(self.paths, search_adapter)

        reg_conans = sorted([str(_reg) for _reg in search_manager.search("*")])
        self.assertEqual(reg_conans, [str(conan_ref5),
                                      str(conan_ref3),
                                      str(conan_ref2),
                                      str(conan_ref4)])

        reg_conans = sorted([str(_reg) for _reg in search_manager.search(pattern="sdl*")])
        self.assertEqual(reg_conans, [str(conan_ref5), str(conan_ref2), str(conan_ref4)])

        # Case sensitive search
        self.assertEqual(str(search_manager.search(pattern="SDL*", ignorecase=False)[0]),
                         str(conan_ref5))
コード例 #2
0
ファイル: copy_packages_test.py プロジェクト: 19317362/conan
    def test_copy_command(self):
        client = TestClient()
        conanfile = """from conans import ConanFile
class Pkg(ConanFile):
    settings = "os"
"""
        client.save({"conanfile.py": conanfile})
        client.run("export . Hello0/0.1@lasote/stable")
        client.run("install Hello0/0.1@lasote/stable -s os=Windows --build missing")
        client.run("install Hello0/0.1@lasote/stable -s os=Linux --build missing")
        client.run("install Hello0/0.1@lasote/stable -s os=Macos --build missing")

        # Copy all packages
        client.run("copy Hello0/0.1@lasote/stable pepe/testing --all")
        pkgdir = client.paths.packages(ConanFileReference.loads("Hello0/0.1@pepe/testing"))
        packages = os.listdir(pkgdir)
        self.assertEquals(len(packages), 3)

        # Copy just one
        client.run("copy Hello0/0.1@lasote/stable pepe/stable -p %s" % packages[0])
        pkgdir = client.paths.packages(ConanFileReference.loads("Hello0/0.1@pepe/stable"))
        packages = os.listdir(pkgdir)
        self.assertEquals(len(packages), 1)

        # Force
        client.run("copy Hello0/0.1@lasote/stable pepe/stable -p %s --force" % packages[0])
        packages = os.listdir(pkgdir)
        self.assertEquals(len(packages), 1)

        # Copy only recipe
        client.run("copy Hello0/0.1@lasote/stable pepe/alpha", ignore_error=True)
        pkgdir = client.paths.packages(ConanFileReference.loads("Hello0/0.1@pepe/alpha"))
        self.assertFalse(os.path.exists(pkgdir))
コード例 #3
0
    def test_override(self):

        files = cpp_hello_conan_files(name="VisualBuild",
                                      version="0.1", build=False, deps=["MinGWBuild/0.1@lasote/testing"])
        self._patch_build_to_print_compiler(files)
        self.client.save(files)
        self.client.run("export . lasote/testing")
        self.client.run("install VisualBuild/0.1@lasote/testing --build missing -s compiler='Visual Studio' "
                        "-s compiler.version=14 -s compiler.runtime=MD "
                        "-s MinGWBuild:compiler='gcc' -s MinGWBuild:compiler.libcxx='libstdc++' "
                        "-s MinGWBuild:compiler.version=4.8")

        self.assertIn("COMPILER=> MinGWBuild gcc", self.client.user_io.out)
        self.assertIn("COMPILER=> VisualBuild Visual Studio", self.client.user_io.out)

        # CHECK CONANINFO FILE
        packs_dir = self.client.paths.packages(ConanFileReference.loads("MinGWBuild/0.1@lasote/testing"))
        pack_dir = os.path.join(packs_dir, os.listdir(packs_dir)[0])
        conaninfo = load(os.path.join(pack_dir, CONANINFO))
        self.assertIn("compiler=gcc", conaninfo)

        # CHECK CONANINFO FILE
        packs_dir = self.client.paths.packages(ConanFileReference.loads("VisualBuild/0.1@lasote/testing"))
        pack_dir = os.path.join(packs_dir, os.listdir(packs_dir)[0])
        conaninfo = load(os.path.join(pack_dir, CONANINFO))
        self.assertIn("compiler=Visual Studio", conaninfo)
        self.assertIn("compiler.version=14", conaninfo)
コード例 #4
0
ファイル: loader.py プロジェクト: WimK/conan
    def load_conan_txt(self, conan_requirements_path, output):

        if not os.path.exists(conan_requirements_path):
            raise NotFoundException("Conanfile not found!")

        conanfile = ConanFile(output, self._runner, self._settings.copy(),
                              os.path.dirname(conan_requirements_path))

        try:
            parser = ConanFileTextLoader(load(conan_requirements_path))
        except Exception as e:
            raise ConanException("%s:\n%s" % (conan_requirements_path, str(e)))
        for requirement_text in parser.requirements:
            ConanFileReference.loads(requirement_text)  # Raise if invalid
            conanfile.requires.add(requirement_text)

        conanfile.generators = parser.generators

        options = OptionsValues.loads(parser.options)
        conanfile.options.values = options
        conanfile.options.initialize_upstream(self._options)

        # imports method
        conanfile.imports = ConanFileTextLoader.imports_method(conanfile,
                                                               parser.import_parameters)
        conanfile.scope = self._scopes.package_scope()
        return conanfile
コード例 #5
0
ファイル: install_test.py プロジェクト: JustgeekDE/conan
    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)
コード例 #6
0
ファイル: json_test.py プロジェクト: 19317362/conan
    def variables_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)

        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.defines = ["MYDEFINE1"]
        cpp_info.cflags.append("-Flag1=23")
        cpp_info.version = "1.3"
        cpp_info.description = "My cool description"

        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder2")
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.version = "2.3"
        cpp_info.exelinkflags = ["-exelinkflag"]
        cpp_info.sharedlinkflags = ["-sharedlinkflag"]
        cpp_info.cppflags = ["-cppflag"]
        cpp_info.public_deps = ["MyPkg"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = JsonGenerator(conanfile)
        json_out = generator.content

        parsed = json.loads(json_out)
        dependencies = parsed["dependencies"]
        self.assertEquals(len(dependencies), 2)
        my_pkg = dependencies[0]
        self.assertEquals(my_pkg["name"], "MyPkg")
        self.assertEquals(my_pkg["description"], "My cool description")
        self.assertEquals(my_pkg["defines"], ["MYDEFINE1"])
コード例 #7
0
ファイル: install_test.py プロジェクト: JustgeekDE/conan
    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())
コード例 #8
0
ファイル: install_test.py プロジェクト: JustgeekDE/conan
    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)
コード例 #9
0
ファイル: command.py プロジェクト: SteffenL/conan
    def copy(self, *args):
        """ Copy packages to another user/channel
        """
        parser = argparse.ArgumentParser(description=self.copy.__doc__, prog="conan copy")
        parser.add_argument("reference", default="",
                            help='reference'
                            'e.g., OpenSSL/1.0.2e@lasote/stable')
        parser.add_argument("user_channel", default="",
                            help='Destination user/channel'
                            'e.g., lasote/testing')
        parser.add_argument("--package", "-p", nargs=1, action=Extender,
                            help='copy specified package ID')
        parser.add_argument("--all", action='store_true',
                            default=False,
                            help='Copy all packages from the specified reference')
        parser.add_argument("--force", action='store_true',
                            default=False,
                            help='Override destination packages and conanfile')
        args = parser.parse_args(*args)

        reference = ConanFileReference.loads(args.reference)
        new_ref = ConanFileReference.loads("%s/%s@%s" % (reference.name,
                                                         reference.version,
                                                         args.user_channel))
        if args.all:
            args.package = []
        self._manager.copy(reference, args.package, new_ref.user, new_ref.channel, args.force)
コード例 #10
0
ファイル: options_test.py プロジェクト: nesono/conan
    def basic_test(self):
        boost_values = PackageOptionValues()
        boost_values.add_option("static", False)
        boost_values.add_option("thread", True)
        boost_values.add_option("thread.multi", "off")
        poco_values = PackageOptionValues()
        poco_values.add_option("deps_bundled", True)
        hello1_values = PackageOptionValues()
        hello1_values.add_option("static", False)
        hello1_values.add_option("optimized", 4)

        options = {"Boost": boost_values,
                   "Poco": poco_values,
                   "Hello1": hello1_values}
        down_ref = ConanFileReference.loads("Hello0/0.1@diego/testing")
        own_ref = ConanFileReference.loads("Hello1/0.1@diego/testing")
        output = TestBufferConanOutput()
        self.sut.propagate_upstream(options, down_ref, own_ref, output)
        self.assertEqual(self.sut.values.as_list(), [("optimized", "4"),
                                                     ("path", "NOTDEF"),
                                                     ("static", "False"),
                                                     ("Boost:static", "False"),
                                                     ("Boost:thread", "True"),
                                                     ("Boost:thread.multi", "off"),
                                                     ("Poco:deps_bundled", "True")])

        boost_values = PackageOptionValues()
        boost_values.add_option("static", 2)
        boost_values.add_option("thread", "Any")
        boost_values.add_option("thread.multi", "on")
        poco_values = PackageOptionValues()
        poco_values.add_option("deps_bundled", "What")
        hello1_values = PackageOptionValues()
        hello1_values.add_option("static", True)
        hello1_values.add_option("optimized", "2")
        options2 = {"Boost": boost_values,
                    "Poco": poco_values,
                    "Hello1": hello1_values}
        down_ref = ConanFileReference.loads("Hello2/0.1@diego/testing")
        self.sut.propagate_upstream(options2, down_ref, own_ref, output)
        self.assertIn("""WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option optimized to 2
but it was already assigned to 4 by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option static to True
but it was already assigned to False by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:static to 2
but it was already assigned to False by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread to Any
but it was already assigned to True by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread.multi to on
but it was already assigned to off by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Poco:deps_bundled to What
but it was already assigned to True by Hello0/0.1@diego/testing""", str(output))
        self.assertEqual(self.sut.values.dumps(),
                         """optimized=4
path=NOTDEF
static=False
Boost:static=False
Boost:thread=True
Boost:thread.multi=off
Poco:deps_bundled=True""")
コード例 #11
0
ファイル: rest_api_test.py プロジェクト: nesono/conan
    def search_test(self):
        # Upload a conan1
        conan_name1 = "HelloOnly/0.10@private_user/testing"
        conan_reference1 = ConanFileReference.loads(conan_name1)
        self._upload_recipe(conan_reference1)

        # Upload a package
        conan_info = """[settings]
    arch=x86_64
    compiler=gcc
    os=Linux
[options]
    386=False
[requires]
    Hello
    Bye/2.9
    Say/2.1@user/testing
    Chat/2.1@user/testing:SHA_ABC
"""
        package_reference = PackageReference(conan_reference1, "1F23223EFDA")
        self._upload_package(package_reference, {CONANINFO: conan_info})

        # Upload a conan2
        conan_name2 = "helloonlyToo/2.1@private_user/stable"
        conan_reference2 = ConanFileReference.loads(conan_name2)
        self._upload_recipe(conan_reference2)

        # Get the info about this ConanFileReference
        info = self.api.search_packages(conan_reference1, None)
        self.assertEqual(ConanInfo.loads(conan_info).serialize_min(), info["1F23223EFDA"])

        # Search packages
        results = self.api.search("HelloOnly*", ignorecase=False)

        self.assertEqual(results, [conan_reference1])
コード例 #12
0
ファイル: loader.py プロジェクト: 19317362/conan
    def _parse_conan_txt(self, contents, path, output):
        conanfile = ConanFile(output, self._runner, Settings())
        # It is necessary to copy the settings, because the above is only a constraint of
        # conanfile settings, and a txt doesn't define settings. Necessary for generators,
        # as cmake_multi, that check build_type.
        conanfile.settings = self._settings.copy_values()

        try:
            parser = ConanFileTextLoader(contents)
        except Exception as e:
            raise ConanException("%s:\n%s" % (path, str(e)))
        for requirement_text in parser.requirements:
            ConanFileReference.loads(requirement_text)  # Raise if invalid
            conanfile.requires.add(requirement_text)
        for build_requirement_text in parser.build_requirements:
            ConanFileReference.loads(build_requirement_text)
            if not hasattr(conanfile, "build_requires"):
                conanfile.build_requires = []
            conanfile.build_requires.append(build_requirement_text)

        conanfile.generators = parser.generators

        options = OptionsValues.loads(parser.options)
        conanfile.options.values = options
        conanfile.options.initialize_upstream(self._user_options)

        # imports method
        conanfile.imports = parser.imports_method(conanfile)
        conanfile._env_values.update(self._env_values)
        return conanfile
コード例 #13
0
ファイル: custom_generator_test.py プロジェクト: nesono/conan
    def reuse_test(self):
        conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable")
        files = cpp_hello_conan_files("Hello0", "0.1", build=False)

        client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})
        client.save(files)
        client.run("export lasote/stable")
        client.run("upload %s" % str(conan_reference))

        gen_reference = ConanFileReference.loads("MyCustomGen/0.2@lasote/stable")
        files = {CONANFILE: generator}
        client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})
        client.save(files)
        client.run("export lasote/stable")
        client.run("upload %s" % str(gen_reference))

        # Test local, no retrieval
        files = {CONANFILE_TXT: consumer}
        client.save(files, clean_first=True)
        client.run("install --build")
        generated = load(os.path.join(client.current_folder, "customfile.gen"))
        self.assertEqual(generated, "My custom generator content")

        # Test retrieval from remote
        client = TestClient(servers=self.servers, users={"default": [("lasote", "mypass")]})
        files = {CONANFILE_TXT: consumer}
        client.save(files)
        client.run("install --build")

        generated = load(os.path.join(client.current_folder, "customfile.gen"))
        self.assertEqual(generated, "My custom generator content")
コード例 #14
0
    def valid_xml_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        ref = ConanFileReference.loads("MyPkg/0.1@user/testing")
        folder1 = temp_folder()
        folder1 = folder1.replace("\\", "/")
        os.makedirs(os.path.join(folder1, "include"))
        os.makedirs(os.path.join(folder1, "lib"))
        cpp_info = CppInfo(folder1)
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing")
        folder2 = temp_folder()
        folder2 = folder2.replace("\\", "/")
        os.makedirs(os.path.join(folder2, "include"))
        os.makedirs(os.path.join(folder2, "lib"))
        cpp_info = CppInfo(folder2)
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = VisualStudioLegacyGenerator(conanfile)

        content = generator.content
        xml.etree.ElementTree.fromstring(content)

        self.assertIn('AdditionalIncludeDirectories=""%s/include";"%s/include";"'
                      % (folder1, folder2), content)
        self.assertIn('AdditionalLibraryDirectories=""%s/lib";"%s/lib";"'
                      % (folder1, folder2), content)
コード例 #15
0
ファイル: uploader.py プロジェクト: 19317362/conan
def _is_a_reference(ref):
    try:
        ConanFileReference.loads(ref)
        return "*" not in ref  # If is a pattern, it is not a reference
    except ConanException:
        pass
    return False
コード例 #16
0
ファイル: conan_api.py プロジェクト: nesono/conan
 def copy(self, reference="", user_channel="", force=False, all=False, package=None):
     reference = ConanFileReference.loads(reference)
     new_ref = ConanFileReference.loads("%s/%s@%s" % (reference.name,
                                                      reference.version,
                                                      user_channel))
     if all:
         package = []
     self._manager.copy(reference, package, new_ref.user, new_ref.channel, force)
コード例 #17
0
    def setUp(self):
        self.ref1 = ConanFileReference.loads("lib1/1.0@conan/stable")
        self.ref2 = ConanFileReference.loads("lib2/1.0@conan/stable")
        self.ref3 = ConanFileReference.loads("lib3/1.0@conan/stable")

        self.ref_p1 = PackageReference(self.ref1, "1")
        self.ref_p2 = PackageReference(self.ref2, "2")
        self.ref_p3 = PackageReference(self.ref3, "3")
コード例 #18
0
ファイル: go_diamond_test.py プロジェクト: davidsanfal/conan
    def reuse_test(self):
        self._export_upload("hello0/0.1@lasote/stable")
        self._export_upload("hello1/0.1@lasote/stable", 1, [0])
        self._export_upload("hello2/0.1@lasote/stable", 2, [0])
        self._export_upload("hello3/0.1@lasote/stable", 3, [1, 2])

        client = TestClient(servers=self.servers, users=[("lasote", "mypass")])  # Mocked userio
        conan_reference = ConanFileReference.loads("hello4/0.2@lasote/stable")
        files3 = hello_conan_files(conan_reference=conan_reference, number=4, deps=[3], lang='go')
        client.save(files3)
        os.chdir(client.current_folder)
        client.run("install --build missing")
        client.run("build")
        command = "say_hello" if platform.system() == "Windows" else "./say_hello"
        with CustomEnvPath(paths_to_add=['$GOPATH/bin'],
                           var_to_add=[('GOPATH', client.current_folder), ]):

            client.runner('go install hello4_main', os.path.join(client.current_folder, 'src'))
        if platform.system() == "Windows":
            command = "hello4_main"
        else:
            command = './hello4_main'
        client.runner(command, os.path.join(client.current_folder, 'bin'))

        self.assertEqual(['Hello 4', 'Hello 3', 'Hello 1', 'Hello 0', 'Hello 2', 'Hello 0'],
                         str(client.user_io.out).splitlines()[-6:])

        # Try to upload and reuse the binaries
        client.run("upload hello3/0.1@lasote/stable --all")
        self.assertEqual(str(client.user_io.out).count("Uploading package"), 1)
        client.run("upload hello1/0.1@lasote/stable --all")
        self.assertEqual(str(client.user_io.out).count("Uploading package"), 1)
        client.run("upload hello2/0.1@lasote/stable --all")
        self.assertEqual(str(client.user_io.out).count("Uploading package"), 1)
        client.run("upload hello0/0.1@lasote/stable --all")
        self.assertEqual(str(client.user_io.out).count("Uploading package"), 1)
#
        client2 = TestClient(servers=self.servers, users=[("lasote", "mypass")])  # Mocked userio
        conan_reference = ConanFileReference.loads("hello4/0.2@lasote/stable")

        files3 = hello_conan_files(conan_reference=conan_reference, number=4, deps=[3], lang='go')
        client2.save(files3)

        client2.run("install --build missing")
        command = "say_hello" if platform.system() == "Windows" else "./say_hello"
        with CustomEnvPath(paths_to_add=['$GOPATH/bin'],
                           var_to_add=[('GOPATH', client2.current_folder), ]):

            client2.runner('go install hello4_main', os.path.join(client2.current_folder, 'src'))
        if platform.system() == "Windows":
            command = "hello4_main"
        else:
            command = './hello4_main'
        client2.runner(command, os.path.join(client2.current_folder, 'bin'))

        self.assertEqual(['Hello 4', 'Hello 3', 'Hello 1', 'Hello 0', 'Hello 2', 'Hello 0'],
                         str(client2.user_io.out).splitlines()[-6:])
コード例 #19
0
ファイル: authorizer_test.py プロジェクト: nesono/conan
    def check_wildcards_test(self):
        # Only pepe can read openssl versions
        read_perms = [("openssl/*@lasote/testing", "pepe"), ("*/*@*/*", "*")]
        # Only pepe (and lasote because its owner) can write it and no more users can write
        write_perms = [(str(self.openssl_ref), "pepe")]

        authorizer = BasicAuthorizer(read_perms, write_perms)
        # Pepe can read all openssl versions
        authorizer.check_read_conan("pepe", self.openssl_ref)
        authorizer.check_read_conan("pepe", self.openssl_ref2)
        # Other user can't
        self.assertRaises(ForbiddenException,
                          authorizer.check_read_conan, "juan", self.openssl_ref)
        self.assertRaises(ForbiddenException,
                          authorizer.check_read_conan, "juan", self.openssl_ref2)

        # Only pepe can read versions 2.0.1 of lasote/testing
        read_perms = [("*/2.0.2@lasote/testing", "pepe"), ("*/*@*/*", "*")]
        authorizer = BasicAuthorizer(read_perms, write_perms)
        # Pepe can read openssl 2.0.1 version and 2.0.2 (only matches 2.0.2, so other is allowed)
        authorizer.check_read_conan("pepe", self.openssl_ref2)
        authorizer.check_read_conan("pepe", self.openssl_ref2)
        # Other user can't read 2.0.2
        authorizer.check_read_conan("juan", self.openssl_ref)
        self.assertRaises(ForbiddenException,
                          authorizer.check_read_conan, "juan", self.openssl_ref2)

        # Only pepe can read openssl version 2.0.1 from any owner
        read_perms = [("openssl/2.0.1@*/testing", "pepe")]
        # Only pepe (and lasote because its owner) can write it and no more users can write
        write_perms = [(str(self.openssl_ref), "pepe")]

        authorizer = BasicAuthorizer(read_perms, write_perms)
        # Pepe can read any openssl/2.0.1
        authorizer.check_read_conan("pepe", self.openssl_ref)
        tmp_ref = ConanFileReference.loads("openssl/2.0.1@alfred/testing")
        authorizer.check_read_conan("pepe", tmp_ref)
        self.assertRaises(ForbiddenException,
                          authorizer.check_read_conan, "juan", self.openssl_ref)
        self.assertRaises(ForbiddenException,
                          authorizer.check_read_conan, "juan", tmp_ref)

        # Only pepe can read openssl version 2.0.1 from lasote/any channel
        read_perms = [("openssl/2.0.1@lasote/*", "pepe")]
        # Only pepe (and lasote because its owner) can write it and no more users can write
        write_perms = [(str(self.openssl_ref), "pepe")]

        authorizer = BasicAuthorizer(read_perms, write_perms)
        # Pepe can read openssl/2.0.1 from any channel but only from lasote
        authorizer.check_read_conan("pepe", self.openssl_ref)
        tmp_ref = ConanFileReference.loads("openssl/2.0.1@alfred/testing")
        self.assertRaises(ForbiddenException,
                          authorizer.check_read_conan, "pepe", tmp_ref)

        tmp_ref = ConanFileReference.loads("openssl/2.0.1@lasote/otherchannel")
        authorizer.check_read_conan("pepe", tmp_ref)
コード例 #20
0
ファイル: boost_build_test.py プロジェクト: 19317362/conan
    def variables_setup_test(self):

        conanfile = ConanFile(None, None, Settings({}), None)

        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.defines = ["MYDEFINE1"]
        cpp_info.cflags.append("-Flag1=23")
        cpp_info.version = "1.3"
        cpp_info.description = "My cool description"
        cpp_info.libs = ["MyLib1"]

        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder2")
        cpp_info.libs = ["MyLib2"]
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.version = "2.3"
        cpp_info.exelinkflags = ["-exelinkflag"]
        cpp_info.sharedlinkflags = ["-sharedlinkflag"]
        cpp_info.cppflags = ["-cppflag"]
        cpp_info.public_deps = ["MyPkg"]
        cpp_info.lib_paths.extend(["Path\\with\\slashes", "regular/path/to/dir"])
        cpp_info.include_paths.extend(["other\\Path\\with\\slashes", "other/regular/path/to/dir"])
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = BoostBuildGenerator(conanfile)

        self.assertEquals(generator.content, """lib MyLib1 :
	: # requirements
	<name>MyLib1
	: # default-build
	: # usage-requirements
	<define>MYDEFINE1
	<cflags>-Flag1=23
	;

lib MyLib2 :
	: # requirements
	<name>MyLib2
	<search>Path/with/slashes
	<search>regular/path/to/dir
	: # default-build
	: # usage-requirements
	<define>MYDEFINE2
	<include>other/Path/with/slashes
	<include>other/regular/path/to/dir
	<cxxflags>-cppflag
	<ldflags>-sharedlinkflag
	;

alias conan-deps :
	MyLib1
	MyLib2
;
""")
コード例 #21
0
ファイル: options_test.py プロジェクト: JustgeekDE/conan
    def basic_test(self):
        options = OptionsValues.loads("""other_option=True
        optimized_var=3
        Poco:deps_bundled=True
        Boost:static=False
        Boost:thread=True
        Boost:thread.multi=off
        Hello1:static=False
        Hello1:optimized=4
        """)
        down_ref = ConanFileReference.loads("Hello0/0.1@diego/testing")
        own_ref = ConanFileReference.loads("Hello1/0.1@diego/testing")
        output = TestBufferConanOutput()
        self.sut.propagate_upstream(options, down_ref, own_ref, output)
        self.assertEqual(self.sut.values.as_list(), [("optimized", "4"),
                                                     ("path", "NOTDEF"),
                                                     ("static", "False"),
                                                     ("Boost:static", "False"),
                                                     ("Boost:thread", "True"),
                                                     ("Boost:thread.multi", "off"),
                                                     ("Poco:deps_bundled", "True")])

        options2 = OptionsValues.loads("""other_option=True
        optimized_var=3
        Poco:deps_bundled=What
        Boost:static=2
        Boost:thread=Any
        Boost:thread.multi=on
        Hello1:static=True
        Hello1:optimized=2
        """)
        down_ref = ConanFileReference.loads("Hello2/0.1@diego/testing")
        self.sut.propagate_upstream(options2, down_ref, own_ref, output)
        self.assertIn("""WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option optimized to 2
but it was already assigned to 4 by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option static to True
but it was already assigned to False by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:static to 2
but it was already assigned to False by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread to Any
but it was already assigned to True by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Boost:thread.multi to on
but it was already assigned to off by Hello0/0.1@diego/testing
WARN: Hello2/0.1@diego/testing tried to change Hello1/0.1@diego/testing option Poco:deps_bundled to What
but it was already assigned to True by Hello0/0.1@diego/testing""", str(output))
        self.assertEqual(self.sut.values.dumps(),
                         """optimized=4
path=NOTDEF
static=False
Boost:static=False
Boost:thread=True
Boost:thread.multi=off
Poco:deps_bundled=True""")
コード例 #22
0
ファイル: options_test.py プロジェクト: 19317362/conan
    def pattern_unmatch_test(self):
        boost_values = PackageOptionValues()
        boost_values.add_option("fake_option", "FuzzBuzz")

        options = {"OpenSSL.*": boost_values}
        down_ref = ConanFileReference.loads("Boost.Assert/0.1@diego/testing")
        own_ref = ConanFileReference.loads("Boost.Assert/0.1@diego/testing")
        self.sut.propagate_upstream(options, down_ref, own_ref)
        self.assertEqual(self.sut.values.as_list(), [("optimized", "3"),
                                                     ("path", "NOTDEF"),
                                                     ("static", "True"),
                                                     ("OpenSSL.*:fake_option", "FuzzBuzz"),
                                                     ])
コード例 #23
0
ファイル: options_test.py プロジェクト: 19317362/conan
    def basic_test(self):
        boost_values = PackageOptionValues()
        boost_values.add_option("static", False)
        boost_values.add_option("thread", True)
        boost_values.add_option("thread.multi", "off")
        poco_values = PackageOptionValues()
        poco_values.add_option("deps_bundled", True)
        hello1_values = PackageOptionValues()
        hello1_values.add_option("static", False)
        hello1_values.add_option("optimized", 4)

        options = {"Boost": boost_values,
                   "Poco": poco_values,
                   "Hello1": hello1_values}
        down_ref = ConanFileReference.loads("Hello0/0.1@diego/testing")
        own_ref = ConanFileReference.loads("Hello1/0.1@diego/testing")
        self.sut.propagate_upstream(options, down_ref, own_ref)
        self.assertEqual(self.sut.values.as_list(), [("optimized", "4"),
                                                     ("path", "NOTDEF"),
                                                     ("static", "False"),
                                                     ("Boost:static", "False"),
                                                     ("Boost:thread", "True"),
                                                     ("Boost:thread.multi", "off"),
                                                     ("Poco:deps_bundled", "True")])

        boost_values = PackageOptionValues()
        boost_values.add_option("static", 2)
        boost_values.add_option("thread", "Any")
        boost_values.add_option("thread.multi", "on")
        poco_values = PackageOptionValues()
        poco_values.add_option("deps_bundled", "What")
        hello1_values = PackageOptionValues()
        hello1_values.add_option("static", True)
        hello1_values.add_option("optimized", "2")
        options2 = {"Boost": boost_values,
                    "Poco": poco_values,
                    "Hello1": hello1_values}
        down_ref = ConanFileReference.loads("Hello2/0.1@diego/testing")

        with self.assertRaisesRegexp(ConanException, "Hello2/0.1@diego/testing tried to change "
                                     "Hello1/0.1@diego/testing option optimized to 2"):
            self.sut.propagate_upstream(options2, down_ref, own_ref)

        self.assertEqual(self.sut.values.dumps(),
                         """optimized=4
path=NOTDEF
static=False
Boost:static=False
Boost:thread=True
Boost:thread.multi=off
Poco:deps_bundled=True""")
コード例 #24
0
ファイル: multi_build_test.py プロジェクト: JustgeekDE/conan
    def reuse_test(self):
        conan_reference = ConanFileReference.loads("Hello0/0.1@lasote/stable")
        files = cpp_hello_conan_files("Hello0", "0.1")

        client = TestClient()
        client.save(files)
        client.run("export lasote/stable")

        configs = []  # ("gcc", "4.8")]
        # Place to add different compilers
        if platform.system() == "Windows2":
            configs.append(("Visual Studio", "12"))
        for compiler, compiler_version in configs:
            client.default_settings(compiler, compiler_version)
            client.run("install %s --build missing" % str(conan_reference))

        # Check compilation ok
        package_ids = client.paths.conan_packages(conan_reference)
        self.assertEquals(len(package_ids), len(configs))
        for package_id in package_ids:
            package_ref = PackageReference(conan_reference, package_id)
            self._assert_library_exists(package_ref, client.paths)

        # Reuse them
        conan_reference = ConanFileReference.loads("Hello1/0.2@lasote/stable")
        files3 = cpp_hello_conan_files("Hello1", "0.1", ["Hello0/0.1@lasote/stable"])
        client.current_folder = temp_folder()

        client.save(files3)
        for compiler, compiler_version in configs:
            client.default_settings(compiler, compiler_version)
            client.run('install')
            client.run('build')

            command = os.sep.join([".", "bin", "say_hello"])
            client.runner(command, cwd=client.current_folder)
            self.assertIn("Hello Hello1", client.user_io.out)
            self.assertIn("Hello Hello0", client.user_io.out)

        new_conanfile = files3[CONANFILE].replace('"language": 0', '"language": 1')
        for compiler, compiler_version in configs:
            client.default_settings(compiler, compiler_version)
            client.save({CONANFILE: new_conanfile})
            client.run('install')
            client.run('build')
            time.sleep(1)

            client.runner(command, cwd=client.current_folder)
            self.assertIn("Hola Hello1", client.user_io.out)
            self.assertIn("Hola Hello0", client.user_io.out)
コード例 #25
0
ファイル: deps_graph_test.py プロジェクト: JustgeekDE/conan
    def test_node(self):
        """ nodes are different even if contain same values,
        so they can be repeated if necessary in the graph (common
        static libraries)
        """
        conan_ref1 = ConanFileReference.loads("Hello/0.1@user/stable")
        conan_ref2 = ConanFileReference.loads("Hello/0.1@user/stable")

        conanfile1 = ConanFile(None, None, Settings({}), ".")
        conanfile2 = ConanFile(None, None, Settings({}), ".")
        n1 = Node(conan_ref1, conanfile1)
        n2 = Node(conan_ref2, conanfile2)

        self.assertNotEqual(n1, n2)
コード例 #26
0
ファイル: ref_test.py プロジェクト: JustgeekDE/conan
    def basic_test(self):
        ref = ConanFileReference.loads("opencv/2.4.10 @ lasote/testing")
        self.assertEqual(ref.name, "opencv")
        self.assertEqual(ref.version, "2.4.10")
        self.assertEqual(ref.user, "lasote")
        self.assertEqual(ref.channel, "testing")
        self.assertEqual(str(ref), "opencv/2.4.10@lasote/testing")

        ref = ConanFileReference.loads("opencv_lite/2.4.10@phil-lewis/testing")
        self.assertEqual(ref.name, "opencv_lite")
        self.assertEqual(ref.version, "2.4.10")
        self.assertEqual(ref.user, "phil-lewis")
        self.assertEqual(ref.channel, "testing")
        self.assertEqual(str(ref), "opencv_lite/2.4.10@phil-lewis/testing")
コード例 #27
0
ファイル: info_test.py プロジェクト: 19317362/conan
        def check_digraph_line(line):
            self.assertTrue(dot_regex.match(line))

            # root node (current project) is special case
            line = line.replace("@PROJECT", "@lasote/stable")

            node_matches = node_regex.findall(line)

            parent = ConanFileReference.loads(node_matches[0])
            deps = [ConanFileReference.loads(ref) for ref in node_matches[1:]]

            check_conan_ref(parent)
            for dep in deps:
                check_conan_ref(dep)
                self.assertIn(dep.name, test_deps[parent.name])
コード例 #28
0
ファイル: options_test.py プロジェクト: 19317362/conan
    def all_positive_test(self):
        boost_values = PackageOptionValues()
        boost_values.add_option("static", False)
        boost_values.add_option("path", "FuzzBuzz")

        options = {"*": boost_values}
        own_ref = ConanFileReference.loads("Boost.Assert/0.1@diego/testing")
        down_ref = ConanFileReference.loads("Consumer/0.1@diego/testing")
        self.sut.propagate_upstream(options, down_ref, own_ref)
        self.assertEqual(self.sut.values.as_list(), [("optimized", "3"),
                                                     ("path", "FuzzBuzz"),
                                                     ("static", "False"),
                                                     ("*:path", "FuzzBuzz"),
                                                     ("*:static", "False"),
                                                     ])
コード例 #29
0
ファイル: build_id_test.py プロジェクト: nesono/conan
    def remove_specific_builds_test(self):
        client = TestClient()
        client.save({"conanfile.py": conanfile})
        client.run("export user/channel")
        client.save({"conanfile.txt": consumer}, clean_first=True)
        client.run('install -s build_type=Debug')
        client.run('install -s build_type=Release')
        ref = ConanFileReference.loads("Pkg/0.1@user/channel")

        def _check_builds():
            builds = client.client_cache.conan_builds(ref)
            self.assertEqual(1, len(builds))
            packages = client.client_cache.conan_packages(ref)
            self.assertEqual(2, len(packages))
            self.assertNotIn(builds[0], packages)
            return builds[0], packages

        build, packages = _check_builds()
        client.run("remove Pkg/0.1@user/channel -b %s -f" % packages[0])
        _check_builds()
        client.run("remove Pkg/0.1@user/channel -b %s -f" % build)
        builds = client.client_cache.conan_builds(ref)
        self.assertEqual(0, len(builds))
        packages = client.client_cache.conan_packages(ref)
        self.assertEqual(2, len(packages))
コード例 #30
0
ファイル: rest_api_test.py プロジェクト: nesono/conan
    def get_package_info_test(self):
        # Upload a conans
        conan_reference = ConanFileReference.loads("conan3/1.0.0@private_user/testing")
        self._upload_recipe(conan_reference)

        # Upload an package
        package_reference = PackageReference(conan_reference, "1F23223EFDA")
        conan_info = """[settings]
    arch=x86_64
    compiler=gcc
    os=Linux
[options]
    386=False
[requires]
    Hello
    Bye/2.9
    Say/2.1@user/testing
    Chat/2.1@user/testing:SHA_ABC
"""
        self._upload_package(package_reference, {CONANINFO: conan_info})

        # Get the package info
        info = self.api.get_package_info(package_reference)
        self.assertIsInstance(info, ConanInfo)
        self.assertEquals(info, ConanInfo.loads(conan_info))
コード例 #31
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:
            digest_path = client.client_cache.digestfile_package(pack_ref)
            expected_manifest = FileTreeManifest.create(
                os.path.dirname(digest_path))
            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
            })
コード例 #32
0
    def valid_xml_test(self, use_toolset):
        tempdir = temp_folder()
        with chdir(tempdir):
            settings = Settings.loads(get_default_settings_yml())
            settings.os = "Windows"
            settings.compiler = "Visual Studio"
            settings.compiler.version = "11"
            settings.compiler.runtime = "MD"
            if use_toolset:
                settings.compiler.toolset = "v110"
            conanfile = ConanFile(TestBufferConanOutput(), None)
            conanfile.initialize(Settings({}), EnvValues())

            ref = ConanFileReference.loads("MyPkg/0.1@user/testing")
            cpp_info = CppInfo(ref.name, "dummy_root_folder1")
            conanfile.deps_cpp_info.add(ref.name, cpp_info)
            ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing")
            cpp_info = CppInfo(ref.name, "dummy_root_folder2")
            conanfile.deps_cpp_info.add(ref.name, cpp_info)

            settings.arch = "x86"
            settings.build_type = "Debug"
            conanfile.settings = settings

            generator = VisualStudioMultiGenerator(conanfile)
            generator.output_path = ""
            content = generator.content

            self.assertEqual(2, len(content))
            self.assertIn('conanbuildinfo_multi.props', content.keys())
            self.assertIn('conanbuildinfo_debug_win32_v110.props',
                          content.keys())

            content_multi = content['conanbuildinfo_multi.props']
            self.assertIn(
                "<Import Condition=\"'$(Configuration)' == 'Debug' "
                "And '$(Platform)' == 'Win32' "
                "And '$(PlatformToolset)' == 'v110'\" "
                "Project=\"conanbuildinfo_debug_win32_v110.props\"/>",
                content_multi)

            with open('conanbuildinfo_multi.props', 'w') as f:
                f.write(content_multi)

            settings.arch = "x86_64"
            settings.build_type = "Release"
            settings.compiler.version = "15"
            settings.compiler.toolset = "v141"
            conanfile.settings = settings

            generator = VisualStudioMultiGenerator(conanfile)
            generator.output_path = ""
            content = generator.content

            self.assertEqual(2, len(content))
            self.assertIn('conanbuildinfo_multi.props', content.keys())
            self.assertIn('conanbuildinfo_release_x64_v141.props',
                          content.keys())

            content_multi = content['conanbuildinfo_multi.props']
            self.assertIn(
                "<Import Condition=\"'$(Configuration)' == 'Debug' "
                "And '$(Platform)' == 'Win32' "
                "And '$(PlatformToolset)' == 'v110'\" "
                "Project=\"conanbuildinfo_debug_win32_v110.props\"/>",
                content_multi)
            self.assertIn(
                "<Import Condition=\"'$(Configuration)' == 'Release' "
                "And '$(Platform)' == 'x64' "
                "And '$(PlatformToolset)' == 'v141'\" "
                "Project=\"conanbuildinfo_release_x64_v141.props\"/>",
                content_multi)

            os.unlink('conanbuildinfo_multi.props')
コード例 #33
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" % list(self.deps_cpp_info.include_paths))
                self.output.info("GLOBAL Library paths: %s" % list(self.deps_cpp_info.lib_paths))
                self.output.info("GLOBAL Binary paths: %s" % list(self.deps_cpp_info.bin_paths))
                self.output.info("GLOBAL Libs: %s" % list(self.deps_cpp_info.libs))
                self.output.info("GLOBAL System libs: %s" % list(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.get_name('txt'))
                    self.output.info("DEPS Include paths: %s" % list(dep_value.include_paths))
                    self.output.info("DEPS Library paths: %s" % list(dep_value.lib_paths))
                    self.output.info("DEPS Binary paths: %s" % list(dep_value.bin_paths))
                    self.output.info("DEPS Libs: %s" % list(dep_value.libs))
                    self.output.info("DEPS System libs: %s" % list(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,
                            list(comp_value.include_paths)))
                        self.output.info("COMP %s Library paths: %s" % (comp_name, list(comp_value.lib_paths)))
                        self.output.info("COMP %s Binary paths: %s" % (comp_name, list(comp_value.bin_paths)))
                        self.output.info("COMP %s Libs: %s" % (comp_name, list(comp_value.libs)))
                        self.output.info("COMP %s Requires: %s" % (comp_name, list(comp_value.requires)))
                        self.output.info("COMP %s System libs: %s" % (comp_name, list(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" %
            list(expected_comp_starlight_include_paths), client.out)
        self.assertIn(
            "COMP Planet Include paths: %s" %
            list(expected_comp_planet_include_paths, ), client.out)
        self.assertIn(
            "COMP Launcher Include paths: %s" %
            list(expected_comp_launcher_include_paths), client.out)
        self.assertIn(
            "COMP ISS Include paths: %s" %
            list(expected_comp_iss_include_paths), client.out)
        self.assertIn(
            "COMP Starlight Library paths: %s" %
            list(expected_comp_starlight_library_paths), client.out)
        self.assertIn(
            "COMP Planet Library paths: %s" %
            list(expected_comp_planet_library_paths), client.out)
        self.assertIn(
            "COMP Launcher Library paths: %s" %
            list(expected_comp_launcher_library_paths), client.out)
        self.assertIn(
            "COMP ISS Library paths: %s" %
            list(expected_comp_iss_library_paths), client.out)
        self.assertIn(
            "COMP Starlight Binary paths: %s" %
            list(expected_comp_iss_binary_paths), client.out)
        self.assertIn(
            "COMP Planet Binary paths: %s" %
            list(expected_comp_planet_binary_paths), client.out)
        self.assertIn(
            "COMP Launcher Binary paths: %s" %
            list(expected_comp_launcher_binary_paths), client.out)
        self.assertIn(
            "COMP ISS Binary paths: %s" % list(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)
コード例 #34
0
 def export_alias(self, reference, target_reference):
     reference = ConanFileReference.loads(str(reference))
     target_reference = ConanFileReference.loads(str(target_reference))
     return self._manager.export_alias(reference, target_reference)
コード例 #35
0
    def test_build_settings(self):
        def install_and_get_info(package_id_text):
            self.client.run("remove * -f")
            self._export("Hello",
                         "1.2.0",
                         package_id_text=package_id_text,
                         channel="user/testing",
                         settings=["os", "os_build", "arch", "arch_build"])
            self.client.run('install Hello/1.2.0@user/testing '
                            ' -s os="Windows" '
                            ' -s os_build="Linux"'
                            ' -s arch="x86_64"'
                            ' -s arch_build="x86"'
                            ' --build missing')

            ref = ConanFileReference.loads("Hello/1.2.0@user/testing")
            pkg = os.listdir(self.client.cache.package_layout(ref).packages())
            pref = PackageReference(ref, pkg[0])
            pkg_folder = self.client.cache.package_layout(
                pref.ref).package(pref)
            return ConanInfo.loads(load(os.path.join(pkg_folder, CONANINFO)))

        info = install_and_get_info(None)  # Default

        self.assertEqual(str(info.settings.os_build), "None")
        self.assertEqual(str(info.settings.arch_build), "None")

        # Package has to be present with only os and arch settings
        self.client.run('install Hello/1.2.0@user/testing '
                        ' -s os="Windows" '
                        ' -s arch="x86_64"')

        # Even with wrong build settings
        self.client.run('install Hello/1.2.0@user/testing '
                        ' -s os="Windows" '
                        ' -s arch="x86_64"'
                        ' -s os_build="Macos"'
                        ' -s arch_build="x86_64"')

        # take into account build
        info = install_and_get_info("self.info.include_build_settings()")
        self.assertEqual(str(info.settings.os_build), "Linux")
        self.assertEqual(str(info.settings.arch_build), "x86")

        # Now the build settings matter
        err = self.client.run(
            'install Hello/1.2.0@user/testing '
            ' -s os="Windows" '
            ' -s arch="x86_64"'
            ' -s os_build="Macos"'
            ' -s arch_build="x86_64"',
            assert_error=True)
        self.assertTrue(err)
        self.assertIn("Can't find", self.client.out)

        self.client.run('install Hello/1.2.0@user/testing '
                        ' -s os="Windows" '
                        ' -s arch="x86_64"'
                        ' -s os_build="Linux"'
                        ' -s arch_build="x86"')

        # Now only settings for build
        self.client.run("remove * -f")
        self._export("Hello",
                     "1.2.0",
                     channel="user/testing",
                     settings=["os_build", "arch_build"])
        self.client.run('install Hello/1.2.0@user/testing '
                        ' -s os_build="Linux"'
                        ' -s arch_build="x86"'
                        ' --build missing')
        ref = ConanFileReference.loads("Hello/1.2.0@user/testing")
        pkg = os.listdir(self.client.cache.package_layout(ref).packages())
        pref = PackageReference(ref, pkg[0])
        pkg_folder = self.client.cache.package_layout(pref.ref).package(pref)
        info = ConanInfo.loads(load(os.path.join(pkg_folder, CONANINFO)))
        self.assertEqual(str(info.settings.os_build), "Linux")
        self.assertEqual(str(info.settings.arch_build), "x86")
コード例 #36
0
    def __init__(self,
                 username=None,
                 channel=None,
                 runner=None,
                 gcc_versions=None,
                 visual_versions=None,
                 visual_runtimes=None,
                 visual_toolsets=None,
                 apple_clang_versions=None,
                 archs=None,
                 options=None,
                 use_docker=None,
                 curpage=None,
                 total_pages=None,
                 docker_image=None,
                 reference=None,
                 password=None,
                 remotes=None,
                 upload=None,
                 stable_branch_pattern=None,
                 vs10_x86_64_enabled=False,
                 mingw_configurations=None,
                 stable_channel=None,
                 platform_info=None,
                 upload_retry=None,
                 clang_versions=None,
                 login_username=None,
                 upload_only_when_stable=None,
                 upload_only_when_tag=None,
                 upload_only_recipe=None,
                 build_types=None,
                 cppstds=None,
                 skip_check_credentials=False,
                 allow_gcc_minors=False,
                 exclude_vcvars_precommand=False,
                 docker_run_options=None,
                 docker_image_skip_update=False,
                 docker_image_skip_pull=False,
                 docker_entry_script=None,
                 docker_32_images=None,
                 docker_conan_home=None,
                 docker_shell=None,
                 pip_install=None,
                 build_policy=None,
                 always_update_conan_in_docker=False,
                 conan_api=None,
                 client_cache=None,
                 conanfile=None,
                 ci_manager=None,
                 out=None,
                 test_folder=None,
                 cwd=None,
                 config_url=None,
                 config_args=None,
                 upload_dependencies=None,
                 force_selinux=None,
                 skip_recipe_export=False,
                 update_dependencies=None,
                 lockfile=None):

        conan_version = get_client_version()

        self.printer = Printer(out)
        self.printer.print_rule()
        self.printer.print_ascci_art()

        self.cwd = cwd or os.getcwd()

        if not conan_api:
            self.conan_api, _, _ = Conan.factory()
            self.conan_api.create_app()
            self.client_cache = self.conan_api.app.cache
        else:
            self.conan_api = conan_api
            self.client_cache = client_cache

        self.ci_manager = ci_manager or CIManager(self.printer)
        self.remotes_manager = RemotesManager(self.conan_api, self.printer,
                                              remotes, upload)
        self.username = username or os.getenv("CONAN_USERNAME", None)

        self.skip_check_credentials = skip_check_credentials or get_bool_from_env(
            "CONAN_SKIP_CHECK_CREDENTIALS")

        self.auth_manager = AuthManager(
            self.conan_api,
            self.printer,
            login_username,
            password,
            default_username=self.username,
            skip_check_credentials=self.skip_check_credentials)

        # Upload related variables
        self.upload_retry = upload_retry or os.getenv("CONAN_UPLOAD_RETRY", 3)

        if upload_only_when_stable is not None:
            self.upload_only_when_stable = upload_only_when_stable
        else:
            self.upload_only_when_stable = get_bool_from_env(
                "CONAN_UPLOAD_ONLY_WHEN_STABLE")

        if upload_only_when_tag is not None:
            self.upload_only_when_tag = upload_only_when_tag
        else:
            self.upload_only_when_tag = get_bool_from_env(
                "CONAN_UPLOAD_ONLY_WHEN_TAG")

        self.upload_only_recipe = upload_only_recipe or get_bool_from_env(
            "CONAN_UPLOAD_ONLY_RECIPE")

        self.remotes_manager.add_remotes_to_conan()
        self.uploader = Uploader(self.conan_api, self.remotes_manager,
                                 self.auth_manager, self.printer,
                                 self.upload_retry)

        self._builds = []
        self._named_builds = {}
        self._packages_summary = []

        self._update_conan_in_docker = always_update_conan_in_docker or get_bool_from_env(
            "CONAN_ALWAYS_UPDATE_CONAN_DOCKER")

        self._platform_info = platform_info or PlatformInfo()

        self.stable_branch_pattern = stable_branch_pattern or \
                                     os.getenv("CONAN_STABLE_BRANCH_PATTERN", None)

        self.stable_channel = stable_channel or os.getenv(
            "CONAN_STABLE_CHANNEL", "stable")
        self.stable_channel = self.stable_channel.rstrip()
        self.partial_reference = reference or os.getenv(
            "CONAN_REFERENCE", None)
        self.channel = self._get_specified_channel(channel, reference)
        self.conanfile = conanfile or os.getenv("CONAN_CONANFILE",
                                                "conanfile.py")

        if self.partial_reference:
            if "@" in self.partial_reference:
                self.reference = ConanFileReference.loads(
                    self.partial_reference)
            else:
                name, version = self.partial_reference.split("/")
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
        else:
            if not os.path.exists(os.path.join(self.cwd, self.conanfile)):
                raise Exception("Conanfile not found, specify a 'reference' "
                                "parameter with name and version")

            conanfile = load_cf_class(os.path.join(self.cwd, self.conanfile),
                                      self.conan_api)
            name, version = conanfile.name, conanfile.version
            if name and version:
                self.reference = ConanFileReference(name, version,
                                                    self.username,
                                                    self.channel)
            else:
                self.reference = None

        self._docker_image = docker_image or os.getenv("CONAN_DOCKER_IMAGE",
                                                       None)

        # If CONAN_DOCKER_IMAGE is specified, then use docker is True
        self.use_docker = (use_docker or os.getenv("CONAN_USE_DOCKER", False)
                           or self._docker_image is not None)

        self.docker_conan_home = docker_conan_home or os.getenv(
            "CONAN_DOCKER_HOME", None)

        os_name = self._platform_info.system(
        ) if not self.use_docker else "Linux"
        self.build_generator = BuildGenerator(
            reference, os_name, gcc_versions, apple_clang_versions,
            clang_versions, visual_versions, visual_runtimes, visual_toolsets,
            vs10_x86_64_enabled, mingw_configurations, archs, allow_gcc_minors,
            build_types, options, cppstds)

        self.build_policy = (build_policy
                             or self.ci_manager.get_commit_build_policy()
                             or split_colon_env("CONAN_BUILD_POLICY"))
        if isinstance(self.build_policy, list):
            self.build_policy = ",".join(self.build_policy)

        self.sudo_docker_command = ""
        if "CONAN_DOCKER_USE_SUDO" in os.environ:
            self.sudo_docker_command = "sudo -E" if get_bool_from_env(
                "CONAN_DOCKER_USE_SUDO") else ""
        elif platform.system() != "Windows":
            self.sudo_docker_command = "sudo -E"

        self.sudo_pip_command = ""
        if "CONAN_PIP_USE_SUDO" in os.environ:
            self.sudo_pip_command = "sudo -E" if get_bool_from_env(
                "CONAN_PIP_USE_SUDO") else ""
        elif platform.system(
        ) != "Windows" and self._docker_image and 'conanio/' not in str(
                self._docker_image):
            self.sudo_pip_command = "sudo -E"
        self.pip_command = os.getenv("CONAN_PIP_COMMAND", "pip")
        pip_found = True if tools.os_info.is_windows else tools.which(
            self.pip_command)
        if not pip_found or not "pip" in self.pip_command:
            raise Exception(
                "CONAN_PIP_COMMAND: '{}' is not a valid pip command.".format(
                    self.pip_command))
        self.docker_pip_command = os.getenv("CONAN_DOCKER_PIP_COMMAND", "pip")

        self.docker_shell = docker_shell or os.getenv("CONAN_DOCKER_SHELL")

        if self.is_wcow:
            if self.docker_conan_home is None:
                self.docker_conan_home = "C:/Users/ContainerAdministrator"
                self.docker_shell = docker_shell or "cmd /C"
        else:
            if self.docker_conan_home is None:
                self.docker_conan_home = "/home/conan"
                self.docker_shell = docker_shell or "/bin/sh -c"

        self.docker_platform_param = ""
        self.lcow_user_workaround = ""

        if self.is_lcow:
            self.docker_platform_param = "--platform=linux"
            # With LCOW, Docker doesn't respect USER directive in dockerfile yet
            self.lcow_user_workaround = "sudo su conan && "

        self.exclude_vcvars_precommand = exclude_vcvars_precommand or \
                                          get_bool_from_env("CONAN_EXCLUDE_VCVARS_PRECOMMAND")
        self._docker_image_skip_update = docker_image_skip_update or \
                                          get_bool_from_env("CONAN_DOCKER_IMAGE_SKIP_UPDATE")
        self._docker_image_skip_pull = docker_image_skip_pull or \
                                        get_bool_from_env("CONAN_DOCKER_IMAGE_SKIP_PULL")

        self.runner = runner or os.system
        self.output_runner = ConanOutputRunner()

        self.docker_run_options = docker_run_options or split_colon_env(
            "CONAN_DOCKER_RUN_OPTIONS")
        if isinstance(self.docker_run_options, list):
            self.docker_run_options = " ".join(self.docker_run_options)

        self.docker_entry_script = docker_entry_script or os.getenv(
            "CONAN_DOCKER_ENTRY_SCRIPT")

        self.pip_install = pip_install or split_colon_env("CONAN_PIP_INSTALL")

        self.upload_dependencies = upload_dependencies or split_colon_env(
            "CONAN_UPLOAD_DEPENDENCIES") or ""
        if isinstance(self.upload_dependencies, list):
            self.upload_dependencies = ",".join(self.upload_dependencies)
        if "all" in self.upload_dependencies and self.upload_dependencies != "all":
            raise Exception(
                "Upload dependencies only accepts or 'all' or package references. Do not mix both!"
            )

        self.update_dependencies = update_dependencies or get_bool_from_env(
            "CONAN_UPDATE_DEPENDENCIES")

        if self.channel:
            os.environ["CONAN_CHANNEL"] = self.channel

        if docker_32_images is not None:
            self.docker_32_images = docker_32_images
        else:
            self.docker_32_images = os.getenv("CONAN_DOCKER_32_IMAGES", False)

        self.force_selinux = force_selinux or get_bool_from_env(
            "CONAN_FORCE_SELINUX")
        self.curpage = curpage or os.getenv("CONAN_CURRENT_PAGE", 1)
        self.total_pages = total_pages or os.getenv("CONAN_TOTAL_PAGES", 1)

        self.conan_pip_package = os.getenv("CONAN_PIP_PACKAGE",
                                           "conan==%s" % conan_version)
        if self.conan_pip_package in ("0", "False"):
            self.conan_pip_package = ""
        self.vs10_x86_64_enabled = vs10_x86_64_enabled

        self.builds_in_current_page = []

        self.test_folder = test_folder or os.getenv("CPT_TEST_FOLDER")

        self.config_url = config_url or os.getenv("CONAN_CONFIG_URL")

        self.skip_recipe_export = skip_recipe_export or \
                                     get_bool_from_env("CONAN_SKIP_RECIPE_EXPORT")
        self.config_args = config_args or os.getenv("CONAN_CONFIG_ARGS")

        self.lockfile = lockfile or os.getenv("CONAN_LOCKFILE")

        def valid_pair(var, value):
            return (isinstance(value, six.string_types)
                    or isinstance(value, bool) or isinstance(value, list)
                    ) and not var.startswith("_") and "password" not in var

        with self.printer.foldable_output("local_vars"):
            self.printer.print_dict({
                var: value
                for var, value in self.__dict__.items()
                if valid_pair(var, value)
            })
コード例 #37
0
    def test_inconsistent_cache(self):
        conanfile = """
import os
from conans import ConanFile, tools


class TestConan(ConanFile):
    name = "test"
    version = "1.0"
    short_paths = {0}
    exports_sources = "source_file.cpp"

    def source(self):
        for item in os.listdir(self.source_folder):
            self.output.info("SOURCE: " + str(item))
    def build(self):
        tools.save(os.path.join(self.build_folder, "artifact"), "")
        for item in os.listdir(self.build_folder):
            self.output.info("BUILD: " + str(item))
    def package(self):
        self.copy("source_file.cpp")
        self.copy("artifact")
        for item in os.listdir(self.build_folder):
            self.output.info("PACKAGE: " + str(item))
"""

        client = TestClient()
        client.save({
            "conanfile.py": conanfile.format("False"),
            "source_file.cpp": ""
        })
        client.run("create . danimtb/testing")
        ref = ConanFileReference("test", "1.0", "danimtb", "testing")
        source_folder = os.path.join(
            client.cache.package_layout(ref).base_folder(), "source")
        build_folder = os.path.join(
            client.cache.package_layout(ref).base_folder(), "build",
            NO_SETTINGS_PACKAGE_ID)
        package_folder = os.path.join(
            client.cache.package_layout(ref).base_folder(), "package",
            NO_SETTINGS_PACKAGE_ID)
        self.assertIn("SOURCE: source_file.cpp", client.out)
        self.assertEqual(["source_file.cpp"], os.listdir(source_folder))
        self.assertIn("BUILD: source_file.cpp", client.out)
        self.assertIn("BUILD: artifact", client.out)
        self.assertEqual(
            sorted([
                "artifact", "conanbuildinfo.txt", "conaninfo.txt",
                "source_file.cpp"
            ]), sorted(os.listdir(build_folder)))
        self.assertIn("PACKAGE: source_file.cpp", client.out)
        self.assertIn("PACKAGE: artifact", client.out)
        self.assertEqual(
            sorted([
                "artifact", "conaninfo.txt", "conanmanifest.txt",
                "source_file.cpp"
            ]), sorted(os.listdir(package_folder)))
        client.save({"conanfile.py": conanfile.format("True")})
        client.run("create . danimtb/testing")
        self.assertIn("SOURCE: source_file.cpp", client.out)
        self.assertEqual([".conan_link"], os.listdir(source_folder))
        self.assertIn("BUILD: source_file.cpp", client.out)
        self.assertIn("BUILD: artifact", client.out)
        self.assertEqual([".conan_link"], os.listdir(build_folder))
        self.assertIn("PACKAGE: source_file.cpp", client.out)
        self.assertIn("PACKAGE: artifact", client.out)
        self.assertEqual([".conan_link"], os.listdir(package_folder))
コード例 #38
0
    def generators_test(self):
        ref = ConanFileReference.loads("Hello/0.1@lasote/stable")
        client = TestClient()
        client.save({
            "conanfile.py":
            """from conans import ConanFile
import os
class Pkg(ConanFile):
    def package(self):
        os.makedirs(os.path.join(self.package_folder, "lib"))
        os.makedirs(os.path.join(self.package_folder, "include"))
    def package_info(self):
        self.cpp_info.libs = ["hello"]
        self.cpp_info.cxxflags = ["-some_cxx_compiler_flag"]
        self.cpp_info.cflags = ["-some_c_compiler_flag"]
"""
        })
        client.run("export . Hello/0.1@lasote/stable")
        conanfile_txt = '''[requires]
Hello/0.1@lasote/stable # My req comment
[generators]
gcc # I need this generator for..
cmake
visual_studio
xcode
'''
        client.save({"conanfile.txt": conanfile_txt}, clean_first=True)

        # Install requirements
        client.run('install . --build missing')
        self.assertEqual(
            sorted([
                CONANFILE_TXT, BUILD_INFO_GCC, BUILD_INFO_CMAKE,
                BUILD_INFO_VISUAL_STUDIO, BUILD_INFO, BUILD_INFO_XCODE,
                CONANINFO, GRAPH_INFO_FILE
            ]), sorted(os.listdir(client.current_folder)))

        cmake = load(os.path.join(client.current_folder, BUILD_INFO_CMAKE))
        gcc = load(os.path.join(client.current_folder, BUILD_INFO_GCC))

        self.assertIn("CONAN_INCLUDE_DIRS", cmake)
        self.assertIn("CONAN_LIB_DIRS", cmake)
        self.assertIn("CONAN_LIBS", cmake)

        self.assertIn("CONAN_INCLUDE_DIRS", cmake)
        self.assertIn("CONAN_LIB_DIRS", cmake)
        self.assertIn(".conan/data/Hello/0.1/lasote/stable/package", cmake)

        self.assertIn("-L", gcc)
        self.assertIn("-l", gcc)
        self.assertIn("-I", gcc)

        self.assertIn(".conan/data/Hello/0.1/lasote/stable/package", gcc)

        # CHECK VISUAL STUDIO GENERATOR

        from xml.dom import minidom
        xmldoc = minidom.parse(
            os.path.join(client.current_folder, BUILD_INFO_VISUAL_STUDIO))
        definition_group = xmldoc.getElementsByTagName(
            'ItemDefinitionGroup')[0]
        compiler = definition_group.getElementsByTagName("ClCompile")[0]

        elem = compiler.getElementsByTagName("AdditionalIncludeDirectories")
        include_dirs = elem[0].firstChild.data
        definitions = compiler.getElementsByTagName(
            "PreprocessorDefinitions")[0].firstChild.data

        linker = definition_group.getElementsByTagName("Link")[0]
        lib_dirs = linker.getElementsByTagName(
            "AdditionalLibraryDirectories")[0].firstChild.data
        libs = linker.getElementsByTagName(
            "AdditionalDependencies")[0].firstChild.data

        package_id = os.listdir(client.cache.package_layout(ref).packages())[0]
        pref = PackageReference(ref, package_id)
        package_path = client.cache.package_layout(pref.ref).package(pref)

        replaced_path = re.sub(os.getenv("USERPROFILE",
                                         "not user profile").replace(
                                             "\\", "\\\\"),
                               "$(USERPROFILE)",
                               package_path,
                               flags=re.I)
        expected_lib_dirs = os.path.join(replaced_path, "lib")
        expected_include_dirs = os.path.join(replaced_path, "include")

        self.assertIn(expected_lib_dirs, lib_dirs)
        self.assertEqual("hello.lib;%(AdditionalDependencies)", libs)
        self.assertEqual("%(PreprocessorDefinitions)", definitions)
        self.assertIn(expected_include_dirs, include_dirs)

        # CHECK XCODE GENERATOR
        xcode = load(os.path.join(client.current_folder, BUILD_INFO_XCODE))

        expected_c_flags = '-some_c_compiler_flag'
        expected_cpp_flags = '-some_cxx_compiler_flag'
        expected_lib_dirs = os.path.join(package_path,
                                         "lib").replace("\\", "/")
        expected_include_dirs = os.path.join(package_path,
                                             "include").replace("\\", "/")

        self.assertIn(
            'LIBRARY_SEARCH_PATHS = $(inherited) "%s"' % expected_lib_dirs,
            xcode)
        self.assertIn(
            'HEADER_SEARCH_PATHS = $(inherited) "%s"' % expected_include_dirs,
            xcode)
        self.assertIn("GCC_PREPROCESSOR_DEFINITIONS = $(inherited)", xcode)
        self.assertIn('OTHER_CFLAGS = $(inherited) %s' % expected_c_flags,
                      xcode)
        self.assertIn(
            'OTHER_CPLUSPLUSFLAGS = $(inherited) %s' % expected_cpp_flags,
            xcode)
        self.assertIn(
            'FRAMEWORK_SEARCH_PATHS = $(inherited) "%s"' %
            package_path.replace("\\", "/"), xcode)
コード例 #39
0
ファイル: conan_env_test.py プロジェクト: torbjoernk/conan
 def load_conaninfo(lib):
     # Read the LIB_A conaninfo
     packages_path = client.client_cache.packages(ConanFileReference.loads("LIB_%s/1.0@lasote/stable" % lib))
     package_path = os.path.join(packages_path, os.listdir(packages_path)[0])
     info = ConanInfo.loads(load(os.path.join(package_path, CONANINFO)))
     return info
コード例 #40
0
 def setUp(self):
     ref = ConanFileReference.loads("lib/version@user/channel")
     self.package_layout = PackageCacheLayout(base_folder=temp_folder(), ref=ref,
                                              short_paths=False, no_lock=True)
     self.output = TestBufferConanOutput()
コード例 #41
0
    def test_package(self,
                     profile_name=None,
                     settings=None,
                     options=None,
                     env=None,
                     scope=None,
                     test_folder=None,
                     not_export=False,
                     build=None,
                     keep_source=False,
                     verify=None,
                     manifests=None,
                     manifests_interactive=None,
                     remote=None,
                     update=False,
                     cwd=None,
                     user=None,
                     channel=None,
                     name=None,
                     version=None):

        self._user_io.out.warn(
            "THIS METHOD IS DEPRECATED and will be removed. "
            "Use 'conan create' to generate binary packages for a "
            "recipe. If you want to test a package you can use 'conan test' "
            "command.")

        settings = settings or []
        options = options or []
        env = env or []
        cwd = prepare_cwd(cwd)

        if name and version:
            package_name = name
            package_version = version
        else:
            conanfile_path = os.path.join(cwd, "conanfile.py")
            conanfile = load_conanfile_class(conanfile_path)
            package_name = getattr(conanfile, "name", None)
            package_version = getattr(conanfile, "version", None)
        if not package_name or not package_version:
            raise ConanException(
                "conanfile.py doesn't declare package name or version")

        test_folders = [test_folder
                        ] if test_folder else ["test_package", "test"]
        for test_folder_name in test_folders:
            test_folder = os.path.join(cwd, test_folder_name)
            test_conanfile_path = os.path.join(test_folder, "conanfile.py")
            if os.path.exists(test_conanfile_path):
                break
        else:
            raise ConanException("test folder '%s' not available, "
                                 "or it doesn't have a conanfile.py" %
                                 test_folder_name)

        sha = hashlib.sha1("".join(options + settings).encode()).hexdigest()
        build_folder = os.path.join(test_folder, "build", sha)
        rmdir(build_folder)
        # shutil.copytree(test_folder, build_folder)

        profile = profile_from_args(profile_name, settings, options, env,
                                    scope, cwd, self._client_cache)

        loader = self._manager.get_loader(profile)
        test_conanfile = loader.load_conan(test_conanfile_path,
                                           self._user_io.out,
                                           consumer=True)

        try:
            if hasattr(test_conanfile, "requirements"):
                test_conanfile.requirements()
        except Exception as e:
            raise ConanException(
                "Error in test_package/conanfile.py requirements(). %s" %
                str(e))

        requirement = test_conanfile.requires.get(package_name)
        if requirement:
            if requirement.conan_reference.version != package_version:
                raise ConanException(
                    "package version is '%s', but test_package/conanfile "
                    "is requiring version '%s'\n"
                    "You can remove this requirement and use "
                    "'conan test_package user/channel' instead" %
                    (package_version, requirement.conan_reference.version))
            user = user or requirement.conan_reference.user
            channel = channel or requirement.conan_reference.channel

        if not user or not channel:
            raise ConanException("Please specify user and channel")
        conanfile_reference = ConanFileReference(package_name, package_version,
                                                 user, channel)

        # Forcing an export!
        if not not_export:
            self._user_io.out.info("Exporting package recipe")
            self._manager.export(user, channel, cwd, keep_source=keep_source)

        if build is None:  # Not specified, force build the tested library
            build = [package_name]

        manifests = _parse_manifests_arguments(verify, manifests,
                                               manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests
        self._manager.install(inject_require=conanfile_reference,
                              reference=test_folder,
                              install_folder=build_folder,
                              manifest_folder=manifest_folder,
                              manifest_verify=manifest_verify,
                              manifest_interactive=manifest_interactive,
                              remote=remote,
                              profile=profile,
                              build_modes=build,
                              update=update,
                              generators=["txt"])

        test_conanfile = os.path.join(test_folder, CONANFILE)
        self._manager.build(test_conanfile,
                            test_folder,
                            build_folder,
                            package_folder=None,
                            install_folder=build_folder,
                            test=str(conanfile_reference))
コード例 #42
0
ファイル: only_source_test.py プロジェクト: ttencate/conan
    def reuse_test(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")
        files[CONANFILE] = files[CONANFILE].replace("build", "build2")

        client.save(files)
        client.run("export . lasote/stable")
        client.run("install %s --build missing" % str(ref))

        self.assertTrue(
            os.path.exists(client.cache.package_layout(ref).builds()))
        self.assertTrue(
            os.path.exists(client.cache.package_layout(ref).packages()))

        # Upload
        client.run("upload %s --all" % str(ref))

        # Now from other "computer" install the uploaded conans with same options (nothing)
        other_client = TestClient(servers=self.servers,
                                  users={"default": [("lasote", "mypass")]})
        other_client.run("install %s --build missing" % str(ref))
        self.assertFalse(
            os.path.exists(other_client.cache.package_layout(ref).builds()))
        self.assertTrue(
            os.path.exists(other_client.cache.package_layout(ref).packages()))

        # Now from other "computer" install the uploaded conans with same options (nothing)
        other_client = TestClient(servers=self.servers,
                                  users={"default": [("lasote", "mypass")]})
        other_client.run("install %s --build" % str(ref))
        self.assertTrue(
            os.path.exists(other_client.cache.package_layout(ref).builds()))
        self.assertTrue(
            os.path.exists(other_client.cache.package_layout(ref).packages()))

        # Use an invalid pattern and check that its not builded from source
        other_client = TestClient(servers=self.servers,
                                  users={"default": [("lasote", "mypass")]})
        other_client.run("install %s --build HelloInvalid" % str(ref))
        self.assertIn("No package matching 'HelloInvalid' pattern",
                      other_client.out)
        self.assertFalse(
            os.path.exists(other_client.cache.package_layout(ref).builds()))
        # self.assertFalse(os.path.exists(other_client.cache.package_layout(ref).packages()))

        # Use another valid pattern and check that its not builded from source
        other_client = TestClient(servers=self.servers,
                                  users={"default": [("lasote", "mypass")]})
        other_client.run("install %s --build HelloInvalid -b Hello" % str(ref))
        self.assertIn("No package matching 'HelloInvalid' pattern",
                      other_client.out)
        # self.assertFalse(os.path.exists(other_client.cache.package_layout(ref).builds()))
        # self.assertFalse(os.path.exists(other_client.cache.package_layout(ref).packages()))

        # Now even if the package is in local store, check that's rebuilded
        other_client.run("install %s -b Hello*" % str(ref))
        self.assertIn("Copying sources to build folder", other_client.out)

        other_client.run("install %s" % str(ref))
        self.assertNotIn("Copying sources to build folder", other_client.out)
コード例 #43
0
    def test_dot_files(self):
        """ Check behavior related to ._ files in Macos OS

            Macos has the ability to store metadata associated to files. This metadata can be
            stored in the HFS+ (Apple native) or Unix/UFS volumes, but if the store does
            not have this capability it will be placed in a ._ file. So these files will
            automatically be created by the OS when it is creating a package in order to
            send this information.

            Nevertheless, Conan is using the Python libraries to copy, tar and untar files
            and this metadata is lost when using them. It can avoid some problems like
            #3529 but there is missing information that can be valuable at some point in time.

            This test is here just to be sure that the behavior is not changed without
            noticing.
            """

        conanfile = textwrap.dedent("""\
            from conans import ConanFile

            class Lib(ConanFile):
                name = "lib"
                version = "version"
                exports_sources = "file.txt"

                def package(self):
                    self.copy("file.txt")
            """)

        default_server = TestServer()
        servers = {"default": default_server}
        t = TestClient(path_with_spaces=False,
                       servers=servers,
                       users={"default": [("lasote", "mypass")]})
        t.save(files={'conanfile.py': conanfile, 'file.txt': "content"})

        def _add_macos_metadata_to_file(filepath):
            subprocess.call(["xattr", "-w", "name", "value", filepath])

        _add_macos_metadata_to_file(os.path.join(t.current_folder, 'file.txt'))
        t.run("create . lasote/channel")

        # Check if the metadata travels through the Conan commands
        pref = PackageReference.loads(
            "lib/version@lasote/channel:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9"
        )
        pkg_folder = t.cache.package_layout(pref.ref).package(pref)

        # 1) When copied to the package folder, the metadata is lost
        self._test_for_metadata(pkg_folder,
                                'file.txt',
                                dot_file_expected=False)

        # 2) If we add metadata to a file, it will be there
        _add_macos_metadata_to_file(os.path.join(pkg_folder, 'file.txt'))
        self._test_for_metadata(pkg_folder, 'file.txt', dot_file_expected=True)

        # 3) In the upload process, the metadata is lost again
        ref = ConanFileReference.loads("lib/version@lasote/channel")
        export_folder = t.cache.package_layout(ref).export()
        tgz = os.path.join(export_folder, EXPORT_SOURCES_TGZ_NAME)
        self.assertFalse(os.path.exists(tgz))
        t.run("upload lib/version@lasote/channel")
        self._test_for_metadata_in_zip_file(tgz,
                                            'file.txt',
                                            dot_file_expected=False)
コード例 #44
0
 def remote_ref_list(self, refs):
     for reference, remote_name in refs.items():
         ref = ConanFileReference.loads(reference)
         self._output.info("%s: %s" % (ref.full_str(), remote_name))
コード例 #45
0
ファイル: graph_manager.py プロジェクト: stkw0/conan
 def add(self, build_require, context):
     if not isinstance(build_require, ConanFileReference):
         build_require = ConanFileReference.loads(build_require)
     self[(build_require.name, context)] = build_require
コード例 #46
0
def inc_recipe_manifest_timestamp(cache, reference, inc_time):
    ref = ConanFileReference.loads(reference)
    path = cache.package_layout(ref).export()
    manifest = FileTreeManifest.load(path)
    manifest.time += inc_time
    manifest.save(path)
コード例 #47
0
    def add_common_builds(self,
                          shared_option_name=None,
                          pure_c=True,
                          dll_with_static_runtime=False,
                          reference=None,
                          header_only=True,
                          build_all_options_values=None):
        if reference:
            if "@" in reference:
                reference = ConanFileReference.loads(reference)
            else:
                name, version = reference.split("/")
                reference = ConanFileReference(name, version, self.username,
                                               self.channel)
        else:
            reference = self.reference

        if not reference:
            raise Exception(
                "Specify a CONAN_REFERENCE or name and version fields in the recipe"
            )

        if shared_option_name is None:
            env_shared_option_name = os.getenv("CONAN_SHARED_OPTION_NAME",
                                               None)
            shared_option_name = env_shared_option_name if str(
                env_shared_option_name).lower() != "false" else False

        build_all_options_values = build_all_options_values or split_colon_env(
            "CONAN_BUILD_ALL_OPTIONS_VALUES") or []
        if not isinstance(build_all_options_values, list):
            raise Exception(
                "'build_all_options_values' must be a list. e.g. ['foo:opt', 'foo:bar']"
            )

        conanfile = None
        if os.path.exists(os.path.join(self.cwd, self.conanfile)):
            conanfile = load_cf_class(os.path.join(self.cwd, self.conanfile),
                                      self.conan_api)

        header_only_option = None
        if conanfile:
            if hasattr(
                    conanfile, "options"
            ) and conanfile.options and "header_only" in conanfile.options:
                header_only_option = "%s:header_only" % reference.name

        if shared_option_name is None:
            if conanfile:
                if hasattr(
                        conanfile, "options"
                ) and conanfile.options and "shared" in conanfile.options:
                    shared_option_name = "%s:shared" % reference.name

        # filter only valid options
        raw_options_for_building = [
            opt[opt.find(":") + 1:] for opt in build_all_options_values
        ]
        for raw_option in reversed(raw_options_for_building):
            if hasattr(conanfile, "options") and conanfile.options and \
               not isinstance(conanfile.options.get(raw_option), list):
                raw_options_for_building.remove(raw_option)
        if raw_options_for_building and conanfile:
            # get option and its values
            cloned_options = copy.copy(conanfile.options)
            for key, value in conanfile.options.items():
                if key == "shared" and shared_option_name:
                    continue
                elif key not in raw_options_for_building:
                    del cloned_options[key]
            cloned_options2 = {}
            for key, value in cloned_options.items():
                # add package reference to the option name
                if not key.startswith("{}:".format(reference.name)):
                    cloned_options2["{}:{}".format(reference.name,
                                                   key)] = value
            # combine all options x values (cartesian product)
            build_all_options_values = [
                dict(zip(cloned_options2, v))
                for v in product(*cloned_options2.values())
            ]

        builds = self.build_generator.get_builds(pure_c, shared_option_name,
                                                 dll_with_static_runtime,
                                                 reference,
                                                 build_all_options_values)

        if header_only_option and header_only:
            if conanfile.default_options.get("header_only"):
                cloned_builds = copy.deepcopy(builds)
                for settings, options, env_vars, build_requires, reference in cloned_builds:
                    options.update({header_only_option: False})
                builds.extend(cloned_builds)
            else:
                settings, options, env_vars, build_requires, reference = builds[
                    0]
                cloned_options = copy.copy(options)
                cloned_options.update({header_only_option: True})
                builds.append(
                    BuildConf(copy.copy(settings), cloned_options,
                              copy.copy(env_vars), copy.copy(build_requires),
                              reference))

        self._builds.extend(builds)
コード例 #48
0
    def upload_test(self):
        client = TestClient(servers={"default": TestServer()},
                            users={"default": [("lasote", "mypass")]})
        ref = ConanFileReference.loads("Hello0/0.1@lasote/stable#%s" %
                                       DEFAULT_REVISION_V1)
        files = cpp_hello_conan_files("Hello0", "0.1", build=False)
        files["to_be_deleted.txt"] = "delete me"
        files["to_be_deleted2.txt"] = "delete me2"

        remote_paths = client.servers["default"].server_store

        client.save(files)
        client.run("export . lasote/stable")

        # Upload conan file
        client.run("upload %s" % str(ref))

        # Verify the files are there
        if client.cache.config.revisions_enabled:
            rev = client.cache.package_layout(ref).recipe_revision()
            ref = ref.copy_with_rev(rev)
        server_conan_path = remote_paths.export(ref)
        self.assertTrue(
            os.path.exists(os.path.join(server_conan_path, EXPORT_TGZ_NAME)))
        tmp = temp_folder()
        untargz(os.path.join(server_conan_path, EXPORT_TGZ_NAME), tmp)
        self.assertTrue(load(os.path.join(tmp, "to_be_deleted.txt")),
                        "delete me")
        self.assertTrue(load(os.path.join(tmp, "to_be_deleted2.txt")),
                        "delete me2")

        # Now delete local files export and upload and check that they are not in server
        os.remove(os.path.join(client.current_folder, "to_be_deleted.txt"))
        client.run("export . lasote/stable")
        client.run("upload %s" % str(ref))
        if client.cache.config.revisions_enabled:
            rev = client.cache.package_layout(ref).recipe_revision()
            ref = ref.copy_with_rev(rev)
        server_conan_path = remote_paths.export(ref)
        self.assertTrue(
            os.path.exists(os.path.join(server_conan_path, EXPORT_TGZ_NAME)))
        tmp = temp_folder()
        untargz(os.path.join(server_conan_path, EXPORT_TGZ_NAME), tmp)
        self.assertFalse(os.path.exists(os.path.join(tmp,
                                                     "to_be_deleted.txt")))
        self.assertTrue(os.path.exists(os.path.join(tmp,
                                                    "to_be_deleted2.txt")))

        # Now modify a file, and delete other, and put a new one.
        files["to_be_deleted2.txt"] = "modified content"
        files["new_file.lib"] = "new file"
        del files["to_be_deleted.txt"]
        client.save(files)
        client.run("export . lasote/stable")
        client.run("upload %s" % str(ref))

        if client.cache.config.revisions_enabled:
            rev = client.cache.package_layout(ref).recipe_revision()
            ref = ref.copy_with_rev(rev)
        server_conan_path = remote_paths.export(ref)

        # Verify all is correct
        self.assertTrue(
            os.path.exists(os.path.join(server_conan_path, EXPORT_TGZ_NAME)))
        tmp = temp_folder()
        untargz(os.path.join(server_conan_path, EXPORT_TGZ_NAME), tmp)
        self.assertTrue(load(os.path.join(tmp, "to_be_deleted2.txt")),
                        "modified content")
        self.assertTrue(load(os.path.join(tmp, "new_file.lib")), "new file")
        self.assertFalse(os.path.exists(os.path.join(tmp,
                                                     "to_be_deleted.txt")))

        ##########################
        # Now try with the package
        ##########################

        client.run("install %s --build missing" % str(ref))
        # Upload package
        package_ids = client.cache.conan_packages(ref)
        client.run("upload %s -p %s" % (str(ref), str(package_ids[0])))

        # Check that conans exists on server
        pref = PackageReference(ref, str(package_ids[0]))
        prev = remote_paths.get_last_package_revision(pref)
        pref = pref.copy_with_revs(pref.ref.revision, prev.revision)
        package_server_path = remote_paths.package(pref)
        self.assertTrue(os.path.exists(package_server_path))

        # Add a new file to package (artificially), upload again and check
        pack_path = client.cache.package(pref)
        new_file_source_path = os.path.join(pack_path, "newlib.lib")
        save(new_file_source_path, "newlib")
        os.unlink(os.path.join(pack_path, PACKAGE_TGZ_NAME))  # Force new tgz

        self._create_manifest(client, pref)
        client.run("upload %s -p %s" % (str(ref), str(package_ids[0])))

        folder = uncompress_packaged_files(remote_paths, pref)
        remote_file_path = os.path.join(folder, "newlib.lib")
        self.assertTrue(os.path.exists(remote_file_path))

        # Now modify the file and check again
        save(new_file_source_path, "othercontent")
        self._create_manifest(client, pref)
        client.run("upload %s -p %s" % (str(ref), str(package_ids[0])))
        folder = uncompress_packaged_files(remote_paths, pref)
        remote_file_path = os.path.join(folder, "newlib.lib")
        self.assertTrue(os.path.exists(remote_file_path))
        self.assertTrue(load(remote_file_path), "othercontent")

        # Now delete the file and check again
        os.remove(new_file_source_path)
        self._create_manifest(client, pref)
        os.unlink(os.path.join(pack_path, PACKAGE_TGZ_NAME))  # Force new tgz
        client.run("upload %s -p %s" % (str(ref), str(package_ids[0])))
        folder = uncompress_packaged_files(remote_paths, pref)
        remote_file_path = os.path.join(folder, "newlib.lib")

        # With revisions makes no sense because there is a new revision always that sources change
        if not client.cache.config.revisions_enabled:
            self.assertFalse(os.path.exists(remote_file_path))
            self.assertNotEqual(remote_file_path, new_file_source_path)
コード例 #49
0
ファイル: remover.py プロジェクト: Sfairat/conan
    def remove(self, pattern, remote_name, src=None, build_ids=None, package_ids_filter=None,
               force=False, packages_query=None, outdated=False):
        """ Remove local/remote conans, package folders, etc.
        @param src: Remove src folder
        @param pattern: it could be OpenCV* or OpenCV or a ConanFileReference
        @param build_ids: Lists with ids or empty for all. (Its a filter)
        @param package_ids_filter: Lists with ids or empty for all. (Its a filter)
        @param force: if True, it will be deleted without requesting anything
        @param packages_query: Only if src is a reference. Query settings and options
        """

        if remote_name and (build_ids is not None or src):
            raise ConanException("Remotes don't have 'build' or 'src' folder, just packages")

        is_reference = check_valid_ref(pattern)
        input_ref = ConanFileReference.loads(pattern) if is_reference else None

        if not input_ref and packages_query is not None:
            raise ConanException("query parameter only allowed with a valid recipe "
                                 "reference as the search pattern.")

        if input_ref and package_ids_filter and not input_ref.revision:
            for package_id in package_ids_filter:
                if "#" in package_id:
                    raise ConanException("Specify a recipe revision if you specify a package "
                                         "revision")

        if remote_name:
            remote = self._remotes[remote_name]
            if input_ref:
                if not self._cache.config.revisions_enabled and input_ref.revision:
                    raise ConanException("Revisions not enabled in the client, cannot remove "
                                         "revisions in the server")
                refs = [input_ref]
            else:
                refs = self._remote_manager.search_recipes(remote, pattern)
        else:
            if input_ref:
                refs = []
                if self._cache.installed_as_editable(input_ref):
                    raise ConanException(self._message_removing_editable(input_ref))
                if not self._cache.package_layout(input_ref).recipe_exists():
                    raise RecipeNotFoundException(input_ref,
                                                  print_rev=self._cache.config.revisions_enabled)
                refs.append(input_ref)
            else:
                refs = search_recipes(self._cache, pattern)
                if not refs:
                    self._user_io.out.warn("No package recipe matches '%s'" % str(pattern))
                    return

        if input_ref and not input_ref.revision:
            # Ignore revisions for deleting if the input was not with a revision
            # (Removing all the recipe revisions from a reference)
            refs = [r.copy_clear_rev() for r in refs]

        deleted_refs = []
        for ref in refs:
            assert isinstance(ref, ConanFileReference)
            package_layout = self._cache.package_layout(ref)
            package_ids = package_ids_filter
            if packages_query or outdated:
                # search packages
                if remote_name:
                    packages = self._remote_manager.search_packages(remote, ref, packages_query)
                else:
                    packages = search_packages(package_layout, packages_query)
                if outdated:
                    if remote_name:
                        manifest, ref = self._remote_manager.get_recipe_manifest(ref, remote)
                        recipe_hash = manifest.summary_hash
                    else:
                        recipe_hash = package_layout.recipe_manifest().summary_hash
                    packages = filter_outdated(packages, recipe_hash)
                if package_ids_filter:
                    package_ids = [p for p in packages if p in package_ids_filter]
                else:
                    package_ids = list(packages.keys())
                if not package_ids:
                    self._user_io.out.warn("No matching packages to remove for %s"
                                           % ref.full_str())
                    continue

            if self._ask_permission(ref, src, build_ids, package_ids, force):
                try:
                    if remote_name:
                        self._remote_remove(ref, package_ids, remote)
                    else:
                        self._local_remove(ref, src, build_ids, package_ids)
                except NotFoundException:
                    # If we didn't specify a pattern but a concrete ref, fail if there is no
                    # ref to remove
                    if input_ref:
                        raise
                else:
                    deleted_refs.append(ref)

        if not remote_name:
            self._cache.delete_empty_dirs(deleted_refs)
コード例 #50
0
def get_mingw_package_reference():
    env_ref = os.getenv("CONAN_MINGW_INSTALLER_REFERENCE")
    return ConanFileReference.loads(env_ref
                                    or "mingw_installer/1.0@conan/stable")
コード例 #51
0
    def test_component_not_found_same_name_as_pkg_require(self):
        zlib = GenConanfile(
            "zlib",
            "0.1").with_setting("build_type").with_generator("CMakeDeps")
        mypkg = GenConanfile(
            "mypkg",
            "0.1").with_setting("build_type").with_generator("CMakeDeps")
        final = GenConanfile("final", "0.1").with_setting("build_type").with_generator("CMakeDeps")\
            .with_require(ConanFileReference("zlib", "0.1", None, None))\
            .with_require(ConanFileReference("mypkg", "0.1", None, None))\
            .with_package_info(cpp_info={"components": {"cmp": {"requires": ["mypkg::zlib",
                                                                             "zlib::zlib"]}}},
                               env_info={})
        consumer = GenConanfile("consumer", "0.1").with_setting("build_type")\
            .with_generator("CMakeDeps")\
            .with_requirement(ConanFileReference("final", "0.1", None, None))

        consumer = textwrap.dedent("""
            from conans import ConanFile
            from conan.tools.cmake import CMakeDeps
            class HelloConan(ConanFile):
                name = 'consumer'
                version = '0.1'

                def generate(self):
                    deps = CMakeDeps(self)
                    deps.check_components_exist = True
                    deps.generate()

                def requirements(self):
                    self.requires("final/0.1")

                settings = "build_type"
            """)

        def test_component_not_found(self):
            conanfile = textwrap.dedent("""
                from conans import ConanFile
                class GreetingsConan(ConanFile):
                    def package_info(self):
                        self.cpp_info.components["hello"].libs = ["hello"]
            """)
            client = TestClient()
            client.save({"conanfile.py": conanfile})
            client.run("create . greetings/0.0.1@")

            conanfile = textwrap.dedent("""
                from conans import ConanFile
                class WorldConan(ConanFile):
                    requires = "greetings/0.0.1"
                    def package_info(self):
                        self.cpp_info.components["helloworld"].requires = ["greetings::non-existent"]
            """)
            client.save({"conanfile.py": conanfile})
            client.run("create . world/0.0.1@")
            client.run("install world/0.0.1@ -g CMakeDeps", assert_error=True)
            assert (
                "Component 'greetings::non-existent' not found in 'greetings' "
                "package requirement" in client.out)

        client = TestClient()
        client.save({
            "zlib.py": zlib,
            "mypkg.py": mypkg,
            "final.py": final,
            "consumer.py": consumer
        })
        client.run("create zlib.py")
        client.run("create mypkg.py")
        client.run("create final.py")
        client.run("install consumer.py", assert_error=True)
        assert "Component 'mypkg::zlib' not found in 'mypkg' package requirement" in client.out
コード例 #52
0
    def complete_hook_test(self):
        server = TestServer([], users={"danimtb": "pass"})
        client = TestClient(servers={"default": server},
                            users={"default": [("danimtb", "pass")]})
        hook_path = os.path.join(client.cache.hooks_path, "complete_hook",
                                 "complete_hook.py")
        client.save({
            hook_path: complete_hook,
            "conanfile.py": conanfile_basic
        })
        conanfile_path = os.path.join(client.current_folder, "conanfile.py")
        conanfile_cache_path = client.cache.package_layout(
            ConanFileReference("basic", "0.1", "danimtb",
                               "testing")).conanfile()
        client.run("config set hooks.complete_hook/complete_hook.py")

        client.run("source .")
        self._check_source(conanfile_path, client.out)

        client.run("install .")
        client.run("build .")
        self._check_build(conanfile_path, client.out)

        client.run("package .")
        self._check_package(conanfile_path, client.out)

        client.run("export . danimtb/testing")
        self._check_export(conanfile_path, conanfile_cache_path, client.out)

        client.run("export-pkg . danimtb/testing")
        self._check_export(conanfile_path, conanfile_cache_path, client.out)
        self._check_export_pkg(conanfile_cache_path, client.out)

        client.run("remove * --force")
        client.run("export-pkg . -pf . danimtb/testing")
        self._check_export(conanfile_path, conanfile_cache_path, client.out)
        self._check_export_pkg(conanfile_cache_path, client.out)

        client.run("remove * --force")
        client.run("create . danimtb/testing")
        self._check_export(conanfile_path, conanfile_cache_path,
                           client.out)  # Export gets
        self._check_source(conanfile_cache_path, client.out, in_cache=True)
        self._check_build(conanfile_cache_path, client.out, in_cache=True)
        self._check_package(conanfile_cache_path, client.out, in_cache=True)
        self._check_package_info(client.out)

        client.run("upload basic/0.1@danimtb/testing -r default")
        self._check_upload(conanfile_cache_path, client.out)
        self._check_upload_recipe(conanfile_cache_path, client.out)
        client.run("upload basic/0.1@danimtb/testing -r default --all")
        self._check_upload(conanfile_cache_path, client.out)
        self._check_upload_recipe(conanfile_cache_path, client.out)
        self._check_upload_package(conanfile_cache_path, client.out)

        client.run("remove * --force")
        client.run("download basic/0.1@danimtb/testing --recipe")
        self._check_download(conanfile_cache_path, client.out)
        self._check_download_recipe(conanfile_cache_path, client.out)
        client.run("remove * --force")
        client.run("download basic/0.1@danimtb/testing")
        self._check_download(conanfile_cache_path, client.out)
        self._check_download_recipe(conanfile_cache_path, client.out)
        self._check_download_package(conanfile_cache_path, client.out)

        client.run("remove * --force")
        client.run("install basic/0.1@danimtb/testing")
        self._check_download_recipe(conanfile_cache_path, client.out)
        self._check_download_package(conanfile_cache_path, client.out)
        self._check_package_info(client.out)
コード例 #53
0
 def get_path(self, reference, package_id=None, path=None, remote=None):
     reference = ConanFileReference.loads(str(reference))
     return self._manager.get_path(reference, package_id, path, remote)
コード例 #54
0
    def variables_setup_test(self):
        tmp_folder1 = temp_folder()
        tmp_folder2 = temp_folder()
        save(os.path.join(tmp_folder1, "include1", "file.h"), "")
        save(os.path.join(tmp_folder2, "include2", "file.h"), "")
        save(os.path.join(tmp_folder1, "lib1", "file.a"), "")
        save(os.path.join(tmp_folder2, "lib2", "file.a"), "")
        save(os.path.join(tmp_folder1, "bin1", "file.bin"), "")
        save(os.path.join(tmp_folder2, "bin2", "file.bin"), "")
        save(os.path.join(tmp_folder1, "SystemFrameworks", "file.bin"), "")

        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg1/0.1@lasote/stables")
        cpp_info = CppInfo(tmp_folder1)
        cpp_info.defines = ["MYDEFINE1"]
        cpp_info.includedirs = ['include1']
        cpp_info.libdirs = ['lib1']
        cpp_info.libs = ['libfoo']
        cpp_info.bindirs = ['bin1']
        cpp_info.version = "0.1"
        cpp_info.cflags = ['-fgimple']
        cpp_info.cxxflags = ['-fdollars-in-identifiers']
        cpp_info.sharedlinkflags = ['-framework Cocoa']
        cpp_info.exelinkflags = ['-framework QuartzCore']
        cpp_info.frameworks = ['AudioUnit']
        cpp_info.frameworkdirs = ['SystemFrameworks']
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("MyPkg2/3.2.3@lasote/stables")
        cpp_info = CppInfo(tmp_folder2)
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.includedirs = ['include2']
        cpp_info.libdirs = ['lib2']
        cpp_info.libs = ['libbar']
        cpp_info.bindirs = ['bin2']
        cpp_info.version = "3.2.3"
        cpp_info.cflags = ['-fno-asm']
        cpp_info.cxxflags = ['-pthread']
        cpp_info.sharedlinkflags = ['-framework AudioFoundation']
        cpp_info.exelinkflags = ['-framework VideoToolbox']
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = MakeGenerator(conanfile)
        content = generator.content

        content_template = """
CONAN_ROOT_MYPKG1 ?=  \\
{conan_root_mypkg1}

CONAN_SYSROOT_MYPKG1 ?=  \\


CONAN_INCLUDE_DIRS_MYPKG1 +=  \\
{conan_include_dirs_mypkg1}

CONAN_LIB_DIRS_MYPKG1 +=  \\
{conan_lib_dirs_mypkg1}

CONAN_BIN_DIRS_MYPKG1 +=  \\
{conan_bin_dirs_mypkg1}

CONAN_BUILD_DIRS_MYPKG1 +=  \\
{conan_build_dirs_mypkg1}

CONAN_RES_DIRS_MYPKG1 +=  \\


CONAN_LIBS_MYPKG1 +=  \\
libfoo

CONAN_DEFINES_MYPKG1 +=  \\
MYDEFINE1

CONAN_CFLAGS_MYPKG1 +=  \\
-fgimple

CONAN_CXXFLAGS_MYPKG1 +=  \\
-fdollars-in-identifiers

CONAN_SHAREDLINKFLAGS_MYPKG1 +=  \\
-framework Cocoa

CONAN_EXELINKFLAGS_MYPKG1 +=  \\
-framework QuartzCore

CONAN_FRAMEWORKS_MYPKG1 +=  \\
AudioUnit

CONAN_FRAMEWORK_PATHS_MYPKG1 +=  \\
{conan_framework_dirs_mypkg1}

CONAN_ROOT_MYPKG2 ?=  \\
{conan_root_mypkg2}

CONAN_SYSROOT_MYPKG2 ?=  \\


CONAN_INCLUDE_DIRS_MYPKG2 +=  \\
{conan_include_dirs_mypkg2}

CONAN_LIB_DIRS_MYPKG2 +=  \\
{conan_lib_dirs_mypkg2}

CONAN_BIN_DIRS_MYPKG2 +=  \\
{conan_bin_dirs_mypkg2}

CONAN_BUILD_DIRS_MYPKG2 +=  \\
{conan_build_dirs_mypkg2}

CONAN_RES_DIRS_MYPKG2 +=  \\


CONAN_LIBS_MYPKG2 +=  \\
libbar

CONAN_DEFINES_MYPKG2 +=  \\
MYDEFINE2

CONAN_CFLAGS_MYPKG2 +=  \\
-fno-asm

CONAN_CXXFLAGS_MYPKG2 +=  \\
-pthread

CONAN_SHAREDLINKFLAGS_MYPKG2 +=  \\
-framework AudioFoundation

CONAN_EXELINKFLAGS_MYPKG2 +=  \\
-framework VideoToolbox

CONAN_FRAMEWORKS_MYPKG2 +=  \\


CONAN_FRAMEWORK_PATHS_MYPKG2 +=  \\


CONAN_ROOTPATH +=  \\
$(CONAN_ROOTPATH_MYPKG1) \\
$(CONAN_ROOTPATH_MYPKG2)

CONAN_SYSROOT +=  \\
$(CONAN_SYSROOT_MYPKG1) \\
$(CONAN_SYSROOT_MYPKG2)

CONAN_INCLUDE_DIRS +=  \\
$(CONAN_INCLUDE_DIRS_MYPKG1) \\
$(CONAN_INCLUDE_DIRS_MYPKG2)

CONAN_LIB_DIRS +=  \\
$(CONAN_LIB_DIRS_MYPKG1) \\
$(CONAN_LIB_DIRS_MYPKG2)

CONAN_BIN_DIRS +=  \\
$(CONAN_BIN_DIRS_MYPKG1) \\
$(CONAN_BIN_DIRS_MYPKG2)

CONAN_BUILD_DIRS +=  \\
$(CONAN_BUILD_DIRS_MYPKG1) \\
$(CONAN_BUILD_DIRS_MYPKG2)

CONAN_RES_DIRS +=  \\
$(CONAN_RES_DIRS_MYPKG1) \\
$(CONAN_RES_DIRS_MYPKG2)

CONAN_LIBS +=  \\
$(CONAN_LIBS_MYPKG1) \\
$(CONAN_LIBS_MYPKG2)

CONAN_DEFINES +=  \\
$(CONAN_DEFINES_MYPKG1) \\
$(CONAN_DEFINES_MYPKG2)

CONAN_CFLAGS +=  \\
$(CONAN_CFLAGS_MYPKG1) \\
$(CONAN_CFLAGS_MYPKG2)

CONAN_CXXFLAGS +=  \\
$(CONAN_CXXFLAGS_MYPKG1) \\
$(CONAN_CXXFLAGS_MYPKG2)

CONAN_SHAREDLINKFLAGS +=  \\
$(CONAN_SHAREDLINKFLAGS_MYPKG1) \\
$(CONAN_SHAREDLINKFLAGS_MYPKG2)

CONAN_EXELINKFLAGS +=  \\
$(CONAN_EXELINKFLAGS_MYPKG1) \\
$(CONAN_EXELINKFLAGS_MYPKG2)

CONAN_FRAMEWORKS +=  \\
$(CONAN_FRAMEWORKS_MYPKG1) \\
$(CONAN_FRAMEWORKS_MYPKG2)

CONAN_FRAMEWORK_PATHS +=  \\
$(CONAN_FRAMEWORK_PATHS_MYPKG1) \\
$(CONAN_FRAMEWORK_PATHS_MYPKG2)
"""
        root1 = tmp_folder1.replace('\\', '/')
        root2 = tmp_folder2.replace('\\', '/')

        inc1 = os.path.join(tmp_folder1, 'include1').replace('\\', '/')
        inc2 = os.path.join(tmp_folder2, 'include2').replace('\\', '/')

        lib1 = os.path.join(tmp_folder1, 'lib1').replace('\\', '/')
        lib2 = os.path.join(tmp_folder2, 'lib2').replace('\\', '/')

        bin1 = os.path.join(tmp_folder1, 'bin1').replace('\\', '/')
        bin2 = os.path.join(tmp_folder2, 'bin2').replace('\\', '/')

        expected_content = content_template.format(
            conan_root_mypkg1=root1,
            conan_include_dirs_mypkg1=inc1,
            conan_lib_dirs_mypkg1=lib1,
            conan_bin_dirs_mypkg1=bin1,
            conan_build_dirs_mypkg1=root1 + "/",
            conan_root_mypkg2=root2,
            conan_include_dirs_mypkg2=inc2,
            conan_lib_dirs_mypkg2=lib2,
            conan_bin_dirs_mypkg2=bin2,
            conan_build_dirs_mypkg2=root2 + "/",
            conan_framework_dirs_mypkg1=root1 + "/SystemFrameworks")
        self.maxDiff = None
        self.assertIn(expected_content, content)
コード例 #55
0
ファイル: package_copier_test.py プロジェクト: zomeck/conan
    def test_copy(self):
        output = TestBufferConanOutput()
        userio = MockedBooleanUserIO(True, out=output)
        paths = SimplePaths(temp_folder())
        copier = PackageCopier(paths, userio)

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

        # Copy all to destination
        copier.copy(reference, ["0101001", "2222222"],
                    "lasote",
                    "stable",
                    force=False)
        new_reference = ConanFileReference.loads("Hello/0.1@lasote/stable")
        self._assert_conanfile_exists(new_reference, paths)
        self._assert_package_exists(new_reference, "0101001", paths)
        self._assert_package_exists(new_reference, "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
        copier.copy(reference, ["0101001", "2222222"],
                    "lasote",
                    "stable",
                    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(reference, paths, "new content")
        self._create_package(reference, "0101001", paths, "new lib content")
        self._create_package(reference, "2222222", paths, "new lib content")
        output._stream.truncate(0)  # Reset output
        copier.copy(reference, ["0101001", "2222222"],
                    "lasote",
                    "stable",
                    force=False)
        conanfile_content = load(
            os.path.join(paths.export(new_reference), "conanfile.py"))
        self.assertEquals(conanfile_content, "new content")
        package_content = load(
            os.path.join(
                paths.package(PackageReference(new_reference, "0101001")),
                "package.lib"))
        self.assertEquals(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)
        copier = PackageCopier(paths, userio)

        self._create_conanfile(reference, paths, "content22")
        self._create_package(reference, "0101001", paths, "newlib22")
        self._create_package(reference, "2222222", paths, "newlib22")
        copier.copy(reference, ["0101001", "2222222"],
                    "lasote",
                    "stable",
                    force=False)
        conanfile_content = load(
            os.path.join(paths.export(new_reference), "conanfile.py"))
        self.assertEquals(conanfile_content, "new content")  # Not content22
        p_ref = PackageReference(new_reference, "0101001")
        package_content = load(
            os.path.join(paths.package(p_ref), "package.lib"))
        self.assertEquals(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
        copier.copy(reference, ["0101001", "2222222"],
                    "lasote",
                    "stable",
                    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
        copier.copy(reference, ["0101001"], "pepe", "mychannel", 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_reference = ConanFileReference.loads("Hello/0.1@pepe/mychannel")
        self._assert_package_exists(new_reference, "0101001", paths)
        self._assert_package_doesnt_exists(new_reference, "2222222", paths)
コード例 #56
0
ファイル: install_update_test.py プロジェクト: yochju/conan
    def update_not_date_test(self):
        # Regression for https://github.com/conan-io/conan/issues/949
        files0 = cpp_hello_conan_files("Hello0", "1.0", build=False)
        files0["conanfile.py"] = files0["conanfile.py"].replace("settings = ", "# settings = ")
        self.client.save(files0)
        self.client.run("export . lasote/stable")
        files1 = cpp_hello_conan_files("Hello1", "1.0", build=False,
                                       deps=["Hello0/1.0@lasote/stable"])
        self.client.save(files1, clean_first=True)
        self.client.run("install . --build")
        self.client.run("upload Hello0/1.0@lasote/stable --all")

        self.client.run("remote list_ref")
        self.assertIn("Hello0/1.0@lasote/stable", self.client.out)
        self.client.run("remote list_pref Hello0/1.0@lasote/stable")
        reference = "Hello0/1.0@lasote/stable"
        package_reference = "%s:55a3af76272ead64e6f543c12ecece30f94d3eda" % reference
        self.assertIn(package_reference, self.client.out)

        ref = ConanFileReference.loads("Hello0/1.0@lasote/stable")
        pref = PackageReference(ref, "55a3af76272ead64e6f543c12ecece30f94d3eda")
        export_folder = self.client.cache.export(ref)
        recipe_manifest = os.path.join(export_folder, CONAN_MANIFEST)
        package_folder = self.client.cache.package(pref)
        package_manifest = os.path.join(package_folder, CONAN_MANIFEST)

        def timestamps():
            recipe_timestamp = load(recipe_manifest).splitlines()[0]
            package_timestamp = load(package_manifest).splitlines()[0]
            return recipe_timestamp, package_timestamp

        initial_timestamps = timestamps()

        time.sleep(1)

        # Change and rebuild package
        files0["helloHello0.h"] += " // useless comment"
        self.client.save(files0, clean_first=True)
        self.client.run("export . lasote/stable")
        self.client.run("install Hello0/1.0@lasote/stable --build")

        self.client.run("remote list_ref")
        # FIXME Conan 2.0 It should be a assertNotIn
        self.assertIn("Hello0/1.0@lasote/stable", self.client.out)

        self.client.run("remote list_pref Hello0/1.0@lasote/stable")
        # FIXME Conan 2.0 It should be a assertNotIn
        self.assertIn("Hello0/1.0@lasote/stable:55a3af76272ead64e6f543c12ecece30f94d3eda",
                      self.client.out)

        rebuild_timestamps = timestamps()
        self.assertNotEqual(rebuild_timestamps, initial_timestamps)

        # back to the consumer, try to update
        self.client.save(files1, clean_first=True)
        # First assign the preference to a remote, it has been cleared when exported locally
        self.client.run("install . --update")
        # *1 With revisions here is removing the package because it doesn't belong to the recipe

        self.assertIn("Hello0/1.0@lasote/stable from 'myremote' - Newer", self.client.out)
        failed_update_timestamps = timestamps()
        self.assertEqual(rebuild_timestamps, failed_update_timestamps)

        # hack manifests, put old time
        for manifest_file in (recipe_manifest, package_manifest):
            manifest = load(manifest_file)
            lines = manifest.splitlines()
            lines[0] = "123"
            save(manifest_file, "\n".join(lines))

        self.client.run("install . --update")
        update_timestamps = timestamps()
        self.assertEqual(update_timestamps, initial_timestamps)
コード例 #57
0
ファイル: create_package_test.py プロジェクト: zhuhaow/conan
    def complete_test(self):
        """ basic installation of a new conans
        """
        client = TestClient()
        client.init_dynamic_vars()
        files = hello_source_files()

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

        client.save(files, path=reg_folder)
        client.save(
            {
                CONANFILE: myconan1,
                "infos/%s" % CONANINFO: "//empty",
                "include/no_copy/lib0.h": "NO copy",
                "include/math/lib1.h": "copy",
                "include/math/lib2.h": "copy",
                "include/physics/lib.hpp": "copy",
                "my_lib/debug/libd.a": "copy",
                "my_data/readme.txt": "copy",
                "my_data/readme.md": "NO copy",
                "contrib/math/math.h": "copy",
                "contrib/physics/gravity.h": "copy",
                "contrib/contrib.h": "copy",
                "include/opencv/opencv.hpp": "copy",
                "include/opencv2/opencv2.hpp": "copy",
                "modules/simu/src/simu.cpp": "NO copy",
                "modules/simu/include/opencv2/simu/simu.hpp": "copy",
                "modules/3D/doc/readme.md": "NO copy",
                "modules/3D/include/opencv2/3D/3D.hpp": "copy",
                "modules/dev/src/dev.cpp": "NO copy",
                "modules/dev/include/opencv2/dev/dev.hpp": "copy",
                "modules/opencv_mod.hpp": "copy"
            },
            path=reg_folder)

        conanfile_path = os.path.join(reg_folder, CONANFILE)
        package_ref = PackageReference(conan_ref, "myfakeid")
        build_folder = client.paths.build(package_ref)
        package_folder = client.paths.package(package_ref)
        install_folder = os.path.join(build_folder, "infos")

        shutil.copytree(reg_folder, build_folder)

        output = ScopedOutput("", TestBufferConanOutput())
        loader = ConanFileLoader(None, None, ConanPythonRequire(None, None))
        conanfile = loader.load_conanfile(conanfile_path, None,
                                          ProcessedProfile())

        create_package(conanfile,
                       None,
                       build_folder,
                       build_folder,
                       package_folder,
                       install_folder,
                       output,
                       copy_info=True)

        # test build folder
        self.assertTrue(os.path.exists(build_folder))
        self.assertTrue(os.path.exists(os.path.join(package_folder,
                                                    CONANINFO)))

        # test pack folder
        self.assertTrue(os.path.exists(package_folder))

        def exist(rel_path):
            return os.path.exists(os.path.join(package_folder, rel_path))

        # Expected files
        self.assertTrue(exist("include/lib1.h"))
        self.assertTrue(exist("include/lib2.h"))
        self.assertTrue(exist("include/physics/lib.hpp"))
        self.assertTrue(exist("include/contrib/math/math.h"))
        self.assertTrue(exist("include/contrib/physics/gravity.h"))
        self.assertTrue(exist("include/contrib/contrib.h"))
        self.assertTrue(exist("include/opencv/opencv.hpp"))
        self.assertTrue(exist("include/opencv2/opencv2.hpp"))
        self.assertTrue(exist("include/opencv2/simu/simu.hpp"))
        self.assertTrue(exist("include/opencv2/3D/3D.hpp"))
        self.assertTrue(exist("include/opencv2/dev/dev.hpp"))
        self.assertTrue(exist("lib/my_lib/libd.a"))
        self.assertTrue(exist("res/shares/readme.txt"))

        # Not expected files
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/opencv2/simu.hpp"))
        self.assertFalse(exist("include/opencv2/3D.hpp"))
        self.assertFalse(exist("include/opencv2/dev.hpp"))
        self.assertFalse(exist("include/modules/simu/src/simu.cpp"))
        self.assertFalse(exist("include/modules/3D/doc/readme.md"))
        self.assertFalse(exist("include/modules/dev/src/dev.cpp"))
        self.assertFalse(exist("include/opencv2/opencv_mod.hpp"))
        self.assertFalse(exist("include/include/no_copy/lib0.h"))
        self.assertFalse(exist("res/my_data/readme.md"))
コード例 #58
0
    def create(self,
               profile_name=None,
               settings=None,
               options=None,
               env=None,
               scope=None,
               test_folder=None,
               not_export=False,
               build_modes=None,
               keep_source=False,
               verify=None,
               manifests=None,
               manifests_interactive=None,
               remote=None,
               update=False,
               conan_file_path=None,
               filename=None,
               user=None,
               channel=None,
               name=None,
               version=None,
               werror=False):

        settings = settings or []
        options = options or []
        env = env or []
        self._user_io.out.werror_active = werror

        cwd = os.getcwd()
        conanfile_folder = self._abs_relative_to(conan_file_path,
                                                 cwd,
                                                 default=cwd)

        if not name or not version:
            conanfile_abs_path = self._get_conanfile_path(
                conanfile_folder, filename or CONANFILE)
            conanfile = load_conanfile_class(conanfile_abs_path)
            name, version = conanfile.name, conanfile.version
            if not name or not version:
                raise ConanException(
                    "conanfile.py doesn't declare package name or version")

        reference = ConanFileReference(name, version, user, channel)
        scoped_output = ScopedOutput(str(reference), self._user_io.out)
        # Forcing an export!
        if not not_export:
            scoped_output.highlight("Exporting package recipe")
            self._manager.export(user,
                                 channel,
                                 conanfile_folder,
                                 keep_source=keep_source,
                                 name=name,
                                 version=version,
                                 filename=filename)

        if build_modes is None:  # Not specified, force build the tested library
            build_modes = [name]

        manifests = _parse_manifests_arguments(verify, manifests,
                                               manifests_interactive, cwd)
        manifest_folder, manifest_interactive, manifest_verify = manifests
        profile = profile_from_args(profile_name, settings, options, env,
                                    scope, cwd, self._client_cache)
        self._manager.install(
            reference=reference,
            install_folder=None,  # Not output anything
            manifest_folder=manifest_folder,
            manifest_verify=manifest_verify,
            manifest_interactive=manifest_interactive,
            remote=remote,
            profile=profile,
            build_modes=build_modes,
            update=update,
            filename=filename)

        base_folder = self._abs_relative_to(conan_file_path, cwd, default=cwd)

        def get_test_conanfile_path(tf):
            """Searchs in the declared test_folder or in the standard locations"""
            test_folders = [tf] if tf else ["test_package", "test"]

            for test_folder_name in test_folders:
                test_folder = os.path.join(base_folder, test_folder_name)
                test_conanfile_path = os.path.join(test_folder, "conanfile.py")
                if os.path.exists(test_conanfile_path):
                    return test_conanfile_path
            else:
                if tf:
                    raise ConanException("test folder '%s' not available, "
                                         "or it doesn't have a conanfile.py" %
                                         tf)

        test_conanfile_path = get_test_conanfile_path(test_folder)
        if test_conanfile_path:
            pt = PackageTester(self._manager, self._user_io)
            scoped_output.highlight("Testing with 'test_package'")
            pt.install_build_and_test(test_conanfile_path, profile, name,
                                      version, user, channel, remote, update)
コード例 #59
0
    def test_only_mingw(self):

        mingw_configurations = [("4.9", "x86_64", "seh", "posix")]
        builder = ConanMultiPackager(
            mingw_configurations=mingw_configurations,
            visual_versions=[],
            username="******",
            platform_info=platform_mock_for("Windows"),
            reference="lib/1.0",
            ci_manager=self.ci_manager)
        builder.add_common_builds(shared_option_name="zlib:shared",
                                  pure_c=True)
        expected = [
            ({
                'compiler.exception': 'seh',
                'compiler.libcxx': "libstdc++",
                'compiler.threads': 'posix',
                'compiler.version': '4.9',
                'arch': 'x86_64',
                'build_type': 'Release',
                'compiler': 'gcc'
            }, {
                'zlib:shared': True
            }, {}, {
                '*':
                [ConanFileReference.loads("mingw_installer/1.0@conan/stable")]
            }),
            ({
                'compiler.exception': 'seh',
                'compiler.libcxx': "libstdc++",
                'arch': 'x86_64',
                'compiler.threads': 'posix',
                'compiler.version': '4.9',
                'build_type': 'Debug',
                'compiler': 'gcc'
            }, {
                'zlib:shared': True
            }, {}, {
                '*':
                [ConanFileReference.loads("mingw_installer/1.0@conan/stable")]
            }),
            ({
                'compiler.exception': 'seh',
                'compiler.libcxx': "libstdc++",
                'compiler.threads': 'posix',
                'compiler.version': '4.9',
                'arch': 'x86_64',
                'build_type': 'Release',
                'compiler': 'gcc'
            }, {
                'zlib:shared': False
            }, {}, {
                '*':
                [ConanFileReference.loads("mingw_installer/1.0@conan/stable")]
            }),
            ({
                'compiler.exception': 'seh',
                'compiler.libcxx': "libstdc++",
                'arch': 'x86_64',
                'compiler.threads': 'posix',
                'compiler.version': '4.9',
                'build_type': 'Debug',
                'compiler': 'gcc'
            }, {
                'zlib:shared': False
            }, {}, {
                '*':
                [ConanFileReference.loads("mingw_installer/1.0@conan/stable")]
            })
        ]

        self.assertEquals([tuple(a) for a in builder.builds], expected)
コード例 #60
0
ファイル: runner.py プロジェクト: sdmg15/conan-package-tools
    def run(self):
        client_version = get_client_version()

        if self._config_url:
            ConfigManager(self._conan_api,
                          self.printer).install(url=self._config_url,
                                                args=self._config_args)

        context = tools.no_op()
        compiler = self.settings.get("compiler", None)
        if not self._exclude_vcvars_precommand:
            if compiler == "Visual Studio" and "compiler.version" in self.settings:
                compiler_set = namedtuple("compiler", "version")(
                    self.settings["compiler.version"])
                mock_sets = namedtuple(
                    "mock_settings", "arch compiler get_safe")(
                        self.settings["arch"], compiler_set,
                        lambda x: self.settings.get(x, None))
                context = tools.vcvars(mock_sets)
        with context:
            self.printer.print_rule()
            self.printer.print_profile(tools.load(self._profile_abs_path))

            with self.printer.foldable_output("conan_create"):
                if client_version < Version("1.10.0"):
                    name, version, user, channel = self._reference
                else:
                    name, version, user, channel, _ = self._reference

                if self._build_policy:
                    self._build_policy = [] if self._build_policy == [
                        "all"
                    ] else self._build_policy
                # https://github.com/conan-io/conan-package-tools/issues/184
                with tools.environment_append({"_CONAN_CREATE_COMMAND_": "1"}):
                    params = {
                        "name": name,
                        "version": version,
                        "user": user,
                        "channel": channel,
                        "build_modes": self._build_policy,
                        "profile_name": self._profile_abs_path
                    }
                    self.printer.print_message("Calling 'conan create'")
                    self.printer.print_dict(params)
                    with tools.chdir(self._cwd):
                        if Version(client_version) >= "1.8.0":
                            from conans.errors import ConanInvalidConfiguration
                            exc_class = ConanInvalidConfiguration
                        else:
                            exc_class = None

                        try:
                            if client_version < Version("1.12.0"):
                                self._results = self._conan_api.create(
                                    self._conanfile,
                                    name=name,
                                    version=version,
                                    user=user,
                                    channel=channel,
                                    build_modes=self._build_policy,
                                    profile_name=self._profile_abs_path,
                                    test_folder=self._test_folder,
                                    not_export=self.skip_recipe_export,
                                    update=self._update_dependencies)
                            else:
                                self._results = self._conan_api.create(
                                    self._conanfile,
                                    name=name,
                                    version=version,
                                    user=user,
                                    channel=channel,
                                    build_modes=self._build_policy,
                                    profile_names=[self._profile_abs_path],
                                    test_folder=self._test_folder,
                                    not_export=self.skip_recipe_export,
                                    update=self._update_dependencies,
                                    lockfile=self._lockfile)
                        except exc_class as e:
                            self.printer.print_rule()
                            self.printer.print_message(
                                "Skipped configuration by the recipe: "
                                "%s" % str(e))
                            self.printer.print_rule()
                            return
                        for installed in self._results['installed']:
                            reference = installed["recipe"]["id"]
                            if client_version >= Version("1.10.0"):
                                reference = ConanFileReference.loads(reference)
                                reference = str(reference.copy_clear_rev())
                            if ((reference == str(self._reference)) or \
                               (reference in self._upload_dependencies) or \
                               ("all" in self._upload_dependencies)) and \
                               installed['packages']:
                                package_id = installed['packages'][0]['id']
                                if installed['packages'][0]["built"]:
                                    if "@" not in reference:
                                        reference += "@"
                                    if self._upload_only_recipe:
                                        self._uploader.upload_recipe(
                                            reference, self._upload)
                                    else:
                                        self._uploader.upload_packages(
                                            reference, self._upload,
                                            package_id)
                                else:
                                    self.printer.print_message(
                                        "Skipping upload for %s, "
                                        "it hasn't been built" % package_id)