Bug 972168 - Add root relative destination paths to mochitest support files. r=ted
authorMartin Thomson [:mt] <martin.thomson@gmail.com>
Thu, 13 Feb 2014 10:15:11 -0800
changeset 170042 7b08710ab4e2c235e0a59bdc6cf3218f93182887
parent 170041 c75ed086763012872e51829a0cf112a112b887e2
child 170043 953fda48369a77edcf4555611c560637e991893b
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersted
bugs972168
milestone30.0a1
Bug 972168 - Add root relative destination paths to mochitest support files. r=ted
build/docs/test_manifests.rst
python/mozbuild/mozbuild/frontend/emitter.py
python/mozbuild/mozbuild/test/frontend/data/test-manifest-absolute-support/absolute-support.ini
python/mozbuild/mozbuild/test/frontend/data/test-manifest-absolute-support/foo.txt
python/mozbuild/mozbuild/test/frontend/data/test-manifest-absolute-support/moz.build
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/build/docs/test_manifests.rst
+++ b/build/docs/test_manifests.rst
@@ -91,16 +91,22 @@ support-files
    Unlike other file lists, *support-files* supports a globbing mechanism
    to facilitate pulling in many files with minimal typing. This globbing
    mechanism is activated if an entry in this value contains a ``*``
    character. A single ``*`` will wildcard match all files in a directory.
    A double ``**`` will descend into child directories. For example,
    ``data/*`` will match ``data/foo`` but not ``data/subdir/bar`` where
    ``data/**`` will match ``data/foo`` and ``data/subdir/bar``.
 
+   Support files starting with ``/`` are placed in a root directory, rather
+   than a location determined by the manifest location. For mochitests,
+   this allows for the placement of files at the server root. The source
+   file is selected from the base name (e.g., ``foo`` for ``/path/foo``).
+   Files starting with ``/`` cannot be selected using globbing.
+
 generated-files
    List of files that are generated as part of the build and don't exist in
    the source tree.
 
    The build system assumes that each manifest file, test file, and file
    listed in **head**, **tail**, and **support-files** is static and
    provided by the source tree (and not automatically generated as part
    of the build). This variable tells the build system not to make this
@@ -176,17 +182,19 @@ Files referenced by manifests are automa
 directory into paths defined in
 :py:func:`mozbuild.frontend.emitter.TreeMetadataEmitter._process_test_manifest`.
 
 Relative paths resolving to parent directory (e.g.
 ``support-files = ../foo.txt`` have special behavior.
 
 For ``support-files``, the file will be installed to the default destination
 for that manifest. Only the file's base name is used to construct the final
-path: directories are irrelevant.
+path: directories are irrelevant.  Files starting with ``/`` are an exception,
+these are installed relative to the root of the destination; the base name is
+instead used to select the file..
 
 For all other entry types, the file installation is skipped.
 
 .. _reftest_manifests:
 
 Reftest Manifests
 =================
 
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -382,24 +382,24 @@ class TreeMetadataEmitter(LoggingMixin):
         #     the tests directory.
         # active indicates whether to filter out inactive tests from the
         #     manifest.
         #
         # We ideally don't filter out inactive tests. However, not every test
         # harness can yet deal with test filtering. Once all harnesses can do
         # this, this feature can be dropped.
         test_manifests = dict(
-            A11Y=('a11y', 'testing/mochitest/a11y', True),
-            BROWSER_CHROME=('browser-chrome', 'testing/mochitest/browser', True),
-            METRO_CHROME=('metro-chrome', 'testing/mochitest/metro', True),
-            MOCHITEST=('mochitest', 'testing/mochitest/tests', True),
-            MOCHITEST_CHROME=('chrome', 'testing/mochitest/chrome', True),
-            MOCHITEST_WEBAPPRT_CHROME=('webapprt-chrome', 'testing/mochitest/webapprtChrome', True),
-            WEBRTC_SIGNALLING_TEST=('steeplechase', 'steeplechase', True),
-            XPCSHELL_TESTS=('xpcshell', 'xpcshell', False),
+            A11Y=('a11y', 'testing/mochitest', 'a11y', True),
+            BROWSER_CHROME=('browser-chrome', 'testing/mochitest', 'browser', True),
+            METRO_CHROME=('metro-chrome', 'testing/mochitest', 'metro', True),
+            MOCHITEST=('mochitest', 'testing/mochitest', 'tests', True),
+            MOCHITEST_CHROME=('chrome', 'testing/mochitest', 'chrome', True),
+            MOCHITEST_WEBAPPRT_CHROME=('webapprt-chrome', 'testing/mochitest', 'webapprtChrome', True),
+            WEBRTC_SIGNALLING_TEST=('steeplechase', 'steeplechase', '.', True),
+            XPCSHELL_TESTS=('xpcshell', 'xpcshell', '.', False),
         )
 
         for prefix, info in test_manifests.items():
             for path in sandbox.get('%s_MANIFESTS' % prefix, []):
                 for obj in self._process_test_manifest(sandbox, info, path):
                     yield obj
 
         jar_manifests = sandbox.get('JAR_MANIFESTS', [])
@@ -437,23 +437,24 @@ class TreeMetadataEmitter(LoggingMixin):
         sub = cls(sandbox)
         sub.input_path = mozpath.join(sandbox['SRCDIR'], '%s.in' % path)
         sub.output_path = mozpath.join(sandbox['OBJDIR'], path)
         sub.relpath = path
 
         return sub
 
     def _process_test_manifest(self, sandbox, info, manifest_path):
-        flavor, install_prefix, filter_inactive = info
+        flavor, install_root, install_subdir, filter_inactive = info
 
         manifest_path = mozpath.normpath(manifest_path)
         path = mozpath.normpath(mozpath.join(sandbox['SRCDIR'], manifest_path))
         manifest_dir = mozpath.dirname(path)
         manifest_reldir = mozpath.dirname(mozpath.relpath(path,
             sandbox['TOPSRCDIR']))
+        install_prefix = mozpath.join(install_root, install_subdir)
 
         try:
             m = manifestparser.TestManifest(manifests=[path], strict=True)
             defaults = m.manifest_defaults[os.path.normpath(path)]
             if not m.tests and not 'support-files' in defaults:
                 raise SandboxValidationError('Empty test manifest: %s'
                     % path)
 
@@ -485,16 +486,23 @@ class TreeMetadataEmitter(LoggingMixin):
                         continue
                     seen.add(value)
                     for pattern in value.split():
                         # We only support globbing on support-files because
                         # the harness doesn't support * for head and tail.
                         if '*' in pattern and thing == 'support-files':
                             obj.pattern_installs.append(
                                 (manifest_dir, pattern, out_dir))
+                        # "absolute" paths identify files that are to be
+                        # placed in the install_root directory (no globs)
+                        elif pattern[0] == '/':
+                            full = mozpath.normpath(mozpath.join(manifest_dir,
+                                mozpath.basename(pattern)))
+                            obj.installs[full] = (mozpath.join(install_root,
+                                pattern[1:]), False)
                         else:
                             full = mozpath.normpath(mozpath.join(manifest_dir,
                                 pattern))
 
                             dest_path = mozpath.join(out_dir, pattern)
 
                             # If the path resolves to a different directory
                             # tree, we take special behavior depending on the
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/test-manifest-absolute-support/absolute-support.ini
@@ -0,0 +1,2 @@
+[DEFAULT]
+support-files = /.well-known/foo.txt
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/test-manifest-absolute-support/foo.txt
@@ -0,0 +1,1 @@
+hello
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/test-manifest-absolute-support/moz.build
@@ -0,0 +1,4 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+MOCHITEST_MANIFESTS += ['absolute-support.ini']
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -325,16 +325,31 @@ class TestEmitterBasic(unittest.TestCase
 
         objs = self.read_topsrcdir(reader)
         self.assertEqual(len(objs), 1)
         o = objs[0]
         self.assertEqual(len(o.installs), 2)
         paths = sorted([k[len(o.directory)+1:] for k in o.installs.keys()])
         self.assertEqual(paths, ["foo.txt", "support-disabled-tests.ini"])
 
+    def test_test_manifest_absolute_support_files(self):
+        """Support files starting with '/' are placed relative to the install root"""
+        reader = self.reader('test-manifest-absolute-support')
+
+        objs = self.read_topsrcdir(reader)
+        self.assertEqual(len(objs), 1)
+        o = objs[0]
+        self.assertEqual(len(o.installs), 2)
+        expected = [
+            mozpath.normpath(mozpath.join(o.install_prefix, "../.well-known/foo.txt")),
+            mozpath.join(o.install_prefix, "absolute-support.ini"),
+        ]
+        paths = sorted([v[0] for v in o.installs.values()])
+        self.assertEqual(paths, expected)
+
     def test_test_manifest_keys_extracted(self):
         """Ensure all metadata from test manifests is extracted."""
         reader = self.reader('test-manifest-keys-extracted')
 
         objs = [o for o in self.read_topsrcdir(reader)
                 if isinstance(o, TestManifest)]
 
         self.assertEqual(len(objs), 6)