Skip to content

Commit 6143d2b

Browse files
authored
refactor: rewrite the configure script with here document (#309)
1 parent 3005d56 commit 6143d2b

File tree

1 file changed

+62
-63
lines changed

1 file changed

+62
-63
lines changed

configure

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ export PATH="$PATH:$HOME/.cargo/bin"
1414

1515
check_cargo() {
1616
if [ ! "$(command -v cargo)" ]; then
17-
echo ""
18-
echo "------------------------- [RUST NOT FOUND] -------------------------"
19-
echo "The 'cargo' command was not found on the PATH. Please install rustc"
20-
echo "from: https://www.rust-lang.org/tools/install"
21-
echo ""
22-
echo "Alternatively, you may install cargo from your OS package manager:"
23-
echo " - Debian/Ubuntu: apt-get install cargo"
24-
echo " - Fedora/CentOS: dnf install cargo"
25-
echo " - macOS: brew install rustc"
26-
echo "--------------------------------------------------------------------"
27-
echo ""
17+
cat <<EOF
18+
------------------------- [RUST NOT FOUND] -------------------------
19+
The 'cargo' command was not found on the PATH. Please install rustc
20+
from: https://www.rust-lang.org/tools/install
21+
22+
Alternatively, you may install cargo from your OS package manager:
23+
- Debian/Ubuntu: apt-get install cargo
24+
- Fedora/CentOS: dnf install cargo
25+
- macOS: brew install rustc
26+
--------------------------------------------------------------------
27+
EOF
2828
exit 1
2929
else
30-
echo ""
31-
echo "--------------------------- [RUST FOUND] ---------------------------"
32-
cargo -V
33-
echo ""
34-
rustc -vV
35-
echo "--------------------------------------------------------------------"
36-
echo ""
30+
cat <<EOF
31+
--------------------------- [RUST FOUND] ---------------------------
32+
$(cargo -V)
33+
34+
$(rustc -vV)
35+
--------------------------------------------------------------------
36+
EOF
3737
fi
3838
}
3939

@@ -44,61 +44,60 @@ check_bin_lib() {
4444

4545
# On R-universe, we try to download the pre-built binary from GitHub releases.
4646
if [ -n "${MY_UNIVERSE}" ] && [ -z "${LIBPRQLR_BUILD}" ]; then
47-
echo ""
48-
echo "--------------------- [SETTING FOR R-UNIVERSE] ---------------------"
49-
echo "It seems that this is on R-universe <${MY_UNIVERSE}>."
50-
echo "Trying to download pre-built binary."
51-
echo "--------------------------------------------------------------------"
52-
echo ""
47+
cat <<EOF
48+
--------------------- [SETTING FOR R-UNIVERSE] ---------------------
49+
It seems that this is on R-universe <${MY_UNIVERSE}>.
50+
Trying to download pre-built binary.
51+
--------------------------------------------------------------------
52+
EOF
5353
LIBPRQLR_BUILD="false"
5454
fi
5555

5656
if [ "${LIBPRQLR_BUILD}" = "false" ] && [ -f "tools/lib-sums.tsv" ] && [ ! -f "${LIBPRQLR_PATH}" ]; then
57-
echo ""
58-
echo "--------------- [TRY TO DOWNLOAD PRE-BUILT BINARY] ---------------"
59-
"${R_HOME}/bin${R_ARCH_BIN}/Rscript" "tools/prep-lib.R" || echo "Failed to download pre-built binary."
60-
echo "------------------------------------------------------------------"
61-
echo ""
57+
cat <<EOF
58+
--------------- [TRY TO DOWNLOAD PRE-BUILT BINARY] ---------------
59+
$("${R_HOME}/bin${R_ARCH_BIN}/Rscript" "tools/prep-lib.R" || echo "Failed to download pre-built binary.")
60+
------------------------------------------------------------------
61+
EOF
6262
fi
6363

6464
if [ "${LIBPRQLR_BUILD}" = "false" ] && [ -f "${LIBPRQLR_PATH}" ]; then
65-
echo ""
66-
echo "---------------------- [LIBRARY BINARY FOUND] ----------------------"
67-
echo "The library was found at <${LIBPRQLR_PATH}>. No need to build it."
68-
echo ""
69-
echo "Note: rustc version: $(command -v rustc >/dev/null && rustc -V || echo 'Not found')"
70-
echo "--------------------------------------------------------------------"
71-
echo ""
65+
cat <<EOF
66+
---------------------- [LIBRARY BINARY FOUND] ----------------------
67+
The library was found at <${LIBPRQLR_PATH}>. No need to build it.
68+
69+
Note: rustc version: $(command -v rustc >/dev/null && rustc -V || echo "Not found")
70+
--------------------------------------------------------------------
71+
EOF
7272
sed -e "s|@RUST_TARGET@||" src/Makevars.in >src/Makevars
7373
if [ "${LIBPRQLR_PATH}" != "${LIBPRQLR_DEFAULT_PATH}" ]; then
74-
echo ""
75-
echo "------------------------ [COPYING BINARY] ------------------------"
76-
echo "Copying <${LIBPRQLR_PATH}> to <${LIBPRQLR_DEFAULT_PATH}>."
77-
mkdir -p "$(dirname "${LIBPRQLR_DEFAULT_PATH}")"
78-
cp "${LIBPRQLR_PATH}" "${LIBPRQLR_DEFAULT_PATH}" || echo "Failed to copy binary."
79-
echo "------------------------------------------------------------------"
80-
echo ""
74+
cat <<EOF
75+
------------------------ [COPYING BINARY] ------------------------
76+
Copying <${LIBPRQLR_PATH}> to <${LIBPRQLR_DEFAULT_PATH}>.
77+
$(mkdir -p "$(dirname "${LIBPRQLR_DEFAULT_PATH}")")
78+
$(cp "${LIBPRQLR_PATH}" "${LIBPRQLR_DEFAULT_PATH}" || echo "Failed to copy binary.")
79+
------------------------------------------------------------------
80+
EOF
8181
fi
8282
exit 0
8383
elif [ "${LIBPRQLR_BUILD}" = "false" ] && [ -f "${LIBPRQLR_DEFAULT_PATH}" ]; then
84-
echo ""
85-
echo "---------------------- [LIBRARY BINARY FOUND] ----------------------"
86-
echo "The library was not found at <${LIBPRQLR_PATH}>,"
87-
echo "but was found at <${LIBPRQLR_DEFAULT_PATH}>."
88-
echo "No need to build it."
89-
echo ""
90-
echo "Note: rustc version: $(command -v rustc >/dev/null && rustc -V || echo 'Not found')"
91-
echo "--------------------------------------------------------------------"
92-
echo ""
84+
cat <<EOF
85+
---------------------- [LIBRARY BINARY FOUND] ----------------------
86+
The library was not found at <${LIBPRQLR_PATH}>,
87+
but was found at <${LIBPRQLR_DEFAULT_PATH}>. No need to build it.
88+
89+
Note: rustc version: $(command -v rustc >/dev/null && rustc -V || echo "Not found")
90+
--------------------------------------------------------------------
91+
EOF
9392
sed -e "s|@RUST_TARGET@||" src/Makevars.in >src/Makevars
9493
exit 0
9594
elif [ "${LIBPRQLR_BUILD}" = "false" ]; then
96-
echo ""
97-
echo "-------------------- [LIBRARY BINARY NOT FOUND] --------------------"
98-
echo "The library was not found at <${LIBPRQLR_PATH}>."
99-
echo "Falling back to building from source."
100-
echo "--------------------------------------------------------------------"
101-
echo ""
95+
cat <<EOF
96+
-------------------- [LIBRARY BINARY NOT FOUND] --------------------
97+
The library was not found at <${LIBPRQLR_PATH}>.
98+
Falling back to building from source.
99+
--------------------------------------------------------------------
100+
EOF
102101
fi
103102
}
104103

@@ -107,11 +106,11 @@ detect_target_option() {
107106
case "${option}" in
108107
--host=*)
109108
specified_target="$(echo "${option}" | sed -e 's/--host=//' | sed -E 's/([0-9]+\.)*[0-9]+$//')"
110-
echo ""
111-
echo "------------------------------ [DETECTED TARGET] ------------------------------"
112-
echo "The target was specified as <${specified_target}> via the '--host' option."
113-
echo "-------------------------------------------------------------------------------"
114-
echo ""
109+
cat <<EOF
110+
------------------------- [DETECTED TARGET] -------------------------
111+
The target was specified as <${specified_target}> via the '--host' option.
112+
---------------------------------------------------------------------
113+
EOF
115114
export TARGET="${specified_target}"
116115
;;
117116
*) ;;

0 commit comments

Comments
 (0)