Brian Silverman | 7d89e28 | 2021-11-17 17:36:54 -0800 | [diff] [blame] | 1 | """Helper transitions for tests.""" |
| 2 | |
| 3 | # This transition function sets `--features=per_object_debug_info` and |
| 4 | # `--fission` as well as the compilation mode. |
| 5 | # |
| 6 | # These three Bazel flags influence whether or not `.dwo` and `.dwp` are |
| 7 | # created. |
| 8 | def _fission_transition_impl(settings, attr): |
| 9 | features = settings["//command_line_option:features"] |
| 10 | if "per_object_debug_info" in features: |
| 11 | features.remove("per_object_debug_info") |
| 12 | |
| 13 | enable_per_object_debug_info = attr.per_object_debug_info |
| 14 | if enable_per_object_debug_info: |
| 15 | features.append("per_object_debug_info") |
| 16 | |
| 17 | compilation_mode = settings["//command_line_option:compilation_mode"] |
| 18 | if attr.override_compilation_mode: |
| 19 | compilation_mode = attr.override_compilation_mode |
| 20 | |
| 21 | return { |
| 22 | "//command_line_option:compilation_mode": compilation_mode, |
| 23 | "//command_line_option:fission": attr.fission, |
| 24 | "//command_line_option:features": features, |
| 25 | } |
| 26 | |
| 27 | fission_transition = transition( |
| 28 | implementation = _fission_transition_impl, |
| 29 | inputs = [ |
| 30 | "//command_line_option:compilation_mode", |
| 31 | "//command_line_option:features", |
| 32 | ], |
| 33 | outputs = [ |
| 34 | "//command_line_option:compilation_mode", |
| 35 | "//command_line_option:features", |
| 36 | "//command_line_option:fission", |
| 37 | ], |
| 38 | ) |
| 39 | |
| 40 | def _dwp_file_impl(ctx): |
| 41 | file = ctx.attr.name |
| 42 | file = ctx.actions.declare_file(file) |
| 43 | ctx.actions.symlink( |
| 44 | output = file, |
| 45 | target_file = ctx.attr.src[0][DebugPackageInfo].dwp_file, |
| 46 | ) |
| 47 | |
| 48 | return [DefaultInfo(files = depset([file]))] |
| 49 | |
| 50 | dwp_file = rule( |
| 51 | implementation = _dwp_file_impl, |
| 52 | attrs = { |
| 53 | "src": attr.label( |
| 54 | cfg = fission_transition, |
| 55 | mandatory = True, |
| 56 | doc = "The actual target to build and grab the .dwp file from.", |
| 57 | providers = [DebugPackageInfo], |
| 58 | ), |
| 59 | # NOTE: we should eventually be able to remove this (see #109). |
| 60 | "per_object_debug_info": attr.bool( |
| 61 | default = True, |
| 62 | ), |
| 63 | "fission": attr.string( |
| 64 | default = "yes", |
| 65 | values = ["yes", "no", "dbg", "fastbuild", "opt"], |
| 66 | ), |
| 67 | # NOTE: this should eventually not be necessary; see #109 for context |
| 68 | # and also: |
| 69 | # - https://reviews.llvm.org/D80391 |
| 70 | # - https://github.com/bazelbuild/bazel/issues/14038 |
| 71 | # - https://github.com/bazelbuild/rules_cc/pull/115 |
| 72 | # |
| 73 | # Essentially, we now need to specify `-g2` explicitly to generate |
| 74 | # `.dwo` files. |
| 75 | "override_compilation_mode": attr.string( |
| 76 | default = "", |
| 77 | mandatory = False, |
| 78 | values = ["dbg", "fastbuild", "opt"], |
| 79 | ), |
| 80 | "_allowlist_function_transition": attr.label( |
| 81 | default = "@bazel_tools//tools/allowlists/function_transition_allowlist", |
| 82 | ), |
| 83 | }, |
| 84 | incompatible_use_toolchain_transition = True, |
| 85 | ) |