From 467bac19976de2bf715d094bd0795abf6683aa85 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Mon, 13 Feb 2017 15:03:22 -0600 Subject: [PATCH] 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. --- tools/project_api.py | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/tools/project_api.py b/tools/project_api.py index 39a3e2460a..f55f57ebf0 100644 --- a/tools/project_api.py +++ b/tools/project_api.py @@ -104,33 +104,32 @@ def zip_export(file_name, prefix, resources, project_files, inc_repos): with zipfile.ZipFile(file_name, "w") as zip_file: for prj_file in project_files: zip_file.write(prj_file, join(prefix, basename(prj_file))) - for loc, resource in resources.iteritems(): - for res in [resource] + resource.features.values(): - to_zip = ( - res.headers + res.s_sources + res.c_sources +\ - res.cpp_sources + res.libraries + res.hex_files + \ - [res.linker_script] + res.bin_files + res.objects + \ - res.json_files + res.lib_refs + res.lib_builds) - if inc_repos: - for directory in res.repo_dirs: - for root, _, files in walk(directory): - for repo_file in files: - source = join(root, repo_file) - to_zip.append(source) - res.file_basepath[source] = res.base_path - to_zip += res.repo_files - for source in to_zip: - if source: - zip_file.write( - source, - join(prefix, loc, - relpath(source, res.file_basepath[source]))) - for source in res.lib_builds: - target_dir, _ = splitext(source) - dest = join(prefix, loc, - relpath(target_dir, res.file_basepath[source]), - ".bld", "bldrc") - zip_file.write(source, dest) + for loc, res in resources.iteritems(): + to_zip = ( + res.headers + res.s_sources + res.c_sources +\ + res.cpp_sources + res.libraries + res.hex_files + \ + [res.linker_script] + res.bin_files + res.objects + \ + res.json_files + res.lib_refs + res.lib_builds) + if inc_repos: + for directory in res.repo_dirs: + for root, _, files in walk(directory): + for repo_file in files: + source = join(root, repo_file) + to_zip.append(source) + res.file_basepath[source] = res.base_path + to_zip += res.repo_files + for source in to_zip: + if source: + zip_file.write( + source, + join(prefix, loc, + relpath(source, res.file_basepath[source]))) + for source in res.lib_builds: + target_dir, _ = splitext(source) + dest = join(prefix, loc, + relpath(target_dir, res.file_basepath[source]), + ".bld", "bldrc") + zip_file.write(source, dest) @@ -223,8 +222,13 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None, macros=macros) files.append(config_header) if zip_proj: + for resource in resource_dict.values(): + for label, res in resource.features.iteritems(): + if label not in toolchain.target.features: + resource.add(res) if isinstance(zip_proj, basestring): - zip_export(join(export_path, zip_proj), name, resource_dict, files, inc_repos) + zip_export(join(export_path, zip_proj), name, resource_dict, files, + inc_repos) else: zip_export(zip_proj, name, resource_dict, files, inc_repos)