From ae327d0a83be3ad56d42cad7db0b15ae8e853f06 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Wed, 29 Nov 2023 19:52:25 +0100 Subject: build(cli): allow to build without upgrade feature (#19910) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The self-upgrade feature is undesirable when deno is installed from (Linux) distribution repository - using a system package manager. This change will allow package maintainers to build deno with the "upgrade" subcommand and background check disabled. When the user runs `deno upgrade ` and the upgrade feature is disabled, it will exit with error message explaining that this deno binary was built without the upgrade feature. Note: This patch is already used in the Alpine Linux’s [deno](https://pkgs.alpinelinux.org/packages?name=deno) package. --- cli/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'cli/main.rs') diff --git a/cli/main.rs b/cli/main.rs index 94b59b9d6..bd29dc532 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -198,9 +198,15 @@ async fn run_subcommand(flags: Flags) -> Result { let types = tsc::get_types_declaration_file_text(flags.unstable); display::write_to_stdout_ignore_sigpipe(types.as_bytes()) }), + #[cfg(feature = "upgrade")] DenoSubcommand::Upgrade(upgrade_flags) => spawn_subcommand(async { tools::upgrade::upgrade(flags, upgrade_flags).await }), + #[cfg(not(feature = "upgrade"))] + DenoSubcommand::Upgrade(_) => exit_with_message( + "This deno was built without the \"upgrade\" feature. Please upgrade using the installation method originally used to install Deno.", + 1, + ), DenoSubcommand::Vendor(vendor_flags) => spawn_subcommand(async { tools::vendor::vendor(flags, vendor_flags).await }), @@ -237,6 +243,15 @@ fn setup_panic_hook() { })); } +fn exit_with_message(message: &str, code: i32) -> ! { + eprintln!( + "{}: {}", + colors::red_bold("error"), + message.trim_start_matches("error: ") + ); + std::process::exit(code); +} + fn unwrap_or_exit(result: Result) -> T { match result { Ok(value) => value, @@ -251,12 +266,7 @@ fn unwrap_or_exit(result: Result) -> T { error_code = 10; } - eprintln!( - "{}: {}", - colors::red_bold("error"), - error_string.trim_start_matches("error: ") - ); - std::process::exit(error_code); + exit_with_message(&error_string, error_code); } } } -- cgit v1.2.3