Skip to content

Commit

Permalink
Show profile name when detect a new one (#4818) (#4824)
Browse files Browse the repository at this point in the history
* #4818 Show profile name when detect a new one

- Detect warning message will show the correct profile name instead of
  print only "default".

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* #4818 Fix tests for detect profile

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* #4818 Retify profile path

- When the profile name is a file path, it should exclude
  the dir path and show only the profile name

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* #4818 Dynamic profile path

- Print profile name and profile path based on its path;

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* #4818 Use profile file path

- When looking for default settings, use the profile
  file path, instead of creating a path by its name

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* #4818 Fix default profile path

- Cache should consume the default profile path.

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* #4818 Fix profile path on Windows

- It doesn't matter which platform is running, detect_default_settings
  does not parse the path.

Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries authored and memsharded committed Mar 26, 2019
1 parent 0f1bd49 commit ae951f6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
2 changes: 1 addition & 1 deletion conans/client/cache/cache.py
Expand Up @@ -187,7 +187,7 @@ def default_profile(self):
"default profile (%s)" % self.default_profile_path,
Color.BRIGHT_YELLOW)

default_settings = detect_defaults_settings(self._output)
default_settings = detect_defaults_settings(self._output, profile_path=self.default_profile_path)
self._output.writeln("Default settings", Color.BRIGHT_YELLOW)
self._output.writeln("\n".join(["\t%s=%s" % (k, v) for (k, v) in default_settings]),
Color.BRIGHT_YELLOW)
Expand Down
2 changes: 1 addition & 1 deletion conans/client/cmd/profile.py
Expand Up @@ -43,7 +43,7 @@ def cmd_profile_create(profile_name, cache_profiles_path, output, detect=False):

profile = Profile()
if detect:
settings = detect_defaults_settings(output)
settings = detect_defaults_settings(output, profile_path)
for name, value in settings:
profile.settings[name] = value

Expand Down
17 changes: 10 additions & 7 deletions conans/client/conf/detect.py
Expand Up @@ -125,7 +125,7 @@ def _get_default_compiler(output):
return gcc or clang


def _detect_compiler_version(result, output):
def _detect_compiler_version(result, output, profile_path):
try:
compiler, version = _get_default_compiler(output)
except:
Expand All @@ -140,18 +140,18 @@ def _detect_compiler_version(result, output):
elif compiler == "gcc":
result.append(("compiler.libcxx", "libstdc++"))
if Version(version) >= Version("5.1"):

profile_name = os.path.basename(profile_path)
msg = """
Conan detected a GCC version > 5 but has adjusted the 'compiler.libcxx' setting to
'libstdc++' for backwards compatibility.
Your compiler is likely using the new CXX11 ABI by default (libstdc++11).
If you want Conan to use the new ABI, edit the default profile at:
If you want Conan to use the new ABI, edit the {profile} profile at:
~/.conan/profiles/default
{profile_path}
adjusting 'compiler.libcxx=libstdc++11'
"""
""".format(profile=profile_name, profile_path=profile_path)
output.writeln("\n************************* WARNING: GCC OLD ABI COMPATIBILITY "
"***********************\n %s\n************************************"
"************************************************\n\n\n" % msg,
Expand Down Expand Up @@ -193,12 +193,15 @@ def _detect_os_arch(result, output):
result.append(("arch_build", arch))


def detect_defaults_settings(output):
def detect_defaults_settings(output, profile_path):
""" try to deduce current machine values without any constraints at all
:param output: Conan Output instance
:param profile_path: Conan profile file path
:return: A list with default settings
"""
result = []
_detect_os_arch(result, output)
_detect_compiler_version(result, output)
_detect_compiler_version(result, output, profile_path)
result.append(("build_type", "Release"))

return result
9 changes: 9 additions & 0 deletions conans/test/functional/command/profile_test.py
Expand Up @@ -12,6 +12,11 @@ class ProfileTest(unittest.TestCase):
def reuse_output_test(self):
client = TestClient()
client.run("profile new myprofile --detect")

if "WARNING: GCC OLD ABI COMPATIBILITY" in client.out:
self.assertIn("edit the myprofile profile at", client.out)
self.assertIn("profiles/myprofile", client.out)

client.run("profile update options.Pkg:myoption=123 myprofile")
client.run("profile update env.Pkg2:myenv=123 myprofile")
client.run("profile show myprofile")
Expand Down Expand Up @@ -69,6 +74,10 @@ def show_test(self):
def profile_update_and_get_test(self):
client = TestClient()
client.run("profile new ./MyProfile --detect")
if "WARNING: GCC OLD ABI COMPATIBILITY" in client.out:
self.assertIn("edit the MyProfile profile at", client.out)
self.assertIn(os.path.join(client.current_folder, "MyProfile"), client.out)

pr_path = os.path.join(client.current_folder, "MyProfile")

client.run("profile update settings.os=FakeOS ./MyProfile")
Expand Down
2 changes: 1 addition & 1 deletion conans/test/integration/conf_default_settings_test.py
Expand Up @@ -53,7 +53,7 @@ def env_setting_override_test(self):
out = MockOut()
cache = ClientCache(tmp_dir, None, out)

base_settings = OrderedDict(detect_defaults_settings(out))
base_settings = OrderedDict(detect_defaults_settings(out, profile_path="~/.conan/profiles/default"))

with tools.environment_append({"CONAN_ENV_COMPILER_VERSION": "4.6"}):
expected = copy.copy(base_settings)
Expand Down
40 changes: 37 additions & 3 deletions conans/test/unittests/util/detect_test.py
@@ -1,3 +1,4 @@
import os
import platform
import subprocess
import unittest
Expand All @@ -6,6 +7,7 @@

from conans.client import tools
from conans.client.conf.detect import detect_defaults_settings
from conans.paths import DEFAULT_PROFILE_NAME
from conans.test.utils.tools import TestBufferConanOutput


Expand All @@ -18,7 +20,7 @@ def detect_default_compilers_test(self):
"Windows": "Visual Studio"
}
output = TestBufferConanOutput()
result = detect_defaults_settings(output)
result = detect_defaults_settings(output, profile_path=DEFAULT_PROFILE_NAME)
# result is a list of tuples (name, value) so converting it to dict
result = dict(result)
platform_compiler = platform_default_compilers.get(platform.system(), None)
Expand Down Expand Up @@ -46,7 +48,7 @@ def detect_default_in_mac_os_using_gcc_as_default_test(self):

output = TestBufferConanOutput()
with tools.environment_append({"CC": "gcc"}):
result = detect_defaults_settings(output)
result = detect_defaults_settings(output, profile_path=DEFAULT_PROFILE_NAME)
# result is a list of tuples (name, value) so converting it to dict
result = dict(result)
# No compiler should be detected
Expand All @@ -56,7 +58,39 @@ def detect_default_in_mac_os_using_gcc_as_default_test(self):

@mock.patch("platform.machine", return_value="")
def test_detect_empty_arch(self, _):
result = detect_defaults_settings(output=TestBufferConanOutput())
result = detect_defaults_settings(output=TestBufferConanOutput(), profile_path=DEFAULT_PROFILE_NAME)
result = dict(result)
self.assertTrue("arch" not in result)
self.assertTrue("arch_build" not in result)

@mock.patch("conans.client.conf.detect._gcc_compiler", return_value=("gcc", "8"))
def detect_custom_profile_test(self, _):
output = TestBufferConanOutput()
with tools.environment_append({"CC": "gcc"}):
detect_defaults_settings(output, profile_path="~/.conan/profiles/mycustomprofile")
self.assertIn("edit the mycustomprofile profile at", output)
self.assertIn("~/.conan/profiles/mycustomprofile", output)

@mock.patch("conans.client.conf.detect._gcc_compiler", return_value=("gcc", "8"))
def detect_default_profile_test(self, _):
output = TestBufferConanOutput()
with tools.environment_append({"CC": "gcc"}):
detect_defaults_settings(output, profile_path="~/.conan/profiles/default")
self.assertIn("edit the default profile at", output)
self.assertIn("~/.conan/profiles/default", output)

@mock.patch("conans.client.conf.detect._gcc_compiler", return_value=("gcc", "8"))
def detect_file_profile_test(self, _):
output = TestBufferConanOutput()
with tools.environment_append({"CC": "gcc"}):
detect_defaults_settings(output, profile_path="./MyProfile")
self.assertIn("edit the MyProfile profile at", output)
self.assertIn("./MyProfile", output)

@mock.patch("conans.client.conf.detect._gcc_compiler", return_value=("gcc", "8"))
def detect_abs_file_profile_test(self, _):
output = TestBufferConanOutput()
with tools.environment_append({"CC": "gcc"}):
detect_defaults_settings(output, profile_path="/foo/bar/quz/custom-profile")
self.assertIn("edit the custom-profile profile at", output)
self.assertIn("/foo/bar/quz/custom-profile", output)

0 comments on commit ae951f6

Please sign in to comment.