Skip to content

Commit f95265f

Browse files
committed
Exporters - progen TARGETS lazy evaluated
To speed up project.py, use @Property for TARGETS. When exporters are used, it would ask progen for all targets support (number of tools x number of targets), this takes a lot of time, thus lazily evaluated, and TARGETS are for backaward compatibility, not currently used by project.py but by other scripts to check if a target is supported. Profiling: ``` python tools\project.py -m K64F -i uvision -n MBED_10 -b Before the change: 1 0.000 0.000 0.010 0.010 definitions.py:113(get_tool_definition) 824 0.004 0.000 2.990 0.004 definitions.py:124(is_supported) 1 0.000 0.000 0.000 0.000 definitions.py:145(get_debugger) 1 0.002 0.002 0.044 0.044 definitions.py:15(<module>) 384 0.002 0.000 2.986 0.008 definitions.py:26(_load_record) 1 0.000 0.000 0.000 0.000 definitions.py:32(ProGenMcus) 992 0.055 0.000 1.959 0.002 definitions.py:34(__init__) 1376 0.002 0.000 0.003 0.000 definitions.py:40(get_mcus) 384 0.001 0.000 1.070 0.003 definitions.py:43(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:50(ProGenTargets) 992 0.000 0.000 0.000 0.000 definitions.py:52(__init__) 1196 0.002 0.000 0.004 0.000 definitions.py:55(get_targets) 204 0.001 0.000 1.922 0.009 definitions.py:58(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:67(get_debugger) 1 0.000 0.000 0.000 0.000 definitions.py:74(ProGenDef) 992 0.008 0.000 1.973 0.002 definitions.py:83(__init__) Days : 0 Hours : 0 Minutes : 0 Seconds : 4 Milliseconds : 723 Ticks : 47237302 TotalDays : 5.46728032407407E-05 TotalHours : 0.00131214727777778 TotalMinutes : 0.0787288366666667 TotalSeconds : 4.7237302 TotalMilliseconds : 4723.7302 After the change: 1 0.000 0.000 0.010 0.010 definitions.py:113(get_tool_definition) 2 0.000 0.000 0.025 0.012 definitions.py:124(is_supported) 1 0.000 0.000 0.000 0.000 definitions.py:145(get_debugger) 1 0.002 0.002 0.042 0.042 definitions.py:15(<module>) 3 0.000 0.000 0.035 0.012 definitions.py:26(_load_record) 1 0.000 0.000 0.000 0.000 definitions.py:32(ProGenMcus) 2 0.000 0.000 0.005 0.002 definitions.py:34(__init__) 5 0.000 0.000 0.000 0.000 definitions.py:40(get_mcus) 3 0.000 0.000 0.000 0.000 definitions.py:43(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:50(ProGenTargets) 2 0.000 0.000 0.000 0.000 definitions.py:52(__init__) 5 0.000 0.000 0.000 0.000 definitions.py:55(get_targets) 3 0.000 0.000 0.035 0.012 definitions.py:58(get_mcu_record) 1 0.000 0.000 0.000 0.000 definitions.py:67(get_debugger) 1 0.000 0.000 0.000 0.000 definitions.py:74(ProGenDef) 2 0.000 0.000 0.005 0.003 definitions.py:83(__init__) Days : 0 Hours : 0 Minutes : 0 Seconds : 1 Milliseconds : 178 Ticks : 11780618 TotalDays : 1.3634974537037E-05 TotalHours : 0.000327239388888889 TotalMinutes : 0.0196343633333333 TotalSeconds : 1.1780618 TotalMilliseconds : 1178.0618 ```
1 parent 967b45a commit f95265f

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

tools/export/iar.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ class IAREmbeddedWorkbench(Exporter):
3535

3636
MBED_CONFIG_HEADER_SUPPORTED = True
3737

38-
# backward compatibility with our scripts
39-
TARGETS = []
40-
for target in TARGET_NAMES:
41-
try:
42-
if (ProGenDef('iar').is_supported(str(TARGET_MAP[target])) or
43-
ProGenDef('iar').is_supported(TARGET_MAP[target].progen['target'])):
44-
TARGETS.append(target)
45-
except AttributeError:
46-
# target is not supported yet
47-
continue
38+
@property
39+
def TARGETS(self):
40+
if not hasattr(self, "_targets_supported"):
41+
self._targets_supported = []
42+
for target in TARGET_NAMES:
43+
try:
44+
if (ProGenDef('iar').is_supported(str(TARGET_MAP[target])) or
45+
ProGenDef('iar').is_supported(TARGET_MAP[target].progen['target'])):
46+
self._targets_supported.append(target)
47+
except AttributeError:
48+
# target is not supported yet
49+
continue
50+
return self._targets_supported
4851

4952
def generate(self):
5053
""" Generates the project files """

tools/export/uvision4.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ class Uvision4(Exporter):
3636

3737
MBED_CONFIG_HEADER_SUPPORTED = True
3838

39-
# backward compatibility with our scripts
40-
TARGETS = []
41-
for target in TARGET_NAMES:
42-
try:
43-
if (ProGenDef('uvision').is_supported(str(TARGET_MAP[target])) or
44-
ProGenDef('uvision').is_supported(TARGET_MAP[target].progen['target'])):
45-
TARGETS.append(target)
46-
except AttributeError:
47-
# target is not supported yet
48-
continue
39+
@property
40+
def TARGETS(self):
41+
if not hasattr(self, "_targets_supported"):
42+
self._targets_supported = []
43+
for target in TARGET_NAMES:
44+
try:
45+
if (ProGenDef('uvision').is_supported(str(TARGET_MAP[target])) or
46+
ProGenDef('uvision').is_supported(TARGET_MAP[target].progen['target'])):
47+
self._targets_supported.append(target)
48+
except AttributeError:
49+
# target is not supported yet
50+
continue
51+
return self._targets_supported
4952

5053
def get_toolchain(self):
5154
return TARGET_MAP[self.target].default_toolchain

tools/export/uvision5.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,22 @@ class Uvision5(Exporter):
3737
MBED_CONFIG_HEADER_SUPPORTED = True
3838

3939
# backward compatibility with our scripts
40-
TARGETS = []
41-
for target in TARGET_NAMES:
42-
try:
43-
if (ProGenDef('uvision5').is_supported(str(TARGET_MAP[target])) or
44-
ProGenDef('uvision5').is_supported(TARGET_MAP[target].progen['target'])):
45-
TARGETS.append(target)
46-
except AttributeError:
47-
# target is not supported yet
48-
continue
40+
def __init__(self):
41+
self._targets = []
42+
43+
@property
44+
def TARGETS(self):
45+
if not hasattr(self, "_targets_supported"):
46+
self._targets_supported = []
47+
for target in TARGET_NAMES:
48+
try:
49+
if (ProGenDef('uvision5').is_supported(str(TARGET_MAP[target])) or
50+
ProGenDef('uvision5').is_supported(TARGET_MAP[target].progen['target'])):
51+
self._targets_supported.append(target)
52+
except AttributeError:
53+
# target is not supported yet
54+
continue
55+
return self._targets_supported
4956

5057
def get_toolchain(self):
5158
return TARGET_MAP[self.target].default_toolchain

0 commit comments

Comments
 (0)