apple / rules_pkl

Bazel build rules for Pkl
Apache License 2.0
22 stars 6 forks source link

`pkl_eval` does not generate proper paths for files generated by Bazel #21

Open mexlez12345 opened 4 weeks ago

mexlez12345 commented 4 weeks ago

version abab6964bacfbadd20ac3239f13fb9f99a385f4d

I believe I've found a bug in how pkl_eval sets up its work subdirectory that breaks when trying to evaluate a generated file .

To reproduce, use this BUILD file and try to bazel build //:eval_entrypoint

genrule(
  name = "gen_entrypoint",
  outs = ["entrypoint.pkl"],
  cmd = """
cat << EOF >> $(location entrypoint.pkl)
x = throw("entrypoint ran!")
EOF
    """
)

pkl_eval(
  name = "eval_entrypoint",
  entrypoints = ["entrypoint.pkl"],
  srcs = [
    "entrypoint.pkl",
  ],
)

Error output:

–– Pkl Error ––
Cannot find module `file:///<REDACTED_SANDBOX_DIR>/eval_entrypoint/work/bazel-out/linux_x86_64_platform-fastbuild/bin/entrypoint.pkl`.
Failed processing PKL configuration with entrypoint(s) 'bazel-out/linux_x86_64_platform-fastbuild/bin/entrypoint.pkl' (PWD: <REDACTED_SANDBOX_DIR>):

Target //:eval_entrypoint failed to build

Poking around in the sandbox, it looks like the file is actually there, but because bazel's expansion the path of the generated entrypoint.pkl includes the bazel-out prefix, pkl can't find it when its working dir is set to the work/ subdirectory.

Sandbox contents

$ cd <REDACTED_SANDBOX_DIR>
$ tree eval_entrypoint
eval_entrypoint
└── work
    └── entrypoint.pkl -> /<REDACTED_SANDBOX_DIR>/bazel-out/linux_x86_64_platform-fastbuild/bin/entrypoint.pkl

$ ls bazel-out/linux_x86_64_platform-fastbuild/bin/
entrypoint.pkl  eval_entrypoint_symlinks.json
mexlez12345 commented 4 weeks ago

This is essentially the "inverse" of the test case here https://github.com/apple/rules_pkl/blob/main/tests/pkl_eval/BUILD.bazel#L166 where instead of using a generated .pkl in a library that's imported by a hand-written entrypoint, I'm trying to use the generated file as the entrypoint

mexlez12345 commented 4 weeks ago

Same behavior if I use an intermediate pkl_library

genrule(
  name = "gen_entrypoint",
  outs = ["entrypoint.pkl"],
  cmd = """
cat << EOF >> $(location entrypoint.pkl)
x = throw("entrypoint ran!")
EOF
    """
)

pkl_library(
    name = "generated_entrypoint_lib",
    srcs = ["entrypoint.pkl"],
)

pkl_eval(
  name = "eval_entrypoint",
  entrypoints = ["generated_entrypoint_lib"],
  deps = [
    ":generated_entrypoint_lib"
  ],
)