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,6 +37,50 @@ 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
+
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 ):
39
84
def build (self , host_target ):
40
85
self .cmake_options .define ('BUILD_SHARED_LIBS' , 'YES' )
41
86
@@ -45,21 +90,96 @@ def build(self, host_target):
45
90
46
91
self .cmake_options .define ('CMAKE_BUILD_TYPE' , self .args .build_variant )
47
92
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 )
93
+ # FIXME: If we build macros for the builder, specify the path.
94
+ self .cmake_options .define ('SwiftTesting_MACRO' , 'NO' )
53
95
96
+ self .generate_toolchain_file_for_darwin_or_linux (host_target )
54
97
self .build_with_cmake ([], self .args .build_variant , [],
55
98
prefer_native_toolchain = True )
56
99
100
+ def install (self , host_target ):
101
+ install_destdir = self .host_install_destdir (host_target )
102
+ install_prefix = install_destdir + self .args .install_prefix
103
+
104
+ self .install_with_cmake (['install' ], install_prefix )
105
+
106
+ class SwiftTestingMacros (product .Product ):
107
+ @classmethod
108
+ def is_build_script_impl_product (cls ):
109
+ return False
110
+
111
+ @classmethod
112
+ def is_before_build_script_impl_product (cls ):
113
+ return False
114
+
115
+ @classmethod
116
+ def product_source_name (cls ):
117
+ return "swift-testing/Sources/SwiftTestingMacros"
118
+
119
+ @classmethod
120
+ def get_dependencies (cls ):
121
+ return [swift .Swift ]
122
+
123
+ def should_build (self , host_target ):
124
+ return True
125
+
57
126
def should_test (self , host_target ):
58
- # TODO
59
127
return False
60
128
61
129
def should_install (self , host_target ):
62
- return self .args .install_swift_testing
130
+ return self .args .install_swift_testing_macros
131
+
132
+ def _impl_product (self , host_target ):
133
+ build_root = os .path .dirname (self .build_dir )
134
+ build_dir = os .path .join (build_root , '%s-%s' % (self .product_name (), host_target ))
135
+
136
+ return SwiftTestingMacrosImpl (
137
+ args = self .args ,
138
+ toolchain = self .toolchain ,
139
+ source_dir = self .source_dir ,
140
+ build_dir = build_dir )
141
+
142
+ def _build_impl (self , host_target ):
143
+ self ._impl_product (host_target ).build (host_target )
144
+
145
+ def build (self , host_target ):
146
+ self ._build_impl (host_target )
147
+
148
+ # For Darwin host, 'build' is only called for the builder.
149
+ # Manually iterate tor the cross compile hosts.
150
+ if self .has_cross_compile_hosts () and self .is_darwin_host (host_target ):
151
+ for target in self .args .cross_compile_hosts :
152
+ self ._build_impl (target )
153
+
154
+ def _install_impl (self , host_target ):
155
+ self ._impl_product (host_target ).install (host_target )
156
+
157
+ def install (self , host_target ):
158
+ self ._install_impl (host_target )
159
+
160
+ # For Darwin host, 'install' is only called for the builder.
161
+ # Manually iterate tor the cross compile hosts.
162
+ if self .has_cross_compile_hosts () and self .is_darwin_host (host_target ):
163
+ for target in self .args .cross_compile_hosts :
164
+ self ._install_impl (target )
165
+
166
+ class SwiftTestingMacrosImpl (cmake_product .CMakeProduct ):
167
+ def build (self , host_target ):
168
+ # Use empty CMake install prefix, since the `DESTDIR` env var is set by
169
+ # `install_with_cmake` later which already has the same prefix.
170
+ self .cmake_options .define ('CMAKE_INSTALL_PREFIX' , '' )
171
+
172
+ self .cmake_options .define ('CMAKE_BUILD_TYPE' , self .args .build_variant )
173
+
174
+ build_root = os .path .dirname (self .build_dir )
175
+ swift_build_dir = os .path .join (
176
+ '..' , build_root , '%s-%s' % ('swift' , host_target ))
177
+ swift_cmake_dir = os .path .join (swift_build_dir , 'cmake' , 'modules' )
178
+ self .cmake_options .define ('SwiftSyntax_DIR:PATH' , swift_cmake_dir )
179
+
180
+ self .generate_toolchain_file_for_darwin_or_linux (host_target )
181
+ self .build_with_cmake ([], self .args .build_variant , [],
182
+ prefer_native_toolchain = True )
63
183
64
184
def install (self , host_target ):
65
185
install_destdir = self .host_install_destdir (host_target )
0 commit comments