Failed to coerce attr `licenses` when using `vendor=false` on a crate containing license metadata
fnichol opened this issue · comments
As mentioned in #11:
so you might encounter wonky targets such as:
rust_library( ... licenses = ["../../../home/steveklabnik/.cargo/registry/src/index.crates.io-6f17d22bba15001f/owo-colors-3.5.0/LICENSE"], )
Funny enough, this is precisely the issue I was running into this afternoon, and with the owo-colors
LICENSE
location, leading to a buck2 targets //...
error like:
❯ buck2 targets //...
File changed: root//third-party/BUCK
Error parsing root//third-party
Error evaluating build file: `root//third-party:BUCK`
Caused by:
Traceback (most recent call last):
* third-party/BUCK:800, in <module>
third_party_rust_library(
* third-party/reindeer.bzl:20, in third_party_rust_library
native.rust_library(
error: Error coercing attribute `licenses` of `root//third-party:owo-colors-3.5.0`
--> third-party/reindeer.bzl:20:5
|
20 | native.rust_library(
| _____^
21 | | doctests = False,
22 | | **kwargs
23 | | )
| |_____^
|
Error coercing attribute `licenses` of `root//third-party:owo-colors-3.5.0`
Caused by:
0: Error coercing attribute `licenses` of type `attrs.list(attrs.source(), default=[])`
1: Error coercing ["../../../../../.cargo/registry/src/github.com-1ecc6299db9ec823/owo-colors-3.5.0/LICENSE"]
2: Error coercing "../../../../../.cargo/registry/src/github.com-1ecc6299db9ec823/owo-colors-3.5.0/LICENSE"
3: Couldn't coerce `../../../../../.cargo/registry/src/github.com-1ecc6299db9ec823/owo-colors-3.5.0/LICENSE` as a source.
Error when treated as a target: Invalid absolute target pattern `../../../../../.cargo/registry/src/github.com-1ecc6299db9ec823/owo-colors-3.5.0/LICENSE` is not allowed: Expected a `:`, a trailing `/...` or the literal `...`.
Error when treated as a path: expected a normalized path but got an un-normalized path instead: `../../../../../.cargo/registry/src/github.com-1ecc6299db9ec823/owo-colors-3.5.0/LICENSE`
Failed to parse 1 package
Build ID: ee2088e2-0803-4464-8ee0-18bc1c64be56
Jobs completed: 4. Time elapsed: 0.0s.
I was operating under the assumption that the relative path to LICENSE
was outside the Buck2 package. Ideally, what would be a reasonable value for the third_party_rust_library
rule's licenses
argument? I'm working backwards in Reindeer's code to understand, so forgive a newcomer 😄
Sorry about the breakage.
I think the correct behavior would be to not emit a licenses
attribute at all in this mode.
licenses
is not meaningful to any code in the prelude as far as I know. The only uses are by external tools, which are able to do things like:
$ buck2 uquery 'kind("rust_library", //...)' --output-attribute license
{
"root//third-party:owo-colors-3.5.0": {
"licenses": [
"root//third-party/vendor/owo-colors-3.5.0/LICENSE"
]
},
...
}
In the short term, you can unblock yourself without reindeer changes by adding a macro (or maybe you already have one).
# third-party/defs.bzl
def rust_library(**kwargs):
kwargs.pop("licenses", None)
native.rust_library(**kwargs)
# reindeer.toml
[buck]
buckfile_imports = """
load("//third_party/defs.bzl", "rust_library")
"""
(Reindeer will still put the bad paths into your generated targets, but it won't break your build anymore.)
Confirmed that's working great, thank you! 🎉