Пример #1
0
 def cpu_count_test(self):
     output = ConanOutput(sys.stdout)
     cpus = tools.cpu_count(output=output)
     self.assertIsInstance(cpus, int)
     self.assertGreaterEqual(cpus, 1)
     with tools.environment_append({"CONAN_CPU_COUNT": "34"}):
         self.assertEqual(tools.cpu_count(output=output), 34)
     with tools.environment_append({"CONAN_CPU_COUNT": "null"}):
         with six.assertRaisesRegex(self, ConanException, "Invalid CONAN_CPU_COUNT value"):
             tools.cpu_count(output=output)
Пример #2
0
 def test_construct_build_helper_without_project_file(self):
     conanfile = MockConanfile(
         MockSettings({'os': 'Linux', 'compiler': 'gcc'}))
     conanfile.source_folder = '.'
     build_helper = qbs.Qbs(conanfile)
     self.assertEqual(build_helper.jobs, tools.cpu_count())
     self.assertEqual(build_helper._project_file, conanfile.source_folder)
Пример #3
0
    def test_cpu_count_in_container(self, get_cpu_quota_mock, get_cpu_period_mock):
        get_cpu_quota_mock.return_value = 12000
        get_cpu_period_mock.return_value = 1000

        output = ConanOutput(sys.stdout)
        cpus = tools.cpu_count(output=output)
        self.assertEqual(12, cpus)
Пример #4
0
    def __init__(self,
                 conanfile,
                 generator=None,
                 generator_platform=None,
                 build_type=None,
                 toolset=None,
                 parallel=True):
        self._conanfile = conanfile

        self.fpic = self._deduce_fpic()
        self.vs_static_runtime = self._deduce_vs_static_runtime()
        self.parallel = parallel

        # To find the generated cmake_find_package finders
        self.cmake_prefix_path = "${CMAKE_BINARY_DIR}"
        self.cmake_module_path = "${CMAKE_BINARY_DIR}"

        self.generator = generator or get_generator(self._conanfile)
        self.generator_platform = (generator_platform
                                   or get_generator_platform(
                                       self._conanfile.settings,
                                       self.generator))
        self.toolset = toolset or get_toolset(self._conanfile.settings,
                                              self.generator)

        self.variables = Variables()
        self.preprocessor_definitions = Variables()
        try:
            self._build_shared_libs = "ON" if self._conanfile.options.shared else "OFF"
        except ConanException:
            self._build_shared_libs = None

        self.set_libcxx, self.glibcxx = self._get_libcxx()

        self.parallel = None
        if parallel:
            if self.generator and "Visual Studio" in self.generator:
                self.parallel = "/MP%s" % cpu_count(
                    output=self._conanfile.output)

        self.cppstd, self.cppstd_extensions = self._cppstd()

        self.skip_rpath = True if self._conanfile.settings.get_safe(
            "os") == "Macos" else False
        self.architecture = self._get_architecture()

        # TODO: I would want to have here the path to the compiler too
        build_type = build_type or self._conanfile.settings.get_safe(
            "build_type")
        self.build_type = build_type if not is_multi_configuration(
            self.generator) else None
        try:
            # This is only defined in the cache, not in the local flow
            self.install_prefix = self._conanfile.package_folder.replace(
                "\\", "/")
        except AttributeError:
            # FIXME: In the local flow, we don't know the package_folder
            self.install_prefix = None
Пример #5
0
    def __init__(self,
                 conanfile,
                 generator=None,
                 generator_platform=None,
                 build_type=None,
                 toolset=None,
                 parallel=True):
        super(CMakeGenericToolchain, self).__init__(conanfile)

        self.fpic = self._deduce_fpic()
        self.vs_static_runtime = self._deduce_vs_static_runtime()
        self.parallel = parallel

        self.generator = generator or get_generator(self._conanfile)
        self.generator_platform = (generator_platform
                                   or get_generator_platform(
                                       self._conanfile.settings,
                                       self.generator))
        self.toolset = toolset or get_toolset(self._conanfile.settings,
                                              self.generator)
        if (self.generator is not None and "Ninja" in self.generator
                and "Visual" in self._conanfile.settings.compiler):
            self.compiler = "cl"
        else:
            self.compiler = None  # compiler defined by default

        try:
            self._build_shared_libs = "ON" if self._conanfile.options.shared else "OFF"
        except ConanException:
            self._build_shared_libs = None

        self.set_libcxx, self.glibcxx = self._get_libcxx()

        self.parallel = None
        if parallel:
            if self.generator and "Visual Studio" in self.generator:
                self.parallel = "/MP%s" % cpu_count(
                    output=self._conanfile.output)

        self.cppstd, self.cppstd_extensions = self._cppstd()

        self.skip_rpath = True if self._conanfile.settings.get_safe(
            "os") == "Macos" else False
        self.architecture = self._get_architecture()

        # TODO: I would want to have here the path to the compiler too
        build_type = build_type or self._conanfile.settings.get_safe(
            "build_type")
        self.build_type = build_type if not is_multi_configuration(
            self.generator) else None
Пример #6
0
    def test_visual(self):
        settings = MockSettings({
            "build_type": "Debug",
            "compiler": "Visual Studio",
            "compiler.runtime": "MDd"
        })
        conanfile = MockConanfile(settings)
        conanfile.deps_cpp_info.include_paths.append("/one/include/path")
        conanfile.deps_cpp_info.include_paths.append("/two/include/path")
        conanfile.deps_cpp_info.lib_paths.append("/one/lib/path")
        conanfile.deps_cpp_info.lib_paths.append("/two/lib/path")
        conanfile.deps_cpp_info.cflags.append("-mycflag")
        conanfile.deps_cpp_info.cflags.append("-mycflag2")
        conanfile.deps_cpp_info.cxxflags.append("-mycxxflag")
        conanfile.deps_cpp_info.cxxflags.append("-mycxxflag2")
        conanfile.deps_cpp_info.exelinkflags.append("-myexelinkflag")
        conanfile.deps_cpp_info.sharedlinkflags.append("-mysharedlinkflag")
        conanfile.deps_cpp_info.libs.extend(['gdi32', 'user32.lib'])

        tool = VisualStudioBuildEnvironment(conanfile)
        self.assertEqual(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path", '-MDd',
                    '-mycflag', '-mycflag2', '-Zi', '-Ob0', '-Od',
                    '-mycxxflag', '-mycxxflag2'
                ],
                "LIB": ["/one/lib/path", "/two/lib/path"],
                "UseEnv":
                "True",
                "_LINK_": [
                    '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                    'user32.lib'
                ]
            })
        tool.parallel = True
        self.assertEqual(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path", '-MDd',
                    '-mycflag', '-mycflag2', '-Zi', '-Ob0', '-Od',
                    '-mycxxflag', '-mycxxflag2',
                    '/MP%s' % tools.cpu_count(output=conanfile.output)
                ],
                "LIB": ["/one/lib/path", "/two/lib/path"],
                "UseEnv":
                "True",
                "_LINK_": [
                    '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                    'user32.lib'
                ]
            })
        tool.parallel = False

        # Now alter the paths before the vars_dict call
        tool.include_paths.append("/three/include/path")
        tool.lib_paths.append("/three/lib/path")

        self.assertEqual(
            tool.vars_dict, {
                "CL": [
                    "-I/one/include/path", "-I/two/include/path",
                    "-I/three/include/path", '-MDd', '-mycflag', '-mycflag2',
                    '-Zi', '-Ob0', '-Od', '-mycxxflag', '-mycxxflag2'
                ],
                "LIB": ["/one/lib/path", "/two/lib/path", "/three/lib/path"],
                "UseEnv":
                "True",
                "_LINK_": [
                    '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                    'user32.lib'
                ]
            })

        # Now try appending to environment
        with tools.environment_append({
                "CL": "-I/four/include/path -I/five/include/path",
                "LIB": "/four/lib/path;/five/lib/path"
        }):
            self.assertEqual(
                tool.vars_dict, {
                    "CL": [
                        "-I/one/include/path", "-I/two/include/path",
                        "-I/three/include/path", '-MDd', '-mycflag',
                        '-mycflag2', '-Zi', '-Ob0', '-Od', '-mycxxflag',
                        '-mycxxflag2',
                        "-I/four/include/path -I/five/include/path"
                    ],
                    "LIB": [
                        "/one/lib/path", "/two/lib/path", "/three/lib/path",
                        "/four/lib/path;/five/lib/path"
                    ],
                    "UseEnv":
                    "True",
                    "_LINK_": [
                        '-myexelinkflag', '-mysharedlinkflag', 'gdi32.lib',
                        'user32.lib'
                    ]
                })

            self.assertEqual(
                tool.vars, {
                    "CL":
                    '-I"/one/include/path" -I"/two/include/path" -I"/three/include/path" -MDd '
                    '-mycflag -mycflag2 -Zi -Ob0 -Od '
                    '-mycxxflag -mycxxflag2 '
                    '-I/four/include/path -I/five/include/path',
                    "LIB":
                    "/one/lib/path;/two/lib/path;/three/lib/path;/four/lib/path;/five/lib/path",
                    "UseEnv":
                    "True",
                    "_LINK_":
                    "-myexelinkflag -mysharedlinkflag gdi32.lib user32.lib"
                })