Skip to content

Commit

Permalink
Add global verbosity conf tools.build:verbosity (#13428)
Browse files Browse the repository at this point in the history
* Initial sketch for global verbosity conf for builds

* Fix c&p typo

* Empty verbosity for mid levels in xcode

* Better conf description

* Remove CMAKE_VERBOSE_MAKEFILE until further testing

* Update conan/tools/apple/xcodebuild.py

Co-authored-by: James <[email protected]>

* Proper conf name 🤦

* Center verbosity levels map

* Update conan/tools/cmake/cmake.py

Co-authored-by: James <[email protected]>

* Use proper conf name

* Typo

* minimal unittest for global conf xcode

* Remove tools.apple.xcodebuild:verbosity

* Remove tools.microsoft.msbuild:verbosity

* Rename tests to tools.build:verbosity

* Fix ON/OFF mapping for verbose

* Move to conan alreayd present log levels

* Add verbosity for cmake

* Improve CMake mapping

* Fix xcodebuild verbosity

* Add verbosity to cmake configure and install

* Add verbosity check for cmake

* Verbosity in presets

* Remove tools.build:verbosity support for CMake for now

* Remove empty changes!

* Normalize tools.build:verbosity description

---------

Co-authored-by: James <[email protected]>
  • Loading branch information
AbrilRBS and memsharded authored Mar 15, 2023
1 parent 0e923d3 commit 8c424de
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 52 deletions.
25 changes: 20 additions & 5 deletions conan/tools/apple/xcodebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@ def __init__(self, conanfile):

@property
def _verbosity(self):
verbosity = self._conanfile.conf.get("tools.apple.xcodebuild:verbosity", default="", check_type=str)
if verbosity == "quiet" or verbosity == "verbose":
return "-{}".format(verbosity)
elif verbosity:
raise ConanException("Value {} for 'tools.apple.xcodebuild:verbosity' is not valid".format(verbosity))
verbosity = self._conanfile.conf.get("tools.build:verbosity")
if verbosity:
if verbosity not in ("quiet", "error", "warning", "notice", "status", "verbose",
"normal", "debug", "v", "trace", "vv"):
raise ConanException(f"Value '{verbosity}' for 'tools.build:verbosity' is not valid")
else:
# quiet, nothing, verbose
verbosity = {"quiet": "quiet",
"error": "quiet",
"warning": "quiet",
"notice": "quiet",
"status": None,
"verbose": None,
"normal": None,
"debug": "verbose",
"v": "verbose",
"trace": "verbose",
"vv": "verbose"}.get(verbosity)
if verbosity is not None:
return "-{}".format(verbosity)
return ""

@property
Expand Down
24 changes: 20 additions & 4 deletions conan/tools/microsoft/msbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@


def msbuild_verbosity_cmd_line_arg(conanfile):
verbosity = conanfile.conf.get("tools.microsoft.msbuild:verbosity")
verbosity = conanfile.conf.get("tools.build:verbosity")
if verbosity:
if verbosity not in ("Quiet", "Minimal", "Normal", "Detailed", "Diagnostic"):
raise ConanException("Unknown msbuild verbosity: {}".format(verbosity))
return '/verbosity:{}'.format(verbosity)
if verbosity not in ("quiet", "error", "warning", "notice", "status", "verbose",
"normal", "debug", "v", "trace", "vv"):
raise ConanException(f"Unknown value '{verbosity}' for 'tools.build:verbosity'")
else:
# "Quiet", "Minimal", "Normal", "Detailed", "Diagnostic"
verbosity = {
"quiet": "Quiet",
"error": "Minimal",
"warning": "Minimal",
"notice": "Minimal",
"status": "Normal",
"verbose": "Normal",
"normal": "Normal",
"debug": "Detailed",
"v": "Detailed",
"trace": "Diagnostic",
"vv": "Diagnostic"
}.get(verbosity)
return '/verbosity:{}'.format(verbosity)


def msbuild_arch(arch):
Expand Down
6 changes: 3 additions & 3 deletions conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"tools.build:sysroot": "Pass the --sysroot=<tools.build:sysroot> flag if available. (None by default)",
"tools.build.cross_building:can_run": "Bool value that indicates whether is possible to run a non-native "
"app on the same architecture. It's used by 'can_run' tool",
"tools.build:verbosity": "Verbosity of MSBuild and XCodeBuild build systems. "
"Possible values are 'quiet', 'error', 'warning', 'notice', 'status', 'verbose', 'normal', 'debug', 'v', 'trace' and 'vv'",
"tools.cmake.cmaketoolchain:generator": "User defined CMake generator to use instead of default",
"tools.cmake.cmaketoolchain:find_package_prefer_config": "Argument for the CMAKE_FIND_PACKAGE_PREFER_CONFIG",
"tools.cmake.cmaketoolchain:toolchain_file": "Use other existing file rather than conan_toolchain.cmake one",
Expand All @@ -66,7 +68,6 @@
"tools.google.bazel:bazelrc_path": "Defines Bazel rc-path",
"tools.meson.mesontoolchain:backend": "Any Meson backend: ninja, vs, vs2010, vs2012, vs2013, vs2015, vs2017, vs2019, xcode",
"tools.meson.mesontoolchain:extra_machine_files": "List of paths for any additional native/cross file references to be appended to the existing Conan ones",
"tools.microsoft.msbuild:verbosity": "Verbosity level for MSBuild: 'Quiet', 'Minimal', 'Normal', 'Detailed', 'Diagnostic'",
"tools.microsoft.msbuild:vs_version": "Defines the IDE version when using the new msvc compiler",
"tools.microsoft.msbuild:max_cpu_count": "Argument for the /m when running msvc to build parallel projects",
"tools.microsoft.msbuild:installation_path": "VS install path, to avoid auto-detect via vswhere, like C:/Program Files (x86)/Microsoft Visual Studio/2019/Community. Use empty string to disable",
Expand All @@ -81,7 +82,6 @@
"tools.system.package_manager:mode": "Mode for package_manager tools: 'check' or 'install'",
"tools.system.package_manager:sudo": "Use 'sudo' when invoking the package manager tools in Linux (False by default)",
"tools.system.package_manager:sudo_askpass": "Use the '-A' argument if using sudo in Linux to invoke the system package manager (False by default)",
"tools.apple.xcodebuild:verbosity": "Verbosity level for xcodebuild: 'verbose' or 'quiet",
"tools.apple:sdk_path": "Path to the SDK to be used",
"tools.apple:enable_bitcode": "(boolean) Enable/Disable Bitcode Apple Clang flags",
"tools.apple:enable_arc": "(boolean) Enable/Disable ARC Apple Clang flags",
Expand Down Expand Up @@ -564,7 +564,7 @@ def rebase_conf_definition(self, other):
def update(self, key, value, profile=False, method="define"):
"""
Define/append/prepend/unset any Conf line
>> update("tools.microsoft.msbuild:verbosity", "Detailed")
>> update("tools.build:verbosity", "verbose")
"""
pattern, name = self._split_pattern_name(key)

Expand Down
34 changes: 17 additions & 17 deletions conans/test/integration/configuration/conf/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ def generate(self):
def test_basic_composition(client):
profile1 = textwrap.dedent("""\
[conf]
tools.microsoft.msbuild:verbosity=Quiet
tools.build:verbosity=quiet
tools.microsoft.msbuild:vs_version=Slow
tools.cmake.cmaketoolchain:generator=Extra
""")
profile2 = textwrap.dedent("""\
[conf]
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
tools.microsoft.msbuild:max_cpu_count=High
tools.meson.mesontoolchain:backend=Super
""")
client.save({"profile1": profile1,
"profile2": profile2})
client.run("install . -pr=profile1")
assert "tools.microsoft.msbuild:verbosity$Quiet" in client.out
assert "tools.build:verbosity$quiet" in client.out
assert "tools.microsoft.msbuild:vs_version$Slow" in client.out
assert "tools.cmake.cmaketoolchain:generator$Extra" in client.out

client.run("install . -pr=profile1 -pr=profile2")
assert "tools.microsoft.msbuild:verbosity$Minimal" in client.out
assert "tools.build:verbosity$notice" in client.out
assert "tools.microsoft.msbuild:vs_version$Slow" in client.out
assert "tools.microsoft.msbuild:max_cpu_count$High" in client.out
assert "tools.cmake.cmaketoolchain:generator$Extra" in client.out
assert "tools.meson.mesontoolchain:backend$Super" in client.out

client.run("install . -pr=profile2 -pr=profile1")
assert "tools.microsoft.msbuild:verbosity$Quiet" in client.out
assert "tools.build:verbosity$quiet" in client.out
assert "tools.microsoft.msbuild:vs_version$Slow" in client.out
assert "tools.microsoft.msbuild:max_cpu_count$High" in client.out
assert "tools.cmake.cmaketoolchain:generator$Extra" in client.out
Expand All @@ -64,22 +64,22 @@ def test_basic_composition(client):
def test_basic_inclusion(client):
profile1 = textwrap.dedent("""\
[conf]
tools.microsoft.msbuild:verbosity=Quiet
tools.build:verbosity=quiet
tools.microsoft.msbuild:vs_version=Slow
tools.cmake.cmaketoolchain:generator=Extra
""")
profile2 = textwrap.dedent("""\
include(profile1)
[conf]
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
tools.microsoft.msbuild:max_cpu_count=High
tools.meson.mesontoolchain:backend=Super
""")
client.save({"profile1": profile1,
"profile2": profile2})

client.run("install . -pr=profile2")
assert "tools.microsoft.msbuild:verbosity$Minimal" in client.out
assert "tools.build:verbosity$notice" in client.out
assert "tools.microsoft.msbuild:vs_version$Slow" in client.out
assert "tools.microsoft.msbuild:max_cpu_count$High" in client.out
assert "tools.cmake.cmaketoolchain:generator$Extra" in client.out
Expand All @@ -88,20 +88,20 @@ def test_basic_inclusion(client):

def test_composition_conan_conf(client):
conf = textwrap.dedent("""\
tools.microsoft.msbuild:verbosity=Quiet
tools.build:verbosity=quiet
tools.microsoft.msbuild:vs_version=Slow
tools.cmake.cmaketoolchain:generator=Extra
""")
save(client.cache.new_config_path, conf)
profile = textwrap.dedent("""\
[conf]
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
tools.microsoft.msbuild:max_cpu_count=High
tools.meson.mesontoolchain:backend=Super
""")
client.save({"profile": profile})
client.run("install . -pr=profile")
assert "tools.microsoft.msbuild:verbosity$Minimal" in client.out
assert "tools.build:verbosity$notice" in client.out
assert "tools.microsoft.msbuild:vs_version$Slow" in client.out
assert "tools.microsoft.msbuild:max_cpu_count$High" in client.out
assert "tools.cmake.cmaketoolchain:generator$Extra" in client.out
Expand All @@ -110,14 +110,14 @@ def test_composition_conan_conf(client):

def test_new_config_file(client):
conf = textwrap.dedent("""\
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
user.mycompany.myhelper:myconfig=myvalue
*:tools.cmake.cmaketoolchain:generator=X
cache:read_only=True
""")
save(client.cache.new_config_path, conf)
client.run("install .")
assert "tools.microsoft.msbuild:verbosity$Minimal" in client.out
assert "tools.build:verbosity$notice" in client.out
assert "user.mycompany.myhelper:myconfig$myvalue" in client.out
assert "tools.cmake.cmaketoolchain:generator$X" in client.out
assert "read_only" not in client.out
Expand All @@ -138,19 +138,19 @@ def test_new_config_file_required_version():

def test_composition_conan_conf_overwritten_by_cli_arg(client):
conf = textwrap.dedent("""\
tools.microsoft.msbuild:verbosity=Quiet
tools.build:verbosity=quiet
tools.microsoft.msbuild:max_cpu_count=Slow
""")
save(client.cache.new_config_path, conf)
profile = textwrap.dedent("""\
[conf]
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
tools.microsoft.msbuild:vs_version=High
""")
client.save({"profile": profile})
client.run("install . -pr=profile -c tools.microsoft.msbuild:verbosity=Detailed "
client.run("install . -pr=profile -c tools.build:verbosity=debug "
"-c tools.meson.mesontoolchain:backend=Super")
assert "tools.microsoft.msbuild:verbosity$Detailed" in client.out
assert "tools.build:verbosity$debug" in client.out
assert "tools.microsoft.msbuild:max_cpu_count$Slow" in client.out
assert "tools.microsoft.msbuild:vs_version$High" in client.out
assert "tools.meson.mesontoolchain:backend$Super" in client.out
Expand Down
12 changes: 6 additions & 6 deletions conans/test/integration/configuration/conf/test_conf_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_cmake_config(client):
compiler.runtime=dynamic
build_type=Release
[conf]
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
""")
client.save({"myprofile": profile})
client.run("create . --name=pkg --version=0.1 -pr=myprofile")
Expand All @@ -71,11 +71,11 @@ def test_cmake_config_error(client):
compiler.runtime=dynamic
build_type=Release
[conf]
tools.microsoft.msbuild:verbosity=non-existing
tools.build:verbosity=non-existing
""")
client.save({"myprofile": profile})
client.run("create . --name=pkg --version=0.1 -pr=myprofile", assert_error=True)
assert "Unknown msbuild verbosity: non-existing" in client.out
assert "Unknown value 'non-existing' for 'tools.build:verbosity'" in client.out


def test_cmake_config_package(client):
Expand All @@ -88,7 +88,7 @@ def test_cmake_config_package(client):
compiler.runtime=dynamic
build_type=Release
[conf]
dep*:tools.microsoft.msbuild:verbosity=Minimal
dep*:tools.build:verbosity=notice
""")
client.save({"myprofile": profile})
client.run("create . --name=pkg --version=0.1 -pr=myprofile")
Expand All @@ -107,7 +107,7 @@ def test_cmake_config_package_not_scoped(client):
compiler.runtime=dynamic
build_type=Release
[conf]
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
""")
client.save({"myprofile": profile})
client.run("create . --name=pkg --version=0.1 -pr=myprofile")
Expand Down Expand Up @@ -149,7 +149,7 @@ def build(self):
compiler.runtime=dynamic
build_type=Release
[conf]
tools.microsoft.msbuild:verbosity=Minimal
tools.build:verbosity=notice
""")
client.save({"myprofile": profile})
client.run("create . --name=pkg --version=0.1 -pr=myprofile")
Expand Down
19 changes: 9 additions & 10 deletions conans/test/unittests/client/tools/apple/test_xcodebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
from conans.test.utils.mocks import ConanFileMock, MockSettings


@pytest.mark.parametrize("mode", ["quiet", "verbose", "invalid"])
def test_verbosity(mode):
@pytest.mark.parametrize("mode", ["quiet", "error", "warning", "notice", "status", "verbose",
"normal", "debug", "v", "trace", "vv"])
def test_verbosity_global(mode):
conanfile = ConanFileMock()
conf = ConfDefinition()
conf.loads("tools.apple.xcodebuild:verbosity={}".format(mode))
conf.loads(f"tools.build:verbosity={mode}")
conanfile.conf = conf
conanfile.settings = MockSettings({})
xcodebuild = XcodeBuild(conanfile)
if mode != "invalid":
xcodebuild.build("app.xcodeproj")
assert "-{}".format(mode) in conanfile.command

xcodebuild.build("app.xcodeproj")
if mode not in ("status", "verbose", "normal"):
assert "-quiet" in conanfile.command or "-verbose" in conanfile.command
else:
with pytest.raises(ConanException) as excinfo:
xcodebuild.build("app.xcodeproj")
assert "Value {} for 'tools.apple.xcodebuild:verbosity' is not valid".format(mode) == str(
excinfo.value)
assert "-quiet" not in conanfile.command and "-verbose" not in conanfile.command


def test_sdk_path():
Expand Down
10 changes: 5 additions & 5 deletions conans/test/unittests/model/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@pytest.fixture()
def conf_definition():
text = textwrap.dedent("""\
tools.microsoft.msbuild:verbosity=minimal
tools.build:verbosity=notice
user.company.toolchain:flags=someflags
""")
c = ConfDefinition()
Expand All @@ -23,7 +23,7 @@ def test_conf_definition(conf_definition):
# Round trip
assert c.dumps() == text
# access
assert c.get("tools.microsoft.msbuild:verbosity") == "minimal"
assert c.get("tools.build:verbosity") == "notice"
assert c.get("user.company.toolchain:flags") == "someflags"
assert c.get("user.microsoft.msbuild:nonexist") is None
assert c.get("user:nonexist") is None
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_conf_update(conf_definition):
c2.loads(text)
c.update_conf_definition(c2)
result = textwrap.dedent("""\
tools.microsoft.msbuild:verbosity=minimal
tools.build:verbosity=notice
user.company.toolchain:flags=newvalue
user.something:key=value
""")
Expand All @@ -65,13 +65,13 @@ def test_conf_rebase(conf_definition):
c, _ = conf_definition
text = textwrap.dedent("""\
user.company.toolchain:flags=newvalue
tools.microsoft.msbuild:verbosity=Diagnostic""")
tools.build:verbosity=trace""")
c2 = ConfDefinition()
c2.loads(text)
c.rebase_conf_definition(c2)
# The c profile will have precedence, and "
result = textwrap.dedent("""\
tools.microsoft.msbuild:verbosity=minimal
tools.build:verbosity=notice
user.company.toolchain:flags=someflags
""")
assert c.dumps() == result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import pytest
from mock import mock
from mock.mock import Mock

from conan.tools.cmake import CMake
from conan.tools.cmake.presets import write_cmake_presets
from conan.tools.build import save_toolchain_args
from conans.model.conan_file import ConanFile
from conans.model.conf import Conf
from conans.model.settings import Settings
from conans.test.utils.test_files import temp_folder
from conans.util.files import load


@pytest.fixture(scope="module")
Expand Down

0 comments on commit 8c424de

Please sign in to comment.