27
27
from . import swiftsyntax
28
28
from . import xctest
29
29
from .. import shell
30
+ from .. import targets
30
31
31
32
32
33
class SwiftFormat (product .Product ):
@@ -57,8 +58,6 @@ def run_build_script_helper(self, action, host_target, additional_params=[]):
57
58
script_path = os .path .join (
58
59
self .source_dir , 'build-script-helper.py' )
59
60
60
- install_destdir = self .host_install_destdir (host_target )
61
-
62
61
helper_cmd = [
63
62
script_path ,
64
63
action ,
@@ -71,9 +70,33 @@ def run_build_script_helper(self, action, host_target, additional_params=[]):
71
70
# reset the dependencies to be local.
72
71
'--update'
73
72
]
74
- helper_cmd .extend ([
75
- '--prefix' , install_destdir + self .args .install_prefix
76
- ])
73
+
74
+ install_destdir = self .host_install_destdir (host_target )
75
+ toolchain_path = self .native_toolchain_path (host_target )
76
+
77
+ # Pass Cross compile host info unless we're testing.
78
+ # It doesn't make sense to run tests of the cross compile host.
79
+ if self .has_cross_compile_hosts () and action != 'test' :
80
+ if self .is_darwin_host (host_target ):
81
+ if len (self .args .cross_compile_hosts ) != 1 :
82
+ raise RuntimeError ("Cross-Compiling swift-format to multiple " +
83
+ "targets is not supported" )
84
+ helper_cmd += ['--cross-compile-host' , self .args .cross_compile_hosts [0 ]]
85
+ elif self .is_cross_compile_target (host_target ):
86
+ helper_cmd .extend (['--cross-compile-host' , host_target ])
87
+ build_toolchain_path = install_destdir + self .args .install_prefix
88
+ resource_dir = f'{ build_toolchain_path } /lib/swift'
89
+ cross_compile_config = targets .StdlibDeploymentTarget \
90
+ .get_target_for_name (host_target ) \
91
+ .platform \
92
+ .swiftpm_config (
93
+ self .args ,
94
+ output_dir = build_toolchain_path ,
95
+ swift_toolchain = toolchain_path ,
96
+ resource_path = resource_dir
97
+ )
98
+ helper_cmd += ['--cross-compile-config' , cross_compile_config ]
99
+
77
100
if self .args .verbose_build :
78
101
helper_cmd .append ('--verbose' )
79
102
helper_cmd .extend (additional_params )
@@ -139,7 +162,12 @@ def should_install(self, host_target):
139
162
return self .args .install_swiftformat
140
163
141
164
def install (self , host_target ):
142
- self .run_build_script_helper ('install' , host_target )
165
+ install_destdir = self .host_install_destdir (host_target )
166
+ self .run_build_script_helper (
167
+ 'install' ,
168
+ host_target ,
169
+ additional_params = ['--prefix' , install_destdir + self .args .install_prefix ]
170
+ )
143
171
144
172
@classmethod
145
173
def get_dependencies (cls ):
0 commit comments