|
| 1 | +"""Regression tests for musl rustdoc native linking.""" |
| 2 | + |
| 3 | +load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") |
| 4 | + |
| 5 | +def _get_action_by_mnemonic(env, tut, mnemonic): |
| 6 | + actions = [action for action in tut.actions if action.mnemonic == mnemonic] |
| 7 | + asserts.equals( |
| 8 | + env, |
| 9 | + 1, |
| 10 | + len(actions), |
| 11 | + "Expected exactly one {} action, got {}".format(mnemonic, [action.mnemonic for action in tut.actions]), |
| 12 | + ) |
| 13 | + return actions[0] |
| 14 | + |
| 15 | +def _assert_argv_contains(env, action, expected): |
| 16 | + asserts.true( |
| 17 | + env, |
| 18 | + expected in action.argv, |
| 19 | + "Expected argv to contain {}, got {}".format(expected, action.argv), |
| 20 | + ) |
| 21 | + |
| 22 | +def _assert_argv_contains_substrings(env, action, substrings, description): |
| 23 | + for arg in action.argv: |
| 24 | + if all([substring in arg for substring in substrings]): |
| 25 | + return |
| 26 | + |
| 27 | + asserts.true( |
| 28 | + env, |
| 29 | + False, |
| 30 | + "Expected argv to contain {}, got {}".format(description, action.argv), |
| 31 | + ) |
| 32 | + |
| 33 | +def _rustdoc_musl_unwind_link_flags_test_impl(ctx): |
| 34 | + env = analysistest.begin(ctx) |
| 35 | + tut = analysistest.target_under_test(env) |
| 36 | + action = _get_action_by_mnemonic(env, tut, "RustdocTest") |
| 37 | + |
| 38 | + _assert_argv_contains(env, action, "--test") |
| 39 | + _assert_argv_contains(env, action, "-Clink-arg=-lrustdoc_musl_unwind_cc") |
| 40 | + _assert_argv_contains_substrings( |
| 41 | + env, |
| 42 | + action, |
| 43 | + ["-Clink-arg=-l", "unwind"], |
| 44 | + "a rustdoc-compatible libunwind link argument", |
| 45 | + ) |
| 46 | + |
| 47 | + return analysistest.end(env) |
| 48 | + |
| 49 | +rustdoc_musl_unwind_link_flags_test = analysistest.make( |
| 50 | + _rustdoc_musl_unwind_link_flags_test_impl, |
| 51 | + config_settings = { |
| 52 | + "//command_line_option:extra_execution_platforms": str(Label("//rs/platforms:x86_64-unknown-linux-musl")), |
| 53 | + "//command_line_option:platforms": str(Label("//rs/platforms:x86_64-unknown-linux-musl")), |
| 54 | + }, |
| 55 | +) |
0 commit comments