bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.89k stars 4.01k forks source link

`bazel coverage //...` for Java on Windows fails #18839

Open Sakrafux opened 1 year ago

Sakrafux commented 1 year ago

Description of the bug:

When running bazel coverage //... for Java on Windows, it fails inexplicably.

BUILD:

load("@rules_jvm_external//:defs.bzl", "artifact")
load("@contrib_rules_jvm//java:defs.bzl", "JUNIT5_DEPS", "java_junit5_test", "java_test_suite")

java_library(
    name = "app-test-jar",
    srcs = glob(["src/main/java/**/*.java"]),
    resources = glob([
        "src/main/resources/**/*",
        "src/test/resources/**/*",
    ]),
    deps = [
        artifact("org.projectlombok:lombok"),
        artifact("org.springframework.boot:spring-boot"),
        artifact("org.springframework.boot:spring-boot-autoconfigure"),
        artifact("org.springframework.boot:spring-boot-starter-data-jpa"),
        artifact("org.springframework.boot:spring-boot-starter-security"),
        artifact("org.springframework.boot:spring-boot-starter-web"),
    ],
)

java_junit5_test(
    name = "test",
    size = "small",
    srcs = glob(["src/test/java/**/*.java"]),
    test_class = "com.example.demo.AdditionalTest",
    runtime_deps = JUNIT5_DEPS,
    deps = [
        ":app-test-jar",
        artifact("org.junit.jupiter:junit-jupiter-api"),
        artifact("org.junit.jupiter:junit-jupiter-params"),
        artifact("org.springframework.boot:spring-boot-starter-test"),
        artifact("org.springframework.boot:spring-boot-test"),
    ],
)

Running bazel coverage test fails with the following error:

==================== Test output for //backend:test:
ERROR(tools/test/windows/tw.cc:1294) ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\...\bazel-out\x64_windows-fastbuild\bin\backend\test.exe.runfiles\__main__\external\bazel_tools\tools\test\collect_coverage.sh"  backend/test.exe): The system cannot find the file specified.
 (error: 2)
ERROR(tools/test/windows/tw.cc:1453) Failed to start test process (arg: C:\users\...\bazel-out\x64_windows-fastbuild\bin\backend\test.exe.runfiles\__main__\external\bazel_tools\tools\test\collect_coverage.sh)
================================================================================
ERROR: E:/.../BUILD:21:17: output 'backend/test/coverage.dat' was not created
ERROR: E:/.../BUILD:21:17: Testing //backend:test failed: not all outputs were created or valid

When I force the missing script into the runfiles via data = ["@bazel_tools//tools/test:collect_coverage"] I instead get %1 is not a valid Win32 application. rather than The system cannot find the file specified.

To further clarify, bazel test test works fine and running everything with WSL successfully runs the coverage.

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

On a Windows machine, clone the given Java example https://github.com/bazelbuild/examples/tree/main/java-maven and run bazel coverage :tests.

Which operating system are you running Bazel on?

Windows 10

What is the output of bazel info release?

release 6.2.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

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

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

No response

hvadehra commented 1 year ago

Unfortunately, as of today, coverage requires being able to execute shell scripts. This is obviously not ideal for windows.

But there is hope this may improve soon, cc @c-mita

albertocavalcante commented 1 month ago

Just wondering, is there anything in particular that brings us hope @hvadehra?

c-mita commented 1 month ago

Nothing in particular; I have a dormant proposal https://github.com/bazelbuild/proposals/pull/351 that would, possibly, mean we wouldn't have to depend on shell scripts and rule authors could provide buildable executables to perform code coverage transformations.