mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 21:30:41 +00:00
Fix unneeded reference
Signed-off-by: Till Wegmueller <toasterson@gmail.com>
This commit is contained in:
parent
da3c398bc8
commit
2d74df13da
1 changed files with 49 additions and 35 deletions
|
|
@ -1,16 +1,16 @@
|
||||||
use std::fs::{create_dir_all, File};
|
|
||||||
use crate::sources::{Source, SourceError};
|
use crate::sources::{Source, SourceError};
|
||||||
use std::process::{Command, Stdio};
|
use libips::actions::{ActionError, File as FileAction, Manifest};
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::io::copy;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::prelude::*;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use libips::actions::{Manifest, File as FileAction, ActionError};
|
use std::env::{current_dir, set_current_dir};
|
||||||
use std::env::{set_current_dir, current_dir};
|
use std::fs::{create_dir_all, File};
|
||||||
use thiserror::Error;
|
use std::io::copy;
|
||||||
use std::result::Result as StdResult;
|
use std::io::prelude::*;
|
||||||
use std::io::Error as IOError;
|
use std::io::Error as IOError;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
use std::result::Result as StdResult;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
type Result<T> = StdResult<T, WorkspaceError>;
|
type Result<T> = StdResult<T, WorkspaceError>;
|
||||||
|
|
||||||
|
|
@ -22,10 +22,7 @@ static DEFAULTSHEBANG: &[u8; 19usize] = b"#!/usr/bin/env bash";
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum WorkspaceError {
|
pub enum WorkspaceError {
|
||||||
#[error("command returned {command} exit code: {code}")]
|
#[error("command returned {command} exit code: {code}")]
|
||||||
NonZeroCommandExitCode {
|
NonZeroCommandExitCode { command: String, code: i32 },
|
||||||
command: String,
|
|
||||||
code: i32,
|
|
||||||
},
|
|
||||||
#[error("source {0} cannot be extracted")]
|
#[error("source {0} cannot be extracted")]
|
||||||
UnextractableSource(Source),
|
UnextractableSource(Source),
|
||||||
#[error("status code invalid")]
|
#[error("status code invalid")]
|
||||||
|
|
@ -48,7 +45,6 @@ pub enum WorkspaceError {
|
||||||
IpsActionError(#[from] ActionError),
|
IpsActionError(#[from] ActionError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct Workspace {
|
pub struct Workspace {
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
source_dir: PathBuf,
|
source_dir: PathBuf,
|
||||||
|
|
@ -67,20 +63,21 @@ fn init_root(ws: &Workspace) -> Result<()> {
|
||||||
|
|
||||||
impl Workspace {
|
impl Workspace {
|
||||||
pub fn new(root: &str) -> Result<Workspace> {
|
pub fn new(root: &str) -> Result<Workspace> {
|
||||||
|
|
||||||
let root_dir = if root.is_empty() {
|
let root_dir = if root.is_empty() {
|
||||||
DEFAULTWORKSPACEROOT
|
DEFAULTWORKSPACEROOT
|
||||||
} else {
|
} else {
|
||||||
root
|
root
|
||||||
};
|
};
|
||||||
|
|
||||||
let expanded_root_dir = shellexpand::full(root_dir).map_err(|e|{
|
let expanded_root_dir = shellexpand::full(root_dir)
|
||||||
WorkspaceError::VariableLookupError(format!("{}", e.cause))
|
.map_err(|e| WorkspaceError::VariableLookupError(format!("{}", e.cause)))?
|
||||||
})?.to_string();
|
.to_string();
|
||||||
|
|
||||||
let ws = Workspace{
|
let ws = Workspace {
|
||||||
root: Path::new(&expanded_root_dir).to_path_buf(),
|
root: Path::new(&expanded_root_dir).to_path_buf(),
|
||||||
build_dir: Path::new(&expanded_root_dir).join("build").join(DEFAULTARCH),
|
build_dir: Path::new(&expanded_root_dir)
|
||||||
|
.join("build")
|
||||||
|
.join(DEFAULTARCH),
|
||||||
source_dir: Path::new(&expanded_root_dir).join("sources"),
|
source_dir: Path::new(&expanded_root_dir).join("sources"),
|
||||||
proto_dir: Path::new(&expanded_root_dir).join("build").join("proto"),
|
proto_dir: Path::new(&expanded_root_dir).join("build").join("proto"),
|
||||||
};
|
};
|
||||||
|
|
@ -110,7 +107,8 @@ impl Workspace {
|
||||||
("proto_dir".to_owned(), self.proto_dir.clone()),
|
("proto_dir".to_owned(), self.proto_dir.clone()),
|
||||||
("build_dir".to_owned(), self.build_dir.clone()),
|
("build_dir".to_owned(), self.build_dir.clone()),
|
||||||
("source_dir".to_owned(), self.source_dir.clone()),
|
("source_dir".to_owned(), self.source_dir.clone()),
|
||||||
].into()
|
]
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_sources(&self, sources: Vec<String>) -> Result<Vec<Source>> {
|
pub fn get_sources(&self, sources: Vec<String>) -> Result<Vec<Source>> {
|
||||||
|
|
@ -138,22 +136,34 @@ impl Workspace {
|
||||||
pub fn unpack_source(&self, src: &Source) -> Result<()> {
|
pub fn unpack_source(&self, src: &Source) -> Result<()> {
|
||||||
match Path::new(&src.local_name).extension() {
|
match Path::new(&src.local_name).extension() {
|
||||||
Some(ext) => {
|
Some(ext) => {
|
||||||
if !ext.to_str().ok_or(WorkspaceError::SourceHasNoExtension(src.clone()))?.contains("tar") {
|
if !ext
|
||||||
|
.to_str()
|
||||||
|
.ok_or(WorkspaceError::SourceHasNoExtension(src.clone()))?
|
||||||
|
.contains("tar")
|
||||||
|
{
|
||||||
return Err(WorkspaceError::UnextractableSource(src.clone()));
|
return Err(WorkspaceError::UnextractableSource(src.clone()));
|
||||||
}
|
}
|
||||||
//TODO support inspecting the tar file to see if we have a top level directory or not
|
//TODO support inspecting the tar file to see if we have a top level directory or not
|
||||||
let mut tar_cmd = Command::new(DEFAULTTAR)
|
let mut tar_cmd = Command::new(DEFAULTTAR)
|
||||||
.args([
|
.args([
|
||||||
"-C",
|
"-C",
|
||||||
self.build_dir.to_str().ok_or(WorkspaceError::UnextractableSource(src.clone()))?,
|
self.build_dir
|
||||||
"-xaf", src.local_name.to_str().ok_or(WorkspaceError::UnextractableSource(src.clone()))?,
|
.to_str()
|
||||||
"--strip-components=1"
|
.ok_or(WorkspaceError::UnextractableSource(src.clone()))?,
|
||||||
|
"-xaf",
|
||||||
|
src.local_name
|
||||||
|
.to_str()
|
||||||
|
.ok_or(WorkspaceError::UnextractableSource(src.clone()))?,
|
||||||
|
"--strip-components=1",
|
||||||
])
|
])
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
|
||||||
let status = tar_cmd.wait()?;
|
let status = tar_cmd.wait()?;
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
return Err(WorkspaceError::NonZeroCommandExitCode {command: "tar".to_owned(), code: status.code().ok_or(WorkspaceError::InvalidStatusCode)?})?;
|
return Err(WorkspaceError::NonZeroCommandExitCode {
|
||||||
|
command: "tar".to_owned(),
|
||||||
|
code: status.code().ok_or(WorkspaceError::InvalidStatusCode)?,
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|
@ -172,15 +182,16 @@ impl Workspace {
|
||||||
file.write_all(build_script.as_bytes())?;
|
file.write_all(build_script.as_bytes())?;
|
||||||
file.write_all(b"\n")?;
|
file.write_all(b"\n")?;
|
||||||
let bash = which::which("bash")?;
|
let bash = which::which("bash")?;
|
||||||
let filtered_env : HashMap<String, String> =
|
let filtered_env: HashMap<String, String> = env::vars()
|
||||||
env::vars().filter(|&(ref k, _)|
|
.filter(|(k, _)| k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH")
|
||||||
k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
|
.collect();
|
||||||
).collect();
|
|
||||||
|
|
||||||
let mut shell = Command::new(bash)
|
let mut shell = Command::new(bash)
|
||||||
.args([
|
.args([
|
||||||
"-ex",
|
"-ex",
|
||||||
build_script_path.to_str().ok_or(WorkspaceError::UnrunableScript("build_script".into()))?
|
build_script_path
|
||||||
|
.to_str()
|
||||||
|
.ok_or(WorkspaceError::UnrunableScript("build_script".into()))?,
|
||||||
])
|
])
|
||||||
.env_clear()
|
.env_clear()
|
||||||
.envs(&filtered_env)
|
.envs(&filtered_env)
|
||||||
|
|
@ -190,7 +201,10 @@ impl Workspace {
|
||||||
|
|
||||||
let status = shell.wait()?;
|
let status = shell.wait()?;
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
return Err(WorkspaceError::NonZeroCommandExitCode {command: "build_script".to_owned(), code: status.code().ok_or(WorkspaceError::InvalidStatusCode)?})?;
|
return Err(WorkspaceError::NonZeroCommandExitCode {
|
||||||
|
command: "build_script".to_owned(),
|
||||||
|
code: status.code().ok_or(WorkspaceError::InvalidStatusCode)?,
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue