question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUILD and WORKSPACE files not captured by data

See original GitHub issue

Description of the problem:

I want to write some tests for the bazel-to-cmake project, and for that i need to grab some BUILD and WORKSPACE files as input testdata. I guess for obvious reasons, some special filenames are excluded, because usually no one needs them. But in this case i do, and not even naming them helps:

py_test(
    name = "test1",
    srcs = ["test1.py"],
    data = glob([
        "input/BUILD",
        "input/WORKSPACE",
        "expected/*",
    ]),
)

everything within the expected directory is caught and visible in *.runfiles.

Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

git clone git@github.com:blackliner/bazel-to-cmake.git
cd bazel-to-cmake
git reset --hard 8bfb4ced3e599f578f8c6e0a8c29966f8c6e5a9f
bazel test ... --test_output=all

see error message: FileNotFoundError: [Errno 2] No such file or directory: 'input/'

What operating system are you running Bazel on?

Ubuntu 18.04@WSL2 on Windows10

What’s the output of bazel info release?

release 1.2.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iirinacommented, Dec 16, 2019

Hi @blackliner, I took a look at your fork and the test you’re trying to write. Here’s what I found was not exactly correct in your BUILD files.

  • the use of glob() shouldn’t include the BUILD and WORKSPACE files because in this case they are targets, not regular files.
  • the input/BUILD file must export WORKSPACE and have the proper package visibility so it can be read from //test/test1

Here’s how I rewrote them:

//test/test1/BUILD

py_test(
    name = "test1",
    srcs = ["test1.py"],
    data = ["//test/test1/input:BUILD", "//test/test1/input:WORKSPACE",] 
             + glob(["expected/*"]),
)

//test/test1/input/BUILD

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

cc_library(name = "main",
           srcs = ["main.h"])

The test still fails because you’re trying to access test/test1/input/test which doesn’t exist, in the sense that it’s not a declared dependency on your test. How is this file created? Can you check it in and declare it as a data dependency which gets rewritten for every test?

0reactions
blacklinercommented, May 13, 2020

If you want the BUILD and WORKSPACE files to not be treated specially by Bazel, you’ll need to rename them, since Bazel uses filenames to determine what files are special to it.

That was what i wanted to find out: how to de-specialize those two files. If that is not possible, workarounds are always a thing of course.

Thanks, can be kept closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to open a workspace that was not exported?
If it doesn't help, try to find workspace files in the folder specified in "Workspace files location" setting (Home | Preferences). Each ...
Read more >
Using Workspaces to Share Data between Jobs - CircleCI
This document describes how to use workspaces to share data to downstream jobs in your workflows.
Read more >
Why is Jenkins suddenly unable to delete a workspace
Someone has logged into Jenkins and is accessing the files from the workspace directly using the file system but not via Jenkins. The...
Read more >
Passing data between build steps | Cloud Build Documentation
To pass data between build steps, store the assets produced by the build step in /workspace and these assets will be available to...
Read more >
Capture Google Drive for desktop logs for support
If you contact Google Workspace support about a Google Drive for desktop issue, ... Capture log files when the application is not available....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found