Example #1
0
 def cmake_generator_test(self):
     conan_file = ConanFileMock()
     conan_file.settings = Settings()
     with tools.environment_append(
         {"CONAN_CMAKE_GENERATOR": "My CMake Generator"}):
         cmake = CMake(conan_file)
         self.assertIn('-G "My CMake Generator"', cmake.command_line)
Example #2
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"

        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)
        generator = JsonGenerator(conanfile)
        json_out = generator.content

        parsed = json.loads(json_out)
        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"])
Example #3
0
    def config_patch_test(self):
        conan_file = ConanFileMock()
        conan_file.name = "MyPkg"
        conan_file.settings = Settings()
        conan_file.source_folder = os.path.join(self.tempdir, "src")
        conan_file.build_folder = os.path.join(self.tempdir, "build")
        conan_file.package_folder = os.path.join(self.tempdir, "pkg")
        conan_file.deps_cpp_info = DepsCppInfo()

        msg = "FOLDER: " + conan_file.package_folder
        for folder in (conan_file.build_folder, conan_file.package_folder):
            save(os.path.join(folder, "file1.cmake"), "Nothing")
            save(os.path.join(folder, "file2"), msg)
            save(os.path.join(folder, "file3.txt"), msg)
            save(os.path.join(folder, "file3.cmake"), msg)
            save(os.path.join(folder, "sub", "file3.cmake"), msg)

        cmake = CMake(conan_file, generator="Unix Makefiles")
        cmake.patch_config_paths()
        for folder in (conan_file.build_folder, conan_file.package_folder):
            self.assertEqual("Nothing",
                             load(os.path.join(folder, "file1.cmake")))
            self.assertEqual(msg, load(os.path.join(folder, "file2")))
            self.assertEqual(msg, load(os.path.join(folder, "file3.txt")))
            self.assertEqual("FOLDER: ${CONAN_MYPKG_ROOT}",
                             load(os.path.join(folder, "file3.cmake")))
            self.assertEqual("FOLDER: ${CONAN_MYPKG_ROOT}",
                             load(os.path.join(folder, "sub", "file3.cmake")))
Example #4
0
    def variables_setup_test(self):
        conanfile = ConanFile(None, None)
        conanfile.initialize(Settings({}), EnvValues())
        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)
    def test_upgrade(self):
        output = ConanOutput(StringIO())
        command = build_sln_command(Settings({}),
                                    sln_path='dummy.sln',
                                    targets=None,
                                    upgrade_project=True,
                                    build_type='Debug',
                                    arch='x86_64',
                                    parallel=False,
                                    output=output)

        self.assertIn('msbuild "dummy.sln"', command)
        self.assertIn('/p:Platform="x64"', command)
        self.assertIn('devenv "dummy.sln" /upgrade', command)
        self.assertNotIn('/m:%s' % cpu_count(output=output), command)
        self.assertNotIn('/target:teapot', command)

        with tools.environment_append({"CONAN_SKIP_VS_PROJECTS_UPGRADE": "1"}):
            output = ConanOutput(StringIO())
            command = build_sln_command(Settings({}),
                                        sln_path='dummy.sln',
                                        targets=None,
                                        upgrade_project=True,
                                        build_type='Debug',
                                        arch='x86_64',
                                        parallel=False,
                                        output=output)

            self.assertIn('msbuild "dummy.sln"', command)
            self.assertIn('/p:Platform="x64"', command)
            self.assertNotIn('devenv "dummy.sln" /upgrade', command)
            self.assertNotIn('/m:%s' % cpu_count(output=output), command)
            self.assertNotIn('/target:teapot', command)

        with tools.environment_append(
            {"CONAN_SKIP_VS_PROJECTS_UPGRADE": "False"}):
            output = ConanOutput(StringIO())
            command = build_sln_command(Settings({}),
                                        sln_path='dummy.sln',
                                        targets=None,
                                        upgrade_project=True,
                                        build_type='Debug',
                                        arch='x86_64',
                                        parallel=False,
                                        output=output)

            self.assertIn('devenv "dummy.sln" /upgrade', command)
Example #6
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("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.cxxflags = ["-cxxflag"]
        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.assertEqual(
            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>-cxxflag
	<ldflags>-sharedlinkflag
	;

alias conan-deps :
	MyLib1
	MyLib2
;
""")
 def target_test(self):
     command = build_sln_command(Settings({}), sln_path='dummy.sln', targets=['teapot'], upgrade_project=False,
                                 build_type='Debug', arch='x86', parallel=False)
     self.assertIn('msbuild dummy.sln', command)
     self.assertIn('/p:Platform="x86"', command)
     self.assertNotIn('devenv dummy.sln /upgrade', command)
     self.assertNotIn('/m:%s' % cpu_count(), command)
     self.assertIn('/target:teapot', command)
Example #8
0
 def test_conan_run_tests(self):
     conan_file = ConanFileMock()
     conan_file.settings = Settings()
     conan_file.should_test = True
     meson = Meson(conan_file)
     with environment_append({"CONAN_RUN_TESTS": "0"}):
         meson.test()
         self.assertIsNone(conan_file.command)
Example #9
0
 def parallel_test(self):
     command = build_sln_command(Settings({}), sln_path='dummy.sln', targets=None, upgrade_project=True,
                                 build_type='Debug', arch='armv7', parallel=False)
     self.assertIn('msbuild "dummy.sln"', command)
     self.assertIn('/p:Platform="ARM"', command)
     self.assertIn('devenv "dummy.sln" /upgrade', command)
     self.assertNotIn('/m:%s' % cpu_count(), command)
     self.assertNotIn('/target:teapot', command)
Example #10
0
 def test_conf_skip_test(self):
     conf = ConfDefinition()
     conf.loads("tools.build:skip_test=1")
     conanfile = ConanFileMock()
     conanfile.settings = Settings()
     conanfile.conf = conf.get_conanfile_conf(None)
     meson = Meson(conanfile)
     meson.test()
     self.assertIsNone(conanfile.command)
Example #11
0
 def test_nmake_no_parallel(self):
     conan_file = ConanFileMock()
     conan_file.deps_cpp_info = self._creat_deps_cpp_info()
     conan_file.settings = Settings()
     be = AutoToolsBuildEnvironment(conan_file)
     be.make(make_program="nmake")
     assert "-j" not in conan_file.command
     be.make(make_program="make")
     assert "-j" in conan_file.command
Example #12
0
 def no_build_type_test(self):
     with self.assertRaises(ConanException):
         build_sln_command(Settings({}),
                           sln_path='dummy.sln',
                           targets=None,
                           upgrade_project=False,
                           build_type=None,
                           arch='x86',
                           parallel=False)
Example #13
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)
 def basic_test(self):
     s = Settings({"os": ["Windows", "Linux"]})
     s.os = "Windows"
     with self.assertRaises(ConanException) as cm:
         self.sut.compiler = "kk"
     self.assertEqual(
         str(cm.exception),
         bad_value_msg("settings.compiler", "kk",
                       "['Visual Studio', 'gcc']"))
Example #15
0
    def no_configuration_test(self):
        dummy = """GlobalSection
            EndGlobalSection
     GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Win32 = Debug|Win32
        Debug|x64 = Debug|x64
        Release|Win32 = Release|Win32
        Release|x64 = Release|x64
    EndGlobalSection
"""
        folder = temp_folder()
        path = os.path.join(folder, "dummy.sln")
        save(path, dummy)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            new_out = StringIO()
            command = build_sln_command(Settings({}), sln_path=path, targets=None, upgrade_project=False,
                                        build_type='Debug', arch="x86", parallel=False,
                                        output=ConanOutput(new_out))

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        self.assertIn('/p:Configuration="Debug" /p:UseEnv=false /p:Platform="x86"', command)
        self.assertIn("WARN: ***** The configuration Debug|x86 does not exist in this solution *****",
                      new_out.getvalue())

        # use platforms
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            new_out = StringIO()
            command = build_sln_command(Settings({}), sln_path=path, targets=None, upgrade_project=False,
                                        build_type='Debug', arch="x86", parallel=False,
                                        platforms={"x86": "Win32"}, output=ConanOutput(new_out))

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        self.assertIn('/p:Configuration="Debug" /p:UseEnv=false /p:Platform="Win32"', command)
        self.assertNotIn("WARN", new_out.getvalue())
        self.assertNotIn("ERROR", new_out.getvalue())
Example #16
0
    def _parse_conan_txt(self, contents, path, display_name, profile):
        conanfile = ConanFile(self._output, self._runner, display_name)
        tmp_settings = profile.processed_settings.copy()
        package_settings_values = profile.package_settings_values
        if "&" in package_settings_values:
            pkg_settings = package_settings_values.get("&")
            if pkg_settings:
                tmp_settings.update_values(pkg_settings)
        conanfile.initialize(Settings(), profile.env_values, profile.buildenv)
        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 = tmp_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)
        if parser.layout:
            layout_method = {
                "cmake_layout": cmake_layout,
                "vs_layout": vs_layout,
                "bazel_layout": bazel_layout
            }.get(parser.layout)
            if not layout_method:
                raise ConanException(
                    "Unknown predefined layout '{}' declared in "
                    "conanfile.txt".format(parser.layout))

            def layout(self):
                layout_method(self)

            conanfile.layout = types.MethodType(layout, conanfile)

        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
 def positive_test(self):
     output = ConanOutput(StringIO())
     command = build_sln_command(Settings({}), sln_path='dummy.sln', targets=None,
                                 upgrade_project=False, build_type='Debug', arch='x86',
                                 parallel=False, output=output)
     self.assertIn('msbuild "dummy.sln"', command)
     self.assertIn('/p:Platform="x86"', command)
     self.assertNotIn('devenv "dummy.sln" /upgrade', command)
     self.assertNotIn('/m:%s' % cpu_count(output=output), command)
     self.assertNotIn('/target:teapot', command)
Example #18
0
 def _createInfo(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)
     ref = ConanFileReference.loads("MyPkg2/0.1@user/testing")
     cpp_info = CppInfo("dummy_root_folder2")
     conanfile.deps_cpp_info.update(cpp_info, ref)
     generator = VisualStudioGenerator(conanfile)
     return generator.content
Example #19
0
 def test_name_and_version_are_generated(self):
     conanfile = ConanFile(Mock(), 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)
Example #20
0
    def test_package_settings(self):
        # CREATE A CONANFILE TO LOAD
        tmp_dir = temp_folder()
        conanfile_path = os.path.join(tmp_dir, "conanfile.py")
        conanfile = """from conans import ConanFile
class MyTest(ConanFile):
    requires = {}
    name = "MyPackage"
    version = "1.0"
    settings = "os"
"""
        save(conanfile_path, conanfile)

        # Apply windows for MyPackage
        profile = Profile()
        profile.package_settings = {
            "MyPackage": OrderedDict([("os", "Windows")])
        }
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}),
                                 profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertEquals(recipe.settings.os, "Windows")

        # Apply Linux for MyPackage
        profile.package_settings = {
            "MyPackage": OrderedDict([("os", "Linux")])
        }
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}),
                                 profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertEquals(recipe.settings.os, "Linux")

        # If the package name is different from the conanfile one, it wont apply
        profile.package_settings = {
            "OtherPACKAGE": OrderedDict([("os", "Linux")])
        }
        loader = ConanFileLoader(None, Settings({"os": ["Windows", "Linux"]}),
                                 profile)

        recipe = loader.load_conan(conanfile_path, None)
        self.assertIsNone(recipe.settings.os.value)
Example #21
0
 def partial_build_test(self):
     conan_file = ConanFileMock()
     conan_file.settings = Settings()
     conan_file.should_configure = False
     conan_file.should_build = False
     meson = Meson(conan_file)
     meson.configure()
     self.assertIsNone(conan_file.command)
     meson.build()
     self.assertIsNone(conan_file.command)
Example #22
0
 def test_exelinkflags(self):
     conanfile = ConanFile(Mock(), None)
     conanfile.initialize(Settings({}), EnvValues())
     framework_path = os.getcwd()  # must exist, otherwise filtered by framework_paths
     cpp_info = CppInfo("MyPkg", "/rootpath")
     cpp_info.exelinkflags = ["-llibrary_for_exe"]
     conanfile.deps_cpp_info.add("MyPkg", DepCppInfo(cpp_info))
     generator = QmakeGenerator(conanfile)
     content = generator.content
     qmake_lines = content.splitlines()
     self.assertIn('CONAN_QMAKE_LFLAGS_APP += -llibrary_for_exe', qmake_lines)
Example #23
0
 def no_prefix_test(self):
     conan_file = ConanFileMock()
     conan_file.settings = Settings()
     conan_file.package_folder = None
     meson = Meson(conan_file)
     meson.configure()
     self.assertNotIn('-Dprefix', conan_file.command)
     meson.build()
     self.assertIn("ninja -C", conan_file.command)
     with self.assertRaises(TypeError):
         meson.install()
Example #24
0
 def test_no_prefix(self):
     conan_file = ConanFileMock()
     conan_file.deps_cpp_info = MockDepsCppInfo()
     conan_file.settings = Settings()
     meson = Meson(conan_file)
     meson.configure()
     self.assertNotIn('-Dprefix', conan_file.command)
     meson.build()
     self.assertIn("ninja -C", conan_file.command)
     with self.assertRaises(TypeError):
         meson.install()
Example #25
0
 def no_arch_test(self):
     with self.assertRaises(ConanException):
         new_out = StringIO()
         build_sln_command(Settings({}),
                           sln_path='dummy.sln',
                           targets=None,
                           upgrade_project=False,
                           build_type='Debug',
                           arch=None,
                           parallel=False,
                           output=ConanOutput(new_out))
Example #26
0
    def test_conanfile_naming(self):
        for member in vars(ConanFile):
            if member.startswith('_') and not member.startswith("__"):
                self.assertTrue(member.startswith('_conan'))

        conanfile = ConanFile(None, None)
        conanfile.initialize(Settings(), EnvValues())

        for member in vars(conanfile):
            if member.startswith('_') and not member.startswith("__"):
                self.assertTrue(member.startswith('_conan'))
Example #27
0
    def no_configuration_test(self):
        dummy = """GlobalSection
            EndGlobalSection
     GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Win32 = Debug|Win32
        Debug|x64 = Debug|x64
        Release|Win32 = Release|Win32
        Release|x64 = Release|x64
    EndGlobalSection
"""
        folder = temp_folder()
        path = os.path.join(folder, "dummy.sln")
        save(path, dummy)
        new_out = StringIO()
        command = build_sln_command(Settings({}),
                                    sln_path=path,
                                    targets=None,
                                    upgrade_project=False,
                                    build_type='Debug',
                                    arch="x86",
                                    parallel=False,
                                    output=ConanOutput(new_out))
        self.assertIn('/p:Configuration="Debug" /p:Platform="x86"', command)
        self.assertIn(
            "WARN: ***** The configuration Debug|x86 does not exist in this solution *****",
            new_out.getvalue())

        # use platforms
        new_out = StringIO()
        command = build_sln_command(Settings({}),
                                    sln_path=path,
                                    targets=None,
                                    upgrade_project=False,
                                    build_type='Debug',
                                    arch="x86",
                                    parallel=False,
                                    platforms={"x86": "Win32"},
                                    output=ConanOutput(new_out))
        self.assertIn('/p:Configuration="Debug" /p:Platform="Win32"', command)
        self.assertNotIn("WARN", new_out.getvalue())
        self.assertNotIn("ERROR", new_out.getvalue())
Example #28
0
 def toolset_test(self):
     command = build_sln_command(Settings({}),
                                 sln_path='dummy.sln',
                                 targets=None,
                                 upgrade_project=False,
                                 build_type='Debug',
                                 arch='armv7',
                                 parallel=False,
                                 toolset="v110")
     self.assertEquals(
         'msbuild dummy.sln /p:Configuration=Debug /p:Platform="ARM" '
         '/p:PlatformToolset=v110', command)
Example #29
0
    def _build_and_check(self, tmp_dir, file_path, text_file, msg):
        loader = ConanFileLoader(None, Settings(), Profile())
        ret = loader.load_conan(file_path, None)
        curdir = os.path.abspath(os.curdir)
        os.chdir(tmp_dir)
        try:
            ret.build()
        finally:
            os.chdir(curdir)

        content = load(text_file)
        self.assertEquals(content, msg)
Example #30
0
    def __init__(self, settings=None, profile=None, create_reference=None):
        settings = settings or Settings()
        profile = profile or Profile()
        assert isinstance(settings, Settings)
        # assert package_settings is None or isinstance(package_settings, dict)
        self._settings = settings
        self._user_options = profile.options.copy()

        self._package_settings = profile.package_settings_values
        self._env_values = profile.env_values
        # Make sure the paths are normalized first, so env_values can be just a copy
        self._dev_reference = create_reference