Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel: test a real-world workspace that uses rules_go and rules_nodejs #43507

Closed
wants to merge 6 commits into from

Conversation

kalbasit
Copy link
Member

@kalbasit kalbasit commented Jul 14, 2018

Motivation for this change

Currently, Bazel installed on NixOS does work on a project that uses rules_go and rules_nodejs.

The purpose of this PR is to open a discussion on what can we do to get rules such as rules_go and rules_nodejs work with no changes, or with minimal changes, to the actual project.

For nodejs, I tried using node_path, but that does not work either since the rules assume you are pointing to the root of the node installation, which works for node itself but does not work for yarn; It tries to execute ${node_path}/bin/node ${yarn_path}/bin/yarn.js. The derivation nixos.yarn provides bin/yarn, so it does not match it and it fails. Besides, this is an actual change to the project that will affect everyone with or without Nix.

cc @mboes @volth @Profpatsch

$ nix-build ./pkgs/top-level/release.nix -A tests.bazel
these derivations will be built:
  /nix/store/0fqhgv2i324drlwzf6lcazmy64q9wi62-bazel-test.drv
building '/nix/store/0fqhgv2i324drlwzf6lcazmy64q9wi62-bazel-test.drv'...
unpacking sources
unpacking source archive /nix/store/8rp8nvqyr52n4s45qg6f1wzkq7mrpw4a-bazel
source root is bazel
patching sources
configuring
no configure script, doing nothing
building
running bazel run //:gazelle Loading:
Loading: 0 packages loaded
Loading: 0 packages loaded
    currently loading:
Analyzing: target //:gazelle (4 packages loaded)
Analyzing: target //:gazelle (7 packages loaded)
Analyzing: target //:gazelle (21 packages loaded)
Analyzing: target //:gazelle (30 packages loaded)
DEBUG: /tmp/.bazel-30001/.bazel/962e61887c2adf20fb3a0a8cd817313c/external/io_bazel_rules_go/go/private/sdk.bzl:84:5: env: 'bin/go': No such file or directory
ERROR: /tmp/.bazel-30001/.bazel/962e61887c2adf20fb3a0a8cd817313c/external/bazel_gazelle/internal/resolve/BUILD.bazel:43:1: no such package '@go_sdk//': Traceback (most recent call last):
        File "/tmp/.bazel-30001/.bazel/962e61887c2adf20fb3a0a8cd817313c/external/io_bazel_rules_go/go/private/sdk.bzl", line 52
                _prepare(ctx)
        File "/tmp/.bazel-30001/.bazel/962e61887c2adf20fb3a0a8cd817313c/external/io_bazel_rules_go/go/private/sdk.bzl", line 85, in _prepare
                fail("failed to list standard package...")
failed to list standard packages and referenced by '@bazel_gazelle//internal/resolve:std_package_list'
ERROR: Analysis of target '//:gazelle' failed; build aborted: no such package '@go_sdk//': Traceback (most recent call last):
        File "/tmp/.bazel-30001/.bazel/962e61887c2adf20fb3a0a8cd817313c/external/io_bazel_rules_go/go/private/sdk.bzl", line 52
                _prepare(ctx)
        File "/tmp/.bazel-30001/.bazel/962e61887c2adf20fb3a0a8cd817313c/external/io_bazel_rules_go/go/private/sdk.bzl", line 85, in _prepare
                fail("failed to list standard package...")
failed to list standard packages
INFO: Elapsed time: 9.978s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (30 packages loaded)
ERROR: Build failed. Not running target
builder for '/nix/store/0fqhgv2i324drlwzf6lcazmy64q9wi62-bazel-test.drv' failed with exit code 1
error: build of '/nix/store/0fqhgv2i324drlwzf6lcazmy64q9wi62-bazel-test.drv' failed
$ cd pkgs/test/bazel; nix-shell -p bazel --run 'bazel test //...'
ERROR: /home/kalbasit/code/opensource/stories/test-bazel/src/github.com/NixOS/nixpkgs/pkgs/test/bazel/rules_nodejs/BUILD.bazel:10:1: no such package '@root_node_modules//': yarn_install failed:  (java.io.IOException: Cannot run program "/home/kalbasit/.cache/bazel/_bazel_kalbasit/61aa1d2a671723c542d4a1c85ce4fd35/external/nodejs/bin/yarn" (in directory "/home/kalbasit/.cache/bazel/_bazel_kalbasit/61aa1d2a671723c542d4a1c85ce4fd35/external/root_node_modules"): error=2, No such file or directory) and referenced by '//rules_nodejs:test'
ERROR: Analysis of target '//rules_nodejs:test' failed; build aborted: no such package '@root_node_modules//': yarn_install failed:  (java.io.IOException: Cannot run program "/home/kalbasit/.cache/bazel/_bazel_kalbasit/61aa1d2a671723c542d4a1c85ce4fd35/external/nodejs/bin/yarn" (in directory "/home/kalbasit/.cache/bazel/_bazel_kalbasit/61aa1d2a671723c542d4a1c85ce4fd35/external/root_node_modules"): error=2, No such file or directory)
INFO: Elapsed time: 0.580s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
ERROR: Couldn't start the build. Unable to run tests

On ArchLinux:

$ bazel test //...
INFO: Analysed 6 targets (0 packages loaded).
INFO: Found 4 targets and 2 test targets...
INFO: Elapsed time: 0.287s, Critical Path: 0.09s
INFO: 3 processes, processwrapper-sandbox.
INFO: Build completed successfully, 4 total actions
//rules_go:go_default_test                                      (cached) PASSED in 0.0s
//rules_nodejs:test                                             (cached) PASSED in 0.2s

Executed 0 out of 2 tests: 2 tests pass.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.

@kalbasit
Copy link
Member Author

I'm going to close this for now and focus on getting the test pass, I'll re-open once I have it working.

@kalbasit kalbasit closed this Jul 16, 2018
@mboes
Copy link
Contributor

mboes commented Jul 24, 2018

For consumers of rules_go, the trick is to tell it to use the "host sdk" in the WORKSPACE file configuration.

@kalbasit
Copy link
Member Author

@mboes and that's fine. But what about rules_typescript? Have you seen #43955?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants