Skip to content

Default runfiles to upwards directory as a last fallback - #587

Closed
Globegitter wants to merge 3 commits into
bazel-contrib:masterfrom
Globegitter:patch-2
Closed

Globegitter wants to merge 3 commits into
bazel-contrib:masterfrom
Globegitter:patch-2

Conversation

@Globegitter

@Globegitter Globegitter commented Feb 28, 2019 •

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

When wanting to run the nodejs_binary in a custom sh_binary, to have some custom setup or run multiple commands for integration tests for example, one just sees the error message ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash when executing the binary and it is not really obvious as to why the bash runfiles can not be found.

After digging further it turns out one has to explicitely set the RUNFILES env variable to .. and I wonder if it is not possible to make this use-case work out of the box as this is what we expected.

simple BUILD file example to illustrate the wrapping:

nodejs_binary(
    name = "app", 
    entry_point = "__main__/app.js",
    data = ["app.js", "@npm//somedep"],
)

sh_binary(
    name = "app",
    srcs = ["my_script.sh"],
    data = [":app"],
)

What is the new behavior?

Defaulting RUNFILES to .. if neither RUNFILES_MANIFEST_FILE nor RUNFILES_DIR can be set in any other way.

Does this PR introduce a breaking change?

I would expect this to not break any existing usages, as it only adds one further case to try for the runfiles dir. And if it is still not there it will still fail.

@Globegitter
Globegitter marked this pull request as ready for review February 28, 2019 14:07
@Globegitter Globegitter changed the title Default runfiles to upwards directory Default runfiles to upwards directory as a last fallback Feb 28, 2019
@Globegitter

Copy link
Copy Markdown
Author

Seems the buildkite tests are very flaky on master also so should be unrelated to my changes.

@Globegitter

Copy link
Copy Markdown
Author

@gregmagolan any chance to get this merged in or to get some feedback on this? Would love to be able to remove our internal workaround for this.

@Globegitter

Copy link
Copy Markdown
Author

I would also be happy to add an e2e example that utilises sh_binary to demonstrate and have a test for this.

@gregmagolan

Copy link
Copy Markdown
Collaborator

Something seems fishy here. That bash runfiles init code is copy pasted from https://github.com/bazelbuild/bazel/blob/master/tools/bash/runfiles/runfiles.bash so I'm hesitant to modify it and its also duplicated in multiple places in the repo.

We do something similar in e2e/ts_library/some_module:

nodejs_binary(
    name = "bin",
    data = [
        ":main",
        ":some_module",
    ],
    entry_point = "e2e_ts_library/some_module/main.js",
)

sh_test(
    name = "module_load_test",
    srcs = ["module_load_test.sh"],
    data = [
        ":bin",
        "@bazel_tools//tools/bash/runfiles",
    ],
)

with e2e/ts_library/some_module/module_load_test.sh using the standard runfiles init code and then using rlocation to find launch the node process:

#!/bin/bash
set -e

# --- begin runfiles.bash initialization ---
...
# --- end runfiles.bash initialization ---

readonly OUT=$($(rlocation "e2e_ts_library/some_module/bin"))

if [ "$OUT" != "hello world" ]; then
  echo "Expected output 'hello world' but was $OUT"
  exit 1
fi

Does that work in your case?

@Globegitter

Copy link
Copy Markdown
Author

Interesting, so maybe something to raise in the bazel main repo. I have not tried the snippet you posted yet but I am sure it would fix it also. But my point is that this is not obvious in any way, that if I want to depend on a nodejs_binary and just execute it via bazel run that I need to provide some location/runflies logic. Even if it was documented, it increases the entry barrier for new developers for something that should be pretty simple.

I did open a PR in bazel for this: bazelbuild/bazel#7774

@github-actions

Copy link
Copy Markdown
Contributor

This Pull Request has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

@github-actions github-actions Bot added the Can Close? We will close this in 30 days if there is no further activity label Nov 18, 2020
@github-actions

github-actions Bot commented Dec 2, 2020

Copy link
Copy Markdown
Contributor

This PR was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

@github-actions github-actions Bot closed this Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Can Close? We will close this in 30 days if there is no further activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants