Skip to content

Commit 467bac1

Browse files
committed
Remove duplicate files in zipped exports
The zipping function of the exporters would unconditionally add all files scanned by scan resources to a zip, including all of the files associated with each feature. This would conflict with `build_api.scan_resources` adding all of the files to the resources object that correspond to the enabled features. To resolve this difference in behavior, I made the zipping function oblivious to features and had the upper level function, which has access to the target configuration, do the proper merging.
1 parent aa6d673 commit 467bac1

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

tools/project_api.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -104,33 +104,32 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos):
104104
with zipfile.ZipFile(file_name, "w") as zip_file:
105105
for prj_file in project_files:
106106
zip_file.write(prj_file, join(prefix, basename(prj_file)))
107-
for loc, resource in resources.iteritems():
108-
for res in [resource] + resource.features.values():
109-
to_zip = (
110-
res.headers + res.s_sources + res.c_sources +\
111-
res.cpp_sources + res.libraries + res.hex_files + \
112-
[res.linker_script] + res.bin_files + res.objects + \
113-
res.json_files + res.lib_refs + res.lib_builds)
114-
if inc_repos:
115-
for directory in res.repo_dirs:
116-
for root, _, files in walk(directory):
117-
for repo_file in files:
118-
source = join(root, repo_file)
119-
to_zip.append(source)
120-
res.file_basepath[source] = res.base_path
121-
to_zip += res.repo_files
122-
for source in to_zip:
123-
if source:
124-
zip_file.write(
125-
source,
126-
join(prefix, loc,
127-
relpath(source, res.file_basepath[source])))
128-
for source in res.lib_builds:
129-
target_dir, _ = splitext(source)
130-
dest = join(prefix, loc,
131-
relpath(target_dir, res.file_basepath[source]),
132-
".bld", "bldrc")
133-
zip_file.write(source, dest)
107+
for loc, res in resources.iteritems():
108+
to_zip = (
109+
res.headers + res.s_sources + res.c_sources +\
110+
res.cpp_sources + res.libraries + res.hex_files + \
111+
[res.linker_script] + res.bin_files + res.objects + \
112+
res.json_files + res.lib_refs + res.lib_builds)
113+
if inc_repos:
114+
for directory in res.repo_dirs:
115+
for root, _, files in walk(directory):
116+
for repo_file in files:
117+
source = join(root, repo_file)
118+
to_zip.append(source)
119+
res.file_basepath[source] = res.base_path
120+
to_zip += res.repo_files
121+
for source in to_zip:
122+
if source:
123+
zip_file.write(
124+
source,
125+
join(prefix, loc,
126+
relpath(source, res.file_basepath[source])))
127+
for source in res.lib_builds:
128+
target_dir, _ = splitext(source)
129+
dest = join(prefix, loc,
130+
relpath(target_dir, res.file_basepath[source]),
131+
".bld", "bldrc")
132+
zip_file.write(source, dest)
134133

135134

136135

@@ -223,8 +222,13 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
223222
macros=macros)
224223
files.append(config_header)
225224
if zip_proj:
225+
for resource in resource_dict.values():
226+
for label, res in resource.features.iteritems():
227+
if label not in toolchain.target.features:
228+
resource.add(res)
226229
if isinstance(zip_proj, basestring):
227-
zip_export(join(export_path, zip_proj), name, resource_dict, files, inc_repos)
230+
zip_export(join(export_path, zip_proj), name, resource_dict, files,
231+
inc_repos)
228232
else:
229233
zip_export(zip_proj, name, resource_dict, files, inc_repos)
230234

0 commit comments

Comments
 (0)