forked from mirrors/gecko-dev
Bug 1880746 - Part 4: Throw error when same directory is added to DIRS twice. r=firefox-build-system-reviewers,glandium
Differential Revision: https://phabricator.services.mozilla.com/D202099
This commit is contained in:
parent
7da058beca
commit
5303190810
2 changed files with 36 additions and 17 deletions
|
|
@ -831,7 +831,7 @@ class BuildReader(object):
|
|||
self.config = config
|
||||
|
||||
self._log = logging.getLogger(__name__)
|
||||
self._read_files = set()
|
||||
self._read_files = {}
|
||||
self._execution_stack = []
|
||||
self.finder = finder
|
||||
|
||||
|
|
@ -1113,7 +1113,16 @@ class BuildReader(object):
|
|||
"Reading file: {path}".format(path=path),
|
||||
)
|
||||
|
||||
if path in self._read_files:
|
||||
time_start = time.monotonic()
|
||||
|
||||
topobjdir = config.topobjdir
|
||||
|
||||
relpath = mozpath.relpath(path, config.topsrcdir)
|
||||
reldir = mozpath.dirname(relpath)
|
||||
|
||||
# NOTE: descend case is handled in the loop below.
|
||||
if not descend:
|
||||
if relpath in self._read_files:
|
||||
log(
|
||||
self._log,
|
||||
logging.WARNING,
|
||||
|
|
@ -1123,14 +1132,7 @@ class BuildReader(object):
|
|||
)
|
||||
return
|
||||
|
||||
self._read_files.add(path)
|
||||
|
||||
time_start = time.monotonic()
|
||||
|
||||
topobjdir = config.topobjdir
|
||||
|
||||
relpath = mozpath.relpath(path, config.topsrcdir)
|
||||
reldir = mozpath.dirname(relpath)
|
||||
self._read_files[relpath] = (relpath, "")
|
||||
|
||||
if mozpath.dirname(relpath) == "js/src" and not config.substs.get(
|
||||
"JS_STANDALONE"
|
||||
|
|
@ -1234,6 +1236,15 @@ class BuildReader(object):
|
|||
if not descend:
|
||||
continue
|
||||
|
||||
child_relpath = mozpath.relpath(child_path, self.config.topsrcdir)
|
||||
|
||||
if child_relpath in self._read_files:
|
||||
(prev_parent, prev_path) = self._read_files[child_relpath]
|
||||
raise Exception(
|
||||
f"File already read. A directory should not be added to DIRS twice: {child_relpath} is referred from {prev_parent} as '{prev_path}', and {relpath} as '{path}'"
|
||||
)
|
||||
self._read_files[child_relpath] = (relpath, path)
|
||||
|
||||
for res in self.read_mozbuild(
|
||||
child_path, context.config, metadata=child_metadata
|
||||
):
|
||||
|
|
|
|||
|
|
@ -83,12 +83,20 @@ class TestBuildReader(unittest.TestCase):
|
|||
contexts = list(reader.read_topsrcdir())
|
||||
self.assertEqual(len(contexts), 3)
|
||||
|
||||
def test_repeated_dirs_ignored(self):
|
||||
# Ensure repeated directories are ignored.
|
||||
def test_repeated_dirs_error(self):
|
||||
reader = self.reader("traversal-repeated-dirs")
|
||||
|
||||
contexts = list(reader.read_topsrcdir())
|
||||
self.assertEqual(len(contexts), 3)
|
||||
with self.assertRaises(BuildReaderError) as bre:
|
||||
list(reader.read_topsrcdir())
|
||||
|
||||
e = bre.exception
|
||||
self.assertEqual(
|
||||
e.actual_file, self.file_path("traversal-repeated-dirs", "bar", "moz.build")
|
||||
)
|
||||
self.assertIn(
|
||||
"File already read. A directory should not be added to DIRS twice: foo/moz.build is referred from moz.build as 'foo', and bar/moz.build as '../foo'",
|
||||
str(e),
|
||||
)
|
||||
|
||||
def test_outside_topsrcdir(self):
|
||||
# References to directories outside the topsrcdir should fail.
|
||||
|
|
|
|||
Loading…
Reference in a new issue