Skip to content

Commit 2ddce27

Browse files
author
Cruz Monrreal
authored
Merge pull request #6769 from theotherjimmy/fix-subtract-basepath
Move subtract basepath into the resources class
2 parents 809f183 + d338e67 commit 2ddce27

File tree

2 files changed

+49
-57
lines changed

2 files changed

+49
-57
lines changed

tools/export/__init__.py

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -138,48 +138,6 @@ def get_exporter_toolchain(ide):
138138
return EXPORTERS[ide], EXPORTERS[ide].TOOLCHAIN
139139

140140

141-
def rewrite_basepath(file_name, resources, export_path, loc):
142-
""" Replace the basepath of filename with export_path
143-
144-
Positional arguments:
145-
file_name - the absolute path to a file
146-
resources - the resources object that the file came from
147-
export_path - the final destination of the file after export
148-
"""
149-
new_f = join(loc, relpath(file_name, resources.file_basepath[file_name]))
150-
resources.file_basepath[new_f] = export_path
151-
return new_f
152-
153-
154-
def subtract_basepath(resources, export_path, loc=""):
155-
""" Rewrite all of the basepaths with the export_path
156-
157-
Positional arguments:
158-
resources - the resource object to rewrite the basepaths of
159-
export_path - the final destination of the resources with respect to the
160-
generated project files
161-
"""
162-
keys = ['s_sources', 'c_sources', 'cpp_sources', 'hex_files',
163-
'objects', 'libraries', 'inc_dirs', 'headers', 'linker_script',
164-
'lib_dirs']
165-
for key in keys:
166-
vals = getattr(resources, key)
167-
if isinstance(vals, set):
168-
vals = list(vals)
169-
if isinstance(vals, list):
170-
new_vals = []
171-
for val in vals:
172-
new_vals.append(rewrite_basepath(val, resources, export_path,
173-
loc))
174-
if isinstance(getattr(resources, key), set):
175-
setattr(resources, key, set(new_vals))
176-
else:
177-
setattr(resources, key, new_vals)
178-
elif vals:
179-
setattr(resources, key, rewrite_basepath(vals, resources,
180-
export_path, loc))
181-
182-
183141
def generate_project_files(resources, export_path, target, name, toolchain, ide,
184142
macros=None):
185143
"""Generate the project files for a project
@@ -305,27 +263,21 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
305263
notify=notify, silent=silent, verbose=verbose,
306264
extra_verbose=extra_verbose, config=config, build_profile=build_profile,
307265
app_config=app_config)
308-
# The first path will give the name to the library
266+
309267
toolchain.RESPONSE_FILES = False
310268
if name is None:
311269
name = basename(normpath(abspath(src_paths[0])))
312270

313-
# Call unified scan_resources
314271
resource_dict = {loc: sum((toolchain.scan_resources(p, collect_ignores=True)
315272
for p in path),
316273
Resources())
317274
for loc, path in src_paths.items()}
318275
resources = Resources()
319276

320-
if zip_proj:
321-
subtract_basepath(resources, ".")
322-
for loc, res in resource_dict.items():
323-
temp = copy.deepcopy(res)
324-
subtract_basepath(temp, ".", loc)
325-
resources.add(temp)
326-
else:
327-
for _, res in resource_dict.items():
328-
resources.add(res)
277+
for loc, res in resource_dict.items():
278+
temp = copy.deepcopy(res)
279+
temp.subtract_basepath(".", loc)
280+
resources.add(temp)
329281

330282
toolchain.build_dir = export_path
331283
toolchain.config.load_resources(resources)
@@ -345,8 +297,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
345297
if zip_proj:
346298
for resource in resource_dict.values():
347299
for label, res in resource.features.items():
348-
if label not in toolchain.target.features:
349-
resource.add(res)
300+
resource.add(res)
350301
if isinstance(zip_proj, basestring):
351302
zip_export(join(export_path, zip_proj), name, resource_dict,
352303
files + list(exporter.static_files), inc_repos)

tools/toolchains/__init__.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ def ignore_dir(self, directory):
169169
self.ignored_dirs.append(directory)
170170

171171
def add(self, resources):
172-
for f,p in resources.file_basepath.items():
173-
self.file_basepath[f] = p
172+
self.file_basepath.update(resources.file_basepath)
174173

175174
self.inc_dirs += resources.inc_dirs
176175
self.headers += resources.headers
@@ -201,6 +200,48 @@ def add(self, resources):
201200

202201
return self
203202

203+
def rewrite_basepath(self, file_name, export_path, loc):
204+
""" Replace the basepath of filename with export_path
205+
206+
Positional arguments:
207+
file_name - the absolute path to a file
208+
export_path - the final destination of the file after export
209+
"""
210+
new_f = join(loc, relpath(file_name, self.file_basepath[file_name]))
211+
self.file_basepath[new_f] = export_path
212+
return new_f
213+
214+
def subtract_basepath(self, export_path, loc=""):
215+
""" Rewrite all of the basepaths with the export_path
216+
217+
Positional arguments:
218+
export_path - the final destination of the resources with respect to the
219+
generated project files
220+
"""
221+
keys = ['s_sources', 'c_sources', 'cpp_sources', 'hex_files',
222+
'objects', 'libraries', 'inc_dirs', 'headers', 'linker_script',
223+
'lib_dirs']
224+
for key in keys:
225+
vals = getattr(self, key)
226+
if isinstance(vals, set):
227+
vals = list(vals)
228+
if isinstance(vals, list):
229+
new_vals = []
230+
for val in vals:
231+
new_vals.append(self.rewrite_basepath(
232+
val, export_path, loc))
233+
if isinstance(getattr(self, key), set):
234+
setattr(self, key, set(new_vals))
235+
else:
236+
setattr(self, key, new_vals)
237+
elif vals:
238+
setattr(self, key, self.rewrite_basepath(
239+
vals, export_path, loc))
240+
def closure(res, export_path=export_path, loc=loc):
241+
res.subtract_basepath(export_path, loc)
242+
return res
243+
self.features.apply(closure)
244+
204245
def _collect_duplicates(self, dupe_dict, dupe_headers):
205246
for filename in self.s_sources + self.c_sources + self.cpp_sources:
206247
objname, _ = splitext(basename(filename))

0 commit comments

Comments
 (0)