Skip to content

Move subtract basepath into the resources class #6769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 6 additions & 55 deletions tools/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,48 +138,6 @@ def get_exporter_toolchain(ide):
return EXPORTERS[ide], EXPORTERS[ide].TOOLCHAIN


def rewrite_basepath(file_name, resources, export_path, loc):
""" Replace the basepath of filename with export_path

Positional arguments:
file_name - the absolute path to a file
resources - the resources object that the file came from
export_path - the final destination of the file after export
"""
new_f = join(loc, relpath(file_name, resources.file_basepath[file_name]))
resources.file_basepath[new_f] = export_path
return new_f


def subtract_basepath(resources, export_path, loc=""):
""" Rewrite all of the basepaths with the export_path

Positional arguments:
resources - the resource object to rewrite the basepaths of
export_path - the final destination of the resources with respect to the
generated project files
"""
keys = ['s_sources', 'c_sources', 'cpp_sources', 'hex_files',
'objects', 'libraries', 'inc_dirs', 'headers', 'linker_script',
'lib_dirs']
for key in keys:
vals = getattr(resources, key)
if isinstance(vals, set):
vals = list(vals)
if isinstance(vals, list):
new_vals = []
for val in vals:
new_vals.append(rewrite_basepath(val, resources, export_path,
loc))
if isinstance(getattr(resources, key), set):
setattr(resources, key, set(new_vals))
else:
setattr(resources, key, new_vals)
elif vals:
setattr(resources, key, rewrite_basepath(vals, resources,
export_path, loc))


def generate_project_files(resources, export_path, target, name, toolchain, ide,
macros=None):
"""Generate the project files for a project
Expand Down Expand Up @@ -305,27 +263,21 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose, config=config, build_profile=build_profile,
app_config=app_config)
# The first path will give the name to the library

toolchain.RESPONSE_FILES = False
if name is None:
name = basename(normpath(abspath(src_paths[0])))

# Call unified scan_resources
resource_dict = {loc: sum((toolchain.scan_resources(p, collect_ignores=True)
for p in path),
Resources())
for loc, path in src_paths.items()}
resources = Resources()

if zip_proj:
subtract_basepath(resources, ".")
for loc, res in resource_dict.items():
temp = copy.deepcopy(res)
subtract_basepath(temp, ".", loc)
resources.add(temp)
else:
for _, res in resource_dict.items():
resources.add(res)
for loc, res in resource_dict.items():
temp = copy.deepcopy(res)
temp.subtract_basepath(".", loc)
resources.add(temp)

toolchain.build_dir = export_path
toolchain.config.load_resources(resources)
Expand All @@ -345,8 +297,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
if zip_proj:
for resource in resource_dict.values():
for label, res in resource.features.items():
if label not in toolchain.target.features:
resource.add(res)
resource.add(res)
if isinstance(zip_proj, basestring):
zip_export(join(export_path, zip_proj), name, resource_dict,
files + list(exporter.static_files), inc_repos)
Expand Down
45 changes: 43 additions & 2 deletions tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ def ignore_dir(self, directory):
self.ignored_dirs.append(directory)

def add(self, resources):
for f,p in resources.file_basepath.items():
self.file_basepath[f] = p
self.file_basepath.update(resources.file_basepath)

self.inc_dirs += resources.inc_dirs
self.headers += resources.headers
Expand Down Expand Up @@ -201,6 +200,48 @@ def add(self, resources):

return self

def rewrite_basepath(self, file_name, export_path, loc):
""" Replace the basepath of filename with export_path

Positional arguments:
file_name - the absolute path to a file
export_path - the final destination of the file after export
"""
new_f = join(loc, relpath(file_name, self.file_basepath[file_name]))
self.file_basepath[new_f] = export_path
return new_f

def subtract_basepath(self, export_path, loc=""):
""" Rewrite all of the basepaths with the export_path

Positional arguments:
export_path - the final destination of the resources with respect to the
generated project files
"""
keys = ['s_sources', 'c_sources', 'cpp_sources', 'hex_files',
'objects', 'libraries', 'inc_dirs', 'headers', 'linker_script',
'lib_dirs']
for key in keys:
vals = getattr(self, key)
if isinstance(vals, set):
vals = list(vals)
if isinstance(vals, list):
new_vals = []
for val in vals:
new_vals.append(self.rewrite_basepath(
val, export_path, loc))
if isinstance(getattr(self, key), set):
setattr(self, key, set(new_vals))
else:
setattr(self, key, new_vals)
elif vals:
setattr(self, key, self.rewrite_basepath(
vals, export_path, loc))
def closure(res, export_path=export_path, loc=loc):
res.subtract_basepath(export_path, loc)
return res
self.features.apply(closure)

def _collect_duplicates(self, dupe_dict, dupe_headers):
for filename in self.s_sources + self.c_sources + self.cpp_sources:
objname, _ = splitext(basename(filename))
Expand Down