mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #9967 from bridadan/fix_vscode_makefile_zip
Fix for projects exported as a zip file (affects online compiler)pull/10019/head
commit
fba8156bda
|
@ -164,13 +164,13 @@ def _inner_zip_export(resources, prj_files, inc_repos):
|
||||||
to_zip = sum((resources.get_file_refs(ftype) for ftype
|
to_zip = sum((resources.get_file_refs(ftype) for ftype
|
||||||
in Resources.ALL_FILE_TYPES),
|
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):
|
for dest, source in resources.get_file_refs(FileType.BLD_REF):
|
||||||
target_dir, _ = splitext(dest)
|
target_dir, _ = splitext(dest)
|
||||||
dest = join(target_dir, ".bld", "bldrc")
|
dest = join(target_dir, ".bld", "bldrc")
|
||||||
to_zip.append(FileRef(dest, source))
|
to_zip.append(FileRef(dest, source))
|
||||||
if inc_repos:
|
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 root, _, files in walk(source):
|
||||||
for repo_file in files:
|
for repo_file in files:
|
||||||
file_source = join(root, repo_file)
|
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
|
# Extend src_paths wit libraries_paths
|
||||||
if libraries_paths is not None:
|
if libraries_paths is not None:
|
||||||
paths.extend(libraries_paths)
|
paths.extend(libraries_paths)
|
||||||
|
|
||||||
if not isinstance(src_paths, dict):
|
if not isinstance(src_paths, dict):
|
||||||
src_paths = {"": paths}
|
src_paths = {"": paths}
|
||||||
|
|
||||||
# Export Directory
|
# Export Directory
|
||||||
if not exists(export_path):
|
if not exists(export_path):
|
||||||
makedirs(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)
|
files + list(exporter.static_files), inc_repos, notify)
|
||||||
else:
|
else:
|
||||||
for static_file in exporter.static_files:
|
for static_file in exporter.static_files:
|
||||||
if not exists(join(export_path, basename(static_file))):
|
if not exists(join(export_path, basename(static_file.name))):
|
||||||
copyfile(static_file, join(export_path, basename(static_file)))
|
copyfile(static_file.path, join(export_path, static_file.name))
|
||||||
|
|
||||||
return exporter
|
return exporter
|
||||||
|
|
|
@ -27,7 +27,7 @@ import copy
|
||||||
|
|
||||||
from tools.targets import TARGET_MAP
|
from tools.targets import TARGET_MAP
|
||||||
from tools.utils import mkdir
|
from tools.utils import mkdir
|
||||||
from tools.resources import FileType
|
from tools.resources import FileType, FileRef
|
||||||
|
|
||||||
"""Just a template for subclassing"""
|
"""Just a template for subclassing"""
|
||||||
|
|
||||||
|
@ -95,9 +95,17 @@ class Exporter(object):
|
||||||
resources.win_to_unix()
|
resources.win_to_unix()
|
||||||
self.resources = resources
|
self.resources = resources
|
||||||
self.generated_files = []
|
self.generated_files = []
|
||||||
|
getting_started_name = "GettingStarted.html"
|
||||||
|
dot_mbed_name = ".mbed"
|
||||||
self.static_files = (
|
self.static_files = (
|
||||||
join(self.TEMPLATE_DIR, "GettingStarted.html"),
|
FileRef(
|
||||||
join(self.TEMPLATE_DIR, ".mbed"),
|
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.builder_files_dict = {}
|
||||||
self.add_config()
|
self.add_config()
|
||||||
|
@ -204,7 +212,7 @@ class Exporter(object):
|
||||||
mkdir(dirname(target_path))
|
mkdir(dirname(target_path))
|
||||||
logging.debug("Generating: %s", target_path)
|
logging.debug("Generating: %s", target_path)
|
||||||
open(target_path, "w").write(target_text)
|
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):
|
def gen_file_nonoverwrite(self, template_file, data, target_file, **kwargs):
|
||||||
"""Generates or selectively appends a project file from a template"""
|
"""Generates or selectively appends a project file from a template"""
|
||||||
|
@ -221,7 +229,7 @@ class Exporter(object):
|
||||||
else:
|
else:
|
||||||
logging.debug("Generating: %s", target_path)
|
logging.debug("Generating: %s", target_path)
|
||||||
open(target_path, "w").write(target_text)
|
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):
|
def _gen_file_inner(self, template_file, data, target_file, **kwargs):
|
||||||
"""Generates a project file from a template using jinja"""
|
"""Generates a project file from a template using jinja"""
|
||||||
|
@ -237,7 +245,7 @@ class Exporter(object):
|
||||||
target_path = join(self.export_dir, target_file)
|
target_path = join(self.export_dir, target_file)
|
||||||
logging.debug("Generating: %s", target_path)
|
logging.debug("Generating: %s", target_path)
|
||||||
open(target_path, "w").write(target_text)
|
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):
|
def make_key(self, src):
|
||||||
"""From a source file, extract group name
|
"""From a source file, extract group name
|
||||||
|
|
|
@ -103,10 +103,7 @@ class Makefile(Exporter):
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'ld_sys_libs': sys_libs,
|
'ld_sys_libs': sys_libs,
|
||||||
'hex_files': self.hex_files,
|
'hex_files': self.hex_files,
|
||||||
'vpath': (["../../.."]
|
'vpath': ([".."]),
|
||||||
if (basename(dirname(dirname(self.export_dir)))
|
|
||||||
== "projectfiles")
|
|
||||||
else [".."]),
|
|
||||||
'cc_cmd': basename(self.toolchain.cc[0]),
|
'cc_cmd': basename(self.toolchain.cc[0]),
|
||||||
'cppc_cmd': basename(self.toolchain.cppc[0]),
|
'cppc_cmd': basename(self.toolchain.cppc[0]),
|
||||||
'asm_cmd': basename(self.toolchain.asm[0]),
|
'asm_cmd': basename(self.toolchain.asm[0]),
|
||||||
|
|
|
@ -30,26 +30,6 @@ class VSCode(Makefile):
|
||||||
"""Generate Makefile and VSCode launch and task files
|
"""Generate Makefile and VSCode launch and task files
|
||||||
"""
|
"""
|
||||||
super(VSCode, self).generate()
|
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
|
# So.... I want all .h and .hpp files in self.resources.inc_dirs
|
||||||
all_directories = []
|
all_directories = []
|
||||||
|
@ -96,8 +76,27 @@ class VSCode(Makefile):
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(join(self.export_dir, '.vscode', 'c_cpp_properties.json'), 'w') as outfile:
|
ctx = {
|
||||||
json.dump(cpp_props, outfile, indent=4, separators=(',', ': '))
|
'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
|
@staticmethod
|
||||||
def clean(_):
|
def clean(_):
|
||||||
|
@ -116,5 +115,3 @@ class VSCodeArmc5(VSCode, Armc5):
|
||||||
class VSCodeIAR(VSCode, IAR):
|
class VSCodeIAR(VSCode, IAR):
|
||||||
LOAD_EXE = True
|
LOAD_EXE = True
|
||||||
NAME = "VSCode-IAR"
|
NAME = "VSCode-IAR"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{{cpp_props}}
|
|
@ -500,7 +500,10 @@ class Resources(object):
|
||||||
start_at = index + 1
|
start_at = index + 1
|
||||||
break
|
break
|
||||||
for n in range(start_at, len(components)):
|
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])
|
parent_path = join(base_path, *components[:n])
|
||||||
yield FileRef(parent_name, parent_path)
|
yield FileRef(parent_name, parent_path)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ import os
|
||||||
import json
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
from hypothesis import given
|
||||||
|
from hypothesis.strategies import sampled_from
|
||||||
from os.path import join, isfile, dirname, abspath, normpath
|
from os.path import join, isfile, dirname, abspath, normpath
|
||||||
from tools.build_api import get_config
|
from tools.build_api import get_config
|
||||||
from tools.targets import set_targets_json_location
|
from tools.targets import set_targets_json_location
|
||||||
|
|
Loading…
Reference in New Issue