1
- import re
1
+ """
2
+ mbed SDK
3
+ Copyright (c) 2016-2019 ARM Limited
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
2
10
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ """
17
+ import re
18
+ import os
19
+ import json
20
+ from collections import namedtuple
21
+ from tools .targets import TARGET_MAP
3
22
from os .path import join , exists
4
23
from os import makedirs , remove
5
24
import shutil
25
+ from copy import deepcopy
6
26
7
27
from tools .export .makefile import Makefile , GccArm , Armc5 , IAR
8
28
29
+ _eclipse_defs = os .path .join (
30
+ os .path .dirname (os .path .abspath (__file__ )), 'cdt_definitions.json' )
31
+
32
+ with open (_eclipse_defs , 'r' ) as f :
33
+ _CONFIGS_OPTIONS = json .load (f )
34
+
35
+ supported_launches = ['debug' , 'program' , 'erase' ]
36
+
9
37
class Eclipse (Makefile ):
10
38
"""Generic Eclipse project. Intended to be subclassed by classes that
11
39
specify a type of Makefile.
12
40
"""
41
+ def get_target_config (self , ctx , configuration ):
42
+ """Retrieve info from cdt_definitions.json"""
43
+ tgt = deepcopy (TARGET_MAP [self .target ])
44
+ defaults = deepcopy (_CONFIGS_OPTIONS ['default' ])
45
+ eclipse_config = deepcopy (defaults ['generic' ])
46
+ if configuration in defaults :
47
+ eclipse_config .update (defaults [configuration ])
48
+
49
+ target_specific = _CONFIGS_OPTIONS ['targets' ]
50
+ if tgt .name in target_specific :
51
+ eclipse_config .update (target_specific [tgt .name ]['generic' ])
52
+ if configuration in target_specific [tgt .name ]:
53
+ eclipse_config .update (target_specific [tgt .name ][configuration ])
54
+
55
+ return eclipse_config
56
+
13
57
def generate (self ):
14
58
"""Generate Makefile, .cproject & .project Eclipse project file,
15
- py_ocd_settings launch file, and software link .p2f file
59
+ pyocd_settings launch files for both GNU ARM Eclipse and
60
+ GNU MCU Eclipse plug-ins, and software link .p2f file
16
61
"""
17
62
super (Eclipse , self ).generate ()
18
63
starting_dot = re .compile (r'(^[.]/|^[.]$)' )
@@ -25,15 +70,30 @@ def generate(self):
25
70
'include_paths' : [starting_dot .sub ('%s/' % self .project_name , inc ) for inc in self .resources .inc_dirs ],
26
71
'load_exe' : str (self .LOAD_EXE ).lower ()
27
72
}
28
-
73
+
74
+ launch_cfgs = {}
75
+ for launch_name in supported_launches :
76
+ launch = deepcopy (ctx )
77
+ launch .update ({'device' : self .get_target_config (ctx , launch_name )})
78
+ launch_cfgs [launch_name ] = launch
79
+
29
80
if not exists (join (self .export_dir ,'eclipse-extras' )):
30
81
makedirs (join (self .export_dir ,'eclipse-extras' ))
31
82
83
+ for launch_name , ctx in launch_cfgs .items ():
84
+ # Generate launch configurations for former GNU ARM Eclipse plug-in
85
+ self .gen_file ('cdt/%s' % 'pyocd_settings_gnu_arm.tmpl' , ctx , join ('eclipse-extras' ,
86
+ '{target}_{project}_{conf}_pyocd_settings.launch' .format (
87
+ target = self .target ,
88
+ project = self .project_name ,
89
+ conf = launch_name )))
90
+ # Generate launch configurations for GNU MCU Eclipse plug-in
91
+ self .gen_file ('cdt/%s' % 'pyocd_settings_gnu_mcu.tmpl' , ctx , join ('eclipse-extras' ,
92
+ '{target}_{project}_{conf}.launch' .format (
93
+ target = self .target ,
94
+ project = self .project_name ,
95
+ conf = launch_name )))
32
96
33
- self .gen_file ('cdt/pyocd_settings.tmpl' , ctx ,
34
- join ('eclipse-extras' ,
35
- '{target}_pyocd_{project}_settings.launch' .format (target = self .target ,
36
- project = self .project_name )))
37
97
self .gen_file ('cdt/necessary_software.tmpl' , ctx ,
38
98
join ('eclipse-extras' ,'necessary_software.p2f' ))
39
99
0 commit comments