From f80b62ed001e9997a80200ea048b7cbb5945c885 Mon Sep 17 00:00:00 2001 From: 0xc0170 Date: Mon, 18 Jul 2016 15:09:07 +0100 Subject: [PATCH 1/2] exporter - fix TARGETS property via descriptors Fixes #2183 issue. --- tools/export/exporters.py | 8 ++++++++ tools/export/iar.py | 14 +++++++------- tools/export/uvision4.py | 14 +++++++------- tools/export/uvision5.py | 14 +++++++------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/tools/export/exporters.py b/tools/export/exporters.py index 2273bf0482..9ccdfa7926 100644 --- a/tools/export/exporters.py +++ b/tools/export/exporters.py @@ -23,6 +23,14 @@ class OldLibrariesException(Exception): pass class FailedBuildException(Exception) : pass +# Exporter descriptor for TARGETS +# TARGETS as class attribute for backward compatibility (allows: if in Exporter.TARGETS) +class ExporterTargetsProperty(object): + def __init__(self, func): + self.func = func + def __get__(self, inst, cls): + return self.func(cls) + class Exporter(object): TEMPLATE_DIR = dirname(__file__) DOT_IN_RELATIVE_PATH = False diff --git a/tools/export/iar.py b/tools/export/iar.py index 2329fdfd16..79fc4a2fd3 100644 --- a/tools/export/iar.py +++ b/tools/export/iar.py @@ -18,7 +18,7 @@ import re import os from project_generator_definitions.definitions import ProGenDef -from tools.export.exporters import Exporter +from tools.export.exporters import Exporter, ExporterTargetsProperty from tools.targets import TARGET_MAP, TARGET_NAMES # If you wish to add a new target, add it to project_generator_definitions, and then @@ -35,19 +35,19 @@ class IAREmbeddedWorkbench(Exporter): MBED_CONFIG_HEADER_SUPPORTED = True - @property - def TARGETS(self): - if not hasattr(self, "_targets_supported"): - self._targets_supported = [] + @ExporterTargetsProperty + def TARGETS(cls): + if not hasattr(cls, "_targets_supported"): + cls._targets_supported = [] for target in TARGET_NAMES: try: if (ProGenDef('iar').is_supported(str(TARGET_MAP[target])) or ProGenDef('iar').is_supported(TARGET_MAP[target].progen['target'])): - self._targets_supported.append(target) + cls._targets_supported.append(target) except AttributeError: # target is not supported yet continue - return self._targets_supported + return cls._targets_supported def generate(self, progen_build=False): """ Generates the project files """ diff --git a/tools/export/uvision4.py b/tools/export/uvision4.py index a46822f173..a3febd616a 100644 --- a/tools/export/uvision4.py +++ b/tools/export/uvision4.py @@ -17,7 +17,7 @@ limitations under the License. from os.path import basename, join, dirname from project_generator_definitions.definitions import ProGenDef -from tools.export.exporters import Exporter +from tools.export.exporters import Exporter, ExporterTargetsProperty from tools.targets import TARGET_MAP, TARGET_NAMES from tools.settings import ARM_INC @@ -36,19 +36,19 @@ class Uvision4(Exporter): MBED_CONFIG_HEADER_SUPPORTED = True - @property - def TARGETS(self): - if not hasattr(self, "_targets_supported"): - self._targets_supported = [] + @ExporterTargetsProperty + def TARGETS(cls): + if not hasattr(cls, "_targets_supported"): + cls._targets_supported = [] for target in TARGET_NAMES: try: if (ProGenDef('uvision').is_supported(str(TARGET_MAP[target])) or ProGenDef('uvision').is_supported(TARGET_MAP[target].progen['target'])): - self._targets_supported.append(target) + cls._targets_supported.append(target) except AttributeError: # target is not supported yet continue - return self._targets_supported + return cls._targets_supported def get_toolchain(self): return TARGET_MAP[self.target].default_toolchain diff --git a/tools/export/uvision5.py b/tools/export/uvision5.py index 75da61089c..bb6edfec8b 100644 --- a/tools/export/uvision5.py +++ b/tools/export/uvision5.py @@ -17,7 +17,7 @@ limitations under the License. from os.path import basename, join, dirname from project_generator_definitions.definitions import ProGenDef -from tools.export.exporters import Exporter +from tools.export.exporters import Exporter, ExporterTargetsProperty from tools.targets import TARGET_MAP, TARGET_NAMES from tools.settings import ARM_INC @@ -40,19 +40,19 @@ class Uvision5(Exporter): def __init__(self): self._targets = [] - @property - def TARGETS(self): - if not hasattr(self, "_targets_supported"): - self._targets_supported = [] + @ExporterTargetsProperty + def TARGETS(cls): + if not hasattr(cls, "_targets_supported"): + cls._targets_supported = [] for target in TARGET_NAMES: try: if (ProGenDef('uvision5').is_supported(str(TARGET_MAP[target])) or ProGenDef('uvision5').is_supported(TARGET_MAP[target].progen['target'])): - self._targets_supported.append(target) + cls._targets_supported.append(target) except AttributeError: # target is not supported yet continue - return self._targets_supported + return cls._targets_supported def get_toolchain(self): return TARGET_MAP[self.target].default_toolchain From 028f7228682921e7a2e82c85d93a8d6a54c55ace Mon Sep 17 00:00:00 2001 From: 0xc0170 Date: Mon, 18 Jul 2016 15:10:34 +0100 Subject: [PATCH 2/2] uvision5 - remove init, not used --- tools/export/uvision5.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/export/uvision5.py b/tools/export/uvision5.py index bb6edfec8b..543625a237 100644 --- a/tools/export/uvision5.py +++ b/tools/export/uvision5.py @@ -36,10 +36,6 @@ class Uvision5(Exporter): MBED_CONFIG_HEADER_SUPPORTED = True - # backward compatibility with our scripts - def __init__(self): - self._targets = [] - @ExporterTargetsProperty def TARGETS(cls): if not hasattr(cls, "_targets_supported"):