Skip to content

Commit 10b0af1

Browse files
theotherjimmyadbridge
authored andcommitted
Resources: Compute parents using only header names
### Description The prior fix made the assumption that you wanted to compute all of the parents for a give header file going all the way up the path. This is not true: you probably want to stop when the project stops. We already keep track of a virtual name within the project, so instead, we compute parents of the name, and generate the actual location of these files in your FS as the path. This makes the solution robust offline and online (I tested it with my local copy of os.mbed.com) ### Pull request type [x] Fix [ ] Refactor [ ] Target update [ ] Functionality change [ ] Docs update [ ] Test update [ ] Breaking change
1 parent fdc867c commit 10b0af1

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

tools/resources/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,25 +261,26 @@ def get_file_refs(self, file_type):
261261
return list(self._file_refs[file_type])
262262

263263
def _all_parents(self, files):
264-
for name in files:
264+
for name, path in files:
265265
components = name.split(self._sep)
266266
start_at = 0
267267
for index, directory in reversed(list(enumerate(components))):
268268
if directory in self._prefixed_labels:
269269
start_at = index + 1
270270
break
271+
prefix = path.replace(name, "")
271272
for n in range(start_at, len(components)):
272-
parent = self._sep.join(components[:n])
273-
yield parent
273+
parent_name = self._sep.join(components[:n])
274+
parent_path = join(prefix, *components[:n])
275+
yield FileRef(parent_name, parent_path)
274276

275277
def _get_from_refs(self, file_type, key):
276278
if file_type is FileType.INC_DIR:
277-
parents = set(self._all_parents(self._get_from_refs(
278-
FileType.HEADER, key)))
279+
parents = set(self._all_parents(self._file_refs[FileType.HEADER]))
279280
else:
280281
parents = set()
281282
return sorted(
282-
list(parents) + [key(f) for f in self.get_file_refs(file_type)]
283+
[key(f) for f in list(parents) + self.get_file_refs(file_type)]
283284
)
284285

285286

tools/toolchains/arm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def get_compile_options(self, defines, includes, for_asm=False):
188188
if self.RESPONSE_FILES:
189189
opts += ['--via', self.get_inc_file(includes)]
190190
else:
191-
opts += ["-I%s" % i for i in includes]
191+
opts += ["-I%s" % i for i in includes if i]
192192

193193
return opts
194194

@@ -474,7 +474,7 @@ def get_config_option(self, config_header):
474474

475475
def get_compile_options(self, defines, includes, for_asm=False):
476476
opts = ['-D%s' % d for d in defines]
477-
opts.extend(["-I%s" % i for i in includes])
477+
opts.extend(["-I%s" % i for i in includes if i])
478478
if for_asm:
479479
return ["--cpreproc",
480480
"--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)]

0 commit comments

Comments
 (0)