The behaviour of python_library when used as a dependency to another build rule is currently inconsistent (or at least, the documentation doesn't make it clear what should and should not work).
Expected behaviour: python_library targets should be usable as dependencies to other build rules
Actual behaviour: python_library targets are usable as dependencies to some targets (e.g. python_binary) but not others (e.g. genrule)
Steps to reproduce: add a python_library target as a src of a genrule.
The documentation provides an example of using a python_library as a dependency to a python_binary rule, implying that there is some output of a python_library that can be referenced by other targets:
python_binary(
name = 'tailer',
main_module = 'tailer',
deps = [
':tailerutils',
],
)
python_library(
name = 'tailerutils',
# The main module, tailer.py, is specified here.
# (Separated out from the glob pattern for clarity.)
srcs = glob(['tailer.py', '*.py']),
)
Building the example works fine, although you can see that the //:tailerutils target does indeed produce no output:
However, trying to include //:tailerutils in other targets (using a trivial genrule as an example) doesn't seem to work, e.g.:
genrule(
name = 'lstailer',
cmd = 'tree * > $OUT',
srcs = [
':tailerutils',
],
out = 'lstailer.txt'
)
Attempting to build this target gives the following error:
$ buck build --show-outputs //:lstailer
No known output for: //:tailerutils
When amending unnamedSources.
When amending srcs.
When amending buildableForRuleKey.
When building rule //:lstailer.
In contrast, depending on the //:tailer target works as expected (which makes sense given that this does appear to have a well-defined output):
genrule(
name = 'lstailer',
cmd = 'tree * > $OUT',
srcs = [
':tailer',
],
out = 'lstailer.txt'
)
I would expect that, given the source files of the python_library target are made available to the python_binary target, this behaviour should be consistent across all build rules?
I wondered if there was a workaround to this by using some kind of string expansion macro that could be used in the genrule, e.g. srcs = [ '$(query_targets "inputs(//:tailerutils)"), but it appears that this also isn't made available.
The behaviour of
python_library
when used as a dependency to another build rule is currently inconsistent (or at least, the documentation doesn't make it clear what should and should not work).python_library
targets should be usable as dependencies to other build rulespython_library
targets are usable as dependencies to some targets (e.g.python_binary
) but not others (e.g.genrule
)python_library
target as asrc
of agenrule
.The documentation provides an example of using a
python_library
as a dependency to apython_binary
rule, implying that there is some output of apython_library
that can be referenced by other targets:Building the example works fine, although you can see that the
//:tailerutils
target does indeed produce no output:However, trying to include
//:tailerutils
in other targets (using a trivialgenrule
as an example) doesn't seem to work, e.g.:Attempting to build this target gives the following error:
In contrast, depending on the
//:tailer
target works as expected (which makes sense given that this does appear to have a well-defined output):I would expect that, given the source files of the
python_library
target are made available to thepython_binary
target, this behaviour should be consistent across all build rules?I wondered if there was a workaround to this by using some kind of string expansion macro that could be used in the
genrule
, e.g.srcs = [ '$(query_targets "inputs(//:tailerutils)")
, but it appears that this also isn't made available.(example: https://github.com/swarren12/buck-python-library-example/).