7
7
from jinja2 .environment import Environment
8
8
from contextlib import closing
9
9
from zipfile import ZipFile , ZIP_DEFLATED
10
+ from operator import add
10
11
11
12
from tools .utils import mkdir
12
13
from tools .toolchains import TOOLCHAIN_CLASSES
16
17
from project_generator .project import Project
17
18
from project_generator .settings import ProjectSettings
18
19
20
+ from tools .config import Config
21
+
19
22
class OldLibrariesException (Exception ): pass
20
23
21
24
class Exporter (object ):
@@ -31,6 +34,7 @@ def __init__(self, target, inputDir, program_name, build_url_resolver, extra_sym
31
34
jinja_loader = FileSystemLoader (os .path .dirname (os .path .abspath (__file__ )))
32
35
self .jinja_environment = Environment (loader = jinja_loader )
33
36
self .extra_symbols = extra_symbols
37
+ self .config_macros = []
34
38
35
39
def get_toolchain (self ):
36
40
return self .TOOLCHAIN
@@ -46,24 +50,40 @@ def __scan_and_copy(self, src_path, trg_path):
46
50
self .toolchain .copy_files (r , trg_path , rel_path = src_path )
47
51
return resources
48
52
53
+ @staticmethod
54
+ def _get_dir_grouped_files (files ):
55
+ """ Get grouped files based on the dirname """
56
+ files_grouped = {}
57
+ for file in files :
58
+ rel_path = os .path .relpath (file , os .getcwd ())
59
+ dir_path = os .path .dirname (rel_path )
60
+ if dir_path == '' :
61
+ # all files within the current dir go into Source_Files
62
+ dir_path = 'Source_Files'
63
+ if not dir_path in files_grouped .keys ():
64
+ files_grouped [dir_path ] = []
65
+ files_grouped [dir_path ].append (file )
66
+ return files_grouped
67
+
49
68
def progen_get_project_data (self ):
50
69
""" Get ProGen project data """
51
70
# provide default data, some tools don't require any additional
52
71
# tool specific settings
53
- sources = []
72
+ code_files = []
54
73
for r_type in ['c_sources' , 'cpp_sources' , 's_sources' ]:
55
74
for file in getattr (self .resources , r_type ):
56
- sources .append (file )
75
+ code_files .append (file )
76
+
77
+ sources_files = code_files + self .resources .hex_files + self .resources .objects + \
78
+ self .resources .libraries
79
+ sources_grouped = Exporter ._get_dir_grouped_files (sources_files )
80
+ headers_grouped = Exporter ._get_dir_grouped_files (self .resources .headers )
57
81
58
82
project_data = {
59
83
'common' : {
60
- 'sources' : {
61
- 'Source Files' : sources + self .resources .hex_files +
62
- self .resources .objects + self .resources .libraries ,
63
- },
64
- 'includes' : {
65
- 'Include Files' : self .resources .headers ,
66
- },
84
+ 'sources' : sources_grouped ,
85
+ 'includes' : headers_grouped ,
86
+ 'build_dir' :'.build' ,
67
87
'target' : [TARGET_MAP [self .target ].progen ['target' ]],
68
88
'macros' : self .get_symbols (),
69
89
'export_dir' : [self .inputDir ],
@@ -73,7 +93,7 @@ def progen_get_project_data(self):
73
93
return project_data
74
94
75
95
def progen_gen_file (self , tool_name , project_data ):
76
- """ Generate project using ProGen Project API """
96
+ """" Generate project using ProGen Project API """
77
97
settings = ProjectSettings ()
78
98
project = Project (self .program_name , [project_data ], settings )
79
99
# TODO: Fix this, the inc_dirs are not valid (our scripts copy files), therefore progen
@@ -95,17 +115,20 @@ def __scan_all(self, path):
95
115
96
116
return resources
97
117
98
- def scan_and_copy_resources (self , prj_path , trg_path ):
118
+ def scan_and_copy_resources (self , prj_paths , trg_path , relative = False ):
99
119
# Copy only the file for the required target and toolchain
100
120
lib_builds = []
121
+ # Create the configuration object
122
+ cfg = Config (self .target , prj_paths )
101
123
for src in ['lib' , 'src' ]:
102
- resources = self .__scan_and_copy (join (prj_path , src ), trg_path )
124
+ resources = reduce ( add , [ self .__scan_and_copy (join (path , src ), trg_path ) for path in prj_paths ] )
103
125
lib_builds .extend (resources .lib_builds )
104
126
105
127
# The repository files
106
128
for repo_dir in resources .repo_dirs :
107
129
repo_files = self .__scan_all (repo_dir )
108
- self .toolchain .copy_files (repo_files , trg_path , rel_path = join (prj_path , src ))
130
+ for path in proj_paths :
131
+ self .toolchain .copy_files (repo_files , trg_path , rel_path = join (path , src ))
109
132
110
133
# The libraries builds
111
134
for bld in lib_builds :
@@ -120,9 +143,17 @@ def scan_and_copy_resources(self, prj_path, trg_path):
120
143
fhandle = file (join (hgdir , 'keep.me' ), 'a' )
121
144
fhandle .close ()
122
145
123
- # Final scan of the actual exported resources
124
- self .resources = self .toolchain .scan_resources (trg_path )
125
- self .resources .relative_to (trg_path , self .DOT_IN_RELATIVE_PATH )
146
+ if not relative :
147
+ # Final scan of the actual exported resources
148
+ self .resources = self .toolchain .scan_resources (trg_path )
149
+ self .resources .relative_to (trg_path , self .DOT_IN_RELATIVE_PATH )
150
+ else :
151
+ # use the prj_dir (source, not destination)
152
+ self .resources = reduce (add , [self .toolchain .scan_resources (path ) for path in prj_paths ])
153
+ # Add all JSON files discovered during scanning to the configuration object
154
+ cfg .add_config_files (self .resources .json_files )
155
+ # Get data from the configuration system
156
+ self .config_macros = cfg .get_config_data_macros ()
126
157
# Check the existence of a binary build of the mbed library for the desired target
127
158
# This prevents exporting the mbed libraries from source
128
159
# if not self.toolchain.mbed_libs:
@@ -141,7 +172,7 @@ def get_symbols(self, add_extra_symbols=True):
141
172
""" This function returns symbols which must be exported.
142
173
Please add / overwrite symbols in each exporter separately
143
174
"""
144
- symbols = self .toolchain .get_symbols ()
175
+ symbols = self .toolchain .get_symbols () + self . config_macros
145
176
# We have extra symbols from e.g. libraries, we want to have them also added to export
146
177
if add_extra_symbols :
147
178
if self .extra_symbols is not None :
0 commit comments