Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faulty tool path handling for "gcov" tool #15411

Open
UlrichEckhardt opened this issue May 6, 2022 · 5 comments
Open

Faulty tool path handling for "gcov" tool #15411

UlrichEckhardt opened this issue May 6, 2022 · 5 comments
Labels
coverage P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)

Comments

@UlrichEckhardt
Copy link

Description of the bug:

The handling of tool paths in C++ toolchains is inconsistent, it works as expected for tools like gcc, ld and ar, but not for gcov. In the end, gcov is not found and no coverage is generated. The error you find in the test.log file is

GCov does not exist at the given path: 'toolchains/mingw/toolchains/mingw/gcov.sh'

Note here the duplication of toolchains/mingw in the path.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I haven't fully extracted a minimal reproducible example yet, but here is the rough layout of it:

toolchain/cc_toolchain_config.bzl

def _impl(ctx):
    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        tool_paths = [
            tool_path(name = "gcc", path = ctx.file.gcc_executable.path),
            tool_path(name = "gcov", path = ctx.file.gcov_executable.path),
        ],
    )


cc_toolchain_config = rule(
    implementation = _impl,
    attrs = {
        "gcc_executable": attr.label(executable = True, allow_single_file = True, cfg = "exec"),
        "gcov_executable": attr.label(executable = True, allow_single_file = True, cfg = "exec"),
    },
    provides = [CcToolchainConfigInfo],
)

toolchain/gcc.sh

#!/bin/sh
# simple wrapper script 
echo gcc "$@"
exec gcc "$@"

toolchain/gcov.sh

#!/bin/sh
# simple wrapper script 
echo gcov "$@"
exec gcov "$@"

toolchain/BUILD

load(":cc_toolchain_config.bzl", "cc_toolchain_config")

package(default_visibility = ["//visibility:public"])

toolchain(
    name = "my_toolchain",
    toolchain = ":my_cc_toolchain",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

cc_toolchain(
    name = "my_cc_toolchain",
    toolchain_config = ":my_cc_toolchain_config",
)

cc_toolchain_config(
    name = "my_cc_toolchain_config",
    gcc_executable = ":gcc.sh",
    gcov_executable = ":gcov.sh",
)

Which operating system are you running Bazel on?

Ubuntu

What is the output of bazel info release?

release 5.1.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

  • There is no action associated with gcov. For all others tools, there are actions (compile, link etc) and action_configs that reference the tools, but not for gcov. That also means I can't define e.g. a PATH to that tool in order to help Bazel find it.
  • Allow cc_toolchain to be defined across multiple repositories #7746 is related to my actual goal, to run a gcov from an archive.
@comius
Copy link
Contributor

comius commented May 24, 2022

@c-mita can you triage?

@oquenchil oquenchil added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed untriaged labels Jul 7, 2022
@ceyxiang
Copy link

Hi @UlrichEckhardt, I encountered this issue when I was setting up a hermetic gcc toolchain. I managed to resolve it by,

  1. adding both the wrapper script and gcov to a filegroup,
filegroup(
    name = "coverage_files",
    srcs = [
        "@repo1//:gcov_wrapper_script",
        "@repo2//:gcov",
    ],
)
  1. Adding that filegroup to the srcs of my gcc_all_files filegroup
filegroup(
    name = "gcc_all_files",
    srcs = [
        ":some_files",
        ":gcc_coverage_files",
    ],
)
  1. Then in the cc_toolchain, all_files = ":gcc_all_files",. So in your case
cc_toolchain(
    name = "my_cc_toolchain",
    all_files = ":gcc_all_files",
    toolchain_config = ":my_cc_toolchain_config",
)

Hopefully this helps!

@charlesoconor
Copy link

This was failing for me as well. Fixed it by installing llvm-cov since the script seems to find that executable.

Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Aug 18, 2024
@hauserx
Copy link
Contributor

hauserx commented Aug 27, 2024

The tool_path accepts either toolchain relative paths or absolute paths, so it's pretty hard to reference gcov binary from external dep. Workaround seems to be using COVERAGE_GCOV_PATH env variable, like: --test_env=COVERAGE_GCOV_PATH=external/my-gcc/bin/gcov but it stopped working in bazel 7.2: #23247. The bug metions also some possible solutions, including using action_configs instead of tool_paths, which seems to be right approach here.

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coverage P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)
Projects
None yet
Development

No branches or pull requests

7 participants