"Could not chdir" when trying to run a gtest using bazel on Windows 10

0

I'm running the command bazel run //examples:gtest_example which yields the resulting output

INFO: Analyzed target //examples:gtest_example (1 packages loaded, 134 targets configured).
INFO: Found 1 target...
Target //examples:gtest_example up-to-date:
  bazel-bin/examples/gtest_example.exe
INFO: Elapsed time: 0.230s, Critical Path: 0.01s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Executing tests from //examples:gtest_example
-----------------------------------------------------------------------------
ERROR(tools/test/windows/tw.cc:462) value: 2 (0x00000002), arg: c:\users\mark\_bazel~1\v57xrjki\execroot\berobot\bazel-out\x64_windows-fastbuild\bin\examples\gtest_example.exe.runfiles\berobot: Could not chdir

The error reported is accurate because c:\users\mark\_bazel~1\v57xrjki\execroot\berobot\bazel-out\x64_windows-fastbuild\bin\examples\gtest_example.exe.runfiles\berobot does not exist because the final folder berobot does not exist. If I create it, the test succeeds. But if I bazel clean the test fails again until I manually create the folder.

More information

In /examples/BUILD I have

cc_test(
    name = "gtest_example",
    srcs = ["gtest_example.cc"],
    deps = [
        "@gtest//:gtest_main",
    ],
)

examples/gtest_example.cpp is a normal google test program. I don't think it's related to the error.

In my WORKSPACE I have

workspace(name = "berobot")

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

http_archive(
    name = "gtest",
    url = "https://github.com/google/googletest/archive/release-1.10.0.zip",
     sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
    strip_prefix = "googletest-release-1.10.0",
)

Bazel Docs

Here is a quote from the bazel docs. It says

The directories are laid out as follows:

       <workspace-name>/                 <== Working tree for the Bazel build & root of symlink forest: execRoot
          _bin/                           <== Helper tools are linked from or copied to here.

          bazel-out/                      <== All actual output of the build is under here: outputPath
            local_linux-fastbuild/        <== one subdirectory per unique target BuildConfiguration instance;
                                              this is currently encoded
              bin/                        <== Bazel outputs binaries for target configuration here: $(BINDIR)
                foo/bar/_objs/baz/        <== Object files for a cc_* rule named //foo/bar:baz
                  foo/bar/baz1.o          <== Object files from source //foo/bar:baz1.cc
                  other_package/other.o   <== Object files from source //other_package:other.cc
                foo/bar/baz               <== foo/bar/baz might be the artifact generated by a cc_binary named
                                              //foo/bar:baz
                foo/bar/baz.runfiles/     <== The runfiles symlink farm for the //foo/bar:baz executable.
                  MANIFEST
                  <workspace-name>/

The last line is the relevant one. It seems in my case, the directory <workspace-name> inside the runfiles directory is not being created.

windows
googletest
bazel
asked on Stack Overflow Dec 16, 2019 by Mark Liu • edited Jun 20, 2020 by Community

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0