Skip to content

Commit 6e63aca

Browse files
committed
Resources: Avoid assuming that deps have a sane name
### Description The prior fix assume that the dependencies through `.lib` references would have a "sane" name. My definition of "sane" here is that the reference will have a path that starts with the path to the `.lib` file and _removes_ the `.lib` suffix. The online compiler does not remove the `.lib` suffix. Instead, it keeps it. This makes the string replacement in the prior PR fail. Also, this is faster, and simpler. ### Pull request type [x] Fix [ ] Refactor [ ] Target update [ ] Functionality change [ ] Docs update [ ] Test update [ ] Breaking change
1 parent 9d95d46 commit 6e63aca

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

tools/resources/__init__.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -254,35 +254,15 @@ def add_file_ref(self, file_type, file_name, file_path):
254254
ref = FileRef(file_name.replace(sep, self._sep), file_path)
255255
else:
256256
ref = FileRef(file_name, file_path)
257-
self._file_refs[file_type].add(ref)
257+
if file_type:
258+
self._file_refs[file_type].add(ref)
258259

259260
def get_file_refs(self, file_type):
260261
"""Return a list of FileRef for every file of the given type"""
261262
return list(self._file_refs[file_type])
262263

263-
def _all_parents(self, files):
264-
for name, path in files:
265-
components = name.split(self._sep)
266-
start_at = 0
267-
for index, directory in reversed(list(enumerate(components))):
268-
if directory in self._prefixed_labels:
269-
start_at = index + 1
270-
break
271-
prefix = path.replace(name, "")
272-
for n in range(start_at, len(components)):
273-
parent_name = self._sep.join(components[:n])
274-
parent_path = join(prefix, *components[:n])
275-
yield FileRef(parent_name, parent_path)
276-
277264
def _get_from_refs(self, file_type, key):
278-
if file_type is FileType.INC_DIR:
279-
parents = set(self._all_parents(self._file_refs[FileType.HEADER]))
280-
else:
281-
parents = set()
282-
return sorted(
283-
[key(f) for f in list(parents) + self.get_file_refs(file_type)]
284-
)
285-
265+
return sorted([key(f) for f in self.get_file_refs(file_type)])
286266

287267
def get_file_names(self, file_type):
288268
return self._get_from_refs(file_type, lambda f: f.name)
@@ -447,6 +427,19 @@ def add_directory(
447427
".ar": FileType.LIB_DIR,
448428
}
449429

430+
def _all_parents(self, file_path, base_path, into_path):
431+
suffix = relpath(file_path, base_path)
432+
components = suffix.split(self._sep)
433+
start_at = 0
434+
for index, directory in reversed(list(enumerate(components))):
435+
if directory in self._prefixed_labels:
436+
start_at = index + 1
437+
break
438+
for n in range(start_at, len(components)):
439+
parent_name = self._sep.join([into_path] + components[:n])
440+
parent_path = join(base_path, *components[:n])
441+
yield FileRef(parent_name, parent_path)
442+
450443
def _add_file(self, file_path, base_path, into_path):
451444
""" Add a single file into the resources object that was found by
452445
scanning starting as base_path
@@ -459,16 +452,15 @@ def _add_file(self, file_path, base_path, into_path):
459452

460453
fake_path = join(into_path, relpath(file_path, base_path))
461454
_, ext = splitext(file_path)
462-
try:
463-
file_type = self._EXT[ext.lower()]
464-
self.add_file_ref(file_type, fake_path, file_path)
465-
except KeyError:
466-
pass
467-
try:
468-
dir_type = self._DIR_EXT[ext.lower()]
469-
self.add_file_ref(dir_type, dirname(fake_path), dirname(file_path))
470-
except KeyError:
471-
pass
455+
456+
file_type = self._EXT.get(ext.lower())
457+
self.add_file_ref(file_type, fake_path, file_path)
458+
if file_type == FileType.HEADER:
459+
for name, path in self._all_parents(file_path, base_path, into_path):
460+
self.add_file_ref(FileType.INC_DIR, name, path)
461+
462+
dir_type = self._DIR_EXT.get(ext.lower())
463+
self.add_file_ref(dir_type, dirname(fake_path), dirname(file_path))
472464

473465

474466
def scan_with_toolchain(self, src_paths, toolchain, dependencies_paths=None,

0 commit comments

Comments
 (0)