{"action":"created","issue":{"url":"https://api.github.com/repos/bazelbuild/bazel/issues/487","labels_url":"https://api.github.com/repos/bazelbuild/bazel/issues/487/labels{/name}","comments_url":"https://api.github.com/repos/bazelbuild/bazel/issues/487/comments","events_url":"https://api.github.com/repos/bazelbuild/bazel/issues/487/events","html_url":"https://github.com/bazelbuild/bazel/issues/487","id":108442609,"number":487,"title":"skylark rule using an java_binary executable fails because runfiles directory is not created","user":{"login":"hhclam","id":14845789,"avatar_url":"https://avatars.githubusercontent.com/u/14845789?v=3","gravatar_id":"","url":"https://api.github.com/users/hhclam","html_url":"https://github.com/hhclam","followers_url":"https://api.github.com/users/hhclam/followers","following_url":"https://api.github.com/users/hhclam/following{/other_user}","gists_url":"https://api.github.com/users/hhclam/gists{/gist_id}","starred_url":"https://api.github.com/users/hhclam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hhclam/subscriptions","organizations_url":"https://api.github.com/users/hhclam/orgs","repos_url":"https://api.github.com/users/hhclam/repos","events_url":"https://api.github.com/users/hhclam/events{/privacy}","received_events_url":"https://api.github.com/users/hhclam/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bazelbuild/bazel/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/bazelbuild/bazel/labels/P3","name":"P3","color":"0052cc"},{"url":"https://api.github.com/repos/bazelbuild/bazel/labels/skylark","name":"skylark","color":"bfe5bf"}],"state":"open","locked":false,"assignee":{"login":"laurentlb","id":485572,"avatar_url":"https://avatars.githubusercontent.com/u/485572?v=3","gravatar_id":"","url":"https://api.github.com/users/laurentlb","html_url":"https://github.com/laurentlb","followers_url":"https://api.github.com/users/laurentlb/followers","following_url":"https://api.github.com/users/laurentlb/following{/other_user}","gists_url":"https://api.github.com/users/laurentlb/gists{/gist_id}","starred_url":"https://api.github.com/users/laurentlb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laurentlb/subscriptions","organizations_url":"https://api.github.com/users/laurentlb/orgs","repos_url":"https://api.github.com/users/laurentlb/repos","events_url":"https://api.github.com/users/laurentlb/events{/privacy}","received_events_url":"https://api.github.com/users/laurentlb/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-09-26T05:46:38Z","updated_at":"2016-02-01T18:43:08Z","closed_at":null,"body":"When I used an executable built from a java_binary from skylark, it fails complaining that the runfiles directory is not available. This is because Bazel builds the wrapper script for the java_binary target but not the runfiles directory.\r\n\r\nHowever if I use a genrule with the same java_binary executable it works fine. This seems like a problem with skylark.\r\n\r\nSee the following example:\r\n\r\n=== BUILD ===\r\n```\r\nload(\"test\", \"test\")\r\n\r\njava_library(\r\n  name = \"test\",\r\n  srcs = [\"TestCase.java\"],\r\n)\r\n\r\njava_binary(\r\n  name = \"test_app\",\r\n  runtime_deps = [\":test\"],\r\n  main_class = \"TestCase\",\r\n)\r\n\r\ntest(name = \"test_txt\")\r\n\r\ngenrule(\r\n  name = \"test_genrule\",\r\n  tools = [\":test_app\"],\r\n  outs = [\"test_txt2\"],\r\n  cmd = \"$(location :test_app) > $@\",\r\n)\r\n```\r\n=== test.bzl ===\r\n```\r\ndef test_impl(ctx):\r\n  ctx.action(\r\n    outputs = [ctx.outputs.txt],\r\n    mnemonic = \"TestStep\",\r\n    inputs = [ctx.executable._test_app],\r\n    command = \"%s > %s\" % (ctx.executable._test_app.path, ctx.outputs.txt.path),\r\n    use_default_shell_env = True)\r\n  return struct()\r\n  \r\ntest = rule(\r\n  test_impl,\r\n  attrs = {\r\n    \"_test_app\": attr.label(executable=True, default=Label(\"//:test_app\"), allow_files=True),\r\n  },\r\n  outputs = {\"txt\": \"lib%{name}.txt\"}\r\n)\r\n```\r\n=== TestCase.java ===\r\n```\r\nclass TestCase {\r\n    public TestCase() {\r\n    }\r\n\r\n    public static void main(String [] args) {\r\n        System.out.println(\"test case\");\r\n    }\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/bazelbuild/bazel/issues/comments/178119424","html_url":"https://github.com/bazelbuild/bazel/issues/487#issuecomment-178119424","issue_url":"https://api.github.com/repos/bazelbuild/bazel/issues/487","id":178119424,"user":{"login":"shaoster","id":129236,"avatar_url":"https://avatars.githubusercontent.com/u/129236?v=3","gravatar_id":"","url":"https://api.github.com/users/shaoster","html_url":"https://github.com/shaoster","followers_url":"https://api.github.com/users/shaoster/followers","following_url":"https://api.github.com/users/shaoster/following{/other_user}","gists_url":"https://api.github.com/users/shaoster/gists{/gist_id}","starred_url":"https://api.github.com/users/shaoster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shaoster/subscriptions","organizations_url":"https://api.github.com/users/shaoster/orgs","repos_url":"https://api.github.com/users/shaoster/repos","events_url":"https://api.github.com/users/shaoster/events{/privacy}","received_events_url":"https://api.github.com/users/shaoster/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T18:43:08Z","updated_at":"2016-02-01T18:43:08Z","body":"The java_binary providers seem to have some new goodies that can be used here.\r\nTo get the \"depends on all outputs of the java_binary target\" behavior, the following can be added to the action inputs:\r\n```\r\njava_binary_input.files_to_run.executable\r\n\r\njava_binary_input.default_runfiles.files\r\n\r\njava_binary_input.data_runfiles.files\r\n```\r\nUnfortunately, it doesn't look like there's any docs for these providers. I just happened to find them using print/dir. :(\r\n"}}