the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Revision:
29:1210849dba19
Parent:
27:5461402c33f8
Child:
30:f12ce67666d0
--- a/toolchains/__init__.py	Mon Aug 29 10:55:42 2016 +0100
+++ b/toolchains/__init__.py	Mon Aug 29 11:18:36 2016 +0100
@@ -188,6 +188,23 @@
 }
 
 
+def check_toolchain_path(function):
+    """Check if the path to toolchain is valid. Exit if not.
+    Use this function as a decorator.  Causes a system exit if the path does
+    not exist. Execute the function as normal if the path does exist.
+
+    Positional arguments:
+    function -- the function to decorate
+    """
+    def perform_check(self, *args, **kwargs):
+        if not exists(self.toolchain_path) and not exists(self.toolchain_path+'.exe'):
+            error_string = 'Could not find executable for %s.\n Currently ' \
+                           'set search path: %s'% (self.name, self.toolchain_path)
+            raise Exception(error_string)
+        return function(self, *args, **kwargs)
+    return perform_check
+
+
 class mbedToolchain:
     # Verbose logging
     VERBOSE = True
@@ -230,7 +247,8 @@
         self.macros = macros or []
 
         # Macros generated from toolchain and target rules/features
-        self.symbols = None
+        self.asm_symbols = None
+        self.cxx_symbols = None
 
         # Labels generated from toolchain and target rules/features (used for selective build)
         self.labels = None
@@ -372,36 +390,50 @@
         event['toolchain'] = self
         return self.notify_fun(event, self.silent)
 
-    def get_symbols(self):
-        if self.symbols is None:
-            # Target and Toolchain symbols
-            labels = self.get_labels()
-            self.symbols = ["TARGET_%s" % t for t in labels['TARGET']]
-            self.symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
+    def get_symbols(self, for_asm=False):
+        if for_asm:
+            if self.asm_symbols is None:
+                self.asm_symbols = []
+
+                # Cortex CPU symbols
+                if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
+                    self.asm_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
 
-            # Cortex CPU symbols
-            if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
-                self.symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
+                # Add target's symbols
+                self.asm_symbols += self.target.macros
+                # Add extra symbols passed via 'macros' parameter
+                self.asm_symbols += self.macros
+            return list(set(self.asm_symbols))  # Return only unique symbols
+        else:
+            if self.cxx_symbols is None:
+                # Target and Toolchain symbols
+                labels = self.get_labels()
+                self.cxx_symbols = ["TARGET_%s" % t for t in labels['TARGET']]
+                self.cxx_symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
 
-            # Symbols defined by the on-line build.system
-            self.symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
-            if MBED_ORG_USER:
-                self.symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
+                # Cortex CPU symbols
+                if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
+                    self.cxx_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
+
+                # Symbols defined by the on-line build.system
+                self.cxx_symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
+                if MBED_ORG_USER:
+                    self.cxx_symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
 
-            # Add target's symbols
-            self.symbols += self.target.macros
-            # Add target's hardware
-            self.symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
-            # Add target's features
-            self.symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
-            # Add extra symbols passed via 'macros' parameter
-            self.symbols += self.macros
+                # Add target's symbols
+                self.cxx_symbols += self.target.macros
+                # Add target's hardware
+                self.cxx_symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
+                # Add target's features
+                self.cxx_symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
+                # Add extra symbols passed via 'macros' parameter
+                self.cxx_symbols += self.macros
 
-            # Form factor variables
-            if hasattr(self.target, 'supported_form_factors'):
-                self.symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
+                # Form factor variables
+                if hasattr(self.target, 'supported_form_factors'):
+                    self.cxx_symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
 
-        return list(set(self.symbols))  # Return only unique symbols
+            return list(set(self.cxx_symbols))  # Return only unique symbols
 
     # Extend the internal list of macros
     def add_macros(self, new_macros):
@@ -687,6 +719,7 @@
 
     # THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
     # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
+    @check_toolchain_path
     def compile_sources(self, resources, build_path, inc_dirs=None):
         # Web IDE progress bar for project build
         files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
@@ -796,7 +829,7 @@
                     except ToolException, err:
                         if p._taskqueue.queue:
                             p._taskqueue.queue.clear()
-                            sleep(0.1)
+                            sleep(0.5)
                         p.terminate()
                         p.join()
                         raise ToolException(err)
@@ -885,6 +918,7 @@
             else:
                 raise ToolException(_stderr)
 
+    @check_toolchain_path
     def build_library(self, objects, dir, name):
         needed_update = False
         lib = self.STD_LIB_NAME % name
@@ -896,6 +930,7 @@
 
         return needed_update
 
+    @check_toolchain_path
     def link_program(self, r, tmp_path, name):
         needed_update = False
         ext = 'bin'
@@ -1020,7 +1055,7 @@
         # Here we return memory statistics structure (constructed after
         # call to generate_output) which contains raw data in bytes
         # about sections + summary
-        return memap.get_memory_summary()
+        return memap.mem_summary
 
     # Set the configuration data
     def set_config_data(self, config_data):