Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxcpucount=0 will use all cpus #17301

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conan/tools/cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def _cmake_cmd_line_args(conanfile, generator):
args.append("-j{}".format(njobs))

maxcpucount = conanfile.conf.get("tools.microsoft.msbuild:max_cpu_count", check_type=int)
if maxcpucount and "Visual Studio" in generator:
args.append("/m:{}".format(maxcpucount))
if maxcpucount is not None and "Visual Studio" in generator:
args.append(f"/m:{maxcpucount}" if maxcpucount > 0 else "/m")

# Arguments for verbosity
if "Visual Studio" in generator:
Expand Down
4 changes: 2 additions & 2 deletions conan/tools/microsoft/msbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def command(self, sln, targets=None):

maxcpucount = self._conanfile.conf.get("tools.microsoft.msbuild:max_cpu_count",
check_type=int)
if maxcpucount:
cmd += " /m:{}".format(maxcpucount)
if maxcpucount is not None:
cmd += f" /m:{maxcpucount}" if maxcpucount > 0 else " /m"

if targets:
if not isinstance(targets, list):
Expand Down
10 changes: 10 additions & 0 deletions test/unittests/tools/cmake/test_cmake_cmd_line_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@ def test_visual_studio(conanfile):

args = _cmake_cmd_line_args(conanfile, 'Ninja')
assert args == ['-j10']


def test_maxcpucount_zero():
c = ConfDefinition()
c.loads("tools.microsoft.msbuild:max_cpu_count=0")

conanfile = ConanFileMock()
conanfile.conf = c.get_conanfile_conf(None)
args = _cmake_cmd_line_args(conanfile, 'Visual Studio 16 2019')
assert ["/m"] == args
22 changes: 10 additions & 12 deletions test/unittests/tools/microsoft/test_msbuild.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import textwrap

import pytest

Expand Down Expand Up @@ -31,23 +30,22 @@ def test_msbuild_targets():

def test_msbuild_cpu_count():
c = ConfDefinition()
c.loads(textwrap.dedent("""\
tools.microsoft.msbuild:max_cpu_count=23
"""))
c.loads("tools.microsoft.msbuild:max_cpu_count=23")

settings = MockSettings({"build_type": "Release",
"compiler": "gcc",
"compiler.version": "7",
"os": "Linux",
"arch": "x86_64"})
conanfile = ConanFileMock()
conanfile.settings = settings
conanfile.conf = c.get_conanfile_conf(None)

msbuild = MSBuild(conanfile)
cmd = msbuild.command('project.sln')
assert 'msbuild "project.sln" /p:Configuration="Release" /p:Platform=x64 /m:23' == cmd

assert '/m:23' in cmd
c.loads("tools.microsoft.msbuild:max_cpu_count=0")
conanfile.conf = c.get_conanfile_conf(None)
cmd = msbuild.command('project.sln')
assert 'msbuild "project.sln" /p:Configuration="Release" /p:Platform=x64 /m' == cmd


def test_msbuild_toolset():
Expand Down Expand Up @@ -81,10 +79,10 @@ def test_msbuild_toolset_for_intel_cc(mode, expected_toolset):
conanfile = ConanFile()
conanfile.settings = "os", "compiler", "build_type", "arch"
conanfile.settings = Settings({"build_type": ["Release"],
"compiler": {"intel-cc": {"version": ["2021.3"], "mode": [mode]},
"msvc": {"version": ["193"], "cppstd": ["20"]}},
"os": ["Windows"],
"arch": ["x86_64"]})
"compiler": {"intel-cc": {"version": ["2021.3"], "mode": [mode]},
"msvc": {"version": ["193"], "cppstd": ["20"]}},
"os": ["Windows"],
"arch": ["x86_64"]})
conanfile.settings.build_type = "Release"
conanfile.settings.compiler = "intel-cc"
conanfile.settings.compiler.version = "2021.3"
Expand Down