| |
@@ -109,6 +109,44 @@
|
| |
fi \
|
| |
)
|
| |
|
| |
+ # This macro prints license information for all crates in the dependency tree
|
| |
+ # that are neither build-dependencies, dev-dependencies nor proc-macro
|
| |
+ # dependencies.
|
| |
+ # Additionally, deprecated SPDX syntax is normalized before sorting the
|
| |
+ # results to ensure consistent order.
|
| |
+ %cargo_license(naf:)\
|
| |
+ %{shrink:\
|
| |
+ %{__cargo} tree \
|
| |
+ --workspace \
|
| |
+ --offline \
|
| |
+ --edges no-build,no-dev,no-proc-macro \
|
| |
+ --no-dedupe \
|
| |
+ --target all \
|
| |
+ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
|
| |
+ --prefix none \
|
| |
+ --format "{l}: {p}" \
|
| |
+ | sed -e "s: ($(pwd)[^)]*)::g" -e "s: / :/:g" -e "s:/: OR :g" \
|
| |
+ | sort -u
|
| |
+ }
|
| |
+
|
| |
+ # This macro prints license summary for all crates in the dependency tree that
|
| |
+ # are neither dev-dependencies nor proc-macros. Additionally, deprecated SPDX
|
| |
+ # syntax is normalized before sorting the results to ensure consistent order.
|
| |
+ %cargo_license_summary(naf:)\
|
| |
+ %{shrink:\
|
| |
+ %{__cargo} tree \
|
| |
+ --workspace \
|
| |
+ --offline \
|
| |
+ --edges no-build,no-dev,no-proc-macro \
|
| |
+ --no-dedupe \
|
| |
+ --target all \
|
| |
+ %{__cargo_parse_opts %{-n} %{-a} %{-f:-f%{-f*}}} \
|
| |
+ --prefix none \
|
| |
+ --format "# {l}" \
|
| |
+ | sed -e "s: / :/:g" -e "s:/: OR :g" \
|
| |
+ | sort -u \
|
| |
+ }
|
| |
+
|
| |
%__cargo_feature_from_name(n:) %{lua:
|
| |
local name = rpm.expand("%{-n*}")
|
| |
local feature = string.match(name, "^[^+]+%+(.+)-devel$")
|
| |
This PR adds
%cargo_license
macros based on thecargo tree
command devised by @alebastr:%cargo_license
: writes list of$license: $crate v$version
to a file (LICENSE.dependencies
)%cargo_license_summary
: prints license summary (without crate names / versions)Both macros replace
/
withOR
and ensure consistent whitespace in SPDX expressions, such that the output ofsort -u
is consistent and sorted correctly.Additionally, I've added the
no-proc-macro
filter to thetree
command to also exclude proc-macro dependencies from the query. Procedural macros are used for code generation, but their source code is not linked into final binaries (similar to build-only dependencies).The macros should also support the
-a
,-f foo,bar
and-n
flags (translating to--all-features
,--features foo,bar
, and--no-default-features
, respectively) that the other%cargo_*
macros support, though I have not tested this yet.What I have tested is that using
%cargo_license
writes theLICENSE.dependencies
file correctly, and that the output of%cargo_license_summary
is correct and matches what we've done manually until now.An additional benefit of using these macros would be that they already produce SPDX expressions, even if not all crate dependencies have not been regenerated with rust2rpm v22 for SPDX "License" tags yet.
Caveat: These macros only take the
license
value in Cargo.toml manifests into account. If there are packages where we apply manual fixes to the "License" tag in the spec file but don't patch the SPDX expression inCargo.toml
, this will not be reflected. But I expect the number of these cases to be small, and we should fix them anyway (or make it a policy that if the License tag needs to be manually modified, the Cargo.toml file also MUST be patched to reflect the correct license).Fixes: #198
Though I'm not sure how to integrate these macros with rust2rpm yet.