hedronvision / bazel-compile-commands-extractor

Goal: Enable awesome tooling for Bazel users of the C language family.
Other
659 stars 109 forks source link

target <target @@hedron_compile_commands//:_refresh_all> does not have rules_python PyRuntimeInfo or builtin PyRuntimeInfo #163

Closed axbycc-mark closed 7 months ago

axbycc-mark commented 7 months ago

Following the setup, I ran bazel run @hedron_compile_commands//:refresh_all and got this error

ERROR: C:/users/marki/_bazel_marki/fmtahulu/external/hedron_compile_commands/BUILD:7:25: in _transition_py_binary rule @@hedron_compile_commands//:refresh_all:
Traceback (most recent call last):
        File "C:/users/marki/_bazel_marki/fmtahulu/external/rules_python/python/config_settings/transition.bzl", line 78, column 13, in _transition_py_impl
                fail("target {} does not have rules_python PyRuntimeInfo or builtin PyRuntimeInfo".format(target))
Error in fail: target <target @@hedron_compile_commands//:_refresh_all> does not have rules_python PyRuntimeInfo or builtin PyRuntimeInfo
ERROR: C:/users/marki/_bazel_marki/fmtahulu/external/hedron_compile_commands/BUILD:7:25: Analysis of target '@@hedron_compile_commands//:refresh_all' failed
ERROR: Analysis of target '@@hedron_compile_commands//:refresh_all' failed; build aborted
INFO: Elapsed time: 16.125s, Critical Path: 0.06s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

Bazel version 7.0.2 Windows 10 x86_64

cpsauer commented 7 months ago

Hi, @axbycc-mark! Thanks for giving the tool a try and for writing in.

I....am not sure based on that description and haven't been able to reproduce it on my machine. One guess if you're importing via the workspace: Could you try bringing in this tool first (rather than at the end of the file)? My first guess is that maybe some other dependency is bringing in an old version of rules_python.

If that doesn't work, could I ask you to explore some more and maybe give me some more details?

Thanks, Chris

axbycc-mark commented 7 months ago

I found out the error occurs even in an otherwise empty project, which I have uploaded below.

https://github.com/axbycc-mark/hedron-compile-commands-repro/tree/master

Is it because I am using a WORKSPACE file instead of using the new module system? Thanks for your help, I am excited to get this working!

cpsauer commented 7 months ago

Phew, yikes. Thanks @axbycc-mark.

I'm guessing it must be a Windows-specific bazelbuild/rules_python issue, then, since that test project runs cleanly on Mac and the error doesn't seem to make a lot of sense...it's rules_python complaining about it's own py_binary rule?

Here's what I think we should do: Would you be down to report this to the folks over at bazelbuild/rules_python, cc me? (It looks like they've got other windows breakages over there....) Then would you be down test with rules python downgraded (use this tool's commit 4d5671472a7272ea19dd61debf1e64d8aed27b41)? If that works, great, temporarily. And if not let's zip you back to 6d58fa6bf39f612304e55566fa628fd160b38177, just to make sure all was working before moving to rules python. I'm so sorry this has caused a headache; we tried to switch to Bazel's new python infrastructure to not reply on system python and to be able to use packages, but they've had quite a few bugs.

axbycc-mark commented 7 months ago

4d5671472a7272ea19dd61debf1e64d8aed27b41 failed with the same error. 6d58fa6bf39f612304e55566fa628fd160b38177 successfully generated a compile_commands.json after I made dummy BUILD file building a simple cc_library. I had to update my WORKSPACE following the previous install instructions


load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
http_archive(
    name = "hedron_compile_commands",

    # Replace the commit hash (daae6f40adfa5fdb7c89684cbe4d88b691c63b2d) in both places (below) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main), rather than using the stale one here.
    # Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
    url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/daae6f40adfa5fdb7c89684cbe4d88b691c63b2d.tar.gz",
    strip_prefix = "bazel-compile-commands-extractor-daae6f40adfa5fdb7c89684cbe4d88b691c63b2d",
    # When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup() 

I hope that helps.

axbycc-mark commented 7 months ago

Not sure what to put for the python_rules version in my upstream issue, can you let me know?

cpsauer commented 7 months ago

Thanks so much for reporting and helping. Replied over there. Sorry again about the headache here. Importance of that test case I was asking you to run is to make sure they aren't just wholly broken on windows. We'll knock this out if we work together :)

cpsauer commented 7 months ago

Reverted rules_python in https://github.com/hedronvision/bazel-compile-commands-extractor/commit/0b821b7e4286aec887757461366f6eaaa0972cb9. Tracking restoration in https://github.com/hedronvision/bazel-compile-commands-extractor/issues/168.

That avoids this for now, but seriously, worth our working with them to get it fixed for future use; this'll be important in the future.

(Just holler if you want me to reopen.)

Thanks again for helping leave things better than you found them!