the other jimmy / mbed-sdk-tools

Fork of mbed-sdk-tools by mbed official

Revision:
21:4fdf0dd04f6f
Parent:
20:835f6355470d
Child:
22:9e85236d8716
diff -r 835f6355470d -r 4fdf0dd04f6f toolchains/iar.py
--- a/toolchains/iar.py	Fri Jul 15 15:28:09 2016 +0100
+++ b/toolchains/iar.py	Fri Jul 15 22:58:15 2016 +0100
@@ -19,7 +19,6 @@
 from os.path import join, exists, dirname, splitext, exists
 
 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
-from tools.settings import GOANNA_PATH
 from tools.hooks import hook_tool
 
 class IAR(mbedToolchain):
@@ -28,6 +27,7 @@
     STD_LIB_NAME = "%s.a"
 
     DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
+    INDEX_PATTERN  = re.compile('(?P<col>\s*)\^')
 
     DEFAULT_FLAGS = {
         'common': [
@@ -93,12 +93,8 @@
         main_cc = join(IAR_BIN, "iccarm")
 
         self.asm  = [join(IAR_BIN, "iasmarm")] + asm_flags_cmd + self.flags["asm"]
-        if not "analyze" in self.options:
-            self.cc   = [main_cc]
-            self.cppc = [main_cc]
-        else:
-            self.cc   = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
-            self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
+        self.cc   = [main_cc]
+        self.cppc = [main_cc]
         self.cc += self.flags["common"] + c_flags_cmd + self.flags["c"]
         self.cppc += self.flags["common"] + c_flags_cmd + cxx_flags_cmd + self.flags["cxx"]
         self.ld   = join(IAR_BIN, "ilinkarm")
@@ -106,29 +102,34 @@
         self.elf2bin = join(IAR_BIN, "ielftool")
 
     def parse_dependencies(self, dep_path):
-        return [path.strip() for path in open(dep_path).readlines()
+        return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines()
                 if (path and not path.isspace())]
 
     def parse_output(self, output):
+        msg = None
         for line in output.splitlines():
             match = IAR.DIAGNOSTIC_PATTERN.match(line)
             if match is not None:
-                self.cc_info(
-                    match.group('severity').lower(),
-                    match.group('file'),
-                    match.group('line'),
-                    match.group('message'),
-                    target_name=self.target.name,
-                    toolchain_name=self.name
-                )
-            match = self.goanna_parse_line(line)
-            if match is not None:
-                self.cc_info(
-                    match.group('severity').lower(),
-                    match.group('file'),
-                    match.group('line'),
-                    match.group('message')
-                )
+                if msg is not None:
+                    self.cc_info(msg)
+                msg = {
+                    'severity': match.group('severity').lower(),
+                    'file': match.group('file'),
+                    'line': match.group('line'),
+                    'col': 0,
+                    'message': match.group('message'),
+                    'text': '',
+                    'target_name': self.target.name,
+                    'toolchain_name': self.name
+                }
+            elif msg is not None:
+                match = IAR.INDEX_PATTERN.match(line)
+                if match is not None:
+                    msg['col'] = len(match.group('col'))
+                    self.cc_info(msg)
+                    msg = None
+                else:
+                    msg['text'] += line+"\n"
 
     def get_dep_option(self, object):
         base, _ = splitext(object)
@@ -143,7 +144,12 @@
         return ['--preinclude=' + config_header]
 
     def get_compile_options(self, defines, includes, for_asm=False):
-        opts = ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
+        opts = ['-D%s' % d for d in defines]
+        if self.RESPONSE_FILES:
+            opts += ['-f', self.get_inc_file(includes)]
+        else:
+            opts += ["-I%s" % i for i in includes]
+
         config_header = self.get_config_header()
         if for_asm:
             # The assembler doesn't support '--preinclude', so we need to add
@@ -200,27 +206,27 @@
         # Call cmdline hook
         cmd = self.hook.get_cmdline_linker(cmd)
 
-        # Split link command to linker executable + response file
-        cmd_linker = cmd[0]
-        link_files = self.get_link_file(cmd[1:])
+        if self.RESPONSE_FILES:
+            # Split link command to linker executable + response file
+            cmd_linker = cmd[0]
+            link_files = self.get_link_file(cmd[1:])
+            cmd = [cmd_linker, '-f', link_files]
 
         # Exec command
-        self.default_cmd([cmd_linker, '-f', link_files])
+        self.cc_verbose("Link: %s" % ' '.join(cmd))
+        self.default_cmd(cmd)
 
     @hook_tool
     def archive(self, objects, lib_path):
-        archive_files = join(dirname(lib_path), ".archive_files.txt")
-        with open(archive_files, "wb") as f:
-            o_list = []
-            for o in objects:
-                o_list.append('"%s"' % o)                    
-            string = " ".join(o_list).replace("\\", "/")
-            f.write(string)
+        if self.RESPONSE_FILES:
+            param = ['-f', self.get_arch_files(objects)]
+        else:
+            param = objects
 
         if exists(lib_path):
             remove(lib_path)
 
-        self.default_cmd([self.ar, lib_path, '-f', archive_files])
+        self.default_cmd([self.ar, lib_path] + param)
 
     @hook_tool
     def binary(self, resources, elf, bin):
@@ -231,4 +237,5 @@
         cmd = self.hook.get_cmdline_binary(cmd)
 
         # Exec command
+        self.cc_verbose("FromELF: %s" % ' '.join(cmd))
         self.default_cmd(cmd)