Building genrule() reports that jar command not found.

635 views
Skip to first unread message

Leo Yin

unread,
Apr 17, 2016, 7:15:42 AM4/17/16
to bazel-discuss
Hi,

My BUILD file has a genrule() as follows:

genrule(
   name = "gen_ism_encry_jar",
   srcs = [":Combine_complieAndJar"],
   outs = ["ism_encry.jar"],
   cmd = "cp $(location :Combine_complieAndJar) $@; jar uf $@ " + baseDir + "Install_Moudle/ISM-Encry/src/log4j.properties",
)

When building bazel reports that jar command not found. However, jar is installed and it is in the PATH (executing 'which jar' will print '/usr/local/java/jdk1.8.0_77/bin/jar').

I used the bazel build command with '-s' option and got the failed command as follows:

(cd /root/.cache/bazel/_bazel_root/62a52d88f2594916d0a2e0364313b1a5/SPA && \
  exec env - \
    PATH=/usr/local/java/bin:/usr/local/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/java/jdk1.8.0_77/bin:/usr/local/java/jdk1.8.0_77/jre//bin:/usr/local/apache-ant/bin:/usr/local/java/jdk1.8.0_77/bin:/usr/local/java/jdk1.8.0_77/jre//bin:/usr/local/apache-ant/bin:/usr/local/java/jdk1.8.0_77/bin:/usr/local/java/jdk1.8.0_77/jre//bin:/usr/local/apache-ant/bin:/usr/local/java/jdk1.8.0_77/bin:/usr/local/java/jdk1.8.0_77/jre//bin:/usr/local/apache-ant/bin \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; cp bazel-out/local_linux-fastbuild/bin/libCombine_complieAndJar.jar bazel-out/local_linux-fastbuild/genfiles/ism_encry.jar; 
  jar uf bazel-out/local_linux-fastbuild/genfiles/ism_encry.jar systemAnalyzer/Install_Moudle/ISM-Encry/src/log4j.properties')

To my surprise, directly executing the above command in the shell returns 0.

In another machine, in which jar is installed in /usr/bin/jar from Oracle jdk 1.8, this failure is not reported.

Can anyone give some help?

Thank you very much!

Regards,

Leo


Brian Silverman

unread,
Apr 17, 2016, 9:20:10 AM4/17/16
to Leo Yin, bazel-discuss
Sounds like the issue is the sandbox including /usr/bin but not /usr/local. Adding '@local_jdk//:jar' to your srcs should fix it.

For future reference, --sandbox_debug in addition to --verbose_failures is helpful for debugging this kind of issue.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/db65600e-3bad-4e03-b89c-f5bd7ead2a10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leo Yin

unread,
Apr 18, 2016, 9:20:00 AM4/18/16
to bazel-discuss, leo...@huawei.com
Hi Brian,

I modified BUILD as follows:

 genrule(
    name = "gen_ism_encry_jar",
    srcs = [
      ":Combine_complieAndJar",
      baseDir + "Install_Moudle/ISM-Encry/src/log4j.properties",
      "@local_jdk//:jar",
   ],
   outs = ["ism_encry.jar"],
   cmd = "cp $(location :Combine_complieAndJar) $@; jar uf $@ " + baseDir + "Install_Moudle/ISM-Encry/src/log4j.properties",
)

Bazel still reported jar could not be found. 

The option --sandbox_debug lets bazel print directories mounted in the sandbox, among which there is no '/usr/local'.

How can '/usr/local' be included into sandbox?

Thank you very much.

-Leo









在 2016年4月17日星期日 UTC+8下午9:20:10,Brian Silverman写道:

Kristina Chodorow

unread,
Apr 18, 2016, 9:59:53 AM4/18/16
to Leo Yin, bazel-discuss
You have to pull the jar location from the srcs list, so change your cmd to:

 "cp $(location :Combine_complieAndJar) $@; $(location @local_jdk//:jar) uf $@ " + baseDir + "Install_Moudle/ISM-Encry/src/log4j.properties",

Alternatively, you can include /usr/local/ by creating a new_local_repository (see http://bazel.io/docs/external.html) but that's probably more work than you want to do to just get jar.

Kristina Chodorow

unread,
Apr 18, 2016, 10:01:22 AM4/18/16
to Leo Yin, bazel-discuss
Also, technically @local_jdk//:jar should probably be listed in tools (http://bazel.io/docs/be/general.html#genrule.tools), but it doesn't really matter in this case.

Leo Yin

unread,
Apr 18, 2016, 11:22:21 PM4/18/16
to bazel-discuss, leo...@huawei.com
Hi Kristina,

genrule() is modified as follows.

genrule(
  name = "gen_ism_encry_jar",
  srcs = [
    ":Combine_complieAndJar",
    baseDir + "Install_Moudle/ISM-Encry/src/log4j.properties",
  ],
  outs = ["ism_encry.jar"],
  tools = ["@local_jdk//:jar"],
  cmd = "cp $(location :Combine_complieAndJar) $@; $(location @local_jdk//:jar) uf $@ " + baseDir + "Install_Moudle/ISM-Encry/src/log4j.properties",
)

Bazel reports "external/local_jdk/bin/jar: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory".

Setting cmd = "cp $(location :Combine_complieAndJar) $@; /usr/local/java/jdk1.8.0_77/bin/jar uf $@ " + baseDir + "Install_Moudle/ISM-Encry/src/log4j.properties", the same error is reported.

Both $(bazel info output_base)/external/local_jdk/bin/jar and /usr/local/java/jdk1.8.0_77/bin/jar can be executed successfully in the shell.

I also included /usr/local/java/jdk1.8.0_77/bin/jar using new_local_repository():

# WORKSPACE
new_local_repository(
  name = "local_jdk8_tools",
  path = "/usr/local/java/jdk1.8.0_77/bin",
  build_file = "local_jdk8.build",
)

# local_jdk8.build
filegroup(
  name = "jar_tool",
  srcs = ["jar"],
  visibility = ["//visibility:public"],
)

libjli.so still cannot be found.  Further more, including libjii.so by using new_local_repository(), it still cannot be found.

Could any advice be provided? 

Thank you very much.

-Leo


在 2016年4月18日星期一 UTC+8下午10:01:22,Kristina Chodorow写道:

Brian Silverman

unread,
Apr 18, 2016, 11:27:18 PM4/18/16
to Leo Yin, bazel-discuss
Try adding '@local_jdk//:jdk-default' to tools too.

Leo Yin

unread,
Apr 20, 2016, 4:31:48 AM4/20/16
to bazel-discuss, leo...@huawei.com
Hi,

I reinstalled jdk8 in /usr/bin and solved the problem. 

Thank all of you very much for the help!

-Leo


在 2016年4月19日星期二 UTC+8上午11:27:18,Brian Silverman写道:
Reply all
Reply to author
Forward
0 new messages