--
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/CAO40MimM-ur0BeaFbuZddgEiA7%2B%2BHpJrTK8G-sK0Z08j4Wn_MA%40mail.gmail.com.
I don't see any data_prefix_map in either https://github.com/jin/rules_ocaml or https://github.com/obazl/rules_ocaml so I really wonder what set of OCaml bazel rules you are using. Did you modify them to add a data_prefix_map attribute yourself?
exec_tools dependencies in a genrule() should pick the target executable's runfiles and you shouldn't need to copy anything.But to achieve this Bazel relies on the DefaultInfo.runfiles information provided by the configured target for your ocaml_binary() definition.
I suspect there is a bug in the implementation function for ocaml_binary(), but it is really hard to tell without more details.
Do you have a simple reproducible test case?
On Wed, Oct 26, 2022 at 9:03 AM David Turner <di...@google.com> wrote:I don't see any data_prefix_map in either https://github.com/jin/rules_ocaml or https://github.com/obazl/rules_ocaml so I really wonder what set of OCaml bazel rules you are using. Did you modify them to add a data_prefix_map attribute yourself?Yes, still under development (I'm the OBazl author). I'm developing and testing a dune->obazl conversion tool, which has exposed some weaknesses in OBazl's testing support. See the dev branch of obazl rules_ocaml.
exec_tools dependencies in a genrule() should pick the target executable's runfiles and you shouldn't need to copy anything.But to achieve this Bazel relies on the DefaultInfo.runfiles information provided by the configured target for your ocaml_binary() definition.
I suspect there is a bug in the implementation function for ocaml_binary(), but it is really hard to tell without more details.You're saying that genrule should configure the runfiles for the tool, relative to "$(execpath test.exe)? Maybe the symlink stuff is the problem. Here's the relevant snippet:
In impl_binary.bzl:rfsymlinks = {}for f in ctx.files.data:
added = False
for (k,v) in ctx.attr.data_prefix_map.items():
if f.path.startswith(k):
rf = v + f.path.removeprefix(k)
rfsymlinks.update({rf: f})
added = True
break
if not added:
rfsymlinks.update({f: f})
if ctx.attr.data_prefix_map:
myrunfiles = ctx.runfiles(
files = rfiles,
symlinks = rfsymlinks,
root_symlinks = rfsymlinks
)
else:
myrunfiles = ctx.runfiles(
files = rfiles
)defaultInfo = DefaultInfo(
executable=out_exe,
runfiles = myrunfiles
)
Do you have a simple reproducible test case?See https://github.com/obazl-repository/yojson/blob/dev/bazel/test/pretty/BUILD.bazel. Note that you probably won't be able to build that unless you set up some local repos, since I'm in the middle of developing stuff. At a minimum `--override_repository=rules_ocaml=/path/to-rules/obazl/rules_ocaml` set to the dev branch. I shooting to cut a new public alpha soon.
Thanks,G
No, the genrule should not do anything. If you use `exec_tools = [ ":some_tool" ]` in your genrule() invocation, the Bazel will ensure that the runfiles of `some_tool` are copied to the execution sandbox at the proper location.
In this case, you need to ensure that the DefaultInfo.runfiles value returned for the configured ocaml_binary() target is correct. Try to use a cquery to see what the providers of your configured target are, e.g. `bazel cquery --output=starlark --starlark:expr="providers(target)" //path/to/your/ocam_binary_target`.
NOTE: Using the same values for symlinks and root_symlinks seems to be incorrect, see https://bazel.build/extending/rules#runfiles_symlinks
Do you have a simple reproducible test case?See https://github.com/obazl-repository/yojson/blob/dev/bazel/test/pretty/BUILD.bazel. Note that you probably won't be able to build that unless you set up some local repos, since I'm in the middle of developing stuff. At a minimum `--override_repository=rules_ocaml=/path/to-rules/obazl/rules_ocaml` set to the dev branch. I shooting to cut a new public alpha soon.Sorry but these are not reproduction steps at all. I hope you will find your bug with the queries above though.
On Wed, Oct 26, 2022 at 11:09 AM David Turner <di...@google.com> wroteNo, the genrule should not do anything. If you use `exec_tools = [ ":some_tool" ]` in your genrule() invocation, the Bazel will ensure that the runfiles of `some_tool` are copied to the execution sandbox at the proper location.
In this case, you need to ensure that the DefaultInfo.runfiles value returned for the configured ocaml_binary() target is correct. Try to use a cquery to see what the providers of your configured target are, e.g. `bazel cquery --output=starlark --starlark:expr="providers(target)" //path/to/your/ocam_binary_target`.Tried that, it does not show DefaultInfo providers. Tried it on a simple ocaml_module rule, same.Just ran the build with --sandbox_debug, then `find -L <sandbox path> -name sample.json`, and it looks like it is indeed exactly where it should be:<sandbox>/bazel-out/darwin-opt-exec-2B5CBBC6/bin/test/pretty/test.exe.runfiles/__main__/test/pretty/sample.json
<sandbox>/bazel-out/darwin-opt-exec-2B5CBBC6/bin/test/pretty/test.exe.runfiles/__main__/sample.json
<sandbox>/bazel-out/darwin-opt-exec-2B5CBBC6/bin/test/pretty/test.exe.runfiles/sample.jsonAnd if I replace the hardcoded "sample.json" with ""bazel-out/darwin-opt-exec-2B5CBBC6/bin/test/pretty/test.exe.runfiles/sample.json", it works.OTOH, if I add sample.json to srcs and add `cp $(location sample.json) .;` to the cmd, I get (in addition to the three just listed):<sandbox>/test/pretty/sample.jsonWhich suggests to me that there is some discombobulation going on here. The genrule cmd is:/bin/bash \
-c \
'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/darwin-opt-exec-2B5CBBC6/bin/test/pretty/test.exe > bazel-out/darwin-fastbuild/bin/test/pretty/test.output.json'Maybe genrule-setup.sh is runnning test.exe from the sandbox root instead of the runfiles-appropriate location?