From e239549585d89c86ff8d9556f7681c81d9e466a5 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Thu, 7 Mar 2019 14:02:31 -0600 Subject: [PATCH 1/8] Fixing path comparisons on Windows --- tools/test/config/config_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/test/config/config_test.py b/tools/test/config/config_test.py index 9e3564c2af..82058ab043 100644 --- a/tools/test/config/config_test.py +++ b/tools/test/config/config_test.py @@ -19,6 +19,8 @@ import os import json import pytest from mock import patch +from hypothesis import given +from hypothesis.strategies import sampled_from from os.path import join, isfile, dirname, abspath, normpath from tools.build_api import get_config from tools.targets import set_targets_json_location From 3b4a463dce85afdb56b4d5894d9aecefe7132322 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Wed, 6 Mar 2019 11:01:06 -0600 Subject: [PATCH 2/8] Move all generated file paths to FileRefs in the exporters. The FileRefs allow you to preserve the correct file paths in the online compiler. It also allows you to preserve the correct file paths for generated files. --- tools/export/__init__.py | 2 +- tools/export/exporters.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/export/__init__.py b/tools/export/__init__.py index 97531f59c4..0cac0c2e1f 100644 --- a/tools/export/__init__.py +++ b/tools/export/__init__.py @@ -164,7 +164,7 @@ def _inner_zip_export(resources, prj_files, inc_repos): to_zip = sum((resources.get_file_refs(ftype) for ftype in Resources.ALL_FILE_TYPES), []) - to_zip.extend(FileRef(basename(pfile), pfile) for pfile in prj_files) + to_zip.extend(prj_files) for dest, source in resources.get_file_refs(FileType.BLD_REF): target_dir, _ = splitext(dest) dest = join(target_dir, ".bld", "bldrc") diff --git a/tools/export/exporters.py b/tools/export/exporters.py index 45a3bae271..fc122085e9 100644 --- a/tools/export/exporters.py +++ b/tools/export/exporters.py @@ -27,7 +27,7 @@ import copy from tools.targets import TARGET_MAP from tools.utils import mkdir -from tools.resources import FileType +from tools.resources import FileType, FileRef """Just a template for subclassing""" @@ -95,9 +95,17 @@ class Exporter(object): resources.win_to_unix() self.resources = resources self.generated_files = [] + getting_started_name = "GettingStarted.html" + dot_mbed_name = ".mbed" self.static_files = ( - join(self.TEMPLATE_DIR, "GettingStarted.html"), - join(self.TEMPLATE_DIR, ".mbed"), + FileRef( + getting_started_name, + join(self.TEMPLATE_DIR, getting_started_name) + ), + FileRef( + dot_mbed_name, + join(self.TEMPLATE_DIR, dot_mbed_name) + ), ) self.builder_files_dict = {} self.add_config() @@ -204,7 +212,7 @@ class Exporter(object): mkdir(dirname(target_path)) logging.debug("Generating: %s", target_path) open(target_path, "w").write(target_text) - self.generated_files += [target_path] + self.generated_files += [FileRef(target_file, target_path)] def gen_file_nonoverwrite(self, template_file, data, target_file, **kwargs): """Generates or selectively appends a project file from a template""" @@ -221,7 +229,7 @@ class Exporter(object): else: logging.debug("Generating: %s", target_path) open(target_path, "w").write(target_text) - self.generated_files += [target_path] + self.generated_files += [FileRef(template_file, target_path)] def _gen_file_inner(self, template_file, data, target_file, **kwargs): """Generates a project file from a template using jinja""" @@ -237,7 +245,7 @@ class Exporter(object): target_path = join(self.export_dir, target_file) logging.debug("Generating: %s", target_path) open(target_path, "w").write(target_text) - self.generated_files += [target_path] + self.generated_files += [FileRef(target_file, target_path)] def make_key(self, src): """From a source file, extract group name From f1c98938c71cae03162a4564a7ee3d0ce70ae780 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Wed, 6 Mar 2019 11:02:25 -0600 Subject: [PATCH 3/8] Fix incorrect reference to a filetype --- tools/export/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/export/__init__.py b/tools/export/__init__.py index 0cac0c2e1f..40ff973616 100644 --- a/tools/export/__init__.py +++ b/tools/export/__init__.py @@ -170,7 +170,7 @@ def _inner_zip_export(resources, prj_files, inc_repos): dest = join(target_dir, ".bld", "bldrc") to_zip.append(FileRef(dest, source)) if inc_repos: - for dest, source in resources.get_file_refs(FileType.REPO_DIRS): + for dest, source in resources.get_file_refs(FileType.REPO_DIR): for root, _, files in walk(source): for repo_file in files: file_source = join(root, repo_file) From e65722262cf7cf46f34fbe398e46f43d393109fd Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Wed, 6 Mar 2019 11:30:14 -0600 Subject: [PATCH 4/8] Create template for missing generated vscode file This file was being dumped to the filesystem without going through the "gen_file" mechanism, thus it was missed when being zipped up. --- tools/export/vscode/c_cpp_properties.tmpl | 1 + 1 file changed, 1 insertion(+) create mode 100644 tools/export/vscode/c_cpp_properties.tmpl diff --git a/tools/export/vscode/c_cpp_properties.tmpl b/tools/export/vscode/c_cpp_properties.tmpl new file mode 100644 index 0000000000..e633d06f98 --- /dev/null +++ b/tools/export/vscode/c_cpp_properties.tmpl @@ -0,0 +1 @@ +{{cpp_props}} From 49ab2b83bd438883603d4492abb89a6bd0bdc361 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Wed, 6 Mar 2019 11:31:27 -0600 Subject: [PATCH 5/8] Add c_cpp_properties file to gen_files for zipping --- tools/export/vscode/__init__.py | 45 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/tools/export/vscode/__init__.py b/tools/export/vscode/__init__.py index 5765adbb95..79b2a08e6a 100644 --- a/tools/export/vscode/__init__.py +++ b/tools/export/vscode/__init__.py @@ -30,26 +30,6 @@ class VSCode(Makefile): """Generate Makefile and VSCode launch and task files """ super(VSCode, self).generate() - ctx = { - 'name': self.project_name, - 'elf_location': join('BUILD', self.project_name)+'.elf', - 'c_symbols': self.toolchain.get_symbols(), - 'asm_symbols': self.toolchain.get_symbols(True), - 'target': self.target, - 'include_paths': self.resources.inc_dirs, - 'load_exe': str(self.LOAD_EXE).lower() - } - - if not exists(join(self.export_dir, '.vscode')): - makedirs(join(self.export_dir, '.vscode')) - - config_files = ['launch', 'settings', 'tasks'] - for file in config_files: - if not exists('.vscode/%s.json' % file): - self.gen_file('vscode/%s.tmpl' % file, ctx, - '.vscode/%s.json' % file) - else: - print('Keeping existing %s.json' % file) # So.... I want all .h and .hpp files in self.resources.inc_dirs all_directories = [] @@ -96,8 +76,27 @@ class VSCode(Makefile): ] } - with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile: - json.dump(cpp_props, outfile, indent=4, separators=(',', ': ')) + ctx = { + 'name': self.project_name, + 'elf_location': join('BUILD', self.project_name)+'.elf', + 'c_symbols': self.toolchain.get_symbols(), + 'asm_symbols': self.toolchain.get_symbols(True), + 'target': self.target, + 'include_paths': self.resources.inc_dirs, + 'load_exe': str(self.LOAD_EXE).lower(), + 'cpp_props': json.dumps(cpp_props, indent=4, separators=(',', ': ')) + } + + if not exists(join(self.export_dir, '.vscode')): + makedirs(join(self.export_dir, '.vscode')) + + config_files = ['launch', 'settings', 'tasks', 'c_cpp_properties'] + for file in config_files: + if not exists('.vscode/%s.json' % file): + self.gen_file('vscode/%s.tmpl' % file, ctx, + '.vscode/%s.json' % file) + else: + print('Keeping existing %s.json' % file) @staticmethod def clean(_): @@ -116,5 +115,3 @@ class VSCodeArmc5(VSCode, Armc5): class VSCodeIAR(VSCode, IAR): LOAD_EXE = True NAME = "VSCode-IAR" - - From a0b9275ec4520ed0e9efc2d125b1913385ad349a Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Wed, 6 Mar 2019 12:11:34 -0600 Subject: [PATCH 6/8] Fixing copying of static filerefs --- tools/export/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/export/__init__.py b/tools/export/__init__.py index 40ff973616..54bfdb0690 100644 --- a/tools/export/__init__.py +++ b/tools/export/__init__.py @@ -242,10 +242,8 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None, # Extend src_paths wit libraries_paths if libraries_paths is not None: paths.extend(libraries_paths) - if not isinstance(src_paths, dict): src_paths = {"": paths} - # Export Directory if not exists(export_path): makedirs(export_path) @@ -293,7 +291,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None, files + list(exporter.static_files), inc_repos, notify) else: for static_file in exporter.static_files: - if not exists(join(export_path, basename(static_file))): - copyfile(static_file, join(export_path, basename(static_file))) + if not exists(join(export_path, basename(static_file.name))): + copyfile(static_file.path, join(export_path, static_file.name)) return exporter From 381223a3294992f8fa0ed1022abecf1c8d704c24 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Wed, 6 Mar 2019 16:21:52 -0600 Subject: [PATCH 7/8] Fixing zipped makefile exports. When zipping up projects, the makefile exporter brings every directory supplied as --source under the same directory, even if they are in a parent directory. There was some code that was clearing the leading "../" components. This lead to an empty string ("") being supplied to the "into_path" arg for "resources.add_directory". Since "" is not None, the default behavior to place it in the same directory was not being used. The extra "" caused a leading "/" to be added, making everything placed a the absolute root of the filesystem ("/"). Now we check to see if the "into_path" is an empty string and ignore it if that's the case. --- tools/resources/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/resources/__init__.py b/tools/resources/__init__.py index 46727769e7..c131d217e7 100644 --- a/tools/resources/__init__.py +++ b/tools/resources/__init__.py @@ -500,7 +500,10 @@ class Resources(object): start_at = index + 1 break for n in range(start_at, len(components)): - parent_name = self._sep.join([into_path] + components[:n]) + parent_name_parts = components[:n] + if into_path: + parent_name_parts.insert(0, into_path) + parent_name = self._sep.join(parent_name_parts) parent_path = join(base_path, *components[:n]) yield FileRef(parent_name, parent_path) From 60910c049c9b333d120e7f0746d044e2a7a96675 Mon Sep 17 00:00:00 2001 From: Brian Daniels Date: Wed, 6 Mar 2019 16:32:08 -0600 Subject: [PATCH 8/8] Remove outdated projectfiles case for makefiles --- tools/export/makefile/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/export/makefile/__init__.py b/tools/export/makefile/__init__.py index 36fb4fd839..959ccafa34 100644 --- a/tools/export/makefile/__init__.py +++ b/tools/export/makefile/__init__.py @@ -103,10 +103,7 @@ class Makefile(Exporter): 'libraries': libraries, 'ld_sys_libs': sys_libs, 'hex_files': self.hex_files, - 'vpath': (["../../.."] - if (basename(dirname(dirname(self.export_dir))) - == "projectfiles") - else [".."]), + 'vpath': ([".."]), 'cc_cmd': basename(self.toolchain.cc[0]), 'cppc_cmd': basename(self.toolchain.cppc[0]), 'asm_cmd': basename(self.toolchain.asm[0]),