16
16
"""
17
17
import re
18
18
from os import remove
19
- from os .path import join , exists
19
+ from os .path import join , exists , dirname
20
20
21
21
from tools .toolchains import mbedToolchain
22
22
from tools .settings import IAR_PATH
@@ -103,8 +103,16 @@ def parse_dependencies(self, dep_path):
103
103
return [path .strip () for path in open (dep_path ).readlines ()
104
104
if (path and not path .isspace ())]
105
105
106
+ @hook_tool
106
107
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 ]
108
116
109
117
@hook_tool
110
118
def archive (self , objects , lib_path ):
@@ -114,9 +122,32 @@ def archive(self, objects, lib_path):
114
122
115
123
@hook_tool
116
124
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 ])
119
143
120
144
@hook_tool
121
145
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