Clone of official tools

Revision:
14:ee1b877e6839
Parent:
13:ab47a20b66f0
Child:
17:04753e1e329d
--- a/build_api.py	Thu Jul 14 20:21:19 2016 +0100
+++ b/build_api.py	Thu Jul 14 20:37:27 2016 +0100
@@ -31,7 +31,8 @@
 from tools.paths import MBED_TARGETS_PATH, MBED_LIBRARIES, MBED_API, MBED_HAL, MBED_COMMON
 from tools.targets import TARGET_NAMES, TARGET_MAP
 from tools.libraries import Library
-from tools.toolchains import TOOLCHAIN_CLASSES
+from tools.toolchains import TOOLCHAIN_CLASSES, mbedToolchain
+from tools.build_profiles import find_build_profile, get_toolchain_profile
 from jinja2 import FileSystemLoader
 from jinja2.environment import Environment
 from tools.config import Config
@@ -155,6 +156,27 @@
         except KeyError:
             raise KeyError("Target '%s' not found" % target)
 
+    # Find build system profile
+    profile = None
+    for path in src_paths:
+        profile = find_build_profile(path) or profile
+
+    if profile:
+        def init_hook(self):
+            profile_data = get_toolchain_profile(self.name, profile)
+            if not profile_data:
+                return
+            self.info("Using toolchain %s profile %s" % (self.name, profile))
+            
+
+            for k,v in profile_data.items():
+                if self.flags.has_key(k):
+                    self.flags[k] = v
+                else:
+                    setattr(self, k, v)
+
+        mbedToolchain.init = init_hook
+
     # Toolchain instance
     try:
         toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose)