diff --git a/api/rs/build/Cargo.toml b/api/rs/build/Cargo.toml index 2f24949d1..01deb3a1c 100644 --- a/api/rs/build/Cargo.toml +++ b/api/rs/build/Cargo.toml @@ -23,4 +23,4 @@ i-slint-compiler = { version = "=0.2.2", path = "../../../internal/compiler", fe spin_on = "0.1" thiserror = "1" -toml_edit = "0.13.4" +toml_edit = "0.14.2" diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index e384bb6d8..ba1148b86 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -17,8 +17,8 @@ cargo_metadata = "0.14" anyhow = "1.0" lazy_static = "1.4.0" regex = "1.4" -toml_edit = "0.6.0" -xshell = "0.1.6" +toml_edit = "0.14.2" +xshell = "0.2.1" serde_json = "1.0" cbindgen = "0.21" proc-macro2 = "1.0.11" diff --git a/xtask/src/nodepackage.rs b/xtask/src/nodepackage.rs index 047644156..8fa0ef5a5 100644 --- a/xtask/src/nodepackage.rs +++ b/xtask/src/nodepackage.rs @@ -2,21 +2,25 @@ // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial use anyhow::Context; -use xshell::{cmd, cp, pushd, read_dir, read_file, rm_rf, write_file}; +use xshell::{cmd, Shell}; -fn cp_r(src: &std::path::Path, dst: &std::path::Path) -> Result<(), Box> { +fn cp_r( + sh: &Shell, + src: &std::path::Path, + dst: &std::path::Path, +) -> Result<(), Box> { if src.is_dir() { assert!(dst.is_dir() || !dst.exists()); - for f in read_dir(src)? { + for f in sh.read_dir(src)? { let src = src.join(&f); let dst = dst.join(&f); - cp_r(&src, &dst)? + cp_r(sh, &src, &dst)? } Ok(()) } else { - cp(src, dst).map_err(|e| e.into()) + sh.copy_file(src, dst).map_err(|e| e.into()) } } @@ -28,8 +32,10 @@ pub fn generate() -> Result<(), Box> { println!("Removing relative paths from {}", cargo_toml_path.to_string_lossy()); + let sh = Shell::new()?; + let toml_source = - read_file(cargo_toml_path.clone()).context("Failed to read Node Cargo.toml")?; + sh.read_file(cargo_toml_path.clone()).context("Failed to read Node Cargo.toml")?; let mut toml: toml_edit::Document = toml_source.parse().context("Error parsing Cargo.toml")?; @@ -47,17 +53,17 @@ pub fn generate() -> Result<(), Box> { let edited_toml = toml.to_string(); - write_file(cargo_toml_path.clone(), edited_toml).context("Error writing Cargo.toml")?; + sh.write_file(cargo_toml_path.clone(), edited_toml).context("Error writing Cargo.toml")?; println!("Putting LICENSE information into place for the source package"); - cp(root.join("LICENSE.md"), node_dir.join("LICENSE.md")) + sh.copy_file(root.join("LICENSE.md"), node_dir.join("LICENSE.md")) .context("Error copying LICENSE.md into the node dir for packaging")?; - cp_r(&root.join("LICENSES"), &node_dir.join("LICENSES"))?; + cp_r(&sh, &root.join("LICENSES"), &node_dir.join("LICENSES"))?; let package_json_source = - read_file(&node_dir.join("package.json")).context("Error reading package.json")?; + sh.read_file(&node_dir.join("package.json")).context("Error reading package.json")?; let package_json: serde_json::Value = serde_json::from_str(&package_json_source)?; @@ -67,22 +73,20 @@ pub fn generate() -> Result<(), Box> { package_json["version"].as_str().unwrap() )); - rm_rf(file_name.clone()).context("Error deleting old archive")?; + sh.remove_path(file_name.clone()).context("Error deleting old archive")?; println!("Running npm package to create the tarball"); { - let _p = pushd(node_dir.clone()) - .context(format!("Error changing to node directory {}", node_dir.to_string_lossy()))?; - - cmd!("npm pack").run()?; + let _p = sh.push_dir(node_dir.clone()); + cmd!(sh, "npm pack").run()?; } println!("Reverting Cargo.toml"); - write_file(cargo_toml_path, toml_source).context("Error writing Cargo.toml")?; + sh.write_file(cargo_toml_path, toml_source).context("Error writing Cargo.toml")?; - rm_rf(node_dir.join("LICENSE.md")).context("Error deleting LICENSE.md copy")?; + sh.remove_path(node_dir.join("LICENSE.md")).context("Error deleting LICENSE.md copy")?; println!("Source package created and located in {}", file_name.to_string_lossy()); diff --git a/xtask/src/reuse_compliance_check.rs b/xtask/src/reuse_compliance_check.rs index ef8dd16fd..05d768227 100644 --- a/xtask/src/reuse_compliance_check.rs +++ b/xtask/src/reuse_compliance_check.rs @@ -3,38 +3,38 @@ use anyhow::{Context, Result}; -use xshell::Cmd; +use xshell::{Cmd, Shell}; use std::collections::BTreeMap; use std::{ffi::OsStr, path::Path, path::PathBuf}; -fn cmd(command: impl AsRef, args: I) -> Result +fn cmd<'a, I>(sh: &'a Shell, command: impl AsRef, args: I) -> Result> where I: IntoIterator, I::Item: AsRef, { let home_dir = std::env::var("HOME").context("HOME is not set in the environment")?; - Ok(Cmd::new(command).args(args).env("PATH", &format!("/bin:/usr/bin:{}/.local/bin", home_dir))) + Ok(sh.cmd(command).args(args).env("PATH", &format!("/bin:/usr/bin:{}/.local/bin", home_dir))) } pub fn find_reuse() -> Result { which::which("reuse").context("Failed to find reuse") } -pub fn install_reuse() -> Result { - cmd("pip", &["install", "reuse"])?.run().context("Failed to pip install reuse.")?; +pub fn install_reuse(sh: &Shell) -> Result { + cmd(sh, "pip", &["install", "reuse"])?.run().context("Failed to pip install reuse.")?; find_reuse().context("Could not find reuse after pip installing it") } -pub fn reuse_download(reuse: &Path) -> Result { - Ok(cmd(reuse, &["download", "--all"])? +pub fn reuse_download(sh: &Shell, reuse: &Path) -> Result { + Ok(cmd(sh, reuse, &["download", "--all"])? .read() .context("Failed to download missing licenses.")?) } -pub fn reuse_lint(reuse: &Path) -> Result<()> { - let output = cmd(reuse, &["lint"])?.ignore_status().output()?; +pub fn reuse_lint(sh: &Shell, reuse: &Path) -> Result<()> { + let output = cmd(sh, reuse, &["lint"])?.ignore_status().output()?; if !output.status.success() { let stdout = String::from_utf8(output.stdout)?; @@ -44,8 +44,8 @@ pub fn reuse_lint(reuse: &Path) -> Result<()> { Ok(()) } -fn parse_spdx_data(reuse: &Path) -> Result>> { - let output = cmd(reuse, &["spdx"])?.read()?; +fn parse_spdx_data(sh: &Shell, reuse: &Path) -> Result>> { + let output = cmd(sh, reuse, &["spdx"])?.read()?; let mut current_filename = String::new(); let mut licenses = Vec::new(); @@ -327,7 +327,7 @@ fn validate_license_directory(dir: &Path, licenses: &[String], fix_it: bool) -> Ok(()) } -pub fn scan_symlinks(reuse: &Path, fix_it: bool) -> Result<()> { +pub fn scan_symlinks(sh: &Shell, reuse: &Path, fix_it: bool) -> Result<()> { let license_directories = find_licenses_directories(&PathBuf::from(".")) .context("Failed to scan for directories containing LICENSES subfolders")?; @@ -340,7 +340,7 @@ pub fn scan_symlinks(reuse: &Path, fix_it: bool) -> Result<()> { .map(|p| (p.clone(), Vec::::new())) .collect::>(); - let file_data = parse_spdx_data(reuse).context("Failed to parse SPDX project data")?; + let file_data = parse_spdx_data(sh, reuse).context("Failed to parse SPDX project data")?; populate_license_map(&mut license_map, file_data); @@ -369,17 +369,19 @@ impl ReuseComplianceCheck { anyhow::bail!("No .reuse directory found in current directory"); } - let reuse = find_reuse().or_else(|_| install_reuse())?; + let sh = Shell::new()?; + + let reuse = find_reuse().or_else(|_| install_reuse(&sh))?; println!("Reuse binary \"{}\".", reuse.to_string_lossy()); if self.download_missing_licenses { - let output = reuse_download(&reuse)?; + let output = reuse_download(&sh, &reuse)?; println!("{}", &output); } - reuse_lint(&reuse)?; + reuse_lint(&sh, &reuse)?; - scan_symlinks(&reuse, self.fix_symlinks) + scan_symlinks(&sh, &reuse, self.fix_symlinks) } }