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

Feature/package settings pattern #5523

Merged
merged 7 commits into from Jul 29, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,3 +1,4 @@
import fnmatch
import imp
import inspect
import os
@@ -95,11 +96,18 @@ def _initialize_conanfile(conanfile, processed_profile):
# Prepare the settings for the loaded conanfile
# Mixing the global settings with the specified for that name if exist
tmp_settings = processed_profile.processed_settings.copy()
if (processed_profile.package_settings_values and
conanfile.name in processed_profile.package_settings_values):
# Update the values, keeping old ones (confusing assign)
values_tuple = processed_profile.package_settings_values[conanfile.name]
tmp_settings.values = Values.from_list(values_tuple)
package_settings_values = processed_profile.package_settings_values
if package_settings_values:
pkg_settings = package_settings_values.get(conanfile.name)
if pkg_settings is None:
ref = "%s/%s@%s/%s" % (conanfile.name, conanfile.version,
conanfile._conan_user, conanfile._conan_channel)
for pattern, settings in package_settings_values.items():
if fnmatch.fnmatchcase(ref, pattern):
pkg_settings = settings
break
if pkg_settings:
tmp_settings.values = Values.from_list(pkg_settings)
This conversation was marked as resolved by lasote

This comment has been minimized.

Copy link
@lasote

lasote Jul 25, 2019

Contributor

Should't this code belong to the Profile class? processed_profile.get_settings_for(reference)


conanfile.initialize(tmp_settings, processed_profile.env_values)

@@ -263,6 +263,46 @@ def install_profile_settings_test(self):
self.assertNotIn("compiler.libcxx=libstdc++11", info)
self.assertIn("compiler.libcxx=libstdc++", info)

def install_profile_package_settings_test(self):
files = cpp_hello_conan_files("Hello0", "0.1", build=False)
self.client.save(files)

# Create a profile and use it
profile_settings = OrderedDict([("os", "Windows"),
("compiler", "Visual Studio"),
("compiler.version", "12"),
("compiler.runtime", "MD"),
("arch", "x86")])

# Use package settings in profile
tmp_settings = OrderedDict()
tmp_settings["compiler"] = "gcc"
tmp_settings["compiler.libcxx"] = "libstdc++11"
tmp_settings["compiler.version"] = "4.8"
package_settings = {"*@lasote/*": tmp_settings}
_create_profile(self.client.cache.profiles_path,
"myprofile", settings=profile_settings,
package_settings=package_settings)
# Try to override some settings in install command
self.client.run("install . lasote/testing -pr myprofile")
info = load(os.path.join(self.client.current_folder, "conaninfo.txt"))
self.assertIn("compiler=gcc", info)
self.assertIn("compiler.libcxx=libstdc++11", info)
self.assertIn("compiler.version=4.8", info)

package_settings = {"*@other/*": tmp_settings}
_create_profile(self.client.cache.profiles_path,
"myprofile", settings=profile_settings,
package_settings=package_settings)
# Try to override some settings in install command
self.client.run("install . lasote/testing -pr myprofile")
info = load(os.path.join(self.client.current_folder, "conaninfo.txt"))
self.assertIn("compiler=Visual Studio", info)
self.assertIn("compiler.runtime=MD", info)
self.assertIn("compiler.version=12", info)
self.assertNotIn("gcc", info)
self.assertNotIn("libcxx", info)

def install_profile_options_test(self):
files = cpp_hello_conan_files("Hello0", "0.1", build=False)

@@ -140,5 +140,13 @@ def test_pattern_matching(self):
reference = ConanFileReference.loads("SomeTool/1.2@user/channel")
self.assertTrue(build_mode.forced(self.conanfile, reference))

build_mode = BuildMode(["Tool/*"], self.output)
reference = ConanFileReference.loads("Tool/0.1@lasote/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("Tool/1.1@user/testing")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("PythonTool/0.1@lasote/stable")
self.assertFalse(build_mode.forced(self.conanfile, reference))

build_mode.report_matches()
self.assertEqual("", self.output)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.