@@ -30,14 +30,18 @@ def verbose_print_command(command):
30
30
31
31
class ResilienceTest (object ):
32
32
33
- def __init__ (self , target_build_swift , target_run , tmp_dir , test_dir ,
34
- test_src , additional_compile_flags_library ,
33
+ def __init__ (self , target_build_swift , target_run , target_codesign ,
34
+ tmp_dir , test_dir , test_src , lib_prefix , lib_suffix ,
35
+ additional_compile_flags_library ,
35
36
no_backward_deployment ):
36
37
self .target_build_swift = shlex .split (target_build_swift )
37
38
self .target_run = shlex .split (target_run )
39
+ self .target_codesign = shlex .split (target_codesign )
38
40
self .tmp_dir = tmp_dir
39
41
self .test_dir = test_dir
40
42
self .test_src = test_src
43
+ self .lib_prefix = lib_prefix
44
+ self .lib_suffix = lib_suffix
41
45
self .additional_compile_flags_library = \
42
46
shlex .split (additional_compile_flags_library )
43
47
@@ -47,7 +51,7 @@ class ResilienceTest(object):
47
51
'AFTER' : self .after_dir }
48
52
49
53
self .lib_src_name = os .path .basename (self .test_src )[5 :]
50
- self .lib_obj_name = self .lib_src_name [:- 6 ] + '.o'
54
+ self .lib_name = self .lib_src_name [:- 6 ]
51
55
self .lib_src = os .path .join (self .test_dir , 'Inputs' , self .lib_src_name )
52
56
53
57
self .no_backward_deployment = no_backward_deployment
@@ -65,22 +69,36 @@ class ResilienceTest(object):
65
69
os .makedirs (self .after_dir )
66
70
os .makedirs (self .before_dir )
67
71
72
+ def is_apple_platform (self ):
73
+ return any ('-apple-' in arg for arg in self .target_build_swift )
74
+
68
75
def compile_library (self ):
69
76
for config in self .config_dir_map :
70
- for emit_flag in ['-emit-library' , '-emit-module' ]:
71
- output_obj = os .path .join (self .config_dir_map [config ],
72
- self .lib_obj_name )
73
- compiler_flags = [emit_flag ,
74
- '-swift-version' , '4' ,
75
- '-Xfrontend' , '-enable-resilience' ,
76
- '-D' , config ,
77
- '-c' , self .lib_src ,
78
- '-o' , output_obj ]
79
- command = self .target_build_swift + \
80
- self .additional_compile_flags_library + compiler_flags
81
- verbose_print_command (command )
82
- returncode = subprocess .call (command )
83
- assert returncode == 0 , str (command )
77
+ lib_file = self .lib_prefix + self .lib_name + self .lib_suffix
78
+ output_dylib = os .path .join (self .config_dir_map [config ],
79
+ lib_file )
80
+ compiler_flags = ['-emit-library' , '-emit-module' ,
81
+ '-swift-version' , '4' ,
82
+ '-Xfrontend' , '-enable-resilience' ,
83
+ '-D' , config ,
84
+ self .lib_src ,
85
+ '-o' , output_dylib ]
86
+ if self .is_apple_platform ():
87
+ compiler_flags += ['-Xlinker' ,
88
+ '-install_name' ,
89
+ '-Xlinker' ,
90
+ os .path .join ('@rpath' , lib_file )]
91
+
92
+ command = self .target_build_swift + \
93
+ self .additional_compile_flags_library + compiler_flags
94
+ verbose_print_command (command )
95
+ returncode = subprocess .call (command )
96
+ assert returncode == 0 , str (command )
97
+
98
+ codesign_cmd = self .target_codesign + [output_dylib ]
99
+ verbose_print_command (codesign_cmd )
100
+ returncode = subprocess .call (codesign_cmd )
101
+ assert returncode == 0 , str (codesign_cmd )
84
102
85
103
def compile_main (self ):
86
104
for config in self .config_dir_map :
@@ -110,13 +128,23 @@ class ResilienceTest(object):
110
128
config2_lower = config2 .lower ()
111
129
output_obj = os .path .join (self .tmp_dir ,
112
130
config1_lower + '_' + config2_lower )
131
+ if self .is_apple_platform ():
132
+ rpath_origin = '@executable_path'
133
+ else :
134
+ rpath_origin = '$ORIGIN'
135
+
113
136
compiler_flags = [
114
- os . path . join ( self .config_dir_map [config1 ],
115
- self .lib_obj_name ) ,
137
+ '-L' , self .config_dir_map [config2 ],
138
+ '-l' + self .lib_name ,
116
139
os .path .join (self .config_dir_map [config2 ],
117
140
'main.o' ),
141
+ '-Xlinker' , '-rpath' , '-Xlinker' ,
142
+ os .path .join (rpath_origin ,
143
+ os .path .relpath (self .config_dir_map [config1 ],
144
+ self .tmp_dir )),
118
145
'-o' , output_obj
119
146
]
147
+
120
148
command = self .target_build_swift + compiler_flags
121
149
verbose_print_command (command )
122
150
returncode = subprocess .call (command )
@@ -128,7 +156,7 @@ class ResilienceTest(object):
128
156
config2_lower = config2 .lower ()
129
157
output_obj = os .path .join (self .tmp_dir ,
130
158
config1_lower + '_' + config2_lower )
131
- command = self .target_run + [output_obj ]
159
+ command = self .target_run + [output_obj , self . tmp_dir ]
132
160
verbose_print_command (command )
133
161
returncode = subprocess .call (command )
134
162
assert returncode == 0 , str (command )
@@ -138,17 +166,22 @@ def main():
138
166
parser = argparse .ArgumentParser (description = 'Resilience test helper' )
139
167
parser .add_argument ('--target-build-swift' , required = True )
140
168
parser .add_argument ('--target-run' , required = True )
169
+ parser .add_argument ('--target-codesign' , default = 'echo' )
141
170
parser .add_argument ('--t' , required = True )
142
171
parser .add_argument ('--S' , required = True )
143
172
parser .add_argument ('--s' , required = True )
173
+ parser .add_argument ('--lib-prefix' , required = True )
174
+ parser .add_argument ('--lib-suffix' , required = True )
144
175
parser .add_argument ('--additional-compile-flags-library' , default = '' )
145
176
parser .add_argument ('--no-backward-deployment' , default = False ,
146
177
action = 'store_true' )
147
178
148
179
args = parser .parse_args ()
149
180
150
181
resilience_test = ResilienceTest (args .target_build_swift , args .target_run ,
151
- args .t , args .S , args .s ,
182
+ args .target_codesign ,
183
+ args .t , args .S , args .s , args .lib_prefix ,
184
+ args .lib_suffix ,
152
185
args .additional_compile_flags_library ,
153
186
args .no_backward_deployment )
154
187
0 commit comments