Skip to content

Commit 6129833

Browse files
committed
Introduce response file for linking with IAR toolchain
1 parent 40fc104 commit 6129833

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

tools/toolchains/arm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
149149

150150
# Build linker command
151151
cmd = self.ld + args + objects + libraries + self.sys_libs
152-
print self.ld
153152

154153
# Call cmdline hook
155154
cmd = self.hook.get_cmdline_linker(cmd)

tools/toolchains/iar.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717
import re
1818
from os import remove
19-
from os.path import join, exists
19+
from os.path import join, exists, dirname
2020

2121
from tools.toolchains import mbedToolchain
2222
from tools.settings import IAR_PATH
@@ -103,8 +103,16 @@ def parse_dependencies(self, dep_path):
103103
return [path.strip() for path in open(dep_path).readlines()
104104
if (path and not path.isspace())]
105105

106+
@hook_tool
106107
def assemble(self, source, object, includes):
107-
return [self.hook.get_cmdline_assembler(self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source])]
108+
# Build assemble command
109+
cmd = self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source]
110+
111+
# Call cmdline hook
112+
cmd = self.hook.get_cmdline_assembler(cmd)
113+
114+
# Return command array, don't execute
115+
return [cmd]
108116

109117
@hook_tool
110118
def archive(self, objects, lib_path):
@@ -114,9 +122,32 @@ def archive(self, objects, lib_path):
114122

115123
@hook_tool
116124
def link(self, output, objects, libraries, lib_dirs, mem_map):
117-
args = [self.ld, "-o", output, "--config", mem_map, "--skip_dynamic_initialization"]
118-
self.default_cmd(self.hook.get_cmdline_linker(args + objects + libraries))
125+
# Build linker command
126+
cmd = [self.ld, "-o", output, "--config", mem_map, "--skip_dynamic_initialization"] + objects + libraries
127+
128+
# Call cmdline hook
129+
cmd = self.hook.get_cmdline_linker(cmd)
130+
131+
# Split link command to linker executable + response file
132+
link_files = join(dirname(output), ".link_files.txt")
133+
with open(link_files, "wb") as f:
134+
cmd_linker = cmd[0]
135+
cmd_list = []
136+
for c in cmd[1:]:
137+
cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
138+
string = " ".join(cmd_list).replace("\\", "/")
139+
f.write(string)
140+
141+
# Exec command
142+
self.default_cmd([cmd_linker, '-f', link_files])
119143

120144
@hook_tool
121145
def binary(self, resources, elf, bin):
122-
self.default_cmd(self.hook.get_cmdline_binary([self.elf2bin, '--bin', elf, bin]))
146+
# Build binary command
147+
cmd = [self.elf2bin, "--bin", elf, bin]
148+
149+
# Call cmdline hook
150+
cmd = self.hook.get_cmdline_binary(cmd)
151+
152+
# Exec command
153+
self.default_cmd(cmd)

0 commit comments

Comments
 (0)