livegrep / livegrep

Interactively grep source code. Source for http://livegrep.com/
Other
2.02k stars 181 forks source link

Unable to install node dependencies using bazel #120

Open akornor opened 7 years ago

akornor commented 7 years ago

I get this error: ERROR: /Users/raymond/code/livegrep/web/npm/css-loader/BUILD:7:1: installing node modules from web/npm/css-loader/npm-shrinkwrap.json failed (Exit 1). /private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/nodejs/bin/node: /private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/nodejs/bin/node: cannot execute binary file Traceback (most recent call last): File "/private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/com_github_livegrep_livegrep/../org_dropbox_rules_node/node/tools/npm/install.py", line 49, in main() File "/private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/com_github_livegrep_livegrep/../org_dropbox_rules_node/node/tools/npm/install.py", line 45, in main npm_install(args.shrinkwrap, args.output) File "/private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/com_github_livegrep_livegrep/../org_dropbox_rules_node/node/tools/npm/install.py", line 27, in npm_install run_npm(['install'], env=env, cwd=output) File "/private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/org_dropbox_rules_node/node/tools/npm/utils.py", line 93, in run_npm full_cmd, env=full_env, cwd=cwd, stderr=subprocess.STDOUT File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 573, in check_output raise CalledProcessError(retcode, cmd, output=output) subprocess.CalledProcessError: Command '['/private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/nodejs/bin/npm', 'install']' returned non-zero exit status 126 INFO: Elapsed time: 101.550s, Critical Path: 10.35s

Bazel version: Build label: 0.5.4-homebrew Build target: bazel-out/darwin_x86_64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Fri Aug 25 16:54:42 2017 (1503680082) Build timestamp: 1503680082 Build timestamp as int: 1503680082

nelhage commented 7 years ago

Hrm. @jboning do you have any ideas?

What's the output of file /private/var/tmp/_bazel_raymond/b8234531df81349f097554a459f6baeb/bazel-sandbox/8119839809326862884/execroot/com_github_livegrep_livegrep/bazel-out/host/bin/external/org_dropbox_rules_node/node/tools/npm/install.runfiles/nodejs/bin/node?

akornor commented 7 years ago

Adding

load("@org_dropbox_rules_node//node:defs.bzl", "node_repositories", "NODEJS_BUILD_FILE_CONTENT")

node_repositories(omit_nodejs=True)

new_http_archive(
    name = "nodejs",
    url = "https://nodejs.org/dist/v6.11.1/node-v6.11.1-darwin-x64.tar.gz",
    strip_prefix = "node-v6.11.1-darwin-x64",
    sha256 = "a2b839259089ef26f20c17864ff5ce9cd1a67e841be3d129b38d288b45fe375b",
    build_file_content = NODEJS_BUILD_FILE_CONTENT,
)

to workspace seems to fix it.

nelhage commented 7 years ago

Hm, that's frustrating. @jboning Do you (or anyone who works on rules_node or otherwise?) have any sense of whether there's a way to automatically conditionalize this in the WORKSPACE or BUILD file?

jboning commented 7 years ago

It miiight be possible to create external workspaces for both linux and darwin nodejs releases, and craft a nodejs workspace of our own that indirects between the two somehow.

It might be easier to extend rules_node itself to select between the two based on some --define flag passed to the bazel build. This sounds like a fun puzzle, so maybe I'll take a swing at it when I can find some time.

alper commented 5 years ago

I have the same problem and the latest checkout of livegrep does not fix it. How do I implement the addition above?

jcsalterego commented 5 years ago

I also ran into this issue on MacOS. Based on @akornor's hint, I extracted out the nodejs installation to the http_archive. Here's my modified diff against current master (129a89dbc51534d04e6abc0f2aa94dbad1e92942):

diff --git a/WORKSPACE b/WORKSPACE
index 532fbc3..0c262c8 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -134,9 +134,19 @@ git_repository(
     remote = "https://github.com/dropbox/rules_node.git",
 )

-load("@org_dropbox_rules_node//node:defs.bzl", "node_repositories")
+load("@org_dropbox_rules_node//node:defs.bzl", "node_repositories", "NODEJS_BUILD_FILE_CONTENT")

-node_repositories()
+node_repositories(omit_nodejs=True)
+
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+    name = "nodejs",
+    url = "https://nodejs.org/dist/v6.11.1/node-v6.11.1-darwin-x64.tar.gz",
+    strip_prefix = "node-v6.11.1-darwin-x64",
+    sha256 = "a2b839259089ef26f20c17864ff5ce9cd1a67e841be3d129b38d288b45fe375b",
+    build_file_content = NODEJS_BUILD_FILE_CONTENT,
+)

 new_git_repository(
     name = "compdb",

Side note: new_http_archive is deprecated, hence the load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") line.