mirror of https://github.com/ARMmbed/mbed-os.git
Added support to export mbed special .bld and .lib files
Added support to export repositories for seamless offline setuppull/107/head
parent
b2733e9b9a
commit
b43e947c3b
|
@ -5,6 +5,7 @@ from jinja2 import Template
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
from zipfile import ZipFile, ZIP_DEFLATED
|
from zipfile import ZipFile, ZIP_DEFLATED
|
||||||
|
|
||||||
|
from workspace_tools.utils import mkdir
|
||||||
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
|
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
|
||||||
from workspace_tools.targets import TARGET_MAP
|
from workspace_tools.targets import TARGET_MAP
|
||||||
|
|
||||||
|
@ -27,17 +28,22 @@ class Exporter():
|
||||||
def __scan_and_copy(self, src_path, trg_path):
|
def __scan_and_copy(self, src_path, trg_path):
|
||||||
resources = self.toolchain.scan_resources(src_path)
|
resources = self.toolchain.scan_resources(src_path)
|
||||||
|
|
||||||
for r_type in ['headers', 's_sources', 'c_sources', 'cpp_sources', 'objects', 'libraries', 'linker_script']:
|
for r_type in ['headers', 's_sources', 'c_sources', 'cpp_sources',
|
||||||
|
'objects', 'libraries', 'linker_script',
|
||||||
|
'lib_builds', 'lib_refs', 'repo_files']:
|
||||||
r = getattr(resources, r_type)
|
r = getattr(resources, r_type)
|
||||||
if r:
|
if r:
|
||||||
self.toolchain.copy_files(r, trg_path, rel_path=src_path)
|
self.toolchain.copy_files(r, trg_path, rel_path=src_path)
|
||||||
return resources.lib_builds
|
return resources
|
||||||
|
|
||||||
def scan_and_copy_resources(self, prj_path, trg_path):
|
def scan_and_copy_resources(self, prj_path, trg_path):
|
||||||
# Copy only the file for the required target and toolchain
|
# Copy only the file for the required target and toolchain
|
||||||
lib_builds = []
|
lib_builds = []
|
||||||
|
repo_dirs = []
|
||||||
for src in ['lib', 'src']:
|
for src in ['lib', 'src']:
|
||||||
lib_builds.extend(self.__scan_and_copy(join(prj_path, src), trg_path))
|
resources = self.__scan_and_copy(join(prj_path, src), trg_path)
|
||||||
|
lib_builds.extend(resources.lib_builds)
|
||||||
|
repo_dirs.extend(resources.repo_dirs)
|
||||||
|
|
||||||
# The libraries builds
|
# The libraries builds
|
||||||
for bld in lib_builds:
|
for bld in lib_builds:
|
||||||
|
@ -45,7 +51,12 @@ class Exporter():
|
||||||
lib_data = self.build_url_resolver(build_url)
|
lib_data = self.build_url_resolver(build_url)
|
||||||
lib_path = lib_data['path'].rstrip('\\/')
|
lib_path = lib_data['path'].rstrip('\\/')
|
||||||
self.__scan_and_copy(lib_path, join(trg_path, lib_data['name']))
|
self.__scan_and_copy(lib_path, join(trg_path, lib_data['name']))
|
||||||
|
# create .hg dir in build dir so it's ignored when versioning
|
||||||
|
hgdir = join(trg_path, lib_data['name'], '.hg')
|
||||||
|
mkdir(hgdir)
|
||||||
|
fhandle = file(join(hgdir, 'keep.me'), 'a')
|
||||||
|
fhandle.close()
|
||||||
|
|
||||||
# Final scan of the actual exported resources
|
# Final scan of the actual exported resources
|
||||||
self.resources = self.toolchain.scan_resources(trg_path)
|
self.resources = self.toolchain.scan_resources(trg_path)
|
||||||
self.resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
|
self.resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
|
||||||
|
|
|
@ -59,6 +59,10 @@ class Resources:
|
||||||
|
|
||||||
# mbed special files
|
# mbed special files
|
||||||
self.lib_builds = []
|
self.lib_builds = []
|
||||||
|
self.lib_refs = []
|
||||||
|
|
||||||
|
self.repo_dirs = []
|
||||||
|
self.repo_files = []
|
||||||
|
|
||||||
self.linker_script = None
|
self.linker_script = None
|
||||||
|
|
||||||
|
@ -75,13 +79,18 @@ class Resources:
|
||||||
self.libraries += resources.libraries
|
self.libraries += resources.libraries
|
||||||
|
|
||||||
self.lib_builds += resources.lib_builds
|
self.lib_builds += resources.lib_builds
|
||||||
|
self.lib_refs += resources.lib_refs
|
||||||
|
|
||||||
|
self.repo_dirs += resources.repo_dirs
|
||||||
|
self.repo_files += resources.repo_files
|
||||||
|
|
||||||
if resources.linker_script is not None:
|
if resources.linker_script is not None:
|
||||||
self.linker_script = resources.linker_script
|
self.linker_script = resources.linker_script
|
||||||
|
|
||||||
def relative_to(self, base, dot=False):
|
def relative_to(self, base, dot=False):
|
||||||
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
|
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
|
||||||
'cpp_sources', 'lib_dirs', 'objects', 'libraries']:
|
'cpp_sources', 'lib_dirs', 'objects', 'libraries',
|
||||||
|
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files']:
|
||||||
v = [rel_path(f, base, dot) for f in getattr(self, field)]
|
v = [rel_path(f, base, dot) for f in getattr(self, field)]
|
||||||
setattr(self, field, v)
|
setattr(self, field, v)
|
||||||
if self.linker_script is not None:
|
if self.linker_script is not None:
|
||||||
|
@ -89,7 +98,8 @@ class Resources:
|
||||||
|
|
||||||
def win_to_unix(self):
|
def win_to_unix(self):
|
||||||
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
|
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
|
||||||
'cpp_sources', 'lib_dirs', 'objects', 'libraries']:
|
'cpp_sources', 'lib_dirs', 'objects', 'libraries',
|
||||||
|
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files']:
|
||||||
v = [f.replace('\\', '/') for f in getattr(self, field)]
|
v = [f.replace('\\', '/') for f in getattr(self, field)]
|
||||||
setattr(self, field, v)
|
setattr(self, field, v)
|
||||||
if self.linker_script is not None:
|
if self.linker_script is not None:
|
||||||
|
@ -244,6 +254,11 @@ class mbedToolchain:
|
||||||
for root, dirs, files in walk(path):
|
for root, dirs, files in walk(path):
|
||||||
# Remove ignored directories
|
# Remove ignored directories
|
||||||
for d in copy(dirs):
|
for d in copy(dirs):
|
||||||
|
if d == '.hg':
|
||||||
|
dir_path = join(root, d)
|
||||||
|
resources.repo_dirs.append(dir_path)
|
||||||
|
resources.repo_files.extend(self.scan_repository(dir_path))
|
||||||
|
|
||||||
if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
|
if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
|
||||||
(d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
|
(d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
|
||||||
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN'])):
|
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN'])):
|
||||||
|
@ -281,11 +296,30 @@ class mbedToolchain:
|
||||||
elif ext == self.LINKER_EXT:
|
elif ext == self.LINKER_EXT:
|
||||||
resources.linker_script = file_path
|
resources.linker_script = file_path
|
||||||
|
|
||||||
|
elif ext == '.lib':
|
||||||
|
resources.lib_refs.append(file_path)
|
||||||
elif ext == '.bld':
|
elif ext == '.bld':
|
||||||
resources.lib_builds.append(file_path)
|
resources.lib_builds.append(file_path)
|
||||||
|
elif file == '.hgignore':
|
||||||
|
resources.repo_files.append(file_path)
|
||||||
|
|
||||||
return resources
|
return resources
|
||||||
|
|
||||||
|
def scan_repository(self, path):
|
||||||
|
resources = []
|
||||||
|
|
||||||
|
for root, dirs, files in walk(path):
|
||||||
|
# Remove ignored directories
|
||||||
|
for d in copy(dirs):
|
||||||
|
if d == '.' or d == '..':
|
||||||
|
dirs.remove(d)
|
||||||
|
|
||||||
|
for file in files:
|
||||||
|
file_path = join(root, file)
|
||||||
|
resources.append(file_path)
|
||||||
|
|
||||||
|
return resources
|
||||||
|
|
||||||
def copy_files(self, files_paths, trg_path, rel_path=None):
|
def copy_files(self, files_paths, trg_path, rel_path=None):
|
||||||
# Handle a single file
|
# Handle a single file
|
||||||
if type(files_paths) != ListType: files_paths = [files_paths]
|
if type(files_paths) != ListType: files_paths = [files_paths]
|
||||||
|
|
Loading…
Reference in New Issue