classpath macro resolution for dependent libraries is broken in cross-cell context
Created by: davido
Given the following cell definition:
[repositories]
jgit = lib/jgit
The calsspath is correctly resolved with classpath
macro:
genrule(
name = 'dump_correct_classpath',
cmd = 'echo $(classpath @jgit//:jgit) > $OUT',
out = 'dump_correct_classpath.txt',
)
The content of the ouput file is correct:
$ cat buck-out/gen/tools/dump_correct_classpath/dump_correct_classpath.txt
/home/davido/projects/gerrit/lib/jgit/buck-out/gen/ewah.jar:/home/davido/projects/gerrit/lib/jgit/buck-out/gen/jgit.jar
The audit classpath
command is correct as well. However, when the same cell library is used in transitive dependency, cell path is erroneously re-located to buck root context:
java_library(
name = 'broken',
srcs = [],
deps = ['@jgit//:jgit'],
visibility = ['PUBLIC']
)
genrule(
name = 'dump_broken_deps_classpath',
cmd = 'echo $(classpath :broken) > $OUT',
out = 'dump_broken_deps_classpath.txt',
)
The output file contains now wrong, non-existing path:
$ cat buck-out/gen/tools/dump_broken_classpath/dump_broken_classpath.txt
/home/davido/projects/gerrit/buck-out/gen/ewah.jar:/home/davido/projects/gerrit/buck-out/gen/jgit.jar
Interestingly, the audit classpath
command still reports the correct classpath:
$ buck audit classpath tools:broken
:::
::: '.nobuckcheck' file is present. Not updating buck.
:::
[+] PROCESSING BUCK FILES...0.1s
/home/davido/projects/gerrit/lib/jgit/buck-out/gen/ewah.jar
/home/davido/projects/gerrit/lib/jgit/buck-out/gen/jgit.jar
Note that, I'm using the most recent Buck version with this PR on top: [1].