Skip to content

Commit af0601b

Browse files
committed
Build Deno from source if use --from-source flag only.
1 parent 348ea85 commit af0601b

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed

dvm.sh

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ export DVM_VERSION="v0.8.1"
6161
# Set global variables to default values
6262
DVM_DENO_VERSION=""
6363
DVM_FILE_TYPE=""
64-
DVM_INSTALL_FROM_BINARY_ONLY=false
65-
DVM_INSTALL_FROM_SOURCE_ONLY=false
64+
DVM_INSTALL_MODE="binary"
6665
DVM_INSTALL_REGISTRY=""
6766
DVM_INSTALL_SKIP_VALIDATION=false
6867
DVM_LATEST_VERSION=""
@@ -783,7 +782,7 @@ export DVM_VERSION="v0.8.1"
783782
fi
784783

785784
cargo clean
786-
785+
787786
if ! cargo build --release
788787
then
789788
dvm_print_error "failed to build deno"
@@ -1118,40 +1117,26 @@ export DVM_VERSION="v0.8.1"
11181117
}
11191118

11201119
# Try to install Deno from the network with the binary file, or try to build
1121-
# Deno from the source code if failed to download the precompiled binary
1122-
# file. It'll skip downloading the binary file if the value of variable
1123-
# `DVM_INSTALL_FROM_SOURCE_ONLY` is true, and skip downloading and building
1124-
# from the source code if the value of variable
1125-
# `DVM_INSTALL_FROM_BINARY_ONLY` is true.
1120+
# Deno from the source code.
11261121
# Parameters:
11271122
# - $1: The Deno version to install.
11281123
dvm_install_deno() {
11291124
local version
11301125

11311126
version="$1"
11321127

1133-
if [ "$DVM_INSTALL_FROM_SOURCE_ONLY" = false ]
1134-
then
1135-
if dvm_install_deno_by_binary "$version"
1136-
then
1137-
return
1138-
fi
1139-
fi
1140-
1141-
if [ "$DVM_INSTALL_FROM_BINARY_ONLY" = false ]
1142-
then
1143-
if [ "$DVM_INSTALL_FROM_SOURCE_ONLY" = false ]
1144-
then
1145-
dvm_print_warning "Failed to downloading Deno binary file, fallback to build from source."
1146-
fi
1147-
1148-
if dvm_install_deno_by_source "$version"
1149-
then
1150-
return
1151-
fi
1152-
fi
1153-
1154-
dvm_failure
1128+
case "$DVM_INSTALL_MODE" in
1129+
"binary")
1130+
dvm_install_deno_by_binary "$version"
1131+
;;
1132+
"source")
1133+
dvm_install_deno_by_source "$version"
1134+
;;
1135+
*)
1136+
dvm_print_error "Unknown install mode: $DVM_INSTALL_MODE"
1137+
dvm_failure
1138+
;;
1139+
esac
11551140
}
11561141

11571142
# Download and install the pre-compiled Deno binary file from the network.
@@ -1442,9 +1427,8 @@ export DVM_VERSION="v0.8.1"
14421427

14431428
# unset global variables
14441429
unset -v DVM_COLOR_MODE DVM_DENO_VERSION DVM_DIR DVM_FILE_TYPE \
1445-
DVM_INSTALL_FROM_BINARY_ONLY DVM_INSTALL_FROM_SOURCE_ONLY \
1446-
DVM_INSTALL_REGISTRY DVM_INSTALL_SKIP_VALIDATION DVM_LATEST_VERSION \
1447-
DVM_PROFILE_FILE DVM_QUIET_MODE DVM_REMOTE_VERSIONS \
1430+
DVM_INSTALL_MODE DVM_INSTALL_REGISTRY DVM_INSTALL_SKIP_VALIDATION \
1431+
DVM_LATEST_VERSION DVM_PROFILE_FILE DVM_QUIET_MODE DVM_REMOTE_VERSIONS \
14481432
DVM_REQUEST_RESPONSE DVM_SOURCE DVM_TARGET_ARCH DVM_TARGET_NAME \
14491433
DVM_TARGET_OS DVM_TARGET_TYPE DVM_TARGET_VERSION DVM_VERBOSE_MODE \
14501434
DVM_VERSION
@@ -1807,10 +1791,10 @@ dvm() {
18071791
DVM_INSTALL_SKIP_VALIDATION=true
18081792
;;
18091793
"--from-binary")
1810-
DVM_INSTALL_FROM_BINARY_ONLY=true
1794+
DVM_INSTALL_MODE="binary"
18111795
;;
18121796
"--from-source")
1813-
DVM_INSTALL_FROM_SOURCE_ONLY=true
1797+
DVM_INSTALL_MODE="source"
18141798
;;
18151799
"-"*)
18161800
;;

0 commit comments

Comments
 (0)