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

conf to default the usage of host and build profile #9468

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions conans/client/conan_api.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 17 additions & 4 deletions conans/client/profile_loader.py
Expand Up @@ -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:
Expand All @@ -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


Expand Down
17 changes: 17 additions & 0 deletions conans/test/integration/configuration/default_profile_test.py
@@ -1,4 +1,5 @@
import os
import textwrap
import unittest

from conans.client import tools
Expand Down Expand Up @@ -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
czoido marked this conversation as resolved.
Show resolved Hide resolved
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