Bug 1378830 - part 2 - add tests for {LIB,PROG}_IS_C_ONLY; r=chmanchester
Adding PROG_IS_C_ONLY seems like a good point to add tests, and once we
have tests for that, adding tests for the existing library support is
not too difficult.
--- a/python/mozbuild/mozbuild/test/backend/common.py
+++ b/python/mozbuild/mozbuild/test/backend/common.py
@@ -156,16 +156,25 @@ CONFIGS = defaultdict(lambda: {
},
'visual-studio': {
'defines': {},
'non_global_defines': [],
'substs': {
'MOZ_APP_NAME': 'my_app',
},
},
+ 'prog-lib-c-only': {
+ 'defines': {},
+ 'non_global_defines': [],
+ 'substs': {
+ 'COMPILE_ENVIRONMENT': '1',
+ 'LIB_SUFFIX': '.a',
+ 'BIN_SUFFIX': '',
+ },
+ }
})
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/prog-lib-c-only/c-library/c-library.c
@@ -0,0 +1,2 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/c-library/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+SharedLibrary('c_library')
+
+SOURCES = ['c-library.c']
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/c-program/c_test_program.c
@@ -0,0 +1,2 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/c-program/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+Program('c_test_program')
+
+SOURCES = ['c_test_program.c']
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/c-simple-programs/c_simple_program.c
@@ -0,0 +1,2 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/c-simple-programs/moz.build
@@ -0,0 +1,5 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+SimplePrograms(['c_simple_program'], ext='.c')
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/cxx-library/c-source.c
@@ -0,0 +1,2 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/cxx-library/cxx-library.cpp
@@ -0,0 +1,2 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/cxx-library/moz.build
@@ -0,0 +1,10 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+SharedLibrary('cxx-library')
+
+SOURCES = [
+ 'c-source.c',
+ 'cxx-library.cpp',
+]
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/cxx-program/cxx_test_program.cpp
@@ -0,0 +1,2 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/cxx-program/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+Program('cxx_test_program')
+
+SOURCES = ['cxx_test_program.cpp']
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/cxx-simple-programs/cxx_simple_program.cpp
@@ -0,0 +1,2 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/cxx-simple-programs/moz.build
@@ -0,0 +1,5 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+SimplePrograms(['cxx_simple_program'])
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/moz.build
@@ -0,0 +1,31 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+DIRS += [
+ 'c-program',
+ 'cxx-program',
+ 'c-simple-programs',
+ 'cxx-simple-programs',
+ 'c-library',
+ 'cxx-library',
+]
+
+@template
+def Program(name):
+ PROGRAM = name
+
+@template
+def SimplePrograms(names, ext='.cpp'):
+ SIMPLE_PROGRAMS += names
+ SOURCES += ['%s%s' % (name, ext) for name in names]
+
+@template
+def Library(name):
+ LIBRARY_NAME = name
+
+@template
+def SharedLibrary(name):
+ Library(name)
+
+ FORCE_SHARED_LIB = True
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/backend/data/prog-lib-c-only/simple-programs/moz.build
@@ -0,0 +1,4 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
--- a/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
+++ b/python/mozbuild/mozbuild/test/backend/test_recursivemake.py
@@ -894,16 +894,64 @@ class TestRecursiveMakeBackend(BackendTe
self.assertEqual(
open(os.path.join(env.topobjdir, 'file'), 'r').readlines(), [
'#ifdef foo\n',
'bar baz\n',
'@bar@\n',
])
+ def test_prog_lib_c_only(self):
+ """Test that C-only binary artifacts are marked as such."""
+ env = self._consume('prog-lib-c-only', RecursiveMakeBackend)
+
+ # PROGRAM C-onlyness.
+ with open(os.path.join(env.topobjdir, 'c-program', 'backend.mk'), 'rb') as fh:
+ lines = fh.readlines()
+ lines = [line.rstrip() for line in lines]
+
+ self.assertIn('PROG_IS_C_ONLY_c_test_program := 1', lines)
+
+ with open(os.path.join(env.topobjdir, 'cxx-program', 'backend.mk'), 'rb') as fh:
+ lines = fh.readlines()
+ lines = [line.rstrip() for line in lines]
+
+ # Test for only the absence of the variable, not the precise
+ # form of the variable assignment.
+ for line in lines:
+ self.assertNotIn('PROG_IS_C_ONLY_cxx_test_program', line)
+
+ # SIMPLE_PROGRAMS C-onlyness.
+ with open(os.path.join(env.topobjdir, 'c-simple-programs', 'backend.mk'), 'rb') as fh:
+ lines = fh.readlines()
+ lines = [line.rstrip() for line in lines]
+
+ self.assertIn('PROG_IS_C_ONLY_c_simple_program := 1', lines)
+
+ with open(os.path.join(env.topobjdir, 'cxx-simple-programs', 'backend.mk'), 'rb') as fh:
+ lines = fh.readlines()
+ lines = [line.rstrip() for line in lines]
+
+ for line in lines:
+ self.assertNotIn('PROG_IS_C_ONLY_cxx_simple_program', line)
+
+ # Libraries C-onlyness.
+ with open(os.path.join(env.topobjdir, 'c-library', 'backend.mk'), 'rb') as fh:
+ lines = fh.readlines()
+ lines = [line.rstrip() for line in lines]
+
+ self.assertIn('LIB_IS_C_ONLY := 1', lines)
+
+ with open(os.path.join(env.topobjdir, 'cxx-library', 'backend.mk'), 'rb') as fh:
+ lines = fh.readlines()
+ lines = [line.rstrip() for line in lines]
+
+ for line in lines:
+ self.assertNotIn('LIB_IS_C_ONLY', line)
+
def test_jar_manifests(self):
env = self._consume('jar-manifests', RecursiveMakeBackend)
with open(os.path.join(env.topobjdir, 'backend.mk'), 'rb') as fh:
lines = fh.readlines()
lines = [line.rstrip() for line in lines]