Backed out changeset 4191b252db9b (bug 1886734) for causing build bustages @netwerk...
[gecko.git] / config / tests / test_mozbuild_reading.py
blob17fecf1452f5b1522a91b139530c32bcbdb242de
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import os
6 import sys
7 import unittest
9 from mozbuild.base import MozbuildObject
10 from mozbuild.frontend.context import Files
11 from mozbuild.frontend.reader import BuildReader, EmptyConfig
12 from mozpack.files import FileFinder
13 from mozunit import main
16 class TestMozbuildReading(unittest.TestCase):
17 # This hack is needed to appease running in automation.
18 def setUp(self):
19 self._old_env = dict(os.environ)
20 os.environ.pop("MOZCONFIG", None)
21 os.environ.pop("MOZ_OBJDIR", None)
23 def tearDown(self):
24 os.environ.clear()
25 os.environ.update(self._old_env)
27 def _mozbuilds(self, reader):
28 if not hasattr(self, "_mozbuild_paths"):
29 self._mozbuild_paths = set(reader.all_mozbuild_paths())
31 return self._mozbuild_paths
33 @unittest.skip("failing in SpiderMonkey builds")
34 def test_filesystem_traversal_reading(self):
35 """Reading moz.build according to filesystem traversal works.
37 We attempt to read every known moz.build file via filesystem traversal.
39 If this test fails, it means that metadata extraction will fail.
40 """
41 mb = MozbuildObject.from_environment(detect_virtualenv_mozinfo=False)
42 config = mb.config_environment
43 reader = BuildReader(config)
44 all_paths = self._mozbuilds(reader)
45 paths, contexts = reader.read_relevant_mozbuilds(all_paths)
46 self.assertEqual(set(paths), all_paths)
47 self.assertGreaterEqual(len(contexts), len(paths))
49 def test_filesystem_traversal_no_config(self):
50 """Reading moz.build files via filesystem traversal mode with no build config.
52 This is similar to the above test except no build config is applied.
53 This will likely fail in more scenarios than the above test because a
54 lot of moz.build files assumes certain variables are present.
55 """
56 here = os.path.abspath(os.path.dirname(__file__))
57 root = os.path.normpath(os.path.join(here, "..", ".."))
58 config = EmptyConfig(root)
59 reader = BuildReader(config)
60 all_paths = self._mozbuilds(reader)
61 paths, contexts = reader.read_relevant_mozbuilds(all_paths)
62 self.assertEqual(set(paths.keys()), all_paths)
63 self.assertGreaterEqual(len(contexts), len(paths))
65 def test_orphan_file_patterns(self):
66 if sys.platform == "win32":
67 raise unittest.SkipTest("failing on windows builds")
69 mb = MozbuildObject.from_environment(detect_virtualenv_mozinfo=False)
71 try:
72 config = mb.config_environment
73 except Exception as e:
74 if str(e) == "config.status not available. Run configure.":
75 raise unittest.SkipTest("failing without config.status")
76 raise
78 if config.substs["MOZ_BUILD_APP"] == "js":
79 raise unittest.SkipTest("failing in Spidermonkey builds")
81 reader = BuildReader(config)
82 all_paths = self._mozbuilds(reader)
83 _, contexts = reader.read_relevant_mozbuilds(all_paths)
85 finder = FileFinder(config.topsrcdir, ignore=["obj*"])
87 def pattern_exists(pat):
88 return [p for p in finder.find(pat)] != []
90 for ctx in contexts:
91 if not isinstance(ctx, Files):
92 continue
93 relsrcdir = ctx.relsrcdir
94 for p in ctx.patterns:
95 if not pattern_exists(os.path.join(relsrcdir, p)):
96 self.fail(
97 "The pattern '%s' in a Files() entry in "
98 "'%s' corresponds to no files in the tree.\n"
99 "Please update this entry." % (p, ctx.main_path)
103 if __name__ == "__main__":
104 main()