bug 1255485 - add some tests for building programs in dist/bin. r?build draft
authorTed Mielczarek <ted@mielczarek.org>
Wed, 17 Jan 2018 11:19:19 -0500
changeset 721626 88d3b062723ea33c9476fdb0ce01cbba8b8540f6
parent 721546 9a66832e441ca76bfb2b9d3eb9ae814423e42d44
child 746391 b6a20efc36ab89052bc5dd81789257e576daf651
push id95899
push userbmo:ted@mielczarek.org
push dateWed, 17 Jan 2018 16:20:39 +0000
reviewersbuild
bugs1255485
milestone59.0a1
bug 1255485 - add some tests for building programs in dist/bin. r?build MozReview-Commit-ID: 94uOsInnWmT
python/mozbuild/mozbuild/test/backend/common.py
python/mozbuild/mozbuild/test/backend/data/program-paths/dist-bin/moz.build
python/mozbuild/mozbuild/test/backend/data/program-paths/dist-subdir/moz.build
python/mozbuild/mozbuild/test/backend/data/program-paths/final-target/moz.build
python/mozbuild/mozbuild/test/backend/data/program-paths/moz.build
python/mozbuild/mozbuild/test/backend/data/program-paths/not-installed/moz.build
python/mozbuild/mozbuild/test/backend/test_recursivemake.py
python/mozbuild/mozbuild/test/frontend/data/program-paths/dist-bin/moz.build
python/mozbuild/mozbuild/test/frontend/data/program-paths/dist-subdir/moz.build
python/mozbuild/mozbuild/test/frontend/data/program-paths/final-target/moz.build
python/mozbuild/mozbuild/test/frontend/data/program-paths/moz.build
python/mozbuild/mozbuild/test/frontend/data/program-paths/not-installed/moz.build
python/mozbuild/mozbuild/test/frontend/test_emitter.py
--- a/python/mozbuild/mozbuild/test/backend/common.py
+++ b/python/mozbuild/mozbuild/test/backend/common.py
@@ -183,16 +183,24 @@ CONFIGS = defaultdict(lambda: {
             'RUST_TARGET': 'x86_64-unknown-linux-gnu',
             'LIB_PREFIX': 'lib',
             'RUST_LIB_PREFIX': 'lib',
             'LIB_SUFFIX': 'a',
             'RUST_LIB_SUFFIX': 'a',
             'OS_TARGET': 'Darwin',
         },
     },
+    'program-paths': {
+        'defines': {},
+        'non_global_defines': [],
+        'substs': {
+            'COMPILE_ENVIRONMENT': '1',
+            'BIN_SUFFIX': '.prog',
+        },
+    },
 })
 
 
 class BackendTester(unittest.TestCase):
     def setUp(self):
         self._old_env = dict(os.environ)
         os.environ.pop('MOZ_OBJDIR', None)
 
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/program-paths/dist-bin/moz.build
@@ -0,0 +1,4 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+Program('dist-bin')
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/program-paths/dist-subdir/moz.build
@@ -0,0 +1,5 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+DIST_SUBDIR = 'foo'
+Program('dist-subdir')
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/program-paths/final-target/moz.build
@@ -0,0 +1,5 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+FINAL_TARGET = 'final/target'
+Program('final-target')
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/program-paths/moz.build
@@ -0,0 +1,13 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+@template
+def Program(name):
+    PROGRAM = name
+
+DIRS += [
+    'dist-bin',
+    'dist-subdir',
+    'final-target',
+    'not-installed',
+]
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/program-paths/not-installed/moz.build
@@ -0,0 +1,5 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+DIST_INSTALL = False
+Program('not-installed')
\ No newline at end of file
--- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
+++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
@@ -987,11 +987,30 @@ class TestRecursiveMakeBackend(BackendTe
         # Only mochitest.js should be in the install manifest.
         self.assertTrue('testing/mochitest/tests/mochitest.js' in m)
 
         # The path is odd here because we do not normalize at test manifest
         # processing time.  This is a fragile test because there's currently no
         # way to iterate the manifest.
         self.assertFalse('instrumentation/./not_packaged.java' in m)
 
+    def test_program_paths(self):
+        """PROGRAMs with various moz.build settings that change the destination should produce
+        the expected paths in backend.mk."""
+        env = self._consume('program-paths', RecursiveMakeBackend)
+
+        expected = [
+            ('dist-bin', '$(DEPTH)/dist/bin/dist-bin.prog'),
+            ('dist-subdir', '$(DEPTH)/dist/bin/foo/dist-subdir.prog'),
+            ('final-target', '$(DEPTH)/final/target/final-target.prog'),
+            ('not-installed', 'not-installed.prog'),
+        ]
+        prefix = 'PROGRAM = '
+        for (subdir, expected_program) in expected:
+            with open(os.path.join(env.topobjdir, subdir, 'backend.mk'), 'rb') as fh:
+                lines = fh.readlines()
+                program = [line.rstrip().split(prefix, 1)[1] for line in lines
+                           if line.startswith(prefix)][0]
+                self.assertEqual(program, expected_program)
+
 
 if __name__ == '__main__':
     main()
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/program-paths/dist-bin/moz.build
@@ -0,0 +1,4 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+Program('dist-bin')
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/program-paths/dist-subdir/moz.build
@@ -0,0 +1,5 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+DIST_SUBDIR = 'foo'
+Program('dist-subdir')
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/program-paths/final-target/moz.build
@@ -0,0 +1,5 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+FINAL_TARGET = 'final/target'
+Program('final-target')
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/program-paths/moz.build
@@ -0,0 +1,13 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+@template
+def Program(name):
+    PROGRAM = name
+
+DIRS += [
+    'dist-bin',
+    'dist-subdir',
+    'final-target',
+    'not-installed',
+]
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/program-paths/not-installed/moz.build
@@ -0,0 +1,5 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+DIST_INSTALL = False
+Program('not-installed')
\ No newline at end of file
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -649,16 +649,29 @@ class TestEmitterBasic(unittest.TestCase
         self.assertIsInstance(objs[2], Program)
         self.assertIsInstance(objs[3], SimpleProgram)
         self.assertIsInstance(objs[4], SimpleProgram)
 
         self.assertEqual(objs[2].program, 'test_program.prog')
         self.assertEqual(objs[3].program, 'test_program1.prog')
         self.assertEqual(objs[4].program, 'test_program2.prog')
 
+    def test_program_paths(self):
+        """Various moz.build settings that change the destination of PROGRAM should be
+        accurately reflected in Program.output_path."""
+        reader = self.reader('program-paths')
+        objs = self.read_topsrcdir(reader)
+        prog_paths = [o.output_path for o in objs if isinstance(o, Program)]
+        self.assertEqual(prog_paths, [
+            '!/dist/bin/dist-bin.prog',
+            '!/dist/bin/foo/dist-subdir.prog',
+            '!/final/target/final-target.prog',
+            '!not-installed.prog',
+        ])
+
     def test_test_manifest_missing_manifest(self):
         """A missing manifest file should result in an error."""
         reader = self.reader('test-manifest-missing-manifest')
 
         with self.assertRaisesRegexp(BuildReaderError, 'IOError: Missing files'):
             self.read_topsrcdir(reader)
 
     def test_empty_test_manifest_rejected(self):