Skip to content

Commit f49f7a6

Browse files
irbullbartlomieju
authored andcommitted
chore(compile): prefer denort binary in target/ directory when available (#27052)
Enhances the deno compile workflow for denort development by automatically checking for a denort binary in the same directory as the deno binary, provided both are located within a target/ directory. If found, this denort binary will be used. Key points: - The DENORT_BIN environment variable remains supported for explicitly specifying a custom denort binary path. - Includes additional logic to verify if the deno binary is a symlink pointing to an executable in the target/ directory. --------- Signed-off-by: Ian Bull <[email protected]>
1 parent 389cde8 commit f49f7a6

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

cli/standalone/binary.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::borrow::Cow;
44
use std::collections::BTreeMap;
55
use std::collections::HashMap;
66
use std::collections::VecDeque;
7+
use std::env;
78
use std::env::current_exe;
89
use std::ffi::OsString;
910
use std::fs;
@@ -15,6 +16,7 @@ use std::io::Seek;
1516
use std::io::SeekFrom;
1617
use std::io::Write;
1718
use std::ops::Range;
19+
use std::path::Component;
1820
use std::path::Path;
1921
use std::path::PathBuf;
2022
use std::process::Command;
@@ -457,7 +459,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
457459
//
458460
// Phase 2 of the 'min sized' deno compile RFC talks
459461
// about adding this as a flag.
460-
if let Some(path) = std::env::var_os("DENORT_BIN") {
462+
if let Some(path) = get_dev_binary_path() {
461463
return std::fs::read(&path).with_context(|| {
462464
format!("Could not find denort at '{}'", path.to_string_lossy())
463465
});
@@ -908,6 +910,31 @@ impl<'a> DenoCompileBinaryWriter<'a> {
908910
}
909911
}
910912

913+
fn get_denort_path(deno_exe: PathBuf) -> Option<OsString> {
914+
let mut denort = deno_exe;
915+
denort.set_file_name(if cfg!(windows) {
916+
"denort.exe"
917+
} else {
918+
"denort"
919+
});
920+
denort.exists().then(|| denort.into_os_string())
921+
}
922+
923+
fn get_dev_binary_path() -> Option<OsString> {
924+
env::var_os("DENORT_BIN").or_else(|| {
925+
env::current_exe().ok().and_then(|exec_path| {
926+
if exec_path
927+
.components()
928+
.any(|component| component == Component::Normal("target".as_ref()))
929+
{
930+
get_denort_path(exec_path)
931+
} else {
932+
None
933+
}
934+
})
935+
})
936+
}
937+
911938
/// This function returns the environment variables specified
912939
/// in the passed environment file.
913940
fn get_file_env_vars(

0 commit comments

Comments
 (0)