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

#4696: Build-Mode pattern now covers the whole reference #4787

Merged
merged 8 commits into from Mar 25, 2019
@@ -1665,7 +1665,7 @@ def _add_common_install_arguments(parser, build_help):
when missing binary package.
--build=[pattern] Build always these packages from source, but never build the others.
Allows multiple --build parameters. 'pattern' is a fnmatch file pattern
of a package name.
of a package reference.
Default behavior: If you don't specify anything, it will be similar to '--build=never', but
package recipes can override it with their 'build_policy' attribute in the conanfile.py.
@@ -53,7 +53,9 @@ def forced(self, conan_file, ref):

# Patterns to match, if package matches pattern, build is forced
for pattern in self.patterns:
if fnmatch.fnmatch(ref.name, pattern) or repr(ref) == pattern:
is_matching_name = fnmatch.fnmatch(ref.name, pattern)
is_matching_ref = fnmatch.fnmatch(repr(ref), pattern)
if is_matching_name or is_matching_ref:
try:
self._unused_patterns.remove(pattern)
except ValueError:
@@ -72,3 +72,47 @@ def test_allowed(self):

build_mode = BuildMode([], self.output)
self.assertFalse(build_mode.allowed(self.conanfile))

def test_pattern_matching(self):
build_mode = BuildMode(["Boost*"], self.output)
reference = ConanFileReference.loads("Boost/1.69.0@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("Boost_Addons/1.0.0@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("MyBoost/1.0@user/stable")
self.assertFalse(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("foo/Boost@user/stable")
self.assertFalse(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("foo/1.0@Boost/stable")
self.assertFalse(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("foo/1.0@user/Boost")
self.assertFalse(build_mode.forced(self.conanfile, reference))

build_mode = BuildMode(["foo/*@user/stable"], self.output)
reference = ConanFileReference.loads("foo/1.0.0@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("foo/1.0@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("foo/1.0.0-abcdefg@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))

build_mode = BuildMode(["*@user/stable"], self.output)
reference = ConanFileReference.loads("foo/1.0.0@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("bar/1.0@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("foo/1.0.0-abcdefg@user/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("foo/1.0.0@NewUser/stable")
self.assertFalse(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("PythonTool/0.1@lasote/stable")
self.assertTrue(build_mode.forced(self.conanfile, reference))
reference = ConanFileReference.loads("SomeTool/1.2@user/channel")
self.assertTrue(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.