1
1
"""
2
2
mbed SDK
3
- Copyright (c) 2011-2017 ARM Limited
3
+ Copyright (c) 2011-2016 ARM Limited
4
4
5
5
Licensed under the Apache License, Version 2.0 (the "License");
6
6
you may not use this file except in compliance with the License.
14
14
See the License for the specific language governing permissions and
15
15
limitations under the License.
16
16
17
- Title: GNU ARM Eclipse (http://gnuarmeclipse.github.io) exporter.
17
+ Title: MCUXpresso exporter.
18
18
19
19
Description: Creates a managed build project that can be imported by
20
- the GNU ARM Eclipse plug-ins.
20
+ the MCUXpresso IDE from NXP
21
21
22
- Author: Liviu Ionescu <[email protected] >
22
+ Based on GNU ARM Eclipse Exporter from Liviu Ionescu <[email protected] >
23
+ modified for MCUXpresso by Johannes Stratmann <[email protected] >
23
24
"""
24
25
25
- import os
26
- import copy
27
- import tempfile
28
- import shutil
29
26
import copy
30
27
31
- from subprocess import call , Popen , PIPE
32
- from os .path import splitext , basename , relpath , dirname , exists , join , dirname
28
+ from os .path import splitext , basename , exists
33
29
from random import randint
34
- from json import load
35
30
36
- from tools .export .exporters import Exporter , apply_supported_whitelist
37
- from tools .options import list_profiles
31
+ from tools .export .gnuarmeclipse import GNUARMEclipse
32
+ from tools .export . exporters import apply_supported_whitelist
38
33
from tools .targets import TARGET_MAP
39
34
from tools .utils import NotSupportedException
40
35
from tools .build_api import prepare_toolchain
41
36
37
+
42
38
# =============================================================================
43
39
44
40
@@ -65,66 +61,21 @@ def id(self):
65
61
"LPC4088Code.binary_hook"
66
62
])
67
63
68
- class MCUXpresso (Exporter ):
64
+ class MCUXpresso (GNUARMEclipse ):
69
65
NAME = 'MCUXpresso'
70
66
TOOLCHAIN = 'GCC_ARM'
71
67
68
+ MBED_CONFIG_HEADER_SUPPORTED = True
69
+
72
70
@classmethod
73
71
def is_target_supported (cls , target_name ):
74
- target = TARGET_MAP [target_name ]
75
- return apply_supported_whitelist (
76
- cls .TOOLCHAIN , POST_BINARY_WHITELIST , target )
77
-
78
- # override
79
- @property
80
- def flags (self ):
81
- """Returns a dictionary of toolchain flags.
82
- Keys of the dictionary are:
83
- cxx_flags - c++ flags
84
- c_flags - c flags
85
- ld_flags - linker flags
86
- asm_flags - assembler flags
87
- common_flags - common options
88
-
89
- The difference from the parent function is that it does not
90
- add macro definitions, since they are passed separately.
91
- """
92
-
93
- config_header = self .toolchain .get_config_header ()
94
- flags = {key + "_flags" : copy .deepcopy (value ) for key , value
95
- in self .toolchain .flags .iteritems ()}
96
- if config_header :
97
- config_header = relpath (config_header ,
98
- self .resources .file_basepath [config_header ])
99
- flags ['c_flags' ] += self .toolchain .get_config_option (config_header )
100
- flags ['cxx_flags' ] += self .toolchain .get_config_option (
101
- config_header )
102
- return flags
103
-
104
- def toolchain_flags (self , toolchain ):
105
- """Returns a dictionary of toolchain flags.
106
- Keys of the dictionary are:
107
- cxx_flags - c++ flags
108
- c_flags - c flags
109
- ld_flags - linker flags
110
- asm_flags - assembler flags
111
- common_flags - common options
112
-
113
- The difference from the above is that it takes a parameter.
114
- """
115
-
116
- # Note: use the config options from the currently selected toolchain.
117
- config_header = self .toolchain .get_config_header ()
118
-
119
- flags = {key + "_flags" : copy .deepcopy (value ) for key , value
120
- in toolchain .flags .iteritems ()}
121
- if config_header :
122
- config_header = relpath (config_header ,
123
- self .resources .file_basepath [config_header ])
124
- header_options = self .toolchain .get_config_option (config_header )
125
- flags ['c_flags' ] += header_options
126
- flags ['cxx_flags' ] += header_options
127
- return flags
72
+ # targes suppoerted when .cproject templatefile exists
73
+ if exists ('./export/mcuxpresso/' + target_name + '_cproject.tmpl' ):
74
+ target = TARGET_MAP [target_name ]
75
+ return apply_supported_whitelist (
76
+ cls .TOOLCHAIN , POST_BINARY_WHITELIST , target )
77
+ else :
78
+ return False
128
79
129
80
# override
130
81
def generate (self ):
@@ -378,93 +329,6 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
378
329
# Seems like something went wrong.
379
330
return - 1
380
331
381
- # -------------------------------------------------------------------------
382
-
383
- @staticmethod
384
- def get_all_profiles ():
385
- tools_path = dirname (dirname (dirname (__file__ )))
386
- file_names = [join (tools_path , "profiles" , fn ) for fn in os .listdir (
387
- join (tools_path , "profiles" )) if fn .endswith (".json" )]
388
-
389
- # print file_names
390
-
391
- profile_names = [basename (fn ).replace (".json" , "" )
392
- for fn in file_names ]
393
- # print profile_names
394
-
395
- profiles = {}
396
-
397
- for fn in file_names :
398
- content = load (open (fn ))
399
- profile_name = basename (fn ).replace (".json" , "" )
400
- profiles [profile_name ] = content
401
-
402
- return profiles
403
-
404
- # -------------------------------------------------------------------------
405
- # Process source files/folders exclusions.
406
-
407
- def compute_exclusions (self ):
408
- """
409
- With the project root as the only source folder known to CDT,
410
- based on the list of source files, compute the folders to not
411
- be included in the build.
412
-
413
- The steps are:
414
- - get the list of source folders, as dirname(source_file)
415
- - compute the top folders (subfolders of the project folder)
416
- - iterate all subfolders and add them to a tree, with all
417
- nodes markes as 'not used'
418
- - iterate the source folders and mark them as 'used' in the
419
- tree, including all intermediate nodes
420
- - recurse the tree and collect all unused folders; descend
421
- the hierarchy only for used nodes
422
- """
423
- source_folders = [self .filter_dot (s ) for s in set (dirname (
424
- src ) for src in self .resources .c_sources + self .resources .cpp_sources + self .resources .s_sources )]
425
-
426
- self .excluded_folders = set (self .resources .ignored_dirs ) - set (self .resources .inc_dirs )
427
- print 'Source folders: {0}, with {1} exclusions' .format (len (source_folders ), len (self .excluded_folders ))
428
-
429
-
430
- # -------------------------------------------------------------------------
431
-
432
- @staticmethod
433
- def filter_dot (str ):
434
- """
435
- Remove the './' prefix, if present.
436
- This function assumes that resources.win_to_unix()
437
- replaced all windows backslashes with slashes.
438
- """
439
- if str == None :
440
- return None
441
- if str [:2 ] == './' :
442
- return str [2 :]
443
- return str
444
-
445
- # -------------------------------------------------------------------------
446
-
447
- def dump_tree (self , nodes , depth = 0 ):
448
- for k in nodes .keys ():
449
- node = nodes [k ]
450
- parent_name = node ['parent' ][
451
- 'name' ] if 'parent' in node .keys () else ''
452
- print ' ' * depth , node ['name' ], node ['is_used' ], parent_name
453
- if len (node ['children' ].keys ()) != 0 :
454
- self .dump_tree (node ['children' ], depth + 1 )
455
-
456
- def dump_paths (self , nodes , depth = 0 ):
457
- for k in nodes .keys ():
458
- node = nodes [k ]
459
- parts = []
460
- while True :
461
- parts .insert (0 , node ['name' ])
462
- if 'parent' not in node :
463
- break
464
- node = node ['parent' ]
465
- path = '/' .join (parts )
466
- print path , nodes [k ]['is_used' ]
467
- self .dump_paths (nodes [k ]['children' ], depth + 1 )
468
332
469
333
# -------------------------------------------------------------------------
470
334
@@ -892,27 +756,3 @@ def process_options(self, opts, flags_in):
892
756
print 'cxx_flags' , flags ['cxx_flags' ]
893
757
print 'ld_flags' , flags ['ld_flags' ]
894
758
895
- @staticmethod
896
- def find_options (lst , option ):
897
- tmp = [str for str in lst if str .startswith (option )]
898
- if len (tmp ) > 0 :
899
- return tmp [0 ]
900
- else :
901
- return None
902
-
903
- @staticmethod
904
- def find_options (lst , prefix ):
905
- other = ''
906
- opts = [str for str in lst if str .startswith (prefix )]
907
- if len (opts ) > 0 :
908
- for opt in opts :
909
- other += ' ' + opt
910
- MCUXpresso .remove_option (lst , opt )
911
- return other .strip ()
912
-
913
- @staticmethod
914
- def remove_option (lst , option ):
915
- if option in lst :
916
- lst .remove (option )
917
-
918
- # =============================================================================
0 commit comments