Skip to content

Exporter features #107

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 1 commit into from
Nov 15, 2013
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
19 changes: 15 additions & 4 deletions workspace_tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED

from workspace_tools.utils import mkdir
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
from workspace_tools.targets import TARGET_MAP

Expand All @@ -27,25 +28,35 @@ def get_toolchain(self):
def __scan_and_copy(self, src_path, trg_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)
if r:
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):
# Copy only the file for the required target and toolchain
lib_builds = []
repo_dirs = []
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
for bld in lib_builds:
build_url = open(bld).read().strip()
lib_data = self.build_url_resolver(build_url)
lib_path = lib_data['path'].rstrip('\\/')
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
self.resources = self.toolchain.scan_resources(trg_path)
self.resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
Expand Down
40 changes: 37 additions & 3 deletions workspace_tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def __init__(self, base_path=None):

# mbed special files
self.lib_builds = []
self.lib_refs = []

self.repo_dirs = []
self.repo_files = []

self.linker_script = None

Expand All @@ -75,21 +79,27 @@ def add(self, resources):
self.libraries += resources.libraries

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:
self.linker_script = resources.linker_script

def relative_to(self, base, dot=False):
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)]
setattr(self, field, v)
if self.linker_script is not None:
self.linker_script = rel_path(self.linker_script, base, dot)

def win_to_unix(self):
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)]
setattr(self, field, v)
if self.linker_script is not None:
Expand Down Expand Up @@ -244,6 +254,11 @@ def scan_resources(self, path):
for root, dirs, files in walk(path):
# Remove ignored directories
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
(d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN'])):
Expand Down Expand Up @@ -281,11 +296,30 @@ def scan_resources(self, path):
elif ext == self.LINKER_EXT:
resources.linker_script = file_path

elif ext == '.lib':
resources.lib_refs.append(file_path)
elif ext == '.bld':
resources.lib_builds.append(file_path)
elif file == '.hgignore':
resources.repo_files.append(file_path)

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):
# Handle a single file
if type(files_paths) != ListType: files_paths = [files_paths]
Expand Down