diff --git a/conans/client/conan_api.py b/conans/client/conan_api.py index 6ffa2190141..53e04dfe2a5 100644 --- a/conans/client/conan_api.py +++ b/conans/client/conan_api.py @@ -1437,6 +1437,7 @@ def lock_create(self, path, lockfile_out, base=None, lockfile=None): # profile_host is mandatory profile_host = profile_host or ProfileData(None, None, None, None, None) + profile_build = profile_build or ProfileData(None, None, None, None, None) cwd = os.getcwd() if path and reference: @@ -1467,11 +1468,11 @@ def lock_create(self, path, lockfile_out, profile_host.options, profile_host.env, profile_host.conf, cwd, self.app.cache) - if profile_build and not pbuild: + if not pbuild: # Only work on the profile_build if something is provided pbuild = profile_from_args(profile_build.profiles, profile_build.settings, profile_build.options, profile_build.env, profile_build.conf, - cwd, self.app.cache) + cwd, self.app.cache, build_profile=True) root_ref = ConanFileReference(name, version, user, channel, validate=False) phost.process_settings(self.app.cache) @@ -1557,14 +1558,14 @@ def get_graph_info(profile_host, profile_build, cwd, install_folder, cache, outp phost = profile_from_args(profile_host.profiles, profile_host.settings, profile_host.options, profile_host.env, profile_host.conf, cwd, cache) phost.process_settings(cache) - if profile_build: - # Only work on the profile_build if something is provided - pbuild = profile_from_args(profile_build.profiles, profile_build.settings, - profile_build.options, profile_build.env, profile_build.conf, - cwd, cache) + + profile_build = profile_build or ProfileData(None, None, None, None, None) + # Only work on the profile_build if something is provided + pbuild = profile_from_args(profile_build.profiles, profile_build.settings, + profile_build.options, profile_build.env, profile_build.conf, + cwd, cache, build_profile=True) + if pbuild is not None: pbuild.process_settings(cache) - else: - pbuild = None root_ref = ConanFileReference(name, version, user, channel, validate=False) graph_info = GraphInfo(profile_host=phost, profile_build=pbuild, root_ref=root_ref) diff --git a/conans/client/profile_loader.py b/conans/client/profile_loader.py index 5683766361b..1ff366141d8 100644 --- a/conans/client/profile_loader.py +++ b/conans/client/profile_loader.py @@ -242,13 +242,25 @@ def get_package_name_value(item): base_profile.buildenv.update_profile_env(buildenv) -def profile_from_args(profiles, settings, options, env, conf, cwd, cache): +def profile_from_args(profiles, settings, options, env, conf, cwd, cache, build_profile=False): """ Return a Profile object, as the result of merging a potentially existing Profile file and the args command-line arguments """ - default_profile = cache.default_profile # Ensures a default profile creating + # Ensures a default profile creating + default_profile = cache.default_profile + create_profile = profiles or settings or options or env or conf or not build_profile + if profiles is None: - result = default_profile + default_name = "core:default_build_profile" if build_profile else "core:default_profile" + default_conf = cache.new_config[default_name] + if default_conf is not None: + default_profile_path = default_conf if os.path.isabs(default_conf) \ + else os.path.join(cache.profiles_path, default_conf) + result, _ = read_profile(default_profile_path, os.getcwd(), cache.profiles_path) + elif create_profile: + result = default_profile + else: + result = None else: result = Profile() for p in profiles: @@ -260,7 +272,8 @@ def profile_from_args(profiles, settings, options, env, conf, cwd, cache): if result: result.compose_profile(args_profile) else: - result = args_profile + if create_profile: + result = args_profile return result diff --git a/conans/test/integration/configuration/default_profile_test.py b/conans/test/integration/configuration/default_profile_test.py index 9809ffbf60a..ae575e9fdda 100644 --- a/conans/test/integration/configuration/default_profile_test.py +++ b/conans/test/integration/configuration/default_profile_test.py @@ -1,4 +1,5 @@ import os +import textwrap import unittest from conans.client import tools @@ -180,3 +181,19 @@ def build(self): "an existing profile file.", client.out) +def test_conf_default_two_profiles(): + client = TestClient() + save(os.path.join(client.cache.profiles_path, "mydefault"), "[settings]\nos=FreeBSD") + save(os.path.join(client.cache.profiles_path, "mydefault_build"), "[settings]\nos=Android") + global_conf = textwrap.dedent(""" + core:default_profile=mydefault + core:default_build_profile=mydefault_build + """) + save(client.cache.new_config_path, global_conf) + client.save({"conanfile.txt": ""}) + client.run("install .") + assert "Configuration (profile_host):" in client.out + assert "os=FreeBSD" in client.out + assert "Configuration (profile_build):" in client.out + assert "os=Android" in client.out +