bazelbuild / rules_perl

Perl rules for Bazel
Apache License 2.0
25 stars 38 forks source link

perl_binary does not work as a data dependency #28

Closed jesseschalken closed 2 years ago

jesseschalken commented 2 years ago

Example:

BUILD:

load("@rules_perl//perl:perl.bzl", "perl_binary")
load("@rules_python//python:defs.bzl", "py_binary")

perl_binary(
    name = "perl",
    srcs = ["perl.pl"],
)

py_binary(
    name = "python",
    srcs = ["python.py"],
    data = [":perl"],
    deps = ["@rules_python//python/runfiles"],
)

WORKSPACE:

workspace(name = "perlrulesbug")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_python",
    sha256 = "954aa89b491be4a083304a2cb838019c8b8c3720a7abb9c4cb81ac7a24230cea",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.4.0/rules_python-0.4.0.tar.gz",
)

http_archive(
    name = "rules_perl",
    sha256 = "9661de92edd38cc878010a4e42088f5ffda3f1e8b7d1124a5cea943e2fb03c0f",
    strip_prefix = "rules_perl-03de09c1dff31920d7bedda0d519e178dd1f1448",
    url = "https://github.com/bazelbuild/rules_perl/archive/03de09c1dff31920d7bedda0d519e178dd1f1448.zip",
)

load("@rules_perl//perl:deps.bzl", "perl_register_toolchains", "perl_rules_dependencies")

perl_rules_dependencies()

perl_register_toolchains()

perl.pl:

use strict;
use warnings;

print("Hello from Perl!\n");

python.py:

import subprocess
from pprint import pprint
from rules_python.python.runfiles import runfiles

my_runfiles = runfiles.Create()
perl_script = my_runfiles.Rlocation("perlrulesbug/perl")

subprocess.call([perl_script])

Test:

$ bazel run //:python
INFO: Analyzed target //:python (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:python up-to-date:
  bazel-bin/python
INFO: Elapsed time: 0.051s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
Traceback (most recent call last):
  File "/home/user1/.cache/bazel/_bazel_user1/ed6bf9cf7ba68480a3230f4c79ec9c4c/execroot/perlrulesbug/bazel-out/k8-fastbuild/bin/python.runfiles/perlrulesbug/python.py", line 8, in <module>
    subprocess.call([perl_script])
  File "/usr/lib/python3.9/subprocess.py", line 349, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.9/subprocess.py", line 1696, in _execute_child
    and os.path.dirname(executable)
  File "/usr/lib/python3.9/posixpath.py", line 152, in dirname
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Despite the data dependency, the runfiles library cannot find perlrulesbug/perl.

It does not appear in the file bazel-out/k8-fastbuild/bin/python.runfiles_manifest or anywhere in the directory bazel-out/k8-fastbuild/bin/python.runfiles. It's like the data dependency just does not work at all. Is perl_binary not communicating its files correctly via DefaultInfo?

Example repo: https://github.com/jesseschalken/perlrulesbug