Inconsistency between sh_binary docs and implementation
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
The sh_binary docs say:
`We recommend that you name your sh_binary() rules after the name of the script minus the extension (e.g. .sh); the rule name and the file name must be distinct`
But on windows, if the sh_binary is written without extension, this error is thrown:
```
throw ruleContext.throwWithRuleError(
"Source file is a Windows executable file,"
+ " target name extension should match source file extension");
```
https://github.com/bazelbuild/bazel/blob/b074ddb86eb0cdb7ca96110d6c3c8b602dde08d8/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/ShBinary.java#L132C27-L132C27
This makes it impossible to declare sh_binaries that wrap pre-compiled windows targets and use them in rules or genrules.
Errors are produced both when an extension is used in target name:
```
sh_binary(
name = "mico-cpp.exe",
srcs = ["mico-cpp.exe"],
)
used in rule attr:
"_mico_cpp": attr.label(default = Label("@MICO//:mico-cpp.exe"), cfg = "host", executable=True),
results in:
ERROR: D:/udu/b/3dsz6nhl/external/MICO/BUILD.bazel:8:10: in sh_binary rule @MICO//:mico-cpp.exe: cycle in dependency graph:
//src/server/icctskel:iccsadmin (9a08aa5e3d90fb8851bc398dec9ff1911a24c740b15279b4060412bc62040da3)
.-> @MICO//:mico-cpp.exe (929e5caa53c9bca4d9772686a4099333b8897f5d50a002376b67885bbefaa012) [self-edge]
```
And without extension:
```
sh_binary(
name = "mico-cpp",
srcs = ["mico-cpp.exe"],
)
used in rule attr:
"_mico_cpp": attr.label(default = Label("@MICO//:mico-cpp"), cfg = "host", executable=True),
gives this:
ERROR: D:/udu/b/3dsz6nhl/external/MICO/BUILD.bazel:8:10: in sh_binary rule @MICO//:mico-cpp: Source file is a Windows executable file, target name extension should match source file extension
```
Contributor guide
Research direction
Start by reading the sh_binary documentation and the linked location in src/main/java/com/google/devtools/build/lib/bazel/rules/sh/ShBinary.java, then reproduce both BUILD examples on Windows. Done means the documented naming guidance and implementation agree, and a pre-compiled Windows executable can be wrapped and used through the shown rule attribute.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100