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.config = config
|
||||||
|
|
||||||
self._log = logging.getLogger(__name__)
|
self._log = logging.getLogger(__name__)
|
||||||
self._read_files = set()
|
self._read_files = {}
|
||||||
self._execution_stack = []
|
self._execution_stack = []
|
||||||
self.finder = finder
|
self.finder = finder
|
||||||
|
|
||||||
|
|
@ -1113,18 +1113,6 @@ class BuildReader(object):
|
||||||
"Reading file: {path}".format(path=path),
|
"Reading file: {path}".format(path=path),
|
||||||
)
|
)
|
||||||
|
|
||||||
if path in self._read_files:
|
|
||||||
log(
|
|
||||||
self._log,
|
|
||||||
logging.WARNING,
|
|
||||||
"read_already",
|
|
||||||
{"path": path},
|
|
||||||
"File already read. Skipping: {path}".format(path=path),
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
self._read_files.add(path)
|
|
||||||
|
|
||||||
time_start = time.monotonic()
|
time_start = time.monotonic()
|
||||||
|
|
||||||
topobjdir = config.topobjdir
|
topobjdir = config.topobjdir
|
||||||
|
|
@ -1132,6 +1120,20 @@ class BuildReader(object):
|
||||||
relpath = mozpath.relpath(path, config.topsrcdir)
|
relpath = mozpath.relpath(path, config.topsrcdir)
|
||||||
reldir = mozpath.dirname(relpath)
|
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,
|
||||||
|
"read_already",
|
||||||
|
{"path": path},
|
||||||
|
"File already read. Skipping: {path}".format(path=path),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
self._read_files[relpath] = (relpath, "")
|
||||||
|
|
||||||
if mozpath.dirname(relpath) == "js/src" and not config.substs.get(
|
if mozpath.dirname(relpath) == "js/src" and not config.substs.get(
|
||||||
"JS_STANDALONE"
|
"JS_STANDALONE"
|
||||||
):
|
):
|
||||||
|
|
@ -1234,6 +1236,15 @@ class BuildReader(object):
|
||||||
if not descend:
|
if not descend:
|
||||||
continue
|
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(
|
for res in self.read_mozbuild(
|
||||||
child_path, context.config, metadata=child_metadata
|
child_path, context.config, metadata=child_metadata
|
||||||
):
|
):
|
||||||
|
|
|
||||||
|
|
@ -83,12 +83,20 @@ class TestBuildReader(unittest.TestCase):
|
||||||
contexts = list(reader.read_topsrcdir())
|
contexts = list(reader.read_topsrcdir())
|
||||||
self.assertEqual(len(contexts), 3)
|
self.assertEqual(len(contexts), 3)
|
||||||
|
|
||||||
def test_repeated_dirs_ignored(self):
|
def test_repeated_dirs_error(self):
|
||||||
# Ensure repeated directories are ignored.
|
|
||||||
reader = self.reader("traversal-repeated-dirs")
|
reader = self.reader("traversal-repeated-dirs")
|
||||||
|
|
||||||
contexts = list(reader.read_topsrcdir())
|
with self.assertRaises(BuildReaderError) as bre:
|
||||||
self.assertEqual(len(contexts), 3)
|
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):
|
def test_outside_topsrcdir(self):
|
||||||
# References to directories outside the topsrcdir should fail.
|
# References to directories outside the topsrcdir should fail.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue