mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 14:51:15 +00:00
Update toml_edit and xshell
This commit is contained in:
parent
452bc2a696
commit
634e4387c6
4 changed files with 43 additions and 37 deletions
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<dyn std::error::Error>> {
|
||||
fn cp_r(
|
||||
sh: &Shell,
|
||||
src: &std::path::Path,
|
||||
dst: &std::path::Path,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
|||
|
||||
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<dyn std::error::Error>> {
|
|||
|
||||
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<dyn std::error::Error>> {
|
|||
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());
|
||||
|
||||
|
|
|
@ -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<I>(command: impl AsRef<Path>, args: I) -> Result<Cmd>
|
||||
fn cmd<'a, I>(sh: &'a Shell, command: impl AsRef<Path>, args: I) -> Result<Cmd<'a>>
|
||||
where
|
||||
I: IntoIterator,
|
||||
I::Item: AsRef<OsStr>,
|
||||
{
|
||||
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<PathBuf> {
|
||||
which::which("reuse").context("Failed to find reuse")
|
||||
}
|
||||
|
||||
pub fn install_reuse() -> Result<PathBuf> {
|
||||
cmd("pip", &["install", "reuse"])?.run().context("Failed to pip install reuse.")?;
|
||||
pub fn install_reuse(sh: &Shell) -> Result<PathBuf> {
|
||||
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<String> {
|
||||
Ok(cmd(reuse, &["download", "--all"])?
|
||||
pub fn reuse_download(sh: &Shell, reuse: &Path) -> Result<String> {
|
||||
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<BTreeMap<PathBuf, Vec<String>>> {
|
||||
let output = cmd(reuse, &["spdx"])?.read()?;
|
||||
fn parse_spdx_data(sh: &Shell, reuse: &Path) -> Result<BTreeMap<PathBuf, Vec<String>>> {
|
||||
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::<String>::new()))
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue