1 |
On 6/12/20 2:04 AM, Georgy Yakovlev wrote: |
2 |
> simple src_configure implementation inspired by cmake.eclass |
3 |
> |
4 |
> Closes: https://bugs.gentoo.org/721936 |
5 |
> |
6 |
> Signed-off-by: Georgy Yakovlev <gyakovlev@g.o> |
7 |
> --- |
8 |
> eclass/cargo.eclass | 51 ++++++++++++++++++++++++++++++++++++++------- |
9 |
> 1 file changed, 44 insertions(+), 7 deletions(-) |
10 |
> |
11 |
> diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass |
12 |
> index ad90a0c7dd8..b084e082730 100644 |
13 |
> --- a/eclass/cargo.eclass |
14 |
> +++ b/eclass/cargo.eclass |
15 |
> @@ -23,7 +23,7 @@ esac |
16 |
> |
17 |
> inherit multiprocessing toolchain-funcs |
18 |
> |
19 |
> -EXPORT_FUNCTIONS src_unpack src_compile src_install src_test |
20 |
> +EXPORT_FUNCTIONS src_unpack src_configure src_compile src_install src_test |
21 |
> |
22 |
> IUSE="${IUSE} debug" |
23 |
> |
24 |
> @@ -35,6 +35,24 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" |
25 |
> # Allows overriding the default cwd to run cargo install from |
26 |
> : ${CARGO_INSTALL_PATH:=.} |
27 |
> |
28 |
> +# @VARIABLE: myfeatures |
29 |
> +# @DEFAULT_UNSET |
30 |
> +# @DESCRIPTION: |
31 |
> +# Optional cargo features defined as bash array. Should be defined before calling |
32 |
> +# src_configure. |
33 |
> +# Example for package that has x11 and wayland as features. |
34 |
> +# Also disables default features, as optional parameter is passed. |
35 |
> +# @CODE |
36 |
> +# src_configure() { |
37 |
> +# local myfeatures=( |
38 |
> +# $(usex X x11 '') |
39 |
> +# $(usev wayland) |
40 |
> +# ) |
41 |
> +# |
42 |
> +# cargo_src_configure --no-default-features |
43 |
> +# } |
44 |
> +# @CODE |
45 |
> + |
46 |
> # @FUNCTION: cargo_crate_uris |
47 |
> # @DESCRIPTION: |
48 |
> # Generates the URIs to put in SRC_URI to help fetch dependencies. |
49 |
> @@ -113,6 +131,7 @@ cargo_live_src_unpack() { |
50 |
> mkdir -p "${S}" || die |
51 |
> |
52 |
> pushd "${S}" > /dev/null || die |
53 |
> + # need to specify CARGO_HOME before cargo_gen_config fired |
54 |
> CARGO_HOME="${ECARGO_HOME}" cargo fetch || die |
55 |
> CARGO_HOME="${ECARGO_HOME}" cargo vendor "${ECARGO_VENDOR}" || die |
56 |
> popd > /dev/null || die |
57 |
> @@ -152,6 +171,26 @@ cargo_gen_config() { |
58 |
> EOF |
59 |
> # honor NOCOLOR setting |
60 |
> [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'" >> "${ECARGO_HOME}/config" |
61 |
> + |
62 |
> + export CARGO_HOME="${ECARGO_HOME}" |
63 |
> +} |
64 |
> + |
65 |
> +# @FUNCTION: cargo_src_configure |
66 |
> +# @DESCRIPTION: |
67 |
> +# Configure cargo package features |
68 |
> +cargo_src_configure() { |
69 |
> + debug-print-function ${FUNCNAME} "$@" |
70 |
> + |
71 |
> + [[ -z ${myfeatures} ]] && declare -a myfeatures=() |
72 |
> + local myfeaturestype=$(declare -p myfeatures 2>&-) |
73 |
> + if [[ "${myfeaturestype}" != "declare -a myfeatures="* ]]; then |
74 |
> + die "myfeatures must be declared as array" |
75 |
> + fi |
76 |
> + |
77 |
> + # transform array from simple feature list |
78 |
> + # to multiple cargo args: |
79 |
> + # --features feature1 --features feature2 ... |
80 |
> + readonly ECARGO_FEATURES=( ${myfeatures[@]/#/--features } ) |
81 |
missed ${@}, fixed locally, this should be, |
82 |
readonly ECARGO_FEATURES=( ${myfeatures[@]/#/--features } ${@} ) |
83 |
> } |
84 |
> |
85 |
> # @FUNCTION: cargo_src_compile |
86 |
> @@ -160,11 +199,9 @@ cargo_gen_config() { |
87 |
> cargo_src_compile() { |
88 |
> debug-print-function ${FUNCNAME} "$@" |
89 |
> |
90 |
> - export CARGO_HOME="${ECARGO_HOME}" |
91 |
> - |
92 |
> tc-export AR CC |
93 |
> |
94 |
> - cargo build $(usex debug "" --release) "$@" \ |
95 |
> + cargo build $(usex debug "" --release) ${ECARGO_FEATURES[@]} "$@" \ |
96 |
> || die "cargo build failed" |
97 |
> } |
98 |
> |
99 |
> @@ -174,8 +211,8 @@ cargo_src_compile() { |
100 |
> cargo_src_install() { |
101 |
> debug-print-function ${FUNCNAME} "$@" |
102 |
> |
103 |
> - cargo install --path ${CARGO_INSTALL_PATH} \ |
104 |
> - --root="${ED}/usr" $(usex debug --debug "") "$@" \ |
105 |
> + cargo install --path ${CARGO_INSTALL_PATH} --root="${ED}/usr" \ |
106 |
> + $(usex debug --debug "") ${ECARGO_FEATURES[@]} "$@" \ |
107 |
> || die "cargo install failed" |
108 |
> rm -f "${ED}/usr/.crates.toml" |
109 |
> rm -f "${ED}/usr/.crates2.json" |
110 |
> @@ -189,7 +226,7 @@ cargo_src_install() { |
111 |
> cargo_src_test() { |
112 |
> debug-print-function ${FUNCNAME} "$@" |
113 |
> |
114 |
> - cargo test $(usex debug "" --release) "$@" \ |
115 |
> + cargo test $(usex debug "" --release) ${ECARGO_FEATURES[@]} "$@" \ |
116 |
> || die "cargo test failed" |
117 |
> } |
118 |
> |
119 |
> |