Clone of official tools

Files at this revision

API Documentation at this revision

Comitter:
screamer
Date:
Fri Jul 15 15:28:09 2016 +0100
Parent:
19:3604ee113e2d
Child:
21:4fdf0dd04f6f
Commit message:
Build system related fixes

Changed in this revision

export/uvision4.py Show annotated file Show diff for this revision Revisions of this file
export/uvision5.py Show annotated file Show diff for this revision Revisions of this file
settings.py Show annotated file Show diff for this revision Revisions of this file
test_api.py Show annotated file Show diff for this revision Revisions of this file
toolchains/__init__.py Show annotated file Show diff for this revision Revisions of this file
toolchains/arm.py Show annotated file Show diff for this revision Revisions of this file
toolchains/gcc.py Show annotated file Show diff for this revision Revisions of this file
toolchains/iar.py Show annotated file Show diff for this revision Revisions of this file
--- a/export/uvision4.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/export/uvision4.py	Fri Jul 15 15:28:09 2016 +0100
@@ -19,7 +19,6 @@
 
 from tools.export.exporters import Exporter
 from tools.targets import TARGET_MAP, TARGET_NAMES
-from tools.settings import ARM_INC
 
 # If you wish to add a new target, add it to project_generator_definitions, and then
 # define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
@@ -76,8 +75,6 @@
         project_data['tool_specific']['uvision']['misc']['c_flags'] = list(set(self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags']))
         # not compatible with c99 flag set in the template
         project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--c99")
-        # ARM_INC is by default as system inclusion, not required for exported project
-        project_data['tool_specific']['uvision']['misc']['c_flags'].remove("-I \""+ARM_INC+"\"")
         # cpp is not required as it's implicit for cpp files
         project_data['tool_specific']['uvision']['misc']['c_flags'].remove("--cpp")
         # we want no-vla for only cxx, but it's also applied for C in IDE, thus we remove it
--- a/export/uvision5.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/export/uvision5.py	Fri Jul 15 15:28:09 2016 +0100
@@ -19,7 +19,6 @@
 
 from tools.export.exporters import Exporter
 from tools.targets import TARGET_MAP, TARGET_NAMES
-from tools.settings import ARM_INC
 
 # If you wish to add a new target, add it to project_generator_definitions, and then
 # define progen_target name in the target class (`` self.progen_target = 'my_target_name' ``)
@@ -74,8 +73,6 @@
         project_data['tool_specific']['uvision5']['misc']['asm_flags'] = list(set(self.progen_flags['asm_flags']))
         # cxx flags included, as uvision have them all in one tab
         project_data['tool_specific']['uvision5']['misc']['c_flags'] = list(set(self.progen_flags['common_flags'] + self.progen_flags['c_flags'] + self.progen_flags['cxx_flags']))
-        # ARM_INC is by default as system inclusion, not required for exported project
-        project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("-I \""+ARM_INC+"\"")
         # not compatible with c99 flag set in the template
         project_data['tool_specific']['uvision5']['misc']['c_flags'].remove("--c99")
         # cpp is not required as it's implicit for cpp files
--- a/settings.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/settings.py	Fri Jul 15 15:28:09 2016 +0100
@@ -77,17 +77,6 @@
 
 
 ##############################################################################
-# ARM Compiler Paths
-##############################################################################
-
-ARM_BIN = join(ARM_PATH, "bin")
-ARM_INC = join(ARM_PATH, "include")
-ARM_LIB = join(ARM_PATH, "lib")
-ARM_CPPLIB = join(ARM_LIB, "cpplib")
-MY_ARM_CLIB = join(ARM_LIB, "lib", "microlib")
-
-
-##############################################################################
 # Test System Settings
 ##############################################################################
 SERVER_PORT = 59432
--- a/test_api.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/test_api.py	Fri Jul 15 15:28:09 2016 +0100
@@ -57,7 +57,7 @@
 from tools.build_api import add_result_to_report
 from tools.build_api import scan_for_source_paths
 from tools.libraries import LIBRARIES, LIBRARY_MAP
-from tools.toolchains import TOOLCHAIN_BIN_PATH
+from tools.toolchains import TOOLCHAIN_PATHS
 from tools.test_exporters import ReportExporter, ResultExporterType
 
 import tools.host_tests.host_tests_plugins as host_tests_plugins
@@ -1335,8 +1335,8 @@
                 if conflict:
                     cell_val += '*'
                 # Check for conflicts: toolchain vs toolchain path
-                if toolchain in TOOLCHAIN_BIN_PATH:
-                    toolchain_path = TOOLCHAIN_BIN_PATH[toolchain]
+                if toolchain in TOOLCHAIN_PATHS:
+                    toolchain_path = TOOLCHAIN_PATHS[toolchain]
                     if not os.path.isdir(toolchain_path):
                         conflict_path = True
                         if toolchain not in toolchain_path_conflicts:
@@ -1360,8 +1360,8 @@
 
         for toolchain in toolchain_path_conflicts:
         # Let's check toolchain configuration
-            if toolchain in TOOLCHAIN_BIN_PATH:
-                toolchain_path = TOOLCHAIN_BIN_PATH[toolchain]
+            if toolchain in TOOLCHAIN_PATHS:
+                toolchain_path = TOOLCHAIN_PATHS[toolchain]
                 if not os.path.isdir(toolchain_path):
                     result += "\t# Toolchain %s path not found: %s\n"% (toolchain, toolchain_path)
     return result
--- a/toolchains/__init__.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/toolchains/__init__.py	Fri Jul 15 15:28:09 2016 +0100
@@ -632,6 +632,20 @@
             mkdir(obj_dir)
         return join(obj_dir, name + '.o')
 
+    def get_link_file(self, cmd):
+        link_file = join(self.build_dir, ".link_files.txt")
+        with open(link_file, "wb") as f:
+            cmd_list = []
+            for c in cmd:
+                if c:
+                    c = c.replace("\\", "/")
+                    if self.CHROOT:
+                        c = c.replace(self.CHROOT, '')
+                    cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
+            string = " ".join(cmd_list)
+            f.write(string)
+        return link_file
+
     def get_inc_file(self, includes):
         include_file = join(self.build_dir, ".includes_%s.txt" % self.inc_md5)
         if not exists(include_file):
@@ -639,7 +653,10 @@
                 cmd_list = []
                 for c in includes:
                     if c:
-                        cmd_list.append(('-I%s' % c).replace("\\", "/"))                    
+                        c = c.replace("\\", "/")
+                        if self.CHROOT:
+                            c = c.replace(self.CHROOT, '')
+                        cmd_list.append('-I%s' % c)
                 string = " ".join(cmd_list)
                 f.write(string)
         return include_file
@@ -858,7 +875,7 @@
 
     def default_cmd(self, command):
         self.debug("Command: %s"% ' '.join(command))
-        _stdout, _stderr, _rc = run_cmd(command)
+        _stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT)
 
         self.debug("Return: %s"% _rc)
 
@@ -949,13 +966,14 @@
     def get_config_macros(self):
         return Config.config_to_macros(self.config_data) if self.config_data else []
 
-from tools.settings import ARM_BIN
+
+from tools.settings import ARM_PATH
 from tools.settings import GCC_ARM_PATH, GCC_CR_PATH
 from tools.settings import IAR_PATH
 
-TOOLCHAIN_BIN_PATH = {
-    'ARM': ARM_BIN,
-    'uARM': ARM_BIN,
+TOOLCHAIN_PATHS = {
+    'ARM': ARM_PATH,
+    'uARM': ARM_PATH,
     'GCC_ARM': GCC_ARM_PATH,
     'GCC_CR': GCC_CR_PATH,
     'IAR': IAR_PATH
--- a/toolchains/arm.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/toolchains/arm.py	Fri Jul 15 15:28:09 2016 +0100
@@ -17,8 +17,8 @@
 import re
 from os.path import join, dirname, splitext, basename, exists
 
-from tools.toolchains import mbedToolchain
-from tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB, GOANNA_PATH
+from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
+from tools.settings import GOANNA_PATH
 from tools.hooks import hook_tool
 from tools.utils import mkdir
 import copy
@@ -35,7 +35,7 @@
     DEFAULT_FLAGS = {
         'common': ["-c", "--gnu",
             "-Otime", "--split_sections", "--apcs=interwork",
-            "--brief_diagnostics", "--restrict", "--multibyte_chars", "-I \""+ARM_INC+"\""],
+            "--brief_diagnostics", "--restrict", "--multibyte_chars"],
         'asm': [],
         'c': ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
         'cxx': ["--cpp", "--no_rtti", "--no_vla"],
@@ -56,6 +56,9 @@
         else:
             cpu = target.core
 
+        ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
+        ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
+        
         main_cc = join(ARM_BIN, "armcc")
 
         self.flags['common'] += ["--cpu=%s" % cpu]
@@ -68,13 +71,13 @@
         else:
             self.flags['c'].append("-O3")
 
-        self.asm = [main_cc] + self.flags['common'] + self.flags['asm']
+        self.asm = [main_cc] + self.flags['common'] + self.flags['asm'] + ["-I \""+ARM_INC+"\""]
         if not "analyze" in self.options:
-            self.cc = [main_cc] + self.flags['common'] + self.flags['c']
-            self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx']
+            self.cc = [main_cc] + self.flags['common'] + self.flags['c'] + ["-I \""+ARM_INC+"\""]
+            self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx'] + ["-I \""+ARM_INC+"\""]
         else:
-            self.cc  = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + self.flags['common'] + self.flags['c'] 
-            self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + self.flags['common'] + self.flags['c'] + self.flags['cxx']
+            self.cc  = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + self.flags['common'] + self.flags['c'] + ["-I \""+ARM_INC+"\""]
+            self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + self.flags['common'] + self.flags['c'] + self.flags['cxx'] + ["-I \""+ARM_INC+"\""]
 
         self.ld = [join(ARM_BIN, "armlink")]
         self.sys_libs = []
@@ -116,7 +119,7 @@
         dep_path = base + '.d'
         return ["--depend", dep_path]
 
-    def get_config_option(self, config_header) :
+    def get_config_option(self, config_header):
         return ['--preinclude=' + config_header]
 
     def get_compile_options(self, defines, includes):        
@@ -184,15 +187,8 @@
         cmd = self.hook.get_cmdline_linker(cmd)
 
         # Split link command to linker executable + response file
-        link_files = join(dirname(output), ".link_files.txt")
-        with open(link_files, "wb") as f:
-            cmd_linker = cmd[0]
-            cmd_list = []
-            for c in cmd[1:]:
-                if c:
-                    cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)                    
-            string = " ".join(cmd_list).replace("\\", "/")
-            f.write(string)
+        cmd_linker = cmd[0]
+        link_files = self.get_link_file(cmd[1:])
 
         # Exec command
         self.default_cmd([cmd_linker, '--via', link_files])
@@ -227,7 +223,7 @@
         ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
 
         # Run-time values
-        self.ld.extend(["--libpath \"%s\"" % ARM_LIB])
+        self.ld.extend(["--libpath \"%s\"" % join(TOOLCHAIN_PATHS['ARM'], "lib")])
 
 
 class ARM_MICRO(ARM):
@@ -260,13 +256,13 @@
             self.ld   += ["--noscanlib"]
 
             # System Libraries
-            self.sys_libs.extend([join(MY_ARM_CLIB, lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]])
+            self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "microlib", lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]])
 
             if target.core == "Cortex-M3":
-                self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ws", "cpprt_w"]])
+                self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "cpplib", lib+".l") for lib in ["cpp_ws", "cpprt_w"]])
 
             elif target.core in ["Cortex-M0", "Cortex-M0+"]:
-                self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
+                self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "cpplib", lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
         else:
             # Run-time values
-            self.ld.extend(["--libpath \"%s\"" % ARM_LIB])
+            self.ld.extend(["--libpath \"%s\"" % join(TOOLCHAIN_PATHS['ARM'], "lib")])
--- a/toolchains/gcc.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/toolchains/gcc.py	Fri Jul 15 15:28:09 2016 +0100
@@ -17,8 +17,7 @@
 import re
 from os.path import join, basename, splitext, dirname, exists
 
-from tools.toolchains import mbedToolchain
-from tools.settings import GCC_ARM_PATH, GCC_CR_PATH
+from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
 from tools.settings import GOANNA_PATH
 from tools.hooks import hook_tool
 
@@ -236,15 +235,8 @@
         cmd = self.hook.get_cmdline_linker(cmd)
 
         # Split link command to linker executable + response file
-        link_files = join(dirname(output), ".link_files.txt")
-        with open(link_files, "wb") as f:
-            cmd_linker = cmd[0]
-            cmd_list = []
-            for c in cmd[1:]:
-                if c:
-                    cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
-            string = " ".join(cmd_list).replace("\\", "/")
-            f.write(string)
+        cmd_linker = cmd[0]
+        link_files = self.get_link_file(cmd[1:])
 
         # Exec command
         self.default_cmd([cmd_linker, "@%s" % link_files])
@@ -276,7 +268,7 @@
 
 class GCC_ARM(GCC):
     def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
-        GCC.__init__(self, target, options, notify, macros, silent, GCC_ARM_PATH, extra_verbose=extra_verbose)
+        GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_ARM'], extra_verbose=extra_verbose)
 
         # Use latest gcc nanolib
         if "big-build" in self.options:
@@ -309,7 +301,7 @@
 
 class GCC_CR(GCC):
     def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
-        GCC.__init__(self, target, options, notify, macros, silent, GCC_CR_PATH, extra_verbose=extra_verbose)
+        GCC.__init__(self, target, options, notify, macros, silent, TOOLCHAIN_PATHS['GCC_CR'], extra_verbose=extra_verbose)
 
         additional_compiler_flags = [
             "-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP",
--- a/toolchains/iar.py	Fri Jul 15 13:11:30 2016 +0100
+++ b/toolchains/iar.py	Fri Jul 15 15:28:09 2016 +0100
@@ -18,8 +18,7 @@
 from os import remove
 from os.path import join, exists, dirname, splitext, exists
 
-from tools.toolchains import mbedToolchain
-from tools.settings import IAR_PATH
+from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
 from tools.settings import GOANNA_PATH
 from tools.hooks import hook_tool
 
@@ -66,12 +65,12 @@
         if target.core == "Cortex-M4F":
           c_flags_cmd = [
               "--cpu", "Cortex-M4F",
-              "--thumb", "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h")
+              "--thumb", "--dlib_config", join(TOOLCHAIN_PATHS['IAR'], "inc", "c", "DLib_Config_Full.h")
           ]
         else:
           c_flags_cmd = [
               "--cpu", cpuchoice,
-              "--thumb", "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h")
+              "--thumb", "--dlib_config", join(TOOLCHAIN_PATHS['IAR'], "inc", "c", "DLib_Config_Full.h")
           ]
         # custom c++ cmd flags
         cxx_flags_cmd = [
@@ -90,7 +89,7 @@
         else:
             c_flags_cmd.append("-Oh")
 
-        IAR_BIN = join(IAR_PATH, "bin")
+        IAR_BIN = join(TOOLCHAIN_PATHS['IAR'], "bin")
         main_cc = join(IAR_BIN, "iccarm")
 
         self.asm  = [join(IAR_BIN, "iasmarm")] + asm_flags_cmd + self.flags["asm"]
@@ -202,15 +201,8 @@
         cmd = self.hook.get_cmdline_linker(cmd)
 
         # Split link command to linker executable + response file
-        link_files = join(dirname(output), ".link_files.txt")
-        with open(link_files, "wb") as f:
-            cmd_linker = cmd[0]
-            cmd_list = []
-            for c in cmd[1:]:
-                if c:
-                    cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)                    
-            string = " ".join(cmd_list).replace("\\", "/")
-            f.write(string)
+        cmd_linker = cmd[0]
+        link_files = self.get_link_file(cmd[1:])
 
         # Exec command
         self.default_cmd([cmd_linker, '-f', link_files])