1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix(cli/compile): do not append .exe depending on target (#9668)

This commit is contained in:
Divy Srivastava 2021-03-07 18:50:01 +05:30 committed by GitHub
parent 2894c0e615
commit 74584eef04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 8 deletions

View file

@ -344,7 +344,7 @@ async fn compile_command(
// Select base binary based on `target` and `lite` arguments
let original_binary =
tools::standalone::get_base_binary(deno_dir, target, lite).await?;
tools::standalone::get_base_binary(deno_dir, target.clone(), lite).await?;
let final_bin = tools::standalone::create_standalone_binary(
original_binary,
@ -354,7 +354,8 @@ async fn compile_command(
info!("{} {}", colors::green("Emit"), output.display());
tools::standalone::write_standalone_binary(output.clone(), final_bin).await?;
tools::standalone::write_standalone_binary(output.clone(), target, final_bin)
.await?;
Ok(())
}

View file

@ -7,6 +7,7 @@ use deno_runtime::deno_fetch::reqwest;
use deno_runtime::deno_websocket::tokio_tungstenite;
use std::fs;
use std::io::{BufRead, Read, Write};
use std::path::Path;
use std::process::Command;
use tempfile::TempDir;
use test_util as util;
@ -5247,6 +5248,31 @@ console.log("finish");
assert_eq!(output.stdout, "Welcome to Deno!\n".as_bytes());
}
#[test]
#[cfg(windows)]
// https://github.com/denoland/deno/issues/9667
fn compile_windows_ext() {
let dir = TempDir::new().expect("tempdir fail");
let exe = dir.path().join("welcome_9667");
let output = util::deno_cmd()
.current_dir(util::root_path())
.arg("compile")
.arg("--unstable")
.arg("--output")
.arg(&exe)
.arg("--target")
.arg("x86_64-unknown-linux-gnu")
.arg("./test_util/std/examples/welcome.ts")
.stdout(std::process::Stdio::piped())
.spawn()
.unwrap()
.wait_with_output()
.unwrap();
assert!(output.status.success());
let exists = Path::new(&exe).exists();
assert!(exists, true);
}
#[test]
fn standalone_args() {
let dir = TempDir::new().expect("tempdir fail");

View file

@ -129,13 +129,24 @@ pub fn create_standalone_binary(
/// is not already standalone binary it will return error instead.
pub async fn write_standalone_binary(
output: PathBuf,
target: Option<String>,
final_bin: Vec<u8>,
) -> Result<(), AnyError> {
let output =
let output = match target {
Some(target) => {
if target.contains("windows") {
PathBuf::from(output.display().to_string() + ".exe")
} else {
output
}
}
None => {
if cfg!(windows) && output.extension().unwrap_or_default() != "exe" {
PathBuf::from(output.display().to_string() + ".exe")
} else {
output
}
}
};
if output.exists() {