diff --git a/Cargo.lock b/Cargo.lock index f939e3995..fc31002d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,12 +29,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bstr" version = "0.2.17" @@ -107,27 +101,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "dirs-next" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf36e65a80337bea855cd4ef9b8401ffce06a7baedf2e85ec467b1ac3f6e82b6" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "encode_unicode" version = "0.3.6" @@ -273,24 +246,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" -[[package]] -name = "proc-macro2" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = [ - "proc-macro2", -] - [[package]] name = "rand" version = "0.8.5" @@ -321,26 +276,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - [[package]] name = "regex-automata" version = "0.1.10" @@ -377,17 +312,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "syn" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "terminal_size" version = "0.1.17" @@ -398,26 +322,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "thiserror" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "types" version = "0.10.0" @@ -425,12 +329,6 @@ dependencies = [ "bytecode", ] -[[package]] -name = "unicode-ident" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" - [[package]] name = "unicode-segmentation" version = "1.9.0" @@ -457,7 +355,6 @@ dependencies = [ "bytecode", "crossbeam-queue", "crossbeam-utils", - "dirs-next", "libc", "libffi", "libloading", diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 2d1c47ccc..82dc4f1fc 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -13,7 +13,6 @@ doctest = false libffi-system = ["libffi/system"] [dependencies] -dirs-next = "^1.0" libloading = "^0.7" libffi = "^3.0" crossbeam-utils = "^0.8" diff --git a/vm/src/builtin_functions/env.rs b/vm/src/builtin_functions/env.rs index 78f5ab3e9..940e8ab99 100644 --- a/vm/src/builtin_functions/env.rs +++ b/vm/src/builtin_functions/env.rs @@ -1,5 +1,4 @@ //! Functions for setting/getting environment and operating system data. -use crate::directories; use crate::mem::{Array, Pointer, String as InkoString}; use crate::platform; use crate::process::ProcessPointer; @@ -48,15 +47,22 @@ pub(crate) fn env_home_directory( _: ProcessPointer, _: &[Pointer], ) -> Result { - let result = if let Some(path) = directories::home() { - InkoString::alloc( - state.permanent_space.string_class(), - canonalize(path), - ) + // Rather than performing all sorts of magical incantations to get the home + // directory, we're just going to require that these environment variables + // are set. + let var = if cfg!(windows) { + state.environment.get("USERPROFILE") } else { - Pointer::undefined_singleton() + state.environment.get("HOME") }; + // If the home is explicitly set to an empty string we still ignore it, + // because there's no scenario in which Some("") is useful. + let result = var + .cloned() + .filter(|p| unsafe { !InkoString::read(p).is_empty() }) + .unwrap_or_else(Pointer::undefined_singleton); + Ok(result) } @@ -66,7 +72,7 @@ pub(crate) fn env_temp_directory( _: ProcessPointer, _: &[Pointer], ) -> Result { - let path = canonalize(directories::temp()); + let path = canonalize(env::temp_dir().to_string_lossy().into_owned()); Ok(InkoString::alloc(state.permanent_space.string_class(), path)) } @@ -77,7 +83,9 @@ pub(crate) fn env_get_working_directory( _: ProcessPointer, _: &[Pointer], ) -> Result { - let path = directories::working_directory().map(canonalize)?; + let path = env::current_dir() + .map(|path| path.to_string_lossy().into_owned()) + .map(canonalize)?; Ok(InkoString::alloc(state.permanent_space.string_class(), path)) } @@ -90,7 +98,7 @@ pub(crate) fn env_set_working_directory( ) -> Result { let dir = unsafe { InkoString::read(&arguments[0]) }; - directories::set_working_directory(dir)?; + env::set_current_dir(dir)?; Ok(Pointer::nil_singleton()) } diff --git a/vm/src/directories.rs b/vm/src/directories.rs deleted file mode 100644 index 9a35bd389..000000000 --- a/vm/src/directories.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! Module for obtaining paths to directories, such as the home directory. -use std::env; -use std::io; - -/// Returns the path to the home directory. -pub(crate) fn home() -> Option { - dirs_next::home_dir().map(|path| path.to_string_lossy().into_owned()) -} - -/// Returns the path to the temporary directory. -pub(crate) fn temp() -> String { - env::temp_dir().to_string_lossy().into_owned() -} - -/// Returns the current working directory. -pub(crate) fn working_directory() -> io::Result { - env::current_dir().map(|path| path.to_string_lossy().into_owned()) -} - -/// Returns the current working directory. -pub(crate) fn set_working_directory(directory: &str) -> io::Result<()> { - env::set_current_dir(directory) -} - -#[cfg(test)] -mod tests { - use super::*; - use std::path::Path; - - #[test] - fn test_home() { - if let Some(path) = home() { - if !path.is_empty() { - assert!(Path::new(&path).is_dir()); - } - } - } - - #[test] - fn test_temp() { - assert!(Path::new(&temp()).is_dir()); - } - - #[test] - fn test_working_directory() { - let dir_res = working_directory(); - - assert!(dir_res.is_ok()); - assert!(Path::new(&dir_res.unwrap()).is_dir()); - } - - #[test] - fn test_set_working_directory() { - let current_dir = working_directory().unwrap(); - - assert!(set_working_directory(¤t_dir).is_ok()); - } -} diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 5729926ec..01eb4a253 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -9,7 +9,6 @@ pub mod arc_without_weak; pub mod builtin_functions; pub mod chunk; pub mod config; -pub mod directories; pub mod execution_context; pub mod ffi; pub mod hasher;