Skip to content

Commit 7e42a9f

Browse files
committed
Merge pull request #107 from ScreamerBG/master
Exporter features
2 parents b2733e9 + b43e947 commit 7e42a9f

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

workspace_tools/export/exporters.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from contextlib import closing
66
from zipfile import ZipFile, ZIP_DEFLATED
77

8+
from workspace_tools.utils import mkdir
89
from workspace_tools.toolchains import TOOLCHAIN_CLASSES
910
from workspace_tools.targets import TARGET_MAP
1011

@@ -27,25 +28,35 @@ def get_toolchain(self):
2728
def __scan_and_copy(self, src_path, trg_path):
2829
resources = self.toolchain.scan_resources(src_path)
2930

30-
for r_type in ['headers', 's_sources', 'c_sources', 'cpp_sources', 'objects', 'libraries', 'linker_script']:
31+
for r_type in ['headers', 's_sources', 'c_sources', 'cpp_sources',
32+
'objects', 'libraries', 'linker_script',
33+
'lib_builds', 'lib_refs', 'repo_files']:
3134
r = getattr(resources, r_type)
3235
if r:
3336
self.toolchain.copy_files(r, trg_path, rel_path=src_path)
34-
return resources.lib_builds
37+
return resources
3538

3639
def scan_and_copy_resources(self, prj_path, trg_path):
3740
# Copy only the file for the required target and toolchain
3841
lib_builds = []
42+
repo_dirs = []
3943
for src in ['lib', 'src']:
40-
lib_builds.extend(self.__scan_and_copy(join(prj_path, src), trg_path))
44+
resources = self.__scan_and_copy(join(prj_path, src), trg_path)
45+
lib_builds.extend(resources.lib_builds)
46+
repo_dirs.extend(resources.repo_dirs)
4147

4248
# The libraries builds
4349
for bld in lib_builds:
4450
build_url = open(bld).read().strip()
4551
lib_data = self.build_url_resolver(build_url)
4652
lib_path = lib_data['path'].rstrip('\\/')
4753
self.__scan_and_copy(lib_path, join(trg_path, lib_data['name']))
48-
54+
# create .hg dir in build dir so it's ignored when versioning
55+
hgdir = join(trg_path, lib_data['name'], '.hg')
56+
mkdir(hgdir)
57+
fhandle = file(join(hgdir, 'keep.me'), 'a')
58+
fhandle.close()
59+
4960
# Final scan of the actual exported resources
5061
self.resources = self.toolchain.scan_resources(trg_path)
5162
self.resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)

workspace_tools/toolchains/__init__.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def __init__(self, base_path=None):
5959

6060
# mbed special files
6161
self.lib_builds = []
62+
self.lib_refs = []
63+
64+
self.repo_dirs = []
65+
self.repo_files = []
6266

6367
self.linker_script = None
6468

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

7781
self.lib_builds += resources.lib_builds
82+
self.lib_refs += resources.lib_refs
83+
84+
self.repo_dirs += resources.repo_dirs
85+
self.repo_files += resources.repo_files
7886

7987
if resources.linker_script is not None:
8088
self.linker_script = resources.linker_script
8189

8290
def relative_to(self, base, dot=False):
8391
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
84-
'cpp_sources', 'lib_dirs', 'objects', 'libraries']:
92+
'cpp_sources', 'lib_dirs', 'objects', 'libraries',
93+
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files']:
8594
v = [rel_path(f, base, dot) for f in getattr(self, field)]
8695
setattr(self, field, v)
8796
if self.linker_script is not None:
8897
self.linker_script = rel_path(self.linker_script, base, dot)
8998

9099
def win_to_unix(self):
91100
for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
92-
'cpp_sources', 'lib_dirs', 'objects', 'libraries']:
101+
'cpp_sources', 'lib_dirs', 'objects', 'libraries',
102+
'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files']:
93103
v = [f.replace('\\', '/') for f in getattr(self, field)]
94104
setattr(self, field, v)
95105
if self.linker_script is not None:
@@ -244,6 +254,11 @@ def scan_resources(self, path):
244254
for root, dirs, files in walk(path):
245255
# Remove ignored directories
246256
for d in copy(dirs):
257+
if d == '.hg':
258+
dir_path = join(root, d)
259+
resources.repo_dirs.append(dir_path)
260+
resources.repo_files.extend(self.scan_repository(dir_path))
261+
247262
if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
248263
(d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
249264
(d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN'])):
@@ -281,11 +296,30 @@ def scan_resources(self, path):
281296
elif ext == self.LINKER_EXT:
282297
resources.linker_script = file_path
283298

299+
elif ext == '.lib':
300+
resources.lib_refs.append(file_path)
284301
elif ext == '.bld':
285302
resources.lib_builds.append(file_path)
303+
elif file == '.hgignore':
304+
resources.repo_files.append(file_path)
286305

287306
return resources
288-
307+
308+
def scan_repository(self, path):
309+
resources = []
310+
311+
for root, dirs, files in walk(path):
312+
# Remove ignored directories
313+
for d in copy(dirs):
314+
if d == '.' or d == '..':
315+
dirs.remove(d)
316+
317+
for file in files:
318+
file_path = join(root, file)
319+
resources.append(file_path)
320+
321+
return resources
322+
289323
def copy_files(self, files_paths, trg_path, rel_path=None):
290324
# Handle a single file
291325
if type(files_paths) != ListType: files_paths = [files_paths]

0 commit comments

Comments
 (0)