From cfdef0c38038e42a4ac40f6e962c5e40a0c5cbe6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 29 Jul 2023 08:06:47 -0400 Subject: [PATCH] chore: remove println in DenoCompileBinaryWriter (#19976) --- cli/args/flags.rs | 9 +++++++++ cli/standalone/binary.rs | 22 ++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index c80b2cdbc8..5c87c5fbb6 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -68,6 +68,15 @@ pub struct CompileFlags { pub include: Vec, } +impl CompileFlags { + pub fn resolve_target(&self) -> String { + self + .target + .clone() + .unwrap_or_else(|| env!("TARGET").to_string()) + } +} + #[derive(Clone, Debug, Eq, PartialEq)] pub struct CompletionsFlags { pub buf: Box<[u8]>, diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index 4d964215c1..bfafcdb6be 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -1,7 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use std::collections::BTreeMap; -use std::env::consts; use std::env::current_exe; use std::io::Read; use std::io::Seek; @@ -385,19 +384,14 @@ impl<'a> DenoCompileBinaryWriter<'a> { cli_options: &CliOptions, ) -> Result<(), AnyError> { // Select base binary based on target - let mut original_binary = - self.get_base_binary(compile_flags.target.clone()).await?; - - let target = compile_flags - .target - .clone() - .unwrap_or(consts::OS.to_string()); + let mut original_binary = self.get_base_binary(compile_flags).await?; if compile_flags.no_terminal { - if target != "x86_64-pc-windows-msvc" && target != "windows" { - println!("{}", target); + let target = compile_flags.resolve_target(); + if !target.contains("windows") { bail!( - "The `--no-terminal` flag is only available when targeting Windows" + "The `--no-terminal` flag is only available when targeting Windows (current: {})", + target, ) } set_windows_binary_to_gui(&mut original_binary)?; @@ -417,14 +411,14 @@ impl<'a> DenoCompileBinaryWriter<'a> { async fn get_base_binary( &self, - target: Option, + compile_flags: &CompileFlags, ) -> Result, AnyError> { - if target.is_none() { + if compile_flags.target.is_none() { let path = std::env::current_exe()?; return Ok(std::fs::read(path)?); } - let target = target.unwrap_or_else(|| env!("TARGET").to_string()); + let target = compile_flags.resolve_target(); let binary_name = format!("deno-{target}.zip"); let binary_path_suffix = if crate::version::is_canary() {