diff options
author | Daniel Pirch <dpirch@gmail.com> | 2018-08-09 19:27:45 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-08-17 00:33:38 +0300 |
commit | 6ecd31af19dc537983311796929a9dd690632999 (patch) | |
tree | bef19217113e7a5f9e17bddddb047aedddad2694 | |
parent | b400cbe058df10bc37e628305c72c574177062e2 (diff) | |
download | meson-6ecd31af19dc537983311796929a9dd690632999.tar.gz |
wraptool: fix manual selection of wrap file to promote
Fixed manually promoting wrap files with a full path, e.g.
`meson wrap promote subprojects/s1/subprojects/projname.wrap`,
which resulted in an error before (new test added:
`./run_unittests.py AllPlatformTests.test_subproject_promotion_wrap`).
Additionally, running promote with an invalid subproject path now fails
properly. Before, it just silently did nothing (added to test:
`./run_unittests.py AllPlatformTests.test_subproject_promotion`).
7 files changed, 45 insertions, 12 deletions
diff --git a/mesonbuild/wrap/wraptool.py b/mesonbuild/wrap/wraptool.py index b88f12970..570e6915d 100644 --- a/mesonbuild/wrap/wraptool.py +++ b/mesonbuild/wrap/wraptool.py @@ -168,23 +168,26 @@ def do_promotion(from_path, spdir_name): def promote(options): argument = options.project_path - path_segment, subproject_name = os.path.split(argument) spdir_name = 'subprojects' sprojs = mesonlib.detect_subprojects(spdir_name) - if subproject_name not in sprojs: - sys.exit('Subproject %s not found in directory tree.' % subproject_name) - matches = sprojs[subproject_name] - if len(matches) == 1: - do_promotion(matches[0], spdir_name) - return - if path_segment == '': - print('There are many versions of %s in tree. Please specify which one to promote:\n' % subproject_name) + + # check if the argument is a full path to a subproject directory or wrap file + system_native_path_argument = argument.replace('/', os.sep) + for _, matches in sprojs.items(): + if system_native_path_argument in matches: + do_promotion(system_native_path_argument, spdir_name) + return + + # otherwise the argument is just a subproject basename which must be unambiguous + if argument not in sprojs: + sys.exit('Subproject %s not found in directory tree.' % argument) + matches = sprojs[argument] + if len(matches) > 1: + print('There is more than one version of %s in tree. Please specify which one to promote:\n' % argument) for s in matches: print(s) sys.exit(1) - system_native_path_argument = argument.replace('/', os.sep) - if system_native_path_argument in matches: - do_promotion(argument, spdir_name) + do_promotion(matches[0], spdir_name) def status(options): print('Subproject status') diff --git a/run_unittests.py b/run_unittests.py index d768028ae..ab5d4b774 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2094,6 +2094,9 @@ int main(int argc, char **argv) { self.assertNotEqual(subprocess.call(self.wrap_command + ['promote', 'scommon'], cwd=workdir, stdout=subprocess.DEVNULL), 0) + self.assertNotEqual(subprocess.call(self.wrap_command + ['promote', 'invalid/path/to/scommon'], + cwd=workdir, + stderr=subprocess.DEVNULL), 0) self.assertFalse(os.path.isdir(scommondir)) subprocess.check_call(self.wrap_command + ['promote', 'subprojects/s2/subprojects/scommon'], cwd=workdir) self.assertTrue(os.path.isdir(scommondir)) @@ -2104,6 +2107,20 @@ int main(int argc, char **argv) { self.init(workdir) self.build() + def test_subproject_promotion_wrap(self): + testdir = os.path.join(self.unit_test_dir, '42 promote wrap') + workdir = os.path.join(self.builddir, 'work') + shutil.copytree(testdir, workdir) + spdir = os.path.join(workdir, 'subprojects') + + ambiguous_wrap = os.path.join(spdir, 'ambiguous.wrap') + self.assertNotEqual(subprocess.call(self.wrap_command + ['promote', 'ambiguous'], + cwd=workdir, + stdout=subprocess.DEVNULL), 0) + self.assertFalse(os.path.isfile(ambiguous_wrap)) + subprocess.check_call(self.wrap_command + ['promote', 'subprojects/s2/subprojects/ambiguous.wrap'], cwd=workdir) + self.assertTrue(os.path.isfile(ambiguous_wrap)) + def test_warning_location(self): tdir = os.path.join(self.unit_test_dir, '22 warning location') out = self.init(tdir) diff --git a/test cases/unit/42 promote wrap/meson.build b/test cases/unit/42 promote wrap/meson.build new file mode 100644 index 000000000..066cf36cf --- /dev/null +++ b/test cases/unit/42 promote wrap/meson.build @@ -0,0 +1,5 @@ +project('promotion test', 'c') + +subproject('s1') +subproject('s2') + diff --git a/test cases/unit/42 promote wrap/subprojects/s1/meson.build b/test cases/unit/42 promote wrap/subprojects/s1/meson.build new file mode 100644 index 000000000..3d1f5bc35 --- /dev/null +++ b/test cases/unit/42 promote wrap/subprojects/s1/meson.build @@ -0,0 +1,2 @@ +project('s1', 'c') + diff --git a/test cases/unit/42 promote wrap/subprojects/s1/subprojects/ambiguous/meson.build b/test cases/unit/42 promote wrap/subprojects/s1/subprojects/ambiguous/meson.build new file mode 100644 index 000000000..296adff4c --- /dev/null +++ b/test cases/unit/42 promote wrap/subprojects/s1/subprojects/ambiguous/meson.build @@ -0,0 +1,2 @@ +project('ambiguous', 'c') + diff --git a/test cases/unit/42 promote wrap/subprojects/s2/meson.build b/test cases/unit/42 promote wrap/subprojects/s2/meson.build new file mode 100644 index 000000000..b5db63429 --- /dev/null +++ b/test cases/unit/42 promote wrap/subprojects/s2/meson.build @@ -0,0 +1,2 @@ +project('s2', 'c') + diff --git a/test cases/unit/42 promote wrap/subprojects/s2/subprojects/ambiguous.wrap b/test cases/unit/42 promote wrap/subprojects/s2/subprojects/ambiguous.wrap new file mode 100644 index 000000000..09ba4e87f --- /dev/null +++ b/test cases/unit/42 promote wrap/subprojects/s2/subprojects/ambiguous.wrap @@ -0,0 +1,2 @@ +The contents of this wrap file are never evaluated so they +can be anything. |