Skip to content

Commit fba8156

Browse files
author
Cruz Monrreal
authored
Merge pull request #9967 from bridadan/fix_vscode_makefile_zip
Fix for projects exported as a zip file (affects online compiler)
2 parents dc1198b + 60910c0 commit fba8156

File tree

7 files changed

+47
-41
lines changed

7 files changed

+47
-41
lines changed

tools/export/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ def _inner_zip_export(resources, prj_files, inc_repos):
164164
to_zip = sum((resources.get_file_refs(ftype) for ftype
165165
in Resources.ALL_FILE_TYPES),
166166
[])
167-
to_zip.extend(FileRef(basename(pfile), pfile) for pfile in prj_files)
167+
to_zip.extend(prj_files)
168168
for dest, source in resources.get_file_refs(FileType.BLD_REF):
169169
target_dir, _ = splitext(dest)
170170
dest = join(target_dir, ".bld", "bldrc")
171171
to_zip.append(FileRef(dest, source))
172172
if inc_repos:
173-
for dest, source in resources.get_file_refs(FileType.REPO_DIRS):
173+
for dest, source in resources.get_file_refs(FileType.REPO_DIR):
174174
for root, _, files in walk(source):
175175
for repo_file in files:
176176
file_source = join(root, repo_file)
@@ -242,10 +242,8 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
242242
# Extend src_paths wit libraries_paths
243243
if libraries_paths is not None:
244244
paths.extend(libraries_paths)
245-
246245
if not isinstance(src_paths, dict):
247246
src_paths = {"": paths}
248-
249247
# Export Directory
250248
if not exists(export_path):
251249
makedirs(export_path)
@@ -293,7 +291,7 @@ def export_project(src_paths, export_path, target, ide, libraries_paths=None,
293291
files + list(exporter.static_files), inc_repos, notify)
294292
else:
295293
for static_file in exporter.static_files:
296-
if not exists(join(export_path, basename(static_file))):
297-
copyfile(static_file, join(export_path, basename(static_file)))
294+
if not exists(join(export_path, basename(static_file.name))):
295+
copyfile(static_file.path, join(export_path, static_file.name))
298296

299297
return exporter

tools/export/exporters.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from tools.targets import TARGET_MAP
2929
from tools.utils import mkdir
30-
from tools.resources import FileType
30+
from tools.resources import FileType, FileRef
3131

3232
"""Just a template for subclassing"""
3333

@@ -95,9 +95,17 @@ def __init__(self, target, export_dir, project_name, toolchain,
9595
resources.win_to_unix()
9696
self.resources = resources
9797
self.generated_files = []
98+
getting_started_name = "GettingStarted.html"
99+
dot_mbed_name = ".mbed"
98100
self.static_files = (
99-
join(self.TEMPLATE_DIR, "GettingStarted.html"),
100-
join(self.TEMPLATE_DIR, ".mbed"),
101+
FileRef(
102+
getting_started_name,
103+
join(self.TEMPLATE_DIR, getting_started_name)
104+
),
105+
FileRef(
106+
dot_mbed_name,
107+
join(self.TEMPLATE_DIR, dot_mbed_name)
108+
),
101109
)
102110
self.builder_files_dict = {}
103111
self.add_config()
@@ -204,7 +212,7 @@ def gen_file(self, template_file, data, target_file, **kwargs):
204212
mkdir(dirname(target_path))
205213
logging.debug("Generating: %s", target_path)
206214
open(target_path, "w").write(target_text)
207-
self.generated_files += [target_path]
215+
self.generated_files += [FileRef(target_file, target_path)]
208216

209217
def gen_file_nonoverwrite(self, template_file, data, target_file, **kwargs):
210218
"""Generates or selectively appends a project file from a template"""
@@ -221,7 +229,7 @@ def gen_file_nonoverwrite(self, template_file, data, target_file, **kwargs):
221229
else:
222230
logging.debug("Generating: %s", target_path)
223231
open(target_path, "w").write(target_text)
224-
self.generated_files += [target_path]
232+
self.generated_files += [FileRef(template_file, target_path)]
225233

226234
def _gen_file_inner(self, template_file, data, target_file, **kwargs):
227235
"""Generates a project file from a template using jinja"""
@@ -237,7 +245,7 @@ def _gen_file_inner(self, template_file, data, target_file, **kwargs):
237245
target_path = join(self.export_dir, target_file)
238246
logging.debug("Generating: %s", target_path)
239247
open(target_path, "w").write(target_text)
240-
self.generated_files += [target_path]
248+
self.generated_files += [FileRef(target_file, target_path)]
241249

242250
def make_key(self, src):
243251
"""From a source file, extract group name

tools/export/makefile/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ def generate(self):
103103
'libraries': libraries,
104104
'ld_sys_libs': sys_libs,
105105
'hex_files': self.hex_files,
106-
'vpath': (["../../.."]
107-
if (basename(dirname(dirname(self.export_dir)))
108-
== "projectfiles")
109-
else [".."]),
106+
'vpath': ([".."]),
110107
'cc_cmd': basename(self.toolchain.cc[0]),
111108
'cppc_cmd': basename(self.toolchain.cppc[0]),
112109
'asm_cmd': basename(self.toolchain.asm[0]),

tools/export/vscode/__init__.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,6 @@ def generate(self):
3030
"""Generate Makefile and VSCode launch and task files
3131
"""
3232
super(VSCode, self).generate()
33-
ctx = {
34-
'name': self.project_name,
35-
'elf_location': join('BUILD', self.project_name)+'.elf',
36-
'c_symbols': self.toolchain.get_symbols(),
37-
'asm_symbols': self.toolchain.get_symbols(True),
38-
'target': self.target,
39-
'include_paths': self.resources.inc_dirs,
40-
'load_exe': str(self.LOAD_EXE).lower()
41-
}
42-
43-
if not exists(join(self.export_dir, '.vscode')):
44-
makedirs(join(self.export_dir, '.vscode'))
45-
46-
config_files = ['launch', 'settings', 'tasks']
47-
for file in config_files:
48-
if not exists('.vscode/%s.json' % file):
49-
self.gen_file('vscode/%s.tmpl' % file, ctx,
50-
'.vscode/%s.json' % file)
51-
else:
52-
print('Keeping existing %s.json' % file)
5333

5434
# So.... I want all .h and .hpp files in self.resources.inc_dirs
5535
all_directories = []
@@ -96,8 +76,27 @@ def generate(self):
9676
]
9777
}
9878

99-
with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile:
100-
json.dump(cpp_props, outfile, indent=4, separators=(',', ': '))
79+
ctx = {
80+
'name': self.project_name,
81+
'elf_location': join('BUILD', self.project_name)+'.elf',
82+
'c_symbols': self.toolchain.get_symbols(),
83+
'asm_symbols': self.toolchain.get_symbols(True),
84+
'target': self.target,
85+
'include_paths': self.resources.inc_dirs,
86+
'load_exe': str(self.LOAD_EXE).lower(),
87+
'cpp_props': json.dumps(cpp_props, indent=4, separators=(',', ': '))
88+
}
89+
90+
if not exists(join(self.export_dir, '.vscode')):
91+
makedirs(join(self.export_dir, '.vscode'))
92+
93+
config_files = ['launch', 'settings', 'tasks', 'c_cpp_properties']
94+
for file in config_files:
95+
if not exists('.vscode/%s.json' % file):
96+
self.gen_file('vscode/%s.tmpl' % file, ctx,
97+
'.vscode/%s.json' % file)
98+
else:
99+
print('Keeping existing %s.json' % file)
101100

102101
@staticmethod
103102
def clean(_):
@@ -116,5 +115,3 @@ class VSCodeArmc5(VSCode, Armc5):
116115
class VSCodeIAR(VSCode, IAR):
117116
LOAD_EXE = True
118117
NAME = "VSCode-IAR"
119-
120-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{cpp_props}}

tools/resources/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ def _all_parents(self, file_path, base_path, into_path):
500500
start_at = index + 1
501501
break
502502
for n in range(start_at, len(components)):
503-
parent_name = self._sep.join([into_path] + components[:n])
503+
parent_name_parts = components[:n]
504+
if into_path:
505+
parent_name_parts.insert(0, into_path)
506+
parent_name = self._sep.join(parent_name_parts)
504507
parent_path = join(base_path, *components[:n])
505508
yield FileRef(parent_name, parent_path)
506509

tools/test/config/config_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import json
2020
import pytest
2121
from mock import patch
22+
from hypothesis import given
23+
from hypothesis.strategies import sampled_from
2224
from os.path import join, isfile, dirname, abspath, normpath
2325
from tools.build_api import get_config
2426
from tools.targets import set_targets_json_location

0 commit comments

Comments
 (0)