예제 #1
0
    def test_make_targets_install(self):
        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)

        ab = AutoToolsBuildEnvironment(conanfile)
        ab.configure()

        ab.make(target="install")
        self.assertEquals(runner.command_called, "make install -j%s" % cpu_count())
        ab.install()
        self.assertEquals(runner.command_called, "make install -j%s" % cpu_count())
예제 #2
0
    def test_mocked_methods(self):

        runner = RunnerMock()
        conanfile = MockConanfile(MockSettings({}), None, runner)
        ab = AutoToolsBuildEnvironment(conanfile)
        ab.make(make_program="othermake")
        self.assertEquals(runner.command_called, "othermake -j%s" % cpu_count())

        with tools.environment_append({"CONAN_MAKE_PROGRAM": "mymake"}):
            ab.make(make_program="othermake")
            self.assertEquals(runner.command_called, "mymake -j%s" % cpu_count())

        ab.make(args=["things"])
        things = "'things'" if platform.system() != "Windows" else "things"
        self.assertEquals(runner.command_called, "make %s -j%s" % (things, cpu_count()))
    def test_parallel(self):
        output = ConanOutput(StringIO())
        command = build_sln_command(Settings({}),
                                    sln_path='dummy.sln',
                                    targets=None,
                                    upgrade_project=True,
                                    build_type='Debug',
                                    arch='armv7',
                                    parallel=False,
                                    output=output)

        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(output=output), command)
        self.assertNotIn('/target:teapot', command)
예제 #4
0
파일: cmake.py 프로젝트: zhongpan/conan
    def test(self,
             args=None,
             build_dir=None,
             target=None,
             output_on_failure=False):
        if not self._conanfile.should_test:
            return
        if not target:
            target = "RUN_TESTS" if self.is_multi_configuration else "test"

        env = {'CTEST_OUTPUT_ON_FAILURE': '1' if output_on_failure else '0'}
        if self.parallel:
            env['CTEST_PARALLEL_LEVEL'] = str(cpu_count(
                self._conanfile.output))
        with tools.environment_append(env):
            self._build(args=args, build_dir=build_dir, target=target)
예제 #5
0
 def make(self, args="", make_program=None, target=None, vars=None):
     if not self._conanfile.should_build:
         return
     if not self._build_type:
         conan_v2_behavior("build_type setting should be defined.",
                           v1_behavior=self._conanfile.output.warn)
     make_program = os.getenv(
         "CONAN_MAKE_PROGRAM") or make_program or "make"
     with environment_append(vars or self.vars):
         str_args = args_to_string(args)
         cpu_count_option = (("-j%s" %
                              cpu_count(output=self._conanfile.output))
                             if "-j" not in str_args else None)
         self._conanfile.run("%s" % join_arguments(
             [make_program, target, str_args, cpu_count_option]),
                             win_bash=self._win_bash,
                             subsystem=self.subsystem)
예제 #6
0
    def positive_test(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            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.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        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)
예제 #7
0
def build_sln_command(settings,
                      sln_path,
                      targets=None,
                      upgrade_project=True,
                      build_type=None,
                      arch=None,
                      parallel=True,
                      toolset=None):
    """
    Use example:
        build_command = build_sln_command(self.settings, "myfile.sln", targets=["SDL2_image"])
        command = "%s && %s" % (tools.vcvars_command(self.settings), build_command)
        self.run(command)
    """
    targets = targets or []
    command = "devenv %s /upgrade && " % sln_path if upgrade_project else ""
    build_type = build_type or settings.build_type
    arch = arch or settings.arch
    if not build_type:
        raise ConanException(
            "Cannot build_sln_command, build_type not defined")
    if not arch:
        raise ConanException("Cannot build_sln_command, arch not defined")
    command += "msbuild %s /p:Configuration=%s" % (sln_path, build_type)
    arch = str(arch)
    msvc_arch = {
        'x86': 'x86',
        'x86_64': 'x64',
        'armv7': 'ARM',
        'armv8': 'ARM64'
    }.get(arch)
    if msvc_arch:
        command += ' /p:Platform="%s"' % msvc_arch

    if parallel:
        command += ' /m:%s' % cpu_count()

    if targets:
        command += " /target:%s" % ";".join(targets)

    if toolset:
        command += " /p:PlatformToolset=%s" % toolset

    return command
예제 #8
0
파일: win.py 프로젝트: manaskarekar/conan
def build_sln_command(settings,
                      sln_path,
                      targets=None,
                      upgrade_project=True,
                      build_type=None,
                      arch=None,
                      parallel=True):
    """
    Use example:
        build_command = build_sln_command(self.settings, "myfile.sln", targets=["SDL2_image"])
        command = "%s && %s" % (tools.vcvars_command(self.settings), build_command)
        self.run(command)
    """
    targets = targets or []
    command = "devenv %s /upgrade && " % sln_path if upgrade_project else ""
    build_type = build_type or settings.build_type
    arch = arch or settings.arch
    if not build_type:
        raise ConanException(
            "Cannot build_sln_command, build_type not defined")
    if not arch:
        raise ConanException("Cannot build_sln_command, arch not defined")
    command += "msbuild %s /p:Configuration=%s" % (sln_path, build_type)
    arch = str(arch)
    if arch in ["x86_64", "x86"]:
        command += ' /p:Platform='
        command += '"x64"' if arch == "x86_64" else '"x86"'
    elif "ARM" in arch.upper():
        command += ' /p:Platform="ARM"'

    if parallel:
        command += ' /m:%s' % cpu_count()

    if targets:
        command += " /target:%s" % ";".join(targets)
    return command
예제 #9
0
    def get_command(self,
                    project_file,
                    props_file_path=None,
                    targets=None,
                    upgrade_project=True,
                    build_type=None,
                    arch=None,
                    parallel=True,
                    toolset=None,
                    platforms=None,
                    use_env=False,
                    properties=None):

        targets = targets or []
        properties = properties or {}
        command = []

        if upgrade_project and not get_env("CONAN_SKIP_VS_PROJECTS_UPGRADE",
                                           False):
            command.append('devenv "%s" /upgrade &&' % project_file)
        else:
            self._output.info("Skipped sln project upgrade")

        build_type = build_type or self._settings.get_safe("build_type")
        arch = arch or self._settings.get_safe("arch")
        if not build_type:
            raise ConanException(
                "Cannot build_sln_command, build_type not defined")
        if not arch:
            raise ConanException("Cannot build_sln_command, arch not defined")

        command.append('msbuild "%s" /p:Configuration="%s"' %
                       (project_file, build_type))
        msvc_arch = {
            'x86': 'x86',
            'x86_64': 'x64',
            'armv7': 'ARM',
            'armv8': 'ARM64'
        }
        if platforms:
            msvc_arch.update(platforms)
        msvc_arch = msvc_arch.get(str(arch))
        try:
            sln = tools.load(project_file)
            pattern = re.compile(
                r"GlobalSection\(SolutionConfigurationPlatforms\)"
                r"(.*?)EndGlobalSection", re.DOTALL)
            solution_global = pattern.search(sln).group(1)
            lines = solution_global.splitlines()
            lines = [s.split("=")[0].strip() for s in lines]
        except Exception:
            pass
        else:
            config = "%s|%s" % (build_type, msvc_arch)
            if config not in "".join(lines):
                self._output.warn(
                    "***** The configuration %s does not exist in this solution *****"
                    % config)
                self._output.warn(
                    "Use 'platforms' argument to define your architectures")

        if use_env:
            command.append('/p:UseEnv=true')

        if msvc_arch:
            command.append('/p:Platform="%s"' % msvc_arch)

        if parallel:
            command.append('/m:%s' % cpu_count())

        if targets:
            command.append("/target:%s" % ";".join(targets))

        if toolset:
            command.append('/p:PlatformToolset="%s"' % toolset)

        if props_file_path:
            command.append('/p:ForceImportBeforeCppTargets="%s"' %
                           props_file_path)

        for name, value in properties.items():
            command.append('/p:%s="%s"' % (name, value))

        return " ".join(command)
예제 #10
0
    def get_command(self, project_file, props_file_path=None, targets=None, upgrade_project=True,
                    build_type=None, arch=None, parallel=True, toolset=None, platforms=None,
                    use_env=False, properties=None, output_binary_log=None, verbosity=None):

        targets = targets or []
        properties = properties or {}
        command = []

        if upgrade_project and not get_env("CONAN_SKIP_VS_PROJECTS_UPGRADE", False):
            command.append('devenv "%s" /upgrade &&' % project_file)
        else:
            self._output.info("Skipped sln project upgrade")

        build_type = build_type or self._settings.get_safe("build_type")
        arch = arch or self._settings.get_safe("arch")
        toolset = toolset or tools.msvs_toolset(self._settings)
        verbosity = os.getenv("CONAN_MSBUILD_VERBOSITY") or verbosity or "minimal"
        if not build_type:
            raise ConanException("Cannot build_sln_command, build_type not defined")
        if not arch:
            raise ConanException("Cannot build_sln_command, arch not defined")

        command.append('msbuild "%s" /p:Configuration="%s"' % (project_file, build_type))
        msvc_arch = {'x86': 'x86',
                     'x86_64': 'x64',
                     'armv7': 'ARM',
                     'armv8': 'ARM64'}
        if platforms:
            msvc_arch.update(platforms)
        msvc_arch = msvc_arch.get(str(arch))
        try:
            sln = tools.load(project_file)
            pattern = re.compile(r"GlobalSection\(SolutionConfigurationPlatforms\)"
                                 r"(.*?)EndGlobalSection", re.DOTALL)
            solution_global = pattern.search(sln).group(1)
            lines = solution_global.splitlines()
            lines = [s.split("=")[0].strip() for s in lines]
        except Exception:
            pass  # TODO: !!! what are we catching here? tools.load? .group(1)? .splitlines?
        else:
            config = "%s|%s" % (build_type, msvc_arch)
            if config not in "".join(lines):
                self._output.warn("***** The configuration %s does not exist in this solution *****"
                                  % config)
                self._output.warn("Use 'platforms' argument to define your architectures")

        if output_binary_log:
            msbuild_version = MSBuild.get_version(self._settings)
            if msbuild_version >= "15.3":  # http://msbuildlog.com/
                command.append('/bl' if isinstance(output_binary_log, bool)
                               else '/bl:"%s"' % output_binary_log)
            else:
                raise ConanException("MSBuild version detected (%s) does not support "
                                     "'output_binary_log' ('/bl')" % msbuild_version)

        if use_env:
            command.append('/p:UseEnv=true')

        if msvc_arch:
            command.append('/p:Platform="%s"' % msvc_arch)

        if parallel:
            command.append('/m:%s' % cpu_count(output=self._output))

        if targets:
            command.append("/target:%s" % ";".join(targets))

        if toolset:
            command.append('/p:PlatformToolset="%s"' % toolset)

        if verbosity:
            command.append('/verbosity:%s' % verbosity)

        if props_file_path:
            command.append('/p:ForceImportBeforeCppTargets="%s"' % props_file_path)

        for name, value in properties.items():
            command.append('/p:%s="%s"' % (name, value))

        return " ".join(command)
예제 #11
0
파일: msbuild.py 프로젝트: 19317362/conan
    def get_command(self, project_file, props_file_path=None, targets=None, upgrade_project=True,
                    build_type=None, arch=None, parallel=True, toolset=None, platforms=None,
                    use_env=False):

        targets = targets or []
        command = []

        if upgrade_project and not get_env("CONAN_SKIP_VS_PROJECTS_UPGRADE", False):
            command.append("devenv %s /upgrade &&" % project_file)
        else:
            self._output.info("Skipped sln project upgrade")

        build_type = build_type or self._settings.get_safe("build_type")
        arch = arch or self._settings.get_safe("arch")
        if not build_type:
            raise ConanException("Cannot build_sln_command, build_type not defined")
        if not arch:
            raise ConanException("Cannot build_sln_command, arch not defined")

        command.append("msbuild %s /p:Configuration=%s" % (project_file, build_type))
        msvc_arch = {'x86': 'x86',
                     'x86_64': 'x64',
                     'armv7': 'ARM',
                     'armv8': 'ARM64'}
        if platforms:
            msvc_arch.update(platforms)
        msvc_arch = msvc_arch.get(str(arch))
        try:
            sln = tools.load(project_file)
            pattern = re.compile(r"GlobalSection\(SolutionConfigurationPlatforms\)"
                                 r"(.*?)EndGlobalSection", re.DOTALL)
            solution_global = pattern.search(sln).group(1)
            lines = solution_global.splitlines()
            lines = [s.split("=")[0].strip() for s in lines]
        except Exception:
            pass
        else:
            config = "%s|%s" % (build_type, msvc_arch)
            if config not in "".join(lines):
                self._output.warn("***** The configuration %s does not exist in this solution *****" % config)
                self._output.warn("Use 'platforms' argument to define your architectures")

        if use_env:
            command.append('/p:UseEnv=true')

        if msvc_arch:
            command.append('/p:Platform="%s"' % msvc_arch)

        if parallel:
            command.append('/m:%s' % cpu_count())

        if targets:
            command.append("/target:%s" % ";".join(targets))

        if toolset:
            command.append("/p:PlatformToolset=%s" % toolset)

        if props_file_path:
            command.append('/p:ForceImportBeforeCppTargets="%s"' % props_file_path)

        return " ".join(command)
예제 #12
0
파일: tools.py 프로젝트: ytljc2003/conan
def cpu_count(*args, **kwargs):
    return tools_oss.cpu_count(output=_global_output, *args, **kwargs)
예제 #13
0
def parallel_compiler_cl_flag(output=None):
    return "/MP%s" % cpu_count(output=output)
예제 #14
0
    def upgrade_test(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            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.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        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"}):
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")

                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.assertEqual(len(w), 1)
                self.assertTrue(issubclass(w[0].category, DeprecationWarning))

            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"}):
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")

                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.assertEqual(len(w), 1)
                self.assertTrue(issubclass(w[0].category, DeprecationWarning))

            self.assertIn('devenv "dummy.sln" /upgrade', command)