Skip to content

Fix for projects exported as a zip file (affects online compiler) #9967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions tools/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
20 changes: 14 additions & 6 deletions tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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"""

Expand Down Expand Up @@ -95,9 +95,17 @@ def __init__(self, target, export_dir, project_name, toolchain,
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()
Expand Down Expand Up @@ -204,7 +212,7 @@ def gen_file(self, template_file, data, target_file, **kwargs):
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"""
Expand All @@ -221,7 +229,7 @@ def gen_file_nonoverwrite(self, template_file, data, target_file, **kwargs):
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"""
Expand All @@ -237,7 +245,7 @@ def _gen_file_inner(self, template_file, data, target_file, **kwargs):
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
Expand Down
5 changes: 1 addition & 4 deletions tools/export/makefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ def generate(self):
'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]),
Expand Down
45 changes: 21 additions & 24 deletions tools/export/vscode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ def generate(self):
"""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 = []
Expand Down Expand Up @@ -96,8 +76,27 @@ def generate(self):
]
}

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(_):
Expand All @@ -116,5 +115,3 @@ class VSCodeArmc5(VSCode, Armc5):
class VSCodeIAR(VSCode, IAR):
LOAD_EXE = True
NAME = "VSCode-IAR"


1 change: 1 addition & 0 deletions tools/export/vscode/c_cpp_properties.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{cpp_props}}
5 changes: 4 additions & 1 deletion tools/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,10 @@ def _all_parents(self, file_path, base_path, into_path):
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theotherjimmy I believe this is the correct fix (see my commit message). If you have any concerns about this let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct. That's the fix.

parent_path = join(base_path, *components[:n])
yield FileRef(parent_name, parent_path)

Expand Down
2 changes: 2 additions & 0 deletions tools/test/config/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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
Expand Down