Demonstrates how to use rules_cpan by building https://github.com/linux-test-project/lcov.
Some projects already deliver a cpanfile.
In the case of Lcov the Perl dependencies are just listed in the Readme: https://github.com/linux-test-project/lcov/blob/v2.1/README#L116.
It's straightforward to convert this into requires 'Capture::Tiny';
(and so on) for the cpanfile.
rules_cpan needs a cpanfile.snapshot
as input.
The user needs to install and run Carton manually to generate this file.
This will actually install the dependencies into a local directory. We just remove this directory afterwards.
curl -L https://cpanmin.us | perl - --sudo App::cpanminus
sudo cpanm --notest Carton
cd e2e
carton
rm -rf local
The cpanfile.snapshot.lock.json
is generated by lock.py of rules_cpan:
bazel run @rules_cpan//lock -- cpanfile.snapshot cpanfile.snapshot.lock.json
It contains the URLs and checksums of the cpan dependencies that will be downloaded by Bazel.
Until bazel-contrib/rules_perl#62 is merged you need to add a rules_perl dependency with a git_override:
bazel_dep(name = "rules_perl")
git_override(
module_name = "rules_perl",
remote = "https://github.com/lalten/rules_perl",
commit = "973efb79defe0c417aa9655ac24a09148d599e9e",
)
Now you can use the cpan extension of rules_cpan to generate the perl_library targets.
cpan = use_extension("@rules_cpan//cpan:extensions.bzl", "cpan")
cpan.install(
name = "cpan_deps",
lock = "//:cpanfile.snapshot.lock.json",
)
use_repo(cpan, "cpan_deps")
In this example we don't have any Perl code of our own and just pull in the latest Lcov release as http_archive
.
Now we can finally depend on the cpan targets in our BUILD file:
load("@rules_perl//perl:perl.bzl", "perl_binary", "perl_library")
perl_library(
name = "liblcov",
srcs = glob(["lib/**/*"]),
deps = ["@cpan_deps"],
)
In this example we have an integration test that runs the gehtml --version
:
bazel test //:integration_test --test_output=all