bug 1419055 - Fix FasterMake backend handling of FINAL_TARGET_FILES with wildcards in filename. r?build draft
authorTed Mielczarek <ted@mielczarek.org>
Mon, 20 Nov 2017 11:35:39 -0500
changeset 700623 431625961055ad3e9b6552764c5dacf099165e06
parent 700576 5c48b5edfc4ca945a2eaa5896454f3f4efa9052a
child 740948 ef0f2f141c4bd1dee7d42ceb6325492d1cceaf82
push id89915
push userbmo:ted@mielczarek.org
push dateMon, 20 Nov 2017 16:39:33 +0000
reviewersbuild
bugs1419055
milestone59.0a1
bug 1419055 - Fix FasterMake backend handling of FINAL_TARGET_FILES with wildcards in filename. r?build This patch fixes a bug in the FasterMake backend and adds a new test_fastermake.py file to add a test for the behavior. The FasterMake backend didn't handle wildcards in file names present in FINAL_TARGET_FILES properly. For an entry like: FINAL_TARGET_FILES.foo += ['*.xyz'] It would wind up trying to install the files to `dist/bin/foo/*.xyz/`, a path with a literal asterisk in it. The code seems to have been written assuming that wildcards would only be present in directory components of the path. This change fixes this specific case, although it's possible that it still doesn't handle all permutations of wildcards properly. MozReview-Commit-ID: rk2tSyDyIu
python/mozbuild/mozbuild/backend/fastermake.py
python/mozbuild/mozbuild/test/backend/data/final-target-files-wildcard/bar.xyz
python/mozbuild/mozbuild/test/backend/data/final-target-files-wildcard/foo.xyz
python/mozbuild/mozbuild/test/backend/data/final-target-files-wildcard/moz.build
python/mozbuild/mozbuild/test/backend/test_fastermake.py
python/mozbuild/mozbuild/test/python.ini
--- a/python/mozbuild/mozbuild/backend/fastermake.py
+++ b/python/mozbuild/mozbuild/backend/fastermake.py
@@ -70,21 +70,26 @@ class FasterMakeBackend(CommonBackend, P
                                              defines=defines)
                     elif '*' in f:
                         def _prefix(s):
                             for p in mozpath.split(s):
                                 if '*' not in p:
                                     yield p + '/'
                         prefix = ''.join(_prefix(f.full_path))
 
+                        if '*' in f.target_basename:
+                            target = path
+                        else:
+                            target = mozpath.join(path, f.target_basename)
+                        mozpath.join(path, f.target_basename)
                         self._install_manifests[obj.install_target] \
                             .add_pattern_link(
                                 prefix,
                                 f.full_path[len(prefix):],
-                                mozpath.join(path, f.target_basename))
+                                target)
                     else:
                         self._install_manifests[obj.install_target].add_link(
                             f.full_path,
                             mozpath.join(path, f.target_basename)
                         )
                     if isinstance(f, ObjDirPath):
                         dep_target = 'install-%s' % obj.install_target
                         self._dependencies[dep_target].append(
new file mode 100644
new file mode 100644
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/final-target-files-wildcard/moz.build
@@ -0,0 +1,5 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+FINAL_TARGET_FILES.foo += ['*.xyz']
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/test_fastermake.py
@@ -0,0 +1,46 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import unicode_literals
+
+import cPickle as pickle
+import json
+import os
+import unittest
+
+from mozpack.copier import FileRegistry
+from mozpack.manifests import InstallManifest
+from mozunit import main
+
+from mozbuild.backend.fastermake import FasterMakeBackend
+
+from mozbuild.test.backend.common import BackendTester
+
+import mozpack.path as mozpath
+
+
+class TestFasterMakeBackend(BackendTester):
+    def test_basic(self):
+        """Ensure the FasterMakeBackend works without error."""
+        env = self._consume('stub0', FasterMakeBackend)
+        self.assertTrue(os.path.exists(mozpath.join(env.topobjdir,
+            'backend.FasterMakeBackend')))
+        self.assertTrue(os.path.exists(mozpath.join(env.topobjdir,
+            'backend.FasterMakeBackend.in')))
+
+    def test_final_target_files_wildcard(self):
+        """Ensure that wildcards in FINAL_TARGET_FILES work properly."""
+        env = self._consume('final-target-files-wildcard', FasterMakeBackend)
+        m = InstallManifest(path=mozpath.join(env.topobjdir,
+            'faster', 'install_dist_bin'))
+        self.assertEqual(len(m), 1)
+        reg = FileRegistry()
+        m.populate_registry(reg)
+        expected = [('foo/bar.xyz', 'bar.xyz'), ('foo/foo.xyz', 'foo.xyz')]
+        actual = [(path, mozpath.relpath(f.path, env.topsrcdir)) for (path, f) in reg]
+        self.assertEqual(expected, actual)
+
+
+if __name__ == '__main__':
+    main()
--- a/python/mozbuild/mozbuild/test/python.ini
+++ b/python/mozbuild/mozbuild/test/python.ini
@@ -1,14 +1,15 @@
 [action/test_buildlist.py]
 [action/test_generate_browsersearch.py]
 [action/test_langpack_manifest.py]
 [action/test_package_fennec_apk.py]
 [backend/test_build.py]
 [backend/test_configenvironment.py]
+[backend/test_fastermake.py]
 [backend/test_partialconfigenvironment.py]
 [backend/test_recursivemake.py]
 [backend/test_test_manifest.py]
 [backend/test_visualstudio.py]
 [codecoverage/test_lcov_rewrite.py]
 [compilation/test_warnings.py]
 [configure/lint.py]
 [configure/test_checks_configure.py]