toolchains_llvm icon indicating copy to clipboard operation
toolchains_llvm copied to clipboard

Coverage flags included when target does not have coverage

Open TroyKomodo opened this issue 5 months ago • 2 comments

Not sure if this issue is related to this repo or not, however I noticed that

def get_cc_compile_args_and_env(cc_toolchain, feature_configuration):
    """Gather cc environment variables from the given `cc_toolchain`

    Args:
        cc_toolchain (cc_toolchain): The current rule's `cc_toolchain`.
        feature_configuration (FeatureConfiguration): Class used to construct command lines from CROSSTOOL features.

    Returns:
        tuple: A tuple of the following items:
            - (sequence): A flattened C command line flags for given action.
            - (sequence): A flattened CXX command line flags for given action.
            - (dict): C environment variables to be set for given action.
    """
    compile_variables = cc_common.create_compile_variables(
        feature_configuration = feature_configuration,
        cc_toolchain = cc_toolchain,
    )
    cc_c_args = cc_common.get_memory_inefficient_command_line(
        feature_configuration = feature_configuration,
        action_name = ACTION_NAMES.c_compile,
        variables = compile_variables,
    )
    cc_cxx_args = cc_common.get_memory_inefficient_command_line(
        feature_configuration = feature_configuration,
        action_name = ACTION_NAMES.cpp_compile,
        variables = compile_variables,
    )
    cc_env = cc_common.get_environment_variables(
        feature_configuration = feature_configuration,
        action_name = ACTION_NAMES.c_compile,
        variables = compile_variables,
    )
    return cc_c_args, cc_cxx_args, cc_env

The following macro if invoked via bazel coverage //... will always return c_args and cxx_args including -fprofile-instr-generate -fcoverage-mapping even if the target is not selected for coverage using --instrumentation_filter.

TroyKomodo avatar Jul 02 '25 20:07 TroyKomodo

Toolchain found via the following macro

def find_cc_toolchain(ctx, extra_unsupported_features = tuple()):
    """Extracts a CcToolchain from the current target's context

    Args:
        ctx (ctx): The current target's rule context object
        extra_unsupported_features (sequence of str): Extra featrures to disable

    Returns:
        tuple: A tuple of (CcToolchain, FeatureConfiguration)
    """
    cc_toolchain = find_rules_cc_toolchain(ctx)

    feature_configuration = cc_common.configure_features(
        ctx = ctx,
        cc_toolchain = cc_toolchain,
        requested_features = ctx.features,
        unsupported_features = UNSUPPORTED_FEATURES + ctx.disabled_features +
                               list(extra_unsupported_features),
    )
    return cc_toolchain, feature_configuration

TroyKomodo avatar Jul 02 '25 20:07 TroyKomodo

This needs to be fixed in Bazel first: https://github.com/bazelbuild/bazel/pull/26355

fmeum avatar Jul 02 '25 20:07 fmeum