1 |
Also honor ECARGO_OFFLINE/EVCS_OFFLINE |
2 |
Good portion of the code/logic inspired by git-r3.eclass. |
3 |
|
4 |
Signed-off-by: Georgy Yakovlev <gyakovlev@g.o> |
5 |
--- |
6 |
eclass/cargo.eclass | 115 +++++++++++++++++++++++++++++++++++++++++--- |
7 |
1 file changed, 108 insertions(+), 7 deletions(-) |
8 |
|
9 |
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass |
10 |
index 6d341601a112..dde601ec4e3c 100644 |
11 |
--- a/eclass/cargo.eclass |
12 |
+++ b/eclass/cargo.eclass |
13 |
@@ -46,6 +46,35 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo" |
14 |
# } |
15 |
# @CODE |
16 |
|
17 |
+# @ECLASS-VARIABLE: ECARGO_REGISTRY_DIR |
18 |
+# @USER_VARIABLE |
19 |
+# @DEFAULT_UNSET |
20 |
+# @DESCRIPTION: |
21 |
+# Storage directory for cargo registry. |
22 |
+# Used by cargo_live_src_unpack to cache downloads. |
23 |
+# This is intended to be set by users. |
24 |
+# Ebuilds must not set it. |
25 |
+# |
26 |
+# Defaults to '${DISTDIR}/ecargo-registry' it not set. |
27 |
+ |
28 |
+# @ECLASS-VARIABLE: ECARGO_OFFLINE |
29 |
+# @USER_VARIABLE |
30 |
+# @DEFAULT_UNSET |
31 |
+# @DESCRIPTION: |
32 |
+# If non-empty, this variable prevents online operations in |
33 |
+# cargo_live_src_unpack. |
34 |
+# Inherits value of EVCS_OFFLINE if not set explicitly. |
35 |
+ |
36 |
+# @ECLASS-VARIABLE: EVCS_UMASK |
37 |
+# @USER_VARIABLE |
38 |
+# @DEFAULT_UNSET |
39 |
+# @DESCRIPTION: |
40 |
+# Set this variable to a custom umask. This is intended to be set by |
41 |
+# users. By setting this to something like 002, it can make life easier |
42 |
+# for people who use cargo in a home directory, but are in the portage |
43 |
+# group, and then switch over to building with FEATURES=userpriv. |
44 |
+# Or vice-versa. |
45 |
+ |
46 |
# @FUNCTION: cargo_crate_uris |
47 |
# @DESCRIPTION: |
48 |
# Generates the URIs to put in SRC_URI to help fetch dependencies. |
49 |
@@ -122,13 +151,84 @@ cargo_live_src_unpack() { |
50 |
[[ "${EBUILD_PHASE}" == unpack ]] || die "${FUNCNAME} only allowed in src_unpack" |
51 |
|
52 |
mkdir -p "${S}" || die |
53 |
+ mkdir -p "${ECARGO_VENDOR}" || die |
54 |
+ mkdir -p "${ECARGO_HOME}" || die |
55 |
+ |
56 |
+ local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}} |
57 |
+ : ${ECARGO_REGISTRY_DIR:=${distdir}/ecargo-registry} |
58 |
+ |
59 |
+ local offline="${ECARGO_OFFLINE:-${EVCS_OFFLINE}}" |
60 |
+ |
61 |
+ if [[ ! -d ${ECARGO_REGISTRY_DIR} && ! ${offline} ]]; then |
62 |
+ ( |
63 |
+ addwrite "${ECARGO_REGISTRY_DIR}" |
64 |
+ mkdir -p "${ECARGO_REGISTRY_DIR}" |
65 |
+ ) || die "Unable to create ${ECARGO_REGISTRY_DIR}" |
66 |
+ fi |
67 |
+ |
68 |
+ if [[ ${offline} ]]; then |
69 |
+ local subdir |
70 |
+ for subdir in cache index src; do |
71 |
+ if [[ ! -d ${ECARGO_REGISTRY_DIR}/registry/${subdir} ]]; then |
72 |
+ eerror "Networking activity has been disabled via ECARGO_OFFLINE or EVCS_OFFLINE" |
73 |
+ eerror "However, no valid cargo registry available at ${ECARGO_REGISTRY_DIR}" |
74 |
+ die "Unable to proceed with ECARGO_OFFLINE/EVCS_OFFLINE." |
75 |
+ fi |
76 |
+ done |
77 |
+ fi |
78 |
+ |
79 |
+ if [[ ${EVCS_UMASK} ]]; then |
80 |
+ local saved_umask=$(umask) |
81 |
+ umask "${EVCS_UMASK}" || die "Bad options to umask: ${EVCS_UMASK}" |
82 |
+ fi |
83 |
|
84 |
pushd "${S}" > /dev/null || die |
85 |
- # need to specify CARGO_HOME before cargo_gen_config fired |
86 |
- CARGO_HOME="${ECARGO_HOME}" cargo fetch || die |
87 |
- CARGO_HOME="${ECARGO_HOME}" cargo vendor "${ECARGO_VENDOR}" || die |
88 |
+ |
89 |
+ # Respect user settings befire cargo_gen_config is called. |
90 |
+ if [[ ! ${CARGO_TERM_COLOR} ]]; then |
91 |
+ [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && export CARGO_TERM_COLOR=never |
92 |
+ local unset_color=true |
93 |
+ fi |
94 |
+ if [[ ! ${CARGO_TERM_VERBOSE} ]]; then |
95 |
+ export CARGO_TERM_VERBOSE=true |
96 |
+ local unset_verbose=true |
97 |
+ fi |
98 |
+ |
99 |
+ # Let cargo fetch to system-wide location. |
100 |
+ # It will keep directory organized by itself. |
101 |
+ addwrite "${ECARGO_REGISTRY_DIR}" |
102 |
+ export CARGO_HOME="${ECARGO_REGISTRY_DIR}" |
103 |
+ |
104 |
+ # Absence of quotes around offline arg is intentional, as cargo bails out if it encounters '' |
105 |
+ einfo "cargo fetch ${offline:+--offline}" |
106 |
+ cargo fetch ${offline:+--offline} || die #nowarn |
107 |
+ |
108 |
+ # Let cargo copy all required crates to "${WORKDIR}" for offline use in later phases. |
109 |
+ einfo "cargo vendor ${offline:+--offline} ${ECARGO_VENDOR}" |
110 |
+ cargo vendor ${offline:+--offline} "${ECARGO_VENDOR}" || die #nowarn |
111 |
+ |
112 |
+ # Users may have git checkouts made by cargo. |
113 |
+ # While cargo vendors the sources, it still needs git checkout to be present. |
114 |
+ # Copying full dir is an overkill, so just symlink it. |
115 |
+ if [[ -d ${ECARGO_REGISTRY_DIR}/git ]]; then |
116 |
+ ln -sv "${ECARGO_REGISTRY_DIR}/git" "${ECARGO_HOME}/git" || die |
117 |
+ fi |
118 |
+ |
119 |
popd > /dev/null || die |
120 |
|
121 |
+ if [[ ${saved_umask} ]]; then |
122 |
+ umask "${saved_umask}" || die |
123 |
+ fi |
124 |
+ |
125 |
+ # Restore settings if needed. |
126 |
+ [[ ${unset_color} ]] && unset CARGO_TERM_COLOR |
127 |
+ [[ ${unset_verbose} ]] && unset CARGO_TERM_VERBOSE |
128 |
+ |
129 |
+ # After following call, cargo will no longer use ${ECARGO_REGISTRY_DIR} as CARGO_HOME |
130 |
+ # It will be forced into offline mode to prevent network access. |
131 |
+ # But since we already vendored crates and symlinked git, it has all it needs |
132 |
+ # to build. |
133 |
+ unset CARGO_HOME |
134 |
cargo_gen_config |
135 |
} |
136 |
|
137 |
@@ -145,7 +245,9 @@ cargo_live_src_unpack() { |
138 |
cargo_gen_config() { |
139 |
debug-print-function ${FUNCNAME} "$@" |
140 |
|
141 |
- cat <<- EOF > "${ECARGO_HOME}/config" |
142 |
+ mkdir -p "${ECARGO_HOME}" || die |
143 |
+ |
144 |
+ cat > "${ECARGO_HOME}/config" <<- _EOF_ || die "Failed to create cargo config" |
145 |
[source.gentoo] |
146 |
directory = "${ECARGO_VENDOR}" |
147 |
|
148 |
@@ -161,9 +263,8 @@ cargo_gen_config() { |
149 |
|
150 |
[term] |
151 |
verbose = true |
152 |
- EOF |
153 |
- # honor NOCOLOR setting |
154 |
- [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'" >> "${ECARGO_HOME}/config" |
155 |
+ $([[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'") |
156 |
+ _EOF_ |
157 |
|
158 |
export CARGO_HOME="${ECARGO_HOME}" |
159 |
} |
160 |
-- |
161 |
2.28.0 |