From 2d26e0f156b6917ff4bff81a0b6e97fcaa6f9383 Mon Sep 17 00:00:00 2001 From: memsharded Date: Tue, 24 Aug 2021 00:07:02 +0200 Subject: [PATCH 1/2] conf to default the usage of host and build profile --- conans/client/conan_api.py | 19 ++++++------- conans/client/profile_loader.py | 27 ++++++++++++++++--- .../configuration/default_profile_test.py | 17 ++++++++++++ 3 files changed, 50 insertions(+), 13 deletions(-) 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..c55c1291e36 100644 --- a/conans/client/profile_loader.py +++ b/conans/client/profile_loader.py @@ -242,13 +242,30 @@ 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 if not build_profile else None + if profiles is None: - result = default_profile + def _get_default_profile_new_conf(default_profile_conf_name): + default_profile_conf = cache.new_config[default_profile_conf_name] + if default_profile_conf is not None: + if os.path.isabs(default_profile_conf): + default_profile_path = default_profile_conf + else: + default_profile_path = os.path.join(cache.profiles_path, default_profile_conf) + prof, _ = read_profile(default_profile_path, os.getcwd(), cache.profiles_path) + return prof + + if build_profile: + result = _get_default_profile_new_conf("core:default_build_profile") + else: + result = _get_default_profile_new_conf("core:default_profile") + if result is None: + result = default_profile else: result = Profile() for p in profiles: @@ -260,7 +277,9 @@ def profile_from_args(profiles, settings, options, env, conf, cwd, cache): if result: result.compose_profile(args_profile) else: - result = args_profile + # avoid creating a build profile when nothing is defined + if not build_profile or settings or options or env or conf: + 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 + From a2252e2dbfef4418f209dc3e060a3f8a22eb29a7 Mon Sep 17 00:00:00 2001 From: memsharded Date: Tue, 24 Aug 2021 01:13:32 +0200 Subject: [PATCH 2/2] try to fix tests --- conans/client/profile_loader.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/conans/client/profile_loader.py b/conans/client/profile_loader.py index c55c1291e36..1ff366141d8 100644 --- a/conans/client/profile_loader.py +++ b/conans/client/profile_loader.py @@ -247,25 +247,20 @@ def profile_from_args(profiles, settings, options, env, conf, cwd, cache, build_ file and the args command-line arguments """ # Ensures a default profile creating - default_profile = cache.default_profile if not build_profile else None + default_profile = cache.default_profile + create_profile = profiles or settings or options or env or conf or not build_profile if profiles is None: - def _get_default_profile_new_conf(default_profile_conf_name): - default_profile_conf = cache.new_config[default_profile_conf_name] - if default_profile_conf is not None: - if os.path.isabs(default_profile_conf): - default_profile_path = default_profile_conf - else: - default_profile_path = os.path.join(cache.profiles_path, default_profile_conf) - prof, _ = read_profile(default_profile_path, os.getcwd(), cache.profiles_path) - return prof - - if build_profile: - result = _get_default_profile_new_conf("core:default_build_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 = _get_default_profile_new_conf("core:default_profile") - if result is None: - result = default_profile + result = None else: result = Profile() for p in profiles: @@ -277,8 +272,7 @@ def _get_default_profile_new_conf(default_profile_conf_name): if result: result.compose_profile(args_profile) else: - # avoid creating a build profile when nothing is defined - if not build_profile or settings or options or env or conf: + if create_profile: result = args_profile return result