diff --git a/Cargo.toml b/Cargo.toml index cdf02574a..7c3c39f64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,7 +68,6 @@ fs_extra = "1" futures = { version = "0.3", default-features = false, features = ["std", "async-await"] } gix = ">=0.55" glob = "0.3" -hyper = "0.14" ignore = "0.4" include_dir = "0.7" indicatif = "0.17" diff --git a/scarb/src/bin/scarb/commands/commands.rs b/scarb/src/bin/scarb/commands/commands.rs index 9de04fe0d..0a6e194e5 100644 --- a/scarb/src/bin/scarb/commands/commands.rs +++ b/scarb/src/bin/scarb/commands/commands.rs @@ -115,7 +115,7 @@ mod tests { use camino::Utf8Path; use scarb::core::Config; - use scarb::process::make_executable; + use scarb_test_support::fsx::make_executable; use super::{list_commands, CommandInfo}; diff --git a/scarb/src/internal/fsx.rs b/scarb/src/internal/fsx.rs index b5f1c5db5..ac9d9464f 100644 --- a/scarb/src/internal/fsx.rs +++ b/scarb/src/internal/fsx.rs @@ -111,6 +111,46 @@ pub fn copy(from: impl AsRef, to: impl AsRef) -> Result { } } +#[cfg(unix)] +pub fn is_executable>(path: P) -> bool { + use std::os::unix::prelude::*; + fs::metadata(path) + .map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0) + .unwrap_or(false) +} + +#[cfg(windows)] +pub fn is_executable>(path: P) -> bool { + path.as_ref().is_file() +} + +#[cfg(unix)] +pub fn is_hidden(entry: impl AsRef) -> bool { + is_hidden_by_dot(entry) +} + +#[cfg(windows)] +pub fn is_hidden(entry: impl AsRef) -> bool { + use std::os::windows::prelude::*; + + let is_hidden = fs::metadata(entry.as_ref()) + .ok() + .map(|metadata| metadata.file_attributes()) + .map(|attributes| (attributes & 0x2) > 0) + .unwrap_or(false); + + is_hidden || is_hidden_by_dot(entry) +} + +fn is_hidden_by_dot(entry: impl AsRef) -> bool { + entry + .as_ref() + .file_stem() + .and_then(|s| s.to_str()) + .map(|s| s.starts_with('.')) + .unwrap_or(false) +} + pub trait PathUtf8Ext { fn try_as_utf8(&'_ self) -> Result<&'_ Utf8Path>; diff --git a/scarb/src/ops/subcommands.rs b/scarb/src/ops/subcommands.rs index 56c9874c7..478b00c18 100644 --- a/scarb/src/ops/subcommands.rs +++ b/scarb/src/ops/subcommands.rs @@ -11,8 +11,9 @@ use tracing::debug; use scarb_ui::components::Status; use crate::core::{Config, Package, ScriptDefinition, Workspace}; +use crate::internal::fsx::is_executable; use crate::ops; -use crate::process::{exec_replace, is_executable}; +use crate::process::exec_replace; use crate::subcommands::{get_env_vars, EXTERNAL_CMD_PREFIX, SCARB_MANIFEST_PATH_ENV}; /// Prepare environment and execute an external subcommand. diff --git a/scarb/src/ops/workspace.rs b/scarb/src/ops/workspace.rs index 9d20c53c5..6dbb9f7d2 100644 --- a/scarb/src/ops/workspace.rs +++ b/scarb/src/ops/workspace.rs @@ -14,9 +14,8 @@ use crate::core::source::SourceId; use crate::core::workspace::Workspace; use crate::core::TomlManifest; use crate::internal::fsx; -use crate::internal::fsx::PathBufUtf8Ext; +use crate::internal::fsx::{is_hidden, PathBufUtf8Ext}; use crate::ops::find_workspace_manifest_path; -use crate::process::is_hidden; use crate::MANIFEST_FILE_NAME; #[tracing::instrument(level = "debug", skip(config))] diff --git a/scarb/src/process.rs b/scarb/src/process.rs index 17044a86a..5bbc02d57 100644 --- a/scarb/src/process.rs +++ b/scarb/src/process.rs @@ -1,6 +1,5 @@ use std::ffi::OsStr; use std::io::{BufRead, BufReader, Read}; -use std::path::Path; use std::process::{Command, Stdio}; use std::sync::Arc; use std::{fmt, thread}; @@ -11,6 +10,7 @@ use tracing::{debug, debug_span, warn, Span}; use scarb_ui::components::{Spinner, Status}; use crate::core::Config; +pub use crate::internal::fsx::is_executable; /// Replaces the current process with the target process. /// @@ -34,10 +34,11 @@ pub fn exec_replace(cmd: &mut Command) -> Result<()> { #[cfg(unix)] mod imp { - use anyhow::{bail, Result}; use std::os::unix::process::CommandExt; use std::process::Command; + use anyhow::{bail, Result}; + pub fn exec_replace(cmd: &mut Command) -> Result<()> { let err = cmd.exec(); bail!("process did not exit successfully: {err}") @@ -46,8 +47,9 @@ mod imp { #[cfg(windows)] mod imp { - use anyhow::{bail, Context, Result}; use std::process::Command; + + use anyhow::{bail, Context, Result}; use windows_sys::Win32::Foundation::{BOOL, FALSE, TRUE}; use windows_sys::Win32::System::Console::SetConsoleCtrlHandler; @@ -144,20 +146,6 @@ pub fn exec(cmd: &mut Command, config: &Config) -> Result<()> { } } -#[cfg(unix)] -pub fn is_executable>(path: P) -> bool { - use std::fs; - use std::os::unix::prelude::*; - fs::metadata(path) - .map(|metadata| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0) - .unwrap_or(false) -} - -#[cfg(windows)] -pub fn is_executable>(path: P) -> bool { - path.as_ref().is_file() -} - /// Python's [`shlex.join`] for [`Command`]. /// /// [`shlex.join`]: https://docs.python.org/3/library/shlex.html#shlex.join @@ -188,42 +176,3 @@ impl<'a> fmt::Display for ShlexJoin<'a> { Ok(()) } } - -#[cfg(unix)] -pub fn make_executable(path: &Path) { - use std::fs; - use std::os::unix::prelude::*; - let mut perms = fs::metadata(path).unwrap().permissions(); - perms.set_mode(perms.mode() | 0o700); - fs::set_permissions(path, perms).unwrap(); -} - -#[cfg(windows)] -pub fn make_executable(_path: &Path) {} - -#[cfg(unix)] -pub fn is_hidden(entry: impl AsRef) -> bool { - is_hidden_by_dot(entry) -} - -#[cfg(windows)] -pub fn is_hidden(entry: impl AsRef) -> bool { - use std::os::windows::prelude::*; - - let is_hidden = std::fs::metadata(entry.as_ref()) - .ok() - .map(|metadata| metadata.file_attributes()) - .map(|attributes| (attributes & 0x2) > 0) - .unwrap_or(false); - - is_hidden || is_hidden_by_dot(entry) -} - -fn is_hidden_by_dot(entry: impl AsRef) -> bool { - entry - .as_ref() - .file_stem() - .and_then(|s| s.to_str()) - .map(|s| s.starts_with('.')) - .unwrap_or(false) -} diff --git a/scarb/tests/scripts.rs b/scarb/tests/scripts.rs index 7ec40087a..ba8311732 100644 --- a/scarb/tests/scripts.rs +++ b/scarb/tests/scripts.rs @@ -5,9 +5,9 @@ use assert_fs::prelude::*; use assert_fs::TempDir; use indoc::{formatdoc, indoc}; -use scarb::process::make_executable; use scarb_test_support::command::{CommandExt, Scarb}; use scarb_test_support::filesystem::{path_with_temp_dir, write_simple_hello_script}; +use scarb_test_support::fsx::make_executable; use scarb_test_support::project_builder::ProjectBuilder; use scarb_test_support::workspace_builder::WorkspaceBuilder; diff --git a/scarb/tests/subcommand.rs b/scarb/tests/subcommand.rs index 4a1ea86a7..e1ae32e04 100644 --- a/scarb/tests/subcommand.rs +++ b/scarb/tests/subcommand.rs @@ -9,7 +9,7 @@ use indoc::indoc; use scarb_test_support::cargo::cargo_bin; use scarb_test_support::command::Scarb; -use scarb_test_support::filesystem::{path_with_temp_dir, write_script, write_simple_hello_script}; +use scarb_test_support::filesystem::{path_with_temp_dir, write_simple_hello_script}; use scarb_test_support::project_builder::ProjectBuilder; #[test] @@ -56,7 +56,7 @@ fn list_commands_e2e() { #[cfg(unix)] fn env_variables_are_passed() { let t = TempDir::new().unwrap(); - write_script( + scarb_test_support::filesystem::write_script( "env", indoc! { r#" @@ -98,7 +98,7 @@ fn env_variables_are_passed() { #[cfg(unix)] fn env_scarb_log_is_passed_verbatim() { let t = TempDir::new().unwrap(); - write_script( + scarb_test_support::filesystem::write_script( "env", indoc! { r#" @@ -196,7 +196,7 @@ fn can_find_scarb_directory_scripts_without_path() { #[test] fn can_list_scarb_directory_scripts() { - let t = assert_fs::TempDir::new().unwrap(); + let t = TempDir::new().unwrap(); write_simple_hello_script("hello", &t); // Set scarb path to folder containing hello script diff --git a/utils/scarb-test-support/Cargo.toml b/utils/scarb-test-support/Cargo.toml index 7b3d0b89b..15bbb85ae 100644 --- a/utils/scarb-test-support/Cargo.toml +++ b/utils/scarb-test-support/Cargo.toml @@ -12,7 +12,7 @@ camino.workspace = true clap.workspace = true data-encoding.workspace = true dunce.workspace = true -hyper.workspace = true +hyper = "*" # Link whatever comes with reqwest. indoc.workspace = true itertools.workspace = true once_cell.workspace = true diff --git a/utils/scarb-test-support/src/filesystem.rs b/utils/scarb-test-support/src/filesystem.rs index 24c8b99d6..50680fe52 100644 --- a/utils/scarb-test-support/src/filesystem.rs +++ b/utils/scarb-test-support/src/filesystem.rs @@ -5,7 +5,8 @@ use std::{env, iter, vec}; use assert_fs::prelude::*; use assert_fs::TempDir; use indoc::indoc; -use scarb::process::make_executable; + +use crate::fsx::make_executable; pub fn write_script(name: &str, script_source: &str, t: &TempDir) { let script = t.child(format!("scarb-{name}{}", env::consts::EXE_SUFFIX)); diff --git a/utils/scarb-test-support/src/fsx.rs b/utils/scarb-test-support/src/fsx.rs index ca8721de6..e7bc15366 100644 --- a/utils/scarb-test-support/src/fsx.rs +++ b/utils/scarb-test-support/src/fsx.rs @@ -1,7 +1,7 @@ use std::fs; use std::fs::File; use std::io::BufReader; -use std::path::{PathBuf, MAIN_SEPARATOR_STR}; +use std::path::{Path, PathBuf, MAIN_SEPARATOR_STR}; use assert_fs::fixture::ChildPath; use assert_fs::TempDir; @@ -15,6 +15,17 @@ pub use internal_fsx::{canonicalize, canonicalize_utf8, PathBufUtf8Ext, PathUtf8 #[path = "../../../scarb/src/internal/fsx.rs"] mod internal_fsx; +#[cfg(unix)] +pub fn make_executable(path: &Path) { + use std::os::unix::prelude::*; + let mut perms = fs::metadata(path).unwrap().permissions(); + perms.set_mode(perms.mode() | 0o700); + fs::set_permissions(path, perms).unwrap(); +} + +#[cfg(windows)] +pub fn make_executable(_path: &Path) {} + pub trait AssertFsUtf8Ext { fn utf8_path(&self) -> &Utf8Path; } diff --git a/utils/scarb-test-support/src/workspace_builder.rs b/utils/scarb-test-support/src/workspace_builder.rs index 94251710e..1d92ff9dd 100644 --- a/utils/scarb-test-support/src/workspace_builder.rs +++ b/utils/scarb-test-support/src/workspace_builder.rs @@ -1,6 +1,5 @@ use crate::project_builder::{DepBuilder, ProjectBuilder}; use assert_fs::prelude::*; -use scarb::MANIFEST_FILE_NAME; use toml_edit::{Array, Document, Item, Value}; #[derive(Default)] @@ -59,6 +58,6 @@ impl WorkspaceBuilder { manifest.push_str(&self.manifest_extra); } - t.child(MANIFEST_FILE_NAME).write_str(&manifest).unwrap(); + t.child("Scarb.toml").write_str(&manifest).unwrap(); } }