示例#1
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
示例#2
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
示例#3
0
 def name_and_version_are_generated_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     conanfile.name = "MyPkg"
     conanfile.version = "1.1.0"
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_PACKAGE_NAME MyPkg)', cmake_lines)
     self.assertIn('set(CONAN_PACKAGE_VERSION 1.1.0)', cmake_lines)
示例#4
0
 def settings_are_generated_tests(self):
     settings = Settings.loads(default_settings_yml)
     settings.os = "Windows"
     settings.compiler = "Visual Studio"
     settings.compiler.version = "12"
     settings.compiler.runtime = "MD"
     settings.arch = "x86"
     settings.build_type = "Debug"
     conanfile = ConanFile(None, None, Settings({}), None)
     conanfile.settings = settings
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_SETTINGS_BUILD_TYPE "Debug")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_ARCH "x86")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_COMPILER "Visual Studio")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_COMPILER_VERSION "12")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_COMPILER_RUNTIME "MD")', cmake_lines)
     self.assertIn('set(CONAN_SETTINGS_OS "Windows")', cmake_lines)
示例#5
0
    def load_virtual(self, reference, path):
        fixed_options = []
        # If user don't specify namespace in options, assume that it's for the reference (keep compatibility)
        for option_name, option_value in self._options.as_list():
            if ":" not in option_name:
                tmp = ("%s:%s" % (reference.name, option_name), option_value)
            else:
                tmp = (option_name, option_value)
            fixed_options.append(tmp)
        options = OptionsValues.from_list(fixed_options)

        conanfile = ConanFile(None, self._runner, self._settings.copy(), path)

        conanfile.requires.add(str(reference))  # Convert to string necessary
        # conanfile.options.values = options
        conanfile.options.initialize_upstream(options)

        conanfile.generators = ["txt"]
        conanfile.scope = self._scopes.package_scope()

        return conanfile
示例#6
0
文件: loader.py 项目: robertmrk/conan
    def parse_conan_txt(self, contents, path, output):
        conanfile = ConanFile(output, self._runner, self._settings.copy(), path)

        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)

        conanfile.generators = parser.generators

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

        # imports method
        conanfile.imports = ConanFileTextLoader.imports_method(conanfile,
                                                               parser.import_parameters)
        conanfile.scope = self._scopes.package_scope()
        return conanfile
示例#7
0
    def load_conan_txt(self, conan_requirements_path):

        if not os.path.exists(conan_requirements_path):
            raise NotFoundException("%s not found!" % CONANFILE_TXT)

        conanfile = ConanFile(self._output, self._runner, self._settings.copy())

        parser = ConanFileTextLoader(load(conan_requirements_path))
        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)

        return conanfile
示例#8
0
文件: loader.py 项目: 19317362/conan
    def load_virtual(self, references, scope_options=True,
                     build_requires_options=None):
        # If user don't specify namespace in options, assume that it is
        # for the reference (keep compatibility)
        conanfile = ConanFile(None, self._runner, self._settings.copy())
        conanfile.settings = self._settings.copy_values()
        # Assign environment
        conanfile._env_values.update(self._env_values)

        for reference in references:
            conanfile.requires.add(str(reference))  # Convert to string necessary
        # Allows options without package namespace in conan install commands:
        #   conan install zlib/1.2.8@lasote/stable -o shared=True
        if scope_options:
            assert len(references) == 1
            self._user_options.scope_options(references[0].name)
        if build_requires_options:
            conanfile.options.initialize_upstream(build_requires_options)
        else:
            conanfile.options.initialize_upstream(self._user_options)

        conanfile.generators = []  # remove the default txt generator

        return conanfile
示例#9
0
 def name_and_version_are_generated_test(self):
     conanfile = ConanFile(None, None)
     conanfile.initialize(Settings({}), EnvValues())
     conanfile.name = "MyPkg"
     conanfile.version = "1.1.0"
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_PACKAGE_NAME MyPkg)', cmake_lines)
     self.assertIn('set(CONAN_PACKAGE_VERSION 1.1.0)', cmake_lines)
示例#10
0
    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 = PkgConfigGenerator(conanfile)
        files = generator.content

        self.assertEquals(
            files["MyPkg2.pc"], """prefix=dummy_root_folder2
libdir=${prefix}/lib
includedir=${prefix}/include

Name: MyPkg2
Description: Conan package: MyPkg2
Version: 2.3
Libs: -L${libdir} -sharedlinkflag -exelinkflag
Cflags: -I${includedir} -cppflag -DMYDEFINE2
Requires: MyPkg
""")

        self.assertEquals(
            files["MyPkg.pc"], """prefix=dummy_root_folder1
libdir=${prefix}/lib
includedir=${prefix}/include

Name: MyPkg
Description: My cool description
Version: 1.3
Libs: -L${libdir}
Cflags: -I${includedir} -Flag1=23 -DMYDEFINE1
""")
示例#11
0
 def variables_cmake_multi_user_vars_escape_test(self):
     settings_mock = namedtuple("Settings",
                                "build_type, os, os_build, constraint")
     conanfile = ConanFile(
         None, None,
         settings_mock("Release", None, None,
                       lambda x, raise_undefined_field: x), None)
     conanfile.deps_user_info["FOO"].myvar = 'my"value"'
     conanfile.deps_user_info["FOO"].myvar2 = 'my${value}'
     conanfile.deps_user_info["FOO"].myvar3 = 'my\\value'
     generator = CMakeMultiGenerator(conanfile)
     content = generator.content["conanbuildinfo_multi.cmake"]
     cmake_lines = content.splitlines()
     self.assertIn(r'set(CONAN_USER_FOO_myvar "my\"value\"")', cmake_lines)
     self.assertIn(r'set(CONAN_USER_FOO_myvar2 "my\${value}")', cmake_lines)
     self.assertIn(r'set(CONAN_USER_FOO_myvar3 "my\\value")', cmake_lines)
示例#12
0
 def variables_setup_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("")
     cpp_info.defines = ["MYDEFINE1"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
     cpp_info = CppInfo("")
     cpp_info.defines = ["MYDEFINE2"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = SConsGenerator(conanfile)
     content = generator.content
     scons_lines = content.splitlines()
     self.assertIn("        \"CPPDEFINES\"  : [\'MYDEFINE2\', \'MYDEFINE1\'],", scons_lines)
     self.assertIn("        \"CPPDEFINES\"  : [\'MYDEFINE1\'],", scons_lines)
     self.assertIn("        \"CPPDEFINES\"  : [\'MYDEFINE2\'],", scons_lines)
示例#13
0
 def variables_cmake_multi_user_vars_test(self):
     settings_mock = namedtuple("Settings",
                                "build_type, os, os_build, constraint")
     conanfile = ConanFile(
         None, None,
         settings_mock("Release", None, None,
                       lambda x, raise_undefined_field: x), None)
     conanfile.deps_user_info["LIB1"].myvar = "myvalue"
     conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2"
     conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4"
     generator = CMakeMultiGenerator(conanfile)
     content = generator.content["conanbuildinfo_multi.cmake"]
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_USER_LIB1_myvar "myvalue")', cmake_lines)
     self.assertIn('set(CONAN_USER_LIB1_myvar2 "myvalue2")', cmake_lines)
     self.assertIn('set(CONAN_USER_LIB2_MYVAR2 "myvalue4")', cmake_lines)
示例#14
0
 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"]
     conanfile.deps_cpp_info.update(cpp_info, ref)
     ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder2")
     cpp_info.defines = ["MYDEFINE2"]
     conanfile.deps_cpp_info.update(cpp_info, ref)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn("set(CONAN_DEFINES_MYPKG -DMYDEFINE1)", cmake_lines)
     self.assertIn("set(CONAN_DEFINES_MYPKG2 -DMYDEFINE2)", cmake_lines)
     self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG MYDEFINE1)", cmake_lines)
     self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG2 MYDEFINE2)", cmake_lines)
示例#15
0
文件: loader.py 项目: swipswaps/conan
    def _parse_conan_txt(self, contents, path, display_name, profile):
        conanfile = ConanFile(self._output, self._runner, display_name)
        conanfile.initialize(Settings(), profile.env_values)
        conanfile.conf = profile.conf.get_conanfile_conf(None)
        # 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 = profile.processed_settings.copy_values()

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

        conanfile.generators = parser.generators

        try:
            options = OptionsValues.loads(parser.options)
        except Exception:
            raise ConanException(
                "Error while parsing [options] in conanfile\n"
                "Options should be specified as 'pkg:option=value'")
        conanfile.options.values = options
        conanfile.options.initialize_upstream(profile.user_options)

        # imports method
        conanfile.imports = parser.imports_method(conanfile)
        return conanfile
示例#16
0
 def escaped_flags_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cppflags = ["-load", r"C:\foo\bar.dll"]
     cpp_info.cflags = ["-load", r"C:\foo\bar2.dll"]
     cpp_info.defines = ['MY_DEF=My string', 'MY_DEF2=My other string']
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn(r'set(CONAN_C_FLAGS_MYPKG "-load C:\\foo\\bar2.dll")',
                   cmake_lines)
     self.assertIn(r'set(CONAN_CXX_FLAGS_MYPKG "-load C:\\foo\\bar.dll")',
                   cmake_lines)
     self.assertIn(r'set(CONAN_DEFINES_MYPKG "-DMY_DEF=My string"',
                   cmake_lines)
     self.assertIn('\t\t\t"-DMY_DEF2=My other string")', cmake_lines)
示例#17
0
    def valid_xml_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        ref = ConanFileReference.loads("MyPkg/0.1@user/testing")
        cpp_info = CppInfo("dummy_root_folder1")
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("My.Fancy-Pkg_2/0.1@user/testing")
        cpp_info = CppInfo("dummy_root_folder2")
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = VisualStudioGenerator(conanfile)

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

        self.assertIn('<PropertyGroup Label="Conan-RootDirs">', content)
        self.assertIn(
            "<Conan-MyPkg-Root>dummy_root_folder1</Conan-MyPkg-Root>", content)
        self.assertIn(
            "<Conan-My-Fancy-Pkg_2-Root>dummy_root_folder2</Conan-My-Fancy-Pkg_2-Root>",
            content)
示例#18
0
    def load_virtual(self,
                     references,
                     profile_host,
                     scope_options=True,
                     build_requires_options=None,
                     is_build_require=False,
                     require_overrides=None):
        # If user don't specify namespace in options, assume that it is
        # for the reference (keep compatibility)
        conanfile = ConanFile(self._output,
                              self._runner,
                              display_name="virtual")
        conanfile.initialize(profile_host.processed_settings.copy(),
                             profile_host.env_values, profile_host.buildenv)
        conanfile.conf = profile_host.conf.get_conanfile_conf(None)
        conanfile.settings = profile_host.processed_settings.copy_values()

        if is_build_require:
            conanfile.build_requires = [str(r) for r in references]
        else:
            for reference in references:
                conanfile.requires.add_ref(reference)

        if require_overrides is not None:
            for req_override in require_overrides:
                req_override = ConanFileReference.loads(req_override)
                conanfile.requires.override(req_override)

        # Allows options without package namespace in conan install commands:
        #   conan install zlib/1.2.8@lasote/stable -o shared=True
        if scope_options:
            assert len(references) == 1
            profile_host.user_options.scope_options(references[0].name)
        if build_requires_options:
            conanfile.options.initialize_upstream(build_requires_options)
        else:
            conanfile.options.initialize_upstream(profile_host.user_options)

        conanfile.generators = []  # remove the default txt generator
        return conanfile
示例#19
0
 def multi_flag_test(self):
     conanfile = ConanFile(None, None, Settings({}), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     cpp_info = CppInfo("dummy_root_folder1")
     cpp_info.includedirs.append("other_include_dir")
     cpp_info.cppflags = ["-DGTEST_USE_OWN_TR1_TUPLE=1", "-DGTEST_LINKED_AS_SHARED_LIBRARY=1"]
     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.cflags = ["-DSOMEFLAG=1"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeGenerator(conanfile)
     content = generator.content
     cmake_lines = content.splitlines()
     self.assertIn('set(CONAN_C_FLAGS_MYPKG2 "-DSOMEFLAG=1")', cmake_lines)
     self.assertIn('set(CONAN_CXX_FLAGS_MYPKG "-DGTEST_USE_OWN_TR1_TUPLE=1'
                   ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1")', cmake_lines)
     self.assertIn('set(CONAN_C_FLAGS "-DSOMEFLAG=1 ${CONAN_C_FLAGS}")', cmake_lines)
     self.assertIn('set(CONAN_CXX_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=1'
                   ' -DGTEST_LINKED_AS_SHARED_LIBRARY=1 ${CONAN_CXX_FLAGS}")', cmake_lines)
示例#20
0
    def aux_cmake_test_setup_test(self):
        conanfile = ConanFile(None, None, Settings({}), None)
        generator = CMakeGenerator(conanfile)
        aux_cmake_test_setup = generator.content

        # extract the conan_basic_setup macro
        macro = self._extract_macro("conan_basic_setup", aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_basic_setup)
    conan_check_compiler()
    conan_output_dirs_setup()
    conan_set_find_library_paths()
    if(NOT "${ARGV0}" STREQUAL "TARGETS")
        message(STATUS "Conan: Using cmake global configuration")
        conan_global_flags()
    else()
        message(STATUS "Conan: Using cmake targets configuration")
        conan_define_targets()
    endif()
    conan_set_rpath()
    conan_set_vs_runtime()
    conan_set_libcxx()
    conan_set_find_paths()
endmacro()""", macro)

        # extract the conan_set_find_paths macro
        macro = self._extract_macro("conan_set_find_paths",
                                    aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_set_find_paths)
    # CMAKE_MODULE_PATH does not have Debug/Release config, but there are variables
    # CONAN_CMAKE_MODULE_PATH_DEBUG to be used by the consumer
    # CMake can find findXXX.cmake files in the root of packages
    set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})

    # Make find_package() to work
    set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_PREFIX_PATH})
endmacro()""", macro)
示例#21
0
    def test_toolchain_linux(self, build_type, arch, compiler, compiler_ver,
                             compiler_cppstd, compiler_libcxx, shared, fpic,
                             expected):

        settings_mock = _MockSettings(build_type, arch, compiler, compiler_ver,
                                      compiler_cppstd, compiler_libcxx)
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.options = {"shared": [True, False], "fPIC": [True, False]}
        conanfile.default_options = {"shared": shared, "fPIC": fpic}
        conanfile.initialize(settings_mock, EnvValues())
        toolchain = MakeToolchain(conanfile)
        toolchain.variables["TEST_VAR_01"] = "TEST_VAR_VAL_01"
        toolchain.variables["TEST_VAR_02"] = "TEST_VAR_VAL_02"
        toolchain.preprocessor_definitions["TEST_PPD_01"] = "TEST_PPD_VAL_01"
        toolchain.preprocessor_definitions["TEST_PPD_02"] = "TEST_PPD_VAL_02"
        content = toolchain.content
        self.maxDiff = None
        self.assertIn(expected, content)
示例#22
0
    def test_user_info_build(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())

        conanfile.user_info_build = DepsUserInfo()
        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.user_info_build["build_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.user_info_build["other-build-pkg"] = user_info

        generator = TXTGenerator(conanfile)
        txt_out = generator.content

        self.assertIn(
            textwrap.dedent("""
                    [USERBUILD_build_pkg]
                    VAR1=value1
                    [USERBUILD_other-build-pkg]
                    VAR1=other-value1"""), txt_out)
示例#23
0
 def paths_cmake_multi_user_vars_test(self):
     settings_mock = namedtuple("Settings",
                                "build_type, os, os_build, constraint")
     conanfile = ConanFile(
         None, None,
         settings_mock("Release", None, None,
                       lambda x, raise_undefined_field: x), None)
     ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
     tmp_folder = temp_folder()
     save(os.path.join(tmp_folder, "lib", "mylib.lib"), "")
     save(os.path.join(tmp_folder, "include", "myheader.h"), "")
     cpp_info = CppInfo(tmp_folder)
     cpp_info.release.libs = ["hello"]
     cpp_info.debug.libs = ["hello_D"]
     conanfile.deps_cpp_info.update(cpp_info, ref.name)
     generator = CMakeMultiGenerator(conanfile)
     release = generator.content["conanbuildinfo_release.cmake"]
     release = release.replace(tmp_folder.replace("\\", "/"), "root_folder")
     cmake_lines = release.splitlines()
     self.assertIn(
         'set(CONAN_INCLUDE_DIRS_MYPKG_RELEASE "root_folder/include")',
         cmake_lines)
     self.assertIn('set(CONAN_LIB_DIRS_MYPKG_RELEASE "root_folder/lib")',
                   cmake_lines)
示例#24
0
    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"]
        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"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        conanfile.deps_user_info["LIB1"].myvar = "myvalue"
        conanfile.deps_user_info["LIB1"].myvar2 = "myvalue2"
        conanfile.deps_user_info["lib2"].MYVAR2 = "myvalue4"
        generator = CMakeGenerator(conanfile)
        content = generator.content
        cmake_lines = content.splitlines()
        self.assertIn("set(CONAN_DEFINES_MYPKG -DMYDEFINE1)", cmake_lines)
        self.assertIn("set(CONAN_DEFINES_MYPKG2 -DMYDEFINE2)", cmake_lines)
        self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG MYDEFINE1)", cmake_lines)
        self.assertIn("set(CONAN_COMPILE_DEFINITIONS_MYPKG2 MYDEFINE2)", cmake_lines)

        self.assertIn('set(CONAN_USER_LIB1_myvar "myvalue")', cmake_lines)
        self.assertIn('set(CONAN_USER_LIB1_myvar2 "myvalue2")', cmake_lines)
        self.assertIn('set(CONAN_USER_LIB2_MYVAR2 "myvalue4")', cmake_lines)
示例#25
0
    def test_user_info(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())

        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.deps_user_info["my_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.deps_user_info["other-pkg"] = user_info

        generator = TXTGenerator(conanfile)
        txt_out = generator.content

        self.assertIn(
            textwrap.dedent("""
                    [USER_my_pkg]
                    VAR1=value1
                    [USER_other-pkg]
                    VAR1=other-value1"""), txt_out)
示例#26
0
    def load_virtual(self, references, processed_profile, scope_options=True,
                     build_requires_options=None):
        # If user don't specify namespace in options, assume that it is
        # for the reference (keep compatibility)
        conanfile = ConanFile(None, self._runner, processed_profile._settings.copy())
        conanfile.initialize(processed_profile._settings.copy(), processed_profile._env_values)
        conanfile.settings = processed_profile._settings.copy_values()

        for reference in references:
            conanfile.requires.add(str(reference))  # Convert to string necessary
        # Allows options without package namespace in conan install commands:
        #   conan install zlib/1.2.8@lasote/stable -o shared=True
        if scope_options:
            assert len(references) == 1
            processed_profile._user_options.scope_options(references[0].name)
        if build_requires_options:
            conanfile.options.initialize_upstream(build_requires_options)
        else:
            conanfile.options.initialize_upstream(processed_profile._user_options)

        conanfile.generators = []  # remove the default txt generator

        return conanfile
示例#27
0
    def valid_xml_test(self, use_toolset):
        tempdir = temp_folder()
        with chdir(tempdir):
            settings = Settings.loads(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(None, None, Settings({}), None)

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

            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')
示例#28
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(ref.name, 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']
        cpp_info.system_libs = ["system_lib1"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)
        ref = ConanFileReference.loads("MyPkg2/3.2.3@lasote/stables")
        cpp_info = CppInfo(ref.name, 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']
        cpp_info.system_libs = ["system_lib2"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)
        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_SYSTEM_LIBS_MYPKG1 +=  \\
system_lib1

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_SYSTEM_LIBS_MYPKG2 +=  \\
system_lib2

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)
示例#29
0
    def variables_setup_test(self):

        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())

        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "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.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "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.cxxflags = ["-cxxflag"]
        cpp_info.public_deps = ["MyPkg"]
        cpp_info.libdirs.extend(["Path\\with\\slashes", "regular/path/to/dir"])
        cpp_info.includedirs.extend(
            ["other\\Path\\with\\slashes", "other/regular/path/to/dir"])
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)
        generator = BoostBuildGenerator(conanfile)

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

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

alias conan-deps :
	MyLib1
	MyLib2
;
""")
示例#30
0
class CMakeBuildModulesTest(unittest.TestCase):
    def setUp(self):
        settings_mock = _MockSettings(build_type="Release")
        self.conanfile = ConanFile(TestBufferConanOutput(), None)
        self.conanfile.initialize(settings_mock, EnvValues())
        ref = ConanFileReference.loads("my_pkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.filter_empty = False  # For testing purposes only
        cpp_info.name = ref.name
        cpp_info.build_modules = ["my-module.cmake"]
        self.conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("my_pkg2/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder2")
        cpp_info.filter_empty = False  # For testing purposes only
        cpp_info.name = ref.name
        cpp_info.build_modules = ["other-mod.cmake", "not-a-cmake-module.pc"]
        cpp_info.release.build_modules = ["release-mod.cmake"]
        cpp_info.release.filter_empty = False  # For testing purposes only
        self.conanfile.deps_cpp_info.update(cpp_info, ref.name)

    def cmake_test(self):
        generator = CMakeGenerator(self.conanfile)
        content = generator.content
        self.assertNotIn("not-a-cmake-module.pc", content)
        self.assertIn(
            'set(CONAN_BUILD_MODULES_PATHS "dummy_root_folder1/my-module.cmake"'
            '\n\t\t\t"dummy_root_folder2/other-mod.cmake" ${CONAN_BUILD_MODULES_PATHS})',
            content)
        self.assertIn(
            'set(CONAN_BUILD_MODULES_PATHS_MY_PKG "dummy_root_folder1/my-module.cmake")',
            content)
        self.assertIn(
            'set(CONAN_BUILD_MODULES_PATHS_MY_PKG2 "dummy_root_folder2/other-mod.cmake")',
            content)
        self.assertIn("macro(conan_include_build_modules)", content)
        self.assertIn("conan_include_build_modules()", content)

    def cmake_multi_test(self):
        generator = CMakeMultiGenerator(self.conanfile)
        content = generator.content
        self.assertNotIn("not-a-cmake-module.pc",
                         content["conanbuildinfo_release.cmake"])
        self.assertIn(
            'set(CONAN_BUILD_MODULES_PATHS_RELEASE '
            '"dummy_root_folder1/my-module.cmake"\n\t\t\t'
            '"dummy_root_folder2/other-mod.cmake"\n\t\t\t'
            '"dummy_root_folder2/release-mod.cmake" '
            '${CONAN_BUILD_MODULES_PATHS_RELEASE})',
            content["conanbuildinfo_release.cmake"])
        self.assertIn(
            'set(CONAN_BUILD_MODULES_PATHS_MY_PKG_RELEASE '
            '"dummy_root_folder1/my-module.cmake")',
            content["conanbuildinfo_release.cmake"])
        self.assertIn(
            'set(CONAN_BUILD_MODULES_PATHS_MY_PKG2_RELEASE '
            '"dummy_root_folder2/other-mod.cmake"\n\t\t\t'
            '"dummy_root_folder2/release-mod.cmake")',
            content["conanbuildinfo_release.cmake"])
        self.assertIn("macro(conan_include_build_modules)",
                      content["conanbuildinfo_multi.cmake"])
        self.assertIn("conan_include_build_modules()",
                      content["conanbuildinfo_multi.cmake"])

    def cmake_find_package_test(self):
        generator = CMakeFindPackageGenerator(self.conanfile)
        content = generator.content
        self.assertIn("Findmy_pkg.cmake", content.keys())
        self.assertIn("Findmy_pkg2.cmake", content.keys())
        self.assertNotIn("not-a-cmake-module.pc", content["Findmy_pkg2.cmake"])
        self.assertIn(
            'set(CMAKE_MODULE_PATH "dummy_root_folder1/" ${CMAKE_MODULE_PATH})',
            content["Findmy_pkg.cmake"])
        self.assertIn(
            'set(CMAKE_PREFIX_PATH "dummy_root_folder1/" ${CMAKE_PREFIX_PATH})',
            content["Findmy_pkg.cmake"])
        self.assertIn(
            'set(CMAKE_MODULE_PATH "dummy_root_folder2/" ${CMAKE_MODULE_PATH})',
            content["Findmy_pkg2.cmake"])
        self.assertIn(
            'set(CMAKE_PREFIX_PATH "dummy_root_folder2/" ${CMAKE_PREFIX_PATH})',
            content["Findmy_pkg2.cmake"])
        self.assertIn(
            'set(my_pkg_BUILD_MODULES_PATHS "dummy_root_folder1/my-module.cmake")',
            content["Findmy_pkg.cmake"])
        self.assertIn(
            'set(my_pkg2_BUILD_MODULES_PATHS "dummy_root_folder2/other-mod.cmake")',
            content["Findmy_pkg2.cmake"])

    def cmake_find_package_multi_test(self):
        generator = CMakeFindPackageMultiGenerator(self.conanfile)
        content = generator.content
        self.assertNotIn("not-a-cmake-module.pc",
                         content["my_pkg2Target-release.cmake"])
        self.assertIn(
            'set(my_pkg_BUILD_MODULES_PATHS_RELEASE "dummy_root_folder1/my-module.cmake")',
            content["my_pkgTarget-release.cmake"])
        self.assertIn(
            'set(my_pkg2_BUILD_MODULES_PATHS_RELEASE "dummy_root_folder2/other-mod.cmake")',
            content["my_pkg2Target-release.cmake"])
示例#31
0
class CMakeCppInfoNameTest(unittest.TestCase):
    """
    Test cpp_info.name values are applied in generators instead of the reference name
    """
    def setUp(self):
        self.conanfile = ConanFile(TestBufferConanOutput(), None)
        settings = _MockSettings()
        settings.build_type = "Debug"
        self.conanfile.initialize(settings, EnvValues())
        ref = ConanFileReference.loads("my_pkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.name = "MyPkG"
        self.conanfile.deps_cpp_info.update(cpp_info, ref.name)
        ref = ConanFileReference.loads("my_pkg2/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder2")
        cpp_info.name = "MyPkG2"
        cpp_info.public_deps = ["my_pkg"]
        self.conanfile.deps_cpp_info.update(cpp_info, ref.name)

    def cmake_test(self):
        generator = CMakeGenerator(self.conanfile)
        content = generator.content
        self.assertIn("set(CONAN_DEPENDENCIES my_pkg my_pkg2)", content)
        content = content.replace("set(CONAN_DEPENDENCIES my_pkg my_pkg2)", "")
        self.assertNotIn("my_pkg", content)
        self.assertNotIn("MY_PKG", content)
        self.assertIn('add_library(CONAN_PKG::MyPkG INTERFACE IMPORTED)',
                      content)
        self.assertIn('add_library(CONAN_PKG::MyPkG2 INTERFACE IMPORTED)',
                      content)
        self.assertNotIn('CONAN_PKG::my_pkg', content)
        self.assertNotIn('CONAN_PKG::my_pkg2', content)

    def cmake_multi_test(self):
        generator = CMakeMultiGenerator(self.conanfile)
        content = generator.content
        self.assertIn("set(CONAN_DEPENDENCIES_DEBUG my_pkg my_pkg2)",
                      content["conanbuildinfo_debug.cmake"])
        self.assertNotIn("my_pkg", content["conanbuildinfo_multi.cmake"])
        self.assertNotIn("MY_PKG", content["conanbuildinfo_multi.cmake"])
        self.assertIn('add_library(CONAN_PKG::MyPkG INTERFACE IMPORTED)',
                      content["conanbuildinfo_multi.cmake"])
        self.assertIn('add_library(CONAN_PKG::MyPkG2 INTERFACE IMPORTED)',
                      content["conanbuildinfo_multi.cmake"])
        self.assertNotIn('CONAN_PKG::my_pkg',
                         content["conanbuildinfo_multi.cmake"])
        self.assertNotIn('CONAN_PKG::my_pkg2',
                         content["conanbuildinfo_multi.cmake"])

    def cmake_find_package_test(self):
        generator = CMakeFindPackageGenerator(self.conanfile)
        content = generator.content
        self.assertIn("FindMyPkG.cmake", content.keys())
        self.assertIn("FindMyPkG2.cmake", content.keys())
        self.assertNotIn("my_pkg", content["FindMyPkG.cmake"])
        self.assertNotIn("MY_PKG", content["FindMyPkG.cmake"])
        self.assertNotIn("my_pkg", content["FindMyPkG2.cmake"])
        self.assertNotIn("MY_PKG", content["FindMyPkG2.cmake"])
        self.assertIn("add_library(MyPkG::MyPkG INTERFACE IMPORTED)",
                      content["FindMyPkG.cmake"])
        self.assertIn("add_library(MyPkG2::MyPkG2 INTERFACE IMPORTED)",
                      content["FindMyPkG2.cmake"])
        self.assertIn("find_dependency(MyPkG REQUIRED)",
                      content["FindMyPkG2.cmake"])

    def cmake_find_package_multi_test(self):
        generator = CMakeFindPackageMultiGenerator(self.conanfile)
        content = generator.content
        six.assertCountEqual(self, [
            'MyPkG2Targets.cmake', 'MyPkGConfig.cmake', 'MyPkG2Config.cmake',
            'MyPkGTargets.cmake', 'MyPkGTarget-debug.cmake',
            'MyPkG2Target-debug.cmake', 'MyPkGConfigVersion.cmake',
            'MyPkG2ConfigVersion.cmake'
        ], content.keys())
        self.assertNotIn("my_pkg", content["MyPkGConfig.cmake"])
        self.assertNotIn("MY_PKG", content["MyPkGConfig.cmake"])
        self.assertNotIn("my_pkg", content["MyPkG2Config.cmake"])
        self.assertNotIn("MY_PKG", content["MyPkG2Config.cmake"])
        self.assertIn("add_library(MyPkG::MyPkG INTERFACE IMPORTED)",
                      content["MyPkGTargets.cmake"])
        self.assertIn("add_library(MyPkG2::MyPkG2 INTERFACE IMPORTED)",
                      content["MyPkG2Targets.cmake"])
        self.assertIn("find_dependency(MyPkG REQUIRED NO_MODULE)",
                      content["MyPkG2Config.cmake"])
示例#32
0
    def valid_xml_test(self, use_toolset):
        tempdir = temp_folder()
        with chdir(tempdir):
            settings = Settings.loads(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(None, None)
            conanfile.initialize(Settings({}), EnvValues())

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

            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 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"), "")

        conanfile = ConanFile(None, 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 = ['-fPIC']
        cpp_info.cppflags = ['-fPIE']
        cpp_info.sharedlinkflags = ['-framework Cocoa']
        cpp_info.exelinkflags = ['-framework QuartzCore']
        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 = ['-mtune=native']
        cpp_info.cppflags = ['-march=native']
        cpp_info.sharedlinkflags = ['-framework AudioFoundation']
        cpp_info.exelinkflags = ['-framework VideoToolbox']
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = PremakeGenerator(conanfile)
        content = generator.content

        self.assertIn('conan_cppdefines = {"MYDEFINE2", "MYDEFINE1"}', content)
        self.assertIn('conan_cppdefines_MyPkg1 = {"MYDEFINE1"}', content)
        self.assertIn('conan_cppdefines_MyPkg2 = {"MYDEFINE2"}', content)

        inc1 = os.path.join(tmp_folder1, 'include1').replace('\\', '/')
        inc2 = os.path.join(tmp_folder2, 'include2').replace('\\', '/')
        self.assertIn('conan_includedirs = {"%s",\n"%s"}' % (inc1, inc2),
                      content)
        self.assertIn('conan_includedirs_MyPkg1 = {"%s"}' % inc1, content)
        self.assertIn('conan_includedirs_MyPkg2 = {"%s"}' % inc2, content)

        lib1 = os.path.join(tmp_folder1, 'lib1').replace('\\', '/')
        lib2 = os.path.join(tmp_folder2, 'lib2').replace('\\', '/')
        self.assertIn('conan_libdirs = {"%s",\n"%s"}' % (lib1, lib2), content)
        self.assertIn('conan_libdirs_MyPkg1 = {"%s"}' % lib1, content)
        self.assertIn('conan_libdirs_MyPkg2 = {"%s"}' % lib2, content)

        bin1 = os.path.join(tmp_folder1, 'bin1').replace('\\', '/')
        bin2 = os.path.join(tmp_folder2, 'bin2').replace('\\', '/')
        self.assertIn('conan_bindirs = {"%s",\n"%s"}' % (bin1, bin2), content)
        self.assertIn('conan_bindirs_MyPkg1 = {"%s"}' % bin1, content)
        self.assertIn('conan_bindirs_MyPkg2 = {"%s"}' % bin2, content)

        self.assertIn('conan_libs = {"libfoo", "libbar"}', content)
        self.assertIn('conan_libs_MyPkg1 = {"libfoo"}', content)
        self.assertIn('conan_libs_MyPkg2 = {"libbar"}', content)

        self.assertIn('conan_cflags = {"-mtune=native", "-fPIC"}', content)
        self.assertIn('conan_cflags_MyPkg1 = {"-fPIC"}', content)
        self.assertIn('conan_cflags_MyPkg2 = {"-mtune=native"}', content)

        self.assertIn('conan_cppflags = {"-march=native", "-fPIE"}', content)
        self.assertIn('conan_cppflags_MyPkg1 = {"-fPIE"}', content)
        self.assertIn('conan_cppflags_MyPkg2 = {"-march=native"}', content)

        self.assertIn(
            'conan_sharedlinkflags = {"-framework AudioFoundation", "-framework Cocoa"}',
            content)
        self.assertIn('conan_sharedlinkflags_MyPkg1 = {"-framework Cocoa"}',
                      content)
        self.assertIn(
            'conan_sharedlinkflags_MyPkg2 = {"-framework AudioFoundation"}',
            content)

        self.assertIn(
            'conan_exelinkflags = {"-framework VideoToolbox", "-framework QuartzCore"}',
            content)
        self.assertIn('conan_exelinkflags_MyPkg1 = {"-framework QuartzCore"}',
                      content)
        self.assertIn(
            'conan_exelinkflags_MyPkg2 = {"-framework VideoToolbox"}', content)
示例#34
0
    def variables_setup_test(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "/dummy_root_folder1")
        cpp_info.filter_empty = False
        cpp_info.name = "my_pkg"
        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.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg1/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "/dummy_root_folder1")
        cpp_info.filter_empty = False
        cpp_info.name = "MYPKG1"
        cpp_info.defines = ["MYDEFINE11"]
        cpp_info.cflags.append("-Flag1=21")
        cpp_info.version = "1.7"
        cpp_info.description = "My other cool description"
        cpp_info.public_deps = ["MyPkg"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "/dummy_root_folder2")
        cpp_info.filter_empty = False
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.version = "2.3"
        cpp_info.exelinkflags = ["-exelinkflag"]
        cpp_info.sharedlinkflags = ["-sharedlinkflag"]
        cpp_info.cxxflags = ["-cxxflag"]
        cpp_info.public_deps = ["MyPkg"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)
        generator = PkgConfigGenerator(conanfile)
        files = generator.content

        self.assertEqual(
            files["MyPkg2.pc"], """prefix=/dummy_root_folder2
libdir=${prefix}/lib
includedir=${prefix}/include

Name: MyPkg2
Description: Conan package: MyPkg2
Version: 2.3
Libs: -L${libdir} -sharedlinkflag -exelinkflag
Cflags: -I${includedir} -cxxflag -DMYDEFINE2
Requires: my_pkg
""")

        self.assertEqual(
            files["mypkg1.pc"], """prefix=/dummy_root_folder1
libdir=${prefix}/lib
includedir=${prefix}/include

Name: mypkg1
Description: My other cool description
Version: 1.7
Libs: -L${libdir}
Cflags: -I${includedir} -Flag1=21 -DMYDEFINE11
Requires: my_pkg
""")

        self.assertEqual(
            files["my_pkg.pc"], """prefix=/dummy_root_folder1
libdir=${prefix}/lib
includedir=${prefix}/include

Name: my_pkg
Description: My cool description
Version: 1.3
Libs: -L${libdir}
Cflags: -I${includedir} -Flag1=23 -DMYDEFINE1
""")
示例#35
0
    def test_idempotent(self):
        conanfile = ConanFile(Mock(), None)
        conanfile.initialize(Settings({}), EnvValues())

        # Add some cpp_info
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder1")
        cpp_info.names["txt"] = "mypkg1-txt"
        cpp_info.version = ref.version
        cpp_info.defines = ["MYDEFINE1"]
        cpp_info.cxxflags = ["-cxxflag_parent"]
        cpp_info.includedirs = ["mypkg1/include"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder2")
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.cxxflags = ["-cxxflag_dep"]
        cpp_info.filter_empty = False
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        # Add env_info
        env_info = EnvInfo()
        env_info.VAR1 = "value1"
        env_info.PATH.append("path-extended")
        conanfile.deps_env_info.update(env_info, "my_pkg")

        env_info = EnvInfo()
        env_info.VAR1 = "other-value1"
        env_info.PATH.append("other-path-extended")
        conanfile.deps_env_info.update(env_info, "other-pkg")

        # Add user_info for HOST
        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.deps_user_info["my_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.deps_user_info["other-pkg"] = user_info

        # Add user_info for BUILD
        conanfile.user_info_build = DepsUserInfo()
        user_info = UserInfo()
        user_info.VAR1 = "value1"
        conanfile.user_info_build["build_pkg"] = user_info

        user_info = UserInfo()
        user_info.VAR1 = "other-value1"
        conanfile.user_info_build["other-build-pkg"] = user_info

        master_content = TXTGenerator(conanfile).content
        after_cpp_info, after_user_info, after_env_info, after_user_info_build = \
            TXTGenerator.loads(master_content, filter_empty=False)
        # Assign them to a different conanfile
        other_conanfile = ConanFile(Mock(), None)
        other_conanfile.initialize(Settings({}), EnvValues())
        other_conanfile.deps_cpp_info = after_cpp_info
        other_conanfile.deps_env_info = after_env_info
        other_conanfile.deps_user_info = after_user_info
        other_conanfile.user_info_build = after_user_info_build
        after_content = TXTGenerator(other_conanfile).content

        self.assertListEqual(master_content.splitlines(),
                             after_content.splitlines())
示例#36
0
    def variables_setup_test(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())

        # Add some cpp_info for dependencies
        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "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.add(ref.name, cpp_info)

        ref = ConanFileReference.loads("MyPkg2/0.1@lasote/stables")
        cpp_info = CppInfo(ref.name, "dummy_root_folder2")
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.version = "2.3"
        cpp_info.exelinkflags = ["-exelinkflag"]
        cpp_info.sharedlinkflags = ["-sharedlinkflag"]
        cpp_info.cxxflags = ["-cxxflag"]
        cpp_info.public_deps = ["MyPkg"]
        conanfile.deps_cpp_info.add(ref.name, cpp_info)

        # Add env_info
        env_info = EnvInfo()
        env_info.VAR1 = "env_info-value1"
        env_info.PATH.append("path-extended")
        conanfile.deps_env_info.update(env_info, "env_info_pkg")

        # Add user_info
        user_info = UserInfo()
        user_info.VAR1 = "user_info-value1"
        conanfile.deps_user_info["user_info_pkg"] = user_info

        # Add user_info_build
        conanfile.user_info_build = DepsUserInfo()
        user_info = UserInfo()
        user_info.VAR1 = "user_info_build-value1"
        conanfile.user_info_build["user_info_build_pkg"] = user_info

        generator = JsonGenerator(conanfile)
        json_out = generator.content
        parsed = json.loads(json_out)

        # Check dependencies
        dependencies = parsed["dependencies"]
        self.assertEqual(len(dependencies), 2)
        my_pkg = dependencies[0]
        self.assertEqual(my_pkg["name"], "MyPkg")
        self.assertEqual(my_pkg["description"], "My cool description")
        self.assertEqual(my_pkg["defines"], ["MYDEFINE1"])

        # Check env_info
        env_info = parsed["deps_env_info"]
        self.assertListEqual(sorted(env_info.keys()), sorted(["VAR1", "PATH"]))
        self.assertEqual(env_info["VAR1"], "env_info-value1")
        self.assertListEqual(env_info["PATH"], ["path-extended"])

        # Check user_info
        user_info = parsed["deps_user_info"]
        self.assertListEqual(list(user_info.keys()), ["user_info_pkg"])
        self.assertListEqual(list(user_info["user_info_pkg"].keys()), ["VAR1"])
        self.assertEqual(user_info["user_info_pkg"]["VAR1"],
                         "user_info-value1")

        # Check user_info_build
        user_info_build = parsed["user_info_build"]
        self.assertListEqual(list(user_info_build.keys()),
                             ["user_info_build_pkg"])
        self.assertListEqual(
            list(user_info_build["user_info_build_pkg"].keys()), ["VAR1"])
        self.assertEqual(user_info_build["user_info_build_pkg"]["VAR1"],
                         "user_info_build-value1")
示例#37
0
    def pkg_config_custom_names_test(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())

        ref = ConanFileReference.loads("MyPkg/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.name = "my_pkg"
        cpp_info.names["pkg_config"] = "my_pkg_custom_name"
        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("MyPkg1/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder1")
        cpp_info.name = "MYPKG1"
        cpp_info.names["pkg_config"] = "my_pkg1_custom_name"
        cpp_info.defines = ["MYDEFINE11"]
        cpp_info.cflags.append("-Flag1=21")
        cpp_info.version = "1.7"
        cpp_info.description = "My other 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.name = ref.name
        cpp_info.names["pkg_config"] = "my_pkg2_custom_name"
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.version = "2.3"
        cpp_info.exelinkflags = ["-exelinkflag"]
        cpp_info.sharedlinkflags = ["-sharedlinkflag"]
        cpp_info.cxxflags = ["-cxxflag"]
        cpp_info.public_deps = ["MyPkg", "MyPkg1"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)

        ref = ConanFileReference.loads("zlib/1.2.11@lasote/stable")
        cpp_info = CppInfo("dummy_root_folder_zlib")
        cpp_info.name = "ZLIB"
        cpp_info.defines = ["MYZLIBDEFINE2"]
        cpp_info.version = "1.2.11"
        conanfile.deps_cpp_info.update(cpp_info, ref.name)

        ref = ConanFileReference.loads("bzip2/0.1@lasote/stables")
        cpp_info = CppInfo("dummy_root_folder2")
        cpp_info.name = "BZip2"
        cpp_info.names["pkg_config"] = "BZip2"
        cpp_info.defines = ["MYDEFINE2"]
        cpp_info.version = "2.3"
        cpp_info.exelinkflags = ["-exelinkflag"]
        cpp_info.sharedlinkflags = ["-sharedlinkflag"]
        cpp_info.cxxflags = ["-cxxflag"]
        cpp_info.public_deps = ["MyPkg", "MyPkg1", "zlib"]
        conanfile.deps_cpp_info.update(cpp_info, ref.name)
        generator = PkgConfigGenerator(conanfile)
        files = generator.content

        self.assertEqual(files["my_pkg2_custom_name.pc"], """prefix=dummy_root_folder2
libdir=${prefix}/lib
includedir=${prefix}/include

Name: my_pkg2_custom_name
Description: Conan package: my_pkg2_custom_name
Version: 2.3
Libs: -L${libdir} -sharedlinkflag -exelinkflag
Cflags: -I${includedir} -cxxflag -DMYDEFINE2
Requires: my_pkg_custom_name my_pkg1_custom_name
""")
        self.assertEqual(files["my_pkg1_custom_name.pc"], """prefix=dummy_root_folder1
libdir=${prefix}/lib
includedir=${prefix}/include

Name: my_pkg1_custom_name
Description: My other cool description
Version: 1.7
Libs: -L${libdir}
Cflags: -I${includedir} -Flag1=21 -DMYDEFINE11
""")
        self.assertEqual(files["my_pkg_custom_name.pc"], """prefix=dummy_root_folder1
libdir=${prefix}/lib
includedir=${prefix}/include

Name: my_pkg_custom_name
Description: My cool description
Version: 1.3
Libs: -L${libdir}
Cflags: -I${includedir} -Flag1=23 -DMYDEFINE1
""")
        self.assertEqual(files["BZip2.pc"], """prefix=dummy_root_folder2
libdir=${prefix}/lib
includedir=${prefix}/include

Name: BZip2
Description: Conan package: BZip2
Version: 2.3
Libs: -L${libdir} -sharedlinkflag -exelinkflag
Cflags: -I${includedir} -cxxflag -DMYDEFINE2
Requires: my_pkg_custom_name my_pkg1_custom_name zlib
""")
示例#38
0
文件: b2_test.py 项目: xaqq/conan
    def b2_test(self):
        settings = Settings.loads(default_settings_yml)
        settings.os = "Linux"
        settings.compiler = "gcc"
        settings.compiler.version = "6.3"
        settings.arch = "x86"
        settings.build_type = "Release"
        settings.cppstd = "gnu17"

        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        conanfile.settings = settings

        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 = B2Generator(conanfile)

        content = {
            'conanbuildinfo.jam':
            '''#|
    B2 definitions for Conan packages. This is a generated file.
    Edit the corresponding conanfile.txt instead.
|#

import path ;
import project ;
import modules ;
import feature ;

local base-project = [ project.current ] ;
local base-project-mod = [ $(base-project).project-module ] ;
local base-project-location = [ project.attribute $(base-project-mod) location ] ;

rule project-define ( id )
{
    id = $(id:L) ;
    local saved-project = [ modules.peek project : .base-project ] ;
    local id-location = [ path.join $(base-project-location) $(id) ] ;
    local id-mod = [ project.load $(id-location) : synthesize ] ;
    project.initialize $(id-mod) : $(id-location) ;
    project.inherit-attributes $(id-mod) : $(base-project-mod) ;
    local attributes = [ project.attributes $(id-mod) ] ;
    $(attributes).set parent-module : $(base-project-mod) : exact ;
    modules.poke $(base-project-mod) : $(id)-mod : $(id-mod) ;
    modules.poke [ CALLER_MODULE ] : $(id)-mod : $(id-mod) ;
    modules.poke project : .base-project : $(saved-project) ;
    IMPORT $(__name__)
        : constant-if call-in-project
        : $(id-mod)
        : constant-if call-in-project ;
    if [ project.is-jamroot-module $(base-project-mod) ]
    {
        use-project /$(id) : $(id) ;
    }
    return $(id-mod) ;
}

rule constant-if ( name : value * )
{
    if $(__define_constants__) && $(value)
    {
        call-in-project : constant $(name) : $(value) ;
        modules.poke $(__name__) : $(name) : [ modules.peek $(base-project-mod) : $(name) ] ;
    }
}

rule call-in-project ( project-mod ? : rule-name args * : * )
{
    project-mod ?= $(base-project-mod) ;
    project.push-current [ project.target $(project-mod) ] ;
    local result = [ modules.call-in $(project-mod) :
        $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) : $(10) :
        $(11) : $(12) : $(13) : $(14) : $(15) : $(16) : $(17) : $(18) :
        $(19) ] ;
    project.pop-current ;
    return $(result) ;
}

rule include-conanbuildinfo ( cbi )
{
    include $(cbi) ;
}

IMPORT $(__name__)
    : project-define constant-if call-in-project include-conanbuildinfo
    : $(base-project-mod)
    : project-define constant-if call-in-project include-conanbuildinfo ;

if ! ( relwithdebinfo in [ feature.values variant ] )
{
    variant relwithdebinfo : : <optimization>speed <debug-symbols>on <inlining>full <runtime-debugging>off ;
}
if ! ( minsizerel in [ feature.values variant ] )
{
    variant minsizerel : : <optimization>space <debug-symbols>off <inlining>full <runtime-debugging>off ;
}

local __conanbuildinfo__ = [ GLOB $(__file__:D) : conanbuildinfo-*.jam : downcase ] ;
{
    local __define_constants__ = yes ;
    for local __cbi__ in $(__conanbuildinfo__)
    {
        call-in-project : include-conanbuildinfo $(__cbi__) ;
    }
}


# mypkg
# mypkg
project-define mypkg ;


# mypkg2
# mypkg2
project-define mypkg2 ;

{
    local __define_targets__ = yes ;
    for local __cbi__ in $(__conanbuildinfo__)
    {
        call-in-project : include-conanbuildinfo $(__cbi__) ;
    }
}
''',
            'conanbuildinfo-316f2f0b155dc874a672d40d98d93f95.jam':
            '''#|
    B2 definitions for Conan packages. This is a generated file.
    Edit the corresponding conanfile.txt instead.
|#

# global
constant-if rootpath(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    ""
    ;

constant-if includedirs(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    "other/Path/with/slashes"
    "other/regular/path/to/dir"
    ;

constant-if libdirs(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    "Path/with/slashes"
    "regular/path/to/dir"
    ;

constant-if defines(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    "MYDEFINE2"
    "MYDEFINE1"
    ;

constant-if cppflags(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-cppflag"
    ;

constant-if cflags(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-Flag1=23"
    ;

constant-if sharedlinkflags(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-sharedlinkflag"
    ;

constant-if exelinkflags(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-exelinkflag"
    ;

constant-if requirements(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    <address-model>32
    <architecture>x86
    <cxxstd>17
    <cxxstd:dialect>gnu
    <target-os>linux
    <toolset>gcc-6.3
    <variant>release
    ;

constant-if usage-requirements(conan,32,x86,17,gnu,linux,gcc-6.3,release) :
    <include>$(includedirs(conan,32,x86,17,gnu,linux,gcc-6.3,release))
    <define>$(defines(conan,32,x86,17,gnu,linux,gcc-6.3,release))
    <cflags>$(cflags(conan,32,x86,17,gnu,linux,gcc-6.3,release))
    <cxxflags>$(cppflags(conan,32,x86,17,gnu,linux,gcc-6.3,release))
    <link>shared:<linkflags>$(sharedlinkflags(conan,32,x86,17,gnu,linux,gcc-6.3,release))
    ;

# mypkg
constant-if rootpath(mypkg,32,x86,17,gnu,linux,gcc-6.3,release) :
    "dummy_root_folder1"
    ;

constant-if defines(mypkg,32,x86,17,gnu,linux,gcc-6.3,release) :
    "MYDEFINE1"
    ;

constant-if cflags(mypkg,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-Flag1=23"
    ;

constant-if requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release) :
    <address-model>32
    <architecture>x86
    <cxxstd>17
    <cxxstd:dialect>gnu
    <target-os>linux
    <toolset>gcc-6.3
    <variant>release
    ;

constant-if usage-requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release) :
    <include>$(includedirs(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
    <define>$(defines(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
    <cflags>$(cflags(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
    <cxxflags>$(cppflags(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
    <link>shared:<linkflags>$(sharedlinkflags(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
    ;

# mypkg2
constant-if rootpath(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    "dummy_root_folder2"
    ;

constant-if includedirs(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    "other/Path/with/slashes"
    "other/regular/path/to/dir"
    ;

constant-if libdirs(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    "Path/with/slashes"
    "regular/path/to/dir"
    ;

constant-if defines(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    "MYDEFINE2"
    ;

constant-if cppflags(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-cppflag"
    ;

constant-if sharedlinkflags(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-sharedlinkflag"
    ;

constant-if exelinkflags(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    "-exelinkflag"
    ;

constant-if requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    <address-model>32
    <architecture>x86
    <cxxstd>17
    <cxxstd:dialect>gnu
    <target-os>linux
    <toolset>gcc-6.3
    <variant>release
    ;

constant-if usage-requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release) :
    <include>$(includedirs(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
    <define>$(defines(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
    <cflags>$(cflags(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
    <cxxflags>$(cppflags(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
    <link>shared:<linkflags>$(sharedlinkflags(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
    ;

# mypkg
if $(__define_targets__) {
    call-in-project $(mypkg-mod) : lib MyLib1
        :
        : <name>MyLib1 <search>$(libdirs(mypkg,32,x86,17,gnu,linux,gcc-6.3,release)) $(requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
        :
        : $(usage-requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release)) ;
    call-in-project $(mypkg-mod) : explicit MyLib1 ; }

if $(__define_targets__) {
    call-in-project $(mypkg-mod) : alias libs
        : MyLib1
        : $(requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release))
        :
        : $(usage-requirements(mypkg,32,x86,17,gnu,linux,gcc-6.3,release)) ;
    call-in-project $(mypkg-mod) : explicit libs ; }

# mypkg2
if $(__define_targets__) {
    call-in-project $(mypkg2-mod) : lib MyLib2
        :
        : <name>MyLib2 <search>$(libdirs(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release)) $(requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
        :
        : $(usage-requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release)) ;
    call-in-project $(mypkg2-mod) : explicit MyLib2 ; }

if $(__define_targets__) {
    call-in-project $(mypkg2-mod) : alias libs
        : MyLib2
        : $(requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release))
        :
        : $(usage-requirements(mypkg2,32,x86,17,gnu,linux,gcc-6.3,release)) ;
    call-in-project $(mypkg2-mod) : explicit libs ; }
''',
        }

        for ck, cv in generator.content.items():
            self.assertEquals(cv, content[ck])
示例#39
0
    def aux_cmake_test_setup_test(self):
        conanfile = ConanFile(TestBufferConanOutput(), None)
        conanfile.initialize(Settings({}), EnvValues())
        generator = CMakeGenerator(conanfile)
        aux_cmake_test_setup = generator.content

        # extract the conan_basic_setup macro
        macro = self._extract_macro("conan_basic_setup", aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_basic_setup)
    set(options TARGETS NO_OUTPUT_DIRS SKIP_RPATH KEEP_RPATHS SKIP_STD SKIP_FPIC)
    cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

    if(CONAN_EXPORTED)
        conan_message(STATUS "Conan: called by CMake conan helper")
    endif()

    if(CONAN_IN_LOCAL_CACHE)
        conan_message(STATUS "Conan: called inside local cache")
    endif()

    if(NOT ARGUMENTS_NO_OUTPUT_DIRS)
        conan_message(STATUS "Conan: Adjusting output directories")
        conan_output_dirs_setup()
    endif()

    if(NOT ARGUMENTS_TARGETS)
        conan_message(STATUS "Conan: Using cmake global configuration")
        conan_global_flags()
    else()
        conan_message(STATUS "Conan: Using cmake targets configuration")
        conan_define_targets()
    endif()

    if(ARGUMENTS_SKIP_RPATH)
        # Change by "DEPRECATION" or "SEND_ERROR" when we are ready
        conan_message(WARNING "Conan: SKIP_RPATH is deprecated, it has been renamed to KEEP_RPATHS")
    endif()

    if(NOT ARGUMENTS_SKIP_RPATH AND NOT ARGUMENTS_KEEP_RPATHS)
        # Parameter has renamed, but we keep the compatibility with old SKIP_RPATH
        conan_message(STATUS "Conan: Adjusting default RPATHs Conan policies")
        conan_set_rpath()
    endif()

    if(NOT ARGUMENTS_SKIP_STD)
        conan_message(STATUS "Conan: Adjusting language standard")
        conan_set_std()
    endif()

    if(NOT ARGUMENTS_SKIP_FPIC)
        conan_set_fpic()
    endif()

    conan_check_compiler()
    conan_set_libcxx()
    conan_set_vs_runtime()
    conan_set_find_paths()
    conan_include_build_modules()
    conan_set_find_library_paths()
endmacro()""", macro)

        # extract the conan_set_find_paths macro
        macro = self._extract_macro("conan_set_find_paths",
                                    aux_cmake_test_setup)
        self.assertEqual(
            """macro(conan_set_find_paths)
    # CMAKE_MODULE_PATH does not have Debug/Release config, but there are variables
    # CONAN_CMAKE_MODULE_PATH_DEBUG to be used by the consumer
    # CMake can find findXXX.cmake files in the root of packages
    set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH})

    # Make find_package() to work
    set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH} ${CMAKE_PREFIX_PATH})

    # Set the find root path (cross build)
    set(CMAKE_FIND_ROOT_PATH ${CONAN_CMAKE_FIND_ROOT_PATH} ${CMAKE_FIND_ROOT_PATH})
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
        set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
    endif()
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
        set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_LIBRARY})
    endif()
    if(CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
        set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${CONAN_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
    endif()
endmacro()""", macro)