13
13
import os
14
14
15
15
from . import cmake_product
16
+ from . import product
16
17
from . import swift
17
18
18
19
19
- class SwiftTesting (cmake_product . CMakeProduct ):
20
+ class SwiftTesting (product . Product ):
20
21
@classmethod
21
22
def is_build_script_impl_product (cls ):
22
23
return False
@@ -36,7 +37,55 @@ def get_dependencies(cls):
36
37
def should_build (self , host_target ):
37
38
return True
38
39
40
+ def should_test (self , host_target ):
41
+ return False
42
+
43
+ def should_install (self , host_target ):
44
+ return self .args .install_swift_testing_macros
45
+
46
+ def _impl_product (self , host_target ):
47
+ build_root = os .path .dirname (self .build_dir )
48
+ build_dir = os .path .join (build_root , '%s-%s' % (self .product_name (), host_target ))
49
+
50
+ return SwiftTestingImpl (
51
+ args = self .args ,
52
+ toolchain = self .toolchain ,
53
+ source_dir = self .source_dir ,
54
+ build_dir = build_dir )
55
+
56
+ def _build_impl (self , host_target ):
57
+ self ._impl_product (host_target ).build (host_target )
58
+
39
59
def build (self , host_target ):
60
+ self ._build_impl (host_target )
61
+
62
+ # For Darwin host, 'build' is only called for the builder.
63
+ # Manually iterate tor the cross compile hosts.
64
+ if self .has_cross_compile_hosts () and self .is_darwin_host (host_target ):
65
+ for target in self .args .cross_compile_hosts :
66
+ self ._build_impl (target )
67
+
68
+ # FIXME: build testing library for 'stdlib_deployment_targets'?
69
+ pass
70
+
71
+ def _install_impl (self , host_target ):
72
+ self ._impl_product (host_target ).install (host_target )
73
+
74
+ def install (self , host_target ):
75
+ self ._install_impl (host_target )
76
+
77
+ # For Darwin host, 'install' is only called for the builder.
78
+ # Manually iterate tor the cross compile hosts.
79
+ if self .has_cross_compile_hosts () and self .is_darwin_host (host_target ):
80
+ for target in self .args .cross_compile_hosts :
81
+ self ._install_impl (target )
82
+
83
+ class SwiftTestingImpl (cmake_product .CMakeProduct ):
84
+ def build (self , host_target ):
85
+ override_version = None
86
+ if host_target .startswith ('macosx' ):
87
+ override_version = '10.15'
88
+
40
89
self .cmake_options .define ('BUILD_SHARED_LIBS' , 'YES' )
41
90
42
91
# Use empty CMake install prefix, since the `DESTDIR` env var is set by
@@ -45,21 +94,102 @@ def build(self, host_target):
45
94
46
95
self .cmake_options .define ('CMAKE_BUILD_TYPE' , self .args .build_variant )
47
96
48
- build_root = os .path .dirname (self .build_dir )
49
- swift_build_dir = os .path .join (
50
- '..' , build_root , '%s-%s' % ('swift' , host_target ))
51
- swift_cmake_dir = os .path .join (swift_build_dir , 'cmake' , 'modules' )
52
- self .cmake_options .define ('SwiftSyntax_DIR:PATH' , swift_cmake_dir )
97
+ # FIXME: If we build macros for the builder, specify the path.
98
+ self .cmake_options .define ('SwiftTesting_MACRO' , 'NO' )
53
99
100
+ self .generate_toolchain_file_for_darwin_or_linux (
101
+ host_target , override_deployment_version = override_version )
54
102
self .build_with_cmake ([], self .args .build_variant , [],
55
103
prefer_native_toolchain = True )
56
104
105
+ def install (self , host_target ):
106
+ install_destdir = self .host_install_destdir (host_target )
107
+ install_prefix = install_destdir + self .args .install_prefix
108
+
109
+ self .install_with_cmake (['install' ], install_prefix )
110
+
111
+ class SwiftTestingMacros (product .Product ):
112
+ @classmethod
113
+ def is_build_script_impl_product (cls ):
114
+ return False
115
+
116
+ @classmethod
117
+ def is_before_build_script_impl_product (cls ):
118
+ return False
119
+
120
+ @classmethod
121
+ def product_source_name (cls ):
122
+ return "swift-testing/Sources/TestingMacros"
123
+
124
+ @classmethod
125
+ def get_dependencies (cls ):
126
+ return [swift .Swift ]
127
+
128
+ def should_build (self , host_target ):
129
+ return True
130
+
57
131
def should_test (self , host_target ):
58
- # TODO
59
132
return False
60
133
61
134
def should_install (self , host_target ):
62
- return self .args .install_swift_testing
135
+ return self .args .install_swift_testing_macros
136
+
137
+ def _impl_product (self , host_target ):
138
+ build_root = os .path .dirname (self .build_dir )
139
+ build_dir = os .path .join (build_root , '%s-%s' % (self .product_name (), host_target ))
140
+
141
+ return SwiftTestingMacrosImpl (
142
+ args = self .args ,
143
+ toolchain = self .toolchain ,
144
+ source_dir = self .source_dir ,
145
+ build_dir = build_dir )
146
+
147
+ def _build_impl (self , host_target ):
148
+ self ._impl_product (host_target ).build (host_target )
149
+
150
+ def build (self , host_target ):
151
+ self ._build_impl (host_target )
152
+
153
+ # For Darwin host, 'build' is only called for the builder.
154
+ # Manually iterate tor the cross compile hosts.
155
+ if self .has_cross_compile_hosts () and self .is_darwin_host (host_target ):
156
+ for target in self .args .cross_compile_hosts :
157
+ self ._build_impl (target )
158
+
159
+ def _install_impl (self , host_target ):
160
+ self ._impl_product (host_target ).install (host_target )
161
+
162
+ def install (self , host_target ):
163
+ self ._install_impl (host_target )
164
+
165
+ # For Darwin host, 'install' is only called for the builder.
166
+ # Manually iterate tor the cross compile hosts.
167
+ if self .has_cross_compile_hosts () and self .is_darwin_host (host_target ):
168
+ for target in self .args .cross_compile_hosts :
169
+ self ._install_impl (target )
170
+
171
+ class SwiftTestingMacrosImpl (cmake_product .CMakeProduct ):
172
+ def build (self , host_target ):
173
+ override_version = None
174
+ if host_target .startswith ('macosx' ):
175
+ override_version = '10.15'
176
+
177
+ # Use empty CMake install prefix, since the `DESTDIR` env var is set by
178
+ # `install_with_cmake` later which already has the same prefix.
179
+ self .cmake_options .define ('CMAKE_INSTALL_PREFIX' , '' )
180
+
181
+ self .cmake_options .define ('CMAKE_BUILD_TYPE' , self .args .build_variant )
182
+
183
+ build_root = os .path .dirname (self .build_dir )
184
+ swift_build_dir = os .path .join (
185
+ '..' , build_root , '%s-%s' % ('swift' , host_target ))
186
+ swift_cmake_dir = os .path .join (swift_build_dir , 'cmake' , 'modules' )
187
+ self .cmake_options .define ('SwiftSyntax_DIR:PATH' , swift_cmake_dir )
188
+
189
+ self .generate_toolchain_file_for_darwin_or_linux (
190
+ host_target , override_deployment_version = override_version )
191
+ self .build_with_cmake ([], self .args .build_variant , [],
192
+ prefer_native_toolchain = True )
63
193
64
194
def install (self , host_target ):
65
195
install_destdir = self .host_install_destdir (host_target )
0 commit comments