diff --git a/tools/export/__init__.py b/tools/export/__init__.py index 97531f59c4..54bfdb0690 100644 --- a/tools/export/__init__.py +++ b/tools/export/__init__.py @@ -164,13 +164,13 @@ 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") 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) @@ -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 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 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]), 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" - - 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}} 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) 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