|
42 | 42 | source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
|
43 | 43 | || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
|
44 | 44 |
|
45 |
| -# `uname` returns the current platform, e.g "MSYS_NT-10.0" or "Linux". |
46 |
| -# `tr` converts all upper case letters to lower case. |
47 |
| -# `case` matches the result if the `uname | tr` expression to string prefixes |
48 |
| -# that use the same wildcards as names do in Bash, i.e. "msys*" matches strings |
49 |
| -# starting with "msys", and "*" matches everything (it's the default case). |
50 |
| -case "$(uname -s | tr [:upper:] [:lower:])" in |
51 |
| -msys*) |
52 |
| - # As of 2019-01-15, Bazel on Windows only supports MSYS Bash. |
53 |
| - declare -r is_windows=true |
54 |
| - ;; |
55 |
| -*) |
56 |
| - declare -r is_windows=false |
57 |
| - ;; |
58 |
| -esac |
59 |
| - |
60 | 45 | function test_platforms_repository_builds_itself() {
|
61 | 46 | # We test that a built-in @platforms repository is buildable.
|
62 | 47 | bazel build @platforms//:all &> $TEST_log \
|
@@ -132,339 +117,5 @@ EOF
|
132 | 117 | grep 'The properties are: {"key2": "value2", "key": "value"}' $TEST_log || fail "Did not find expected properties"
|
133 | 118 | }
|
134 | 119 |
|
135 |
| -function test_target_exec_properties_starlark() { |
136 |
| -cat > rules.bzl << 'EOF' |
137 |
| -def _impl(ctx): |
138 |
| - out_file = ctx.outputs.output |
139 |
| - ctx.actions.run_shell(inputs = [], outputs = [out_file], arguments=[out_file.path], progress_message = "Saying hello", command = "echo hello > \"$1\"") |
140 |
| -
|
141 |
| -my_rule = rule( |
142 |
| - implementation = _impl, |
143 |
| - attrs = { |
144 |
| - "output": attr.output(), |
145 |
| - } |
146 |
| -) |
147 |
| -EOF |
148 |
| - cat > BUILD << 'EOF' |
149 |
| -load("//:rules.bzl", "my_rule") |
150 |
| -
|
151 |
| -my_rule( |
152 |
| - name = "a", |
153 |
| - output = "out.txt", |
154 |
| - exec_properties = {"key3": "value3", "overridden": "child_value"} |
155 |
| -) |
156 |
| -
|
157 |
| -platform( |
158 |
| - name = "my_platform", |
159 |
| - exec_properties = { |
160 |
| - "key2": "value2", |
161 |
| - "overridden": "parent_value", |
162 |
| - } |
163 |
| -) |
164 |
| -EOF |
165 |
| - |
166 |
| - bazel build --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt &> $TEST_log || fail "Build failed" |
167 |
| - grep "key2" out.txt || fail "Did not find the platform key" |
168 |
| - grep "key3" out.txt || fail "Did not find the target attribute key" |
169 |
| - grep "child_value" out.txt || fail "Did not find the overriding value" |
170 |
| -} |
171 |
| - |
172 |
| - |
173 |
| -function test_target_exec_properties_starlark_test() { |
174 |
| -if "$is_windows"; then |
175 |
| - script_name="test_script.bat" |
176 |
| - script_content="@echo off\necho hello\n" |
177 |
| -else |
178 |
| - script_name="test_script.sh" |
179 |
| - script_content="#!/bin/bash\necho hello\n" |
180 |
| -fi |
181 |
| -cat > rules.bzl <<EOF |
182 |
| -def _impl(ctx): |
183 |
| - out_file = ctx.actions.declare_file("$script_name") |
184 |
| - ctx.actions.write(out_file, "$script_content", is_executable=True) |
185 |
| - return [DefaultInfo(executable = out_file)] |
186 |
| -
|
187 |
| -my_rule_test = rule( |
188 |
| - implementation = _impl, |
189 |
| - test = True, |
190 |
| -) |
191 |
| -EOF |
192 |
| - cat > BUILD << 'EOF' |
193 |
| -load("//:rules.bzl", "my_rule_test") |
194 |
| -
|
195 |
| -my_rule_test( |
196 |
| - name = "a", |
197 |
| - exec_properties = {"key3": "value3", "overridden": "child_value"} |
198 |
| -) |
199 |
| -
|
200 |
| -platform( |
201 |
| - name = "my_platform", |
202 |
| - exec_properties = { |
203 |
| - "key2": "value2", |
204 |
| - "overridden": "parent_value", |
205 |
| - } |
206 |
| -) |
207 |
| -EOF |
208 |
| - |
209 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt &> $TEST_log || fail "Build failed" |
210 |
| - grep "key2" out.txt || fail "Did not find the platform key" |
211 |
| - grep "key3" out.txt || fail "Did not find the target attribute key" |
212 |
| - grep "child_value" out.txt || fail "Did not find the overriding value" |
213 |
| -} |
214 |
| - |
215 |
| -function test_target_exec_properties_cc() { |
216 |
| - cat > a.cc <<'EOF' |
217 |
| -#include <stdio.h> |
218 |
| -int main() { |
219 |
| - printf("Hello\n"); |
220 |
| -} |
221 |
| -EOF |
222 |
| - cat > BUILD <<'EOF' |
223 |
| -cc_binary( |
224 |
| - name = "a", |
225 |
| - srcs = ["a.cc"], |
226 |
| - exec_properties = {"key3": "value3", "overridden": "child_value"} |
227 |
| -) |
228 |
| -
|
229 |
| -platform( |
230 |
| - name = "my_platform", |
231 |
| - parents = ["@local_config_platform//:host"], |
232 |
| - exec_properties = { |
233 |
| - "key2": "value2", |
234 |
| - "overridden": "parent_value", |
235 |
| - } |
236 |
| -) |
237 |
| -EOF |
238 |
| - bazel build --extra_execution_platforms=":my_platform" --toolchain_resolution_debug :a --execution_log_json_file out.txt &> $TEST_log || fail "Build failed" |
239 |
| - grep "key3" out.txt || fail "Did not find the target attribute key" |
240 |
| - grep "child_value" out.txt || fail "Did not find the overriding value" |
241 |
| - grep "key2" out.txt || fail "Did not find the platform key" |
242 |
| -} |
243 |
| - |
244 |
| -function test_target_exec_properties_cc_test() { |
245 |
| - cat > a.cc <<'EOF' |
246 |
| -#include <stdio.h> |
247 |
| -int main() { |
248 |
| - printf("Hello\n"); |
249 |
| -} |
250 |
| -EOF |
251 |
| - cat > BUILD <<'EOF' |
252 |
| -
|
253 |
| -cc_test( |
254 |
| - name = "a", |
255 |
| - srcs = ["a.cc"], |
256 |
| - exec_properties = {"key3": "value3", "overridden": "child_value"} |
257 |
| -) |
258 |
| -
|
259 |
| -platform( |
260 |
| - name = "my_platform", |
261 |
| - parents = ["@local_config_platform//:host"], |
262 |
| - exec_properties = { |
263 |
| - "key2": "value2", |
264 |
| - "overridden": "parent_value", |
265 |
| - } |
266 |
| -) |
267 |
| -EOF |
268 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt &> $TEST_log || fail "Build failed" |
269 |
| - grep "key2" out.txt || fail "Did not find the platform key" |
270 |
| - grep "key3" out.txt || fail "Did not find the target attribute key" |
271 |
| - grep "child_value" out.txt || fail "Did not find the overriding value" |
272 |
| -} |
273 |
| - |
274 |
| -function test_target_test_properties_sh_test() { |
275 |
| - cat > a.sh <<'EOF' |
276 |
| -#!/bin/bash |
277 |
| -echo hello |
278 |
| -EOF |
279 |
| - chmod u+x a.sh |
280 |
| - cat > BUILD <<'EOF' |
281 |
| -sh_test( |
282 |
| - name = "a", |
283 |
| - srcs = ["a.sh"], |
284 |
| - exec_properties = {"key3": "value3", "overridden": "child_value"} |
285 |
| -) |
286 |
| -
|
287 |
| -platform( |
288 |
| - name = "my_platform", |
289 |
| - parents = ["@local_config_platform//:host"], |
290 |
| - exec_properties = { |
291 |
| - "key2": "value2", |
292 |
| - "overridden": "parent_value", |
293 |
| - } |
294 |
| -) |
295 |
| -EOF |
296 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt &> $TEST_log || fail "Build failed" |
297 |
| - grep "key2" out.txt || fail "Did not find the platform key" |
298 |
| - grep "key3" out.txt || fail "Did not find the target attribute key" |
299 |
| - grep "child_value" out.txt || fail "Did not find the overriding value" |
300 |
| -} |
301 |
| - |
302 |
| -function test_platform_execgroup_properties_cc_test() { |
303 |
| - cat > a.cc <<'EOF' |
304 |
| -int main() {} |
305 |
| -EOF |
306 |
| - cat > BUILD <<'EOF' |
307 |
| -cc_test( |
308 |
| - name = "a", |
309 |
| - srcs = ["a.cc"], |
310 |
| -) |
311 |
| -
|
312 |
| -platform( |
313 |
| - name = "my_platform", |
314 |
| - parents = ["@local_config_platform//:host"], |
315 |
| - exec_properties = { |
316 |
| - "platform_key": "default_value", |
317 |
| - "test.platform_key": "test_value", |
318 |
| - } |
319 |
| -) |
320 |
| -EOF |
321 |
| - bazel build --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Build failed" |
322 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
323 |
| - grep "default_value" out.txt || fail "Did not find the default value" |
324 |
| - grep "test_value" out.txt && fail "Used the test-action value when not testing" |
325 |
| - |
326 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Test failed" |
327 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
328 |
| - grep "test_value" out.txt || fail "Did not find the test-action value" |
329 |
| -} |
330 |
| - |
331 |
| -function test_platform_execgroup_properties_nongroup_override_cc_test() { |
332 |
| - cat > a.cc <<'EOF' |
333 |
| -int main() {} |
334 |
| -EOF |
335 |
| - cat > BUILD <<'EOF' |
336 |
| -cc_test( |
337 |
| - name = "a", |
338 |
| - srcs = ["a.cc"], |
339 |
| - exec_properties = { |
340 |
| - "platform_key": "override_value", |
341 |
| - }, |
342 |
| -) |
343 |
| -
|
344 |
| -platform( |
345 |
| - name = "my_platform", |
346 |
| - parents = ["@local_config_platform//:host"], |
347 |
| - exec_properties = { |
348 |
| - "platform_key": "default_value", |
349 |
| - "test.platform_key": "test_value", |
350 |
| - } |
351 |
| -) |
352 |
| -EOF |
353 |
| - bazel build --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Build failed" |
354 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
355 |
| - grep "override_value" out.txt || fail "Did not find the overriding value" |
356 |
| - grep "default_value" out.txt && fail "Used the default value" |
357 |
| - |
358 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Test failed" |
359 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
360 |
| - grep "override_value" out.txt || fail "Did not find the overriding value" |
361 |
| -} |
362 |
| - |
363 |
| -function test_platform_execgroup_properties_group_override_cc_test() { |
364 |
| - cat > a.cc <<'EOF' |
365 |
| -int main() {} |
366 |
| -EOF |
367 |
| - cat > BUILD <<'EOF' |
368 |
| -cc_test( |
369 |
| - name = "a", |
370 |
| - srcs = ["a.cc"], |
371 |
| - exec_properties = { |
372 |
| - "test.platform_key": "test_override", |
373 |
| - }, |
374 |
| -) |
375 |
| -
|
376 |
| -platform( |
377 |
| - name = "my_platform", |
378 |
| - parents = ["@local_config_platform//:host"], |
379 |
| - exec_properties = { |
380 |
| - "platform_key": "default_value", |
381 |
| - "test.platform_key": "test_value", |
382 |
| - } |
383 |
| -) |
384 |
| -EOF |
385 |
| - bazel build --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Build failed" |
386 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
387 |
| - grep "default_value" out.txt || fail "Used the default value" |
388 |
| - |
389 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Test failed" |
390 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
391 |
| - grep "test_override" out.txt || fail "Did not find the overriding test-action value" |
392 |
| -} |
393 |
| - |
394 |
| -function test_platform_execgroup_properties_override_group_and_default_cc_test() { |
395 |
| - cat > a.cc <<'EOF' |
396 |
| -int main() {} |
397 |
| -EOF |
398 |
| - cat > BUILD <<'EOF' |
399 |
| -cc_test( |
400 |
| - name = "a", |
401 |
| - srcs = ["a.cc"], |
402 |
| - exec_properties = { |
403 |
| - "platform_key": "override_value", |
404 |
| - "test.platform_key": "test_override", |
405 |
| - }, |
406 |
| -) |
407 |
| -
|
408 |
| -platform( |
409 |
| - name = "my_platform", |
410 |
| - parents = ["@local_config_platform//:host"], |
411 |
| - exec_properties = { |
412 |
| - "platform_key": "default_value", |
413 |
| - "test.platform_key": "test_value", |
414 |
| - } |
415 |
| -) |
416 |
| -EOF |
417 |
| - bazel build --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Build failed" |
418 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
419 |
| - grep "override_value" out.txt || fail "Did not find the overriding value" |
420 |
| - grep "default_value" out.txt && fail "Used the default value" |
421 |
| - |
422 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Test failed" |
423 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
424 |
| - grep "test_override" out.txt || fail "Did not find the overriding test-action value" |
425 |
| -} |
426 |
| - |
427 |
| -function test_platform_properties_only_applied_for_relevant_execgroups_cc_test() { |
428 |
| - cat > a.cc <<'EOF' |
429 |
| -int main() {} |
430 |
| -EOF |
431 |
| - cat > BUILD <<'EOF' |
432 |
| -cc_test( |
433 |
| - name = "a", |
434 |
| - srcs = ["a.cc"], |
435 |
| -) |
436 |
| -
|
437 |
| -platform( |
438 |
| - name = "my_platform", |
439 |
| - parents = ["@local_config_platform//:host"], |
440 |
| - exec_properties = { |
441 |
| - "platform_key": "default_value", |
442 |
| - "unknown.platform_key": "unknown_value", |
443 |
| - } |
444 |
| -) |
445 |
| -EOF |
446 |
| - bazel test --extra_execution_platforms=":my_platform" :a --execution_log_json_file out.txt || fail "Build failed" |
447 |
| - grep "platform_key" out.txt || fail "Did not find the platform key" |
448 |
| - grep "default_value" out.txt || fail "Did not find the default value" |
449 |
| -} |
450 |
| - |
451 |
| -function test_cannot_set_properties_for_irrelevant_execgroup_on_target_cc_test() { |
452 |
| - cat > a.cc <<'EOF' |
453 |
| -int main() {} |
454 |
| -EOF |
455 |
| - cat > BUILD <<'EOF' |
456 |
| -cc_test( |
457 |
| - name = "a", |
458 |
| - srcs = ["a.cc"], |
459 |
| - exec_properties = { |
460 |
| - "platform_key": "default_value", |
461 |
| - "unknown.platform_key": "unknown_value", |
462 |
| - } |
463 |
| -) |
464 |
| -EOF |
465 |
| - bazel test :a &> $TEST_log && fail "Build passed when we expected an error" |
466 |
| - grep "Tried to set properties for non-existent exec group" $TEST_log || fail "Did not complain about unknown exec group" |
467 |
| -} |
468 |
| - |
469 |
| -run_suite "platform mapping test" |
| 120 | +run_suite "platform repo test" |
470 | 121 |
|
0 commit comments