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
pull/8660/head
Jimmy Brisson 2018-11-08 09:23:49 -06:00
parent 0cba0a34dd
commit 95e2b07ad8
2 changed files with 9 additions and 8 deletions

View File

@ -261,25 +261,26 @@ class Resources(object):
return list(self._file_refs[file_type])
def _all_parents(self, files):
for name in files:
for name, path in files:
components = name.split(self._sep)
start_at = 0
for index, directory in reversed(list(enumerate(components))):
if directory in self._prefixed_labels:
start_at = index + 1
break
prefix = path.replace(name, "")
for n in range(start_at, len(components)):
parent = self._sep.join(components[:n])
yield parent
parent_name = self._sep.join(components[:n])
parent_path = join(prefix, *components[:n])
yield FileRef(parent_name, parent_path)
def _get_from_refs(self, file_type, key):
if file_type is FileType.INC_DIR:
parents = set(self._all_parents(self._get_from_refs(
FileType.HEADER, key)))
parents = set(self._all_parents(self._file_refs[FileType.HEADER]))
else:
parents = set()
return sorted(
list(parents) + [key(f) for f in self.get_file_refs(file_type)]
[key(f) for f in list(parents) + self.get_file_refs(file_type)]
)

View File

@ -188,7 +188,7 @@ class ARM(mbedToolchain):
if self.RESPONSE_FILES:
opts += ['--via', self.get_inc_file(includes)]
else:
opts += ["-I%s" % i for i in includes]
opts += ["-I%s" % i for i in includes if i]
return opts
@ -471,7 +471,7 @@ class ARMC6(ARM_STD):
def get_compile_options(self, defines, includes, for_asm=False):
opts = ['-D%s' % d for d in defines]
opts.extend(["-I%s" % i for i in includes])
opts.extend(["-I%s" % i for i in includes if i])
if for_asm:
return ["--cpreproc",
"--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)]