diff options
author | Lars Wirzenius <liw@liw.fi> | 2024-01-26 19:43:12 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2024-01-26 19:43:12 +0200 |
commit | b11ee78fe32b9482b4b83d636ea8cfb7b6563a8a (patch) | |
tree | 41507f07d551a984a4f4c523cc4d08b1db250a6a | |
parent | 974f72059c42ec32d138e9f05e94aa2bfbb8b019 (diff) | |
download | ambient-driver-b11ee78fe32b9482b4b83d636ea8cfb7b6563a8a.tar.gz |
refactor: pass around a reference to a State, not a statedir path
Gotta use them types.
Signed-off-by: Lars Wirzenius <liw@liw.fi>
Sponsored-by: author
-rw-r--r-- | src/action.rs | 16 | ||||
-rw-r--r-- | src/project.rs | 5 | ||||
-rw-r--r-- | src/run.rs | 4 | ||||
-rw-r--r-- | src/util.rs | 2 |
4 files changed, 16 insertions, 11 deletions
diff --git a/src/action.rs b/src/action.rs index fd31c68..de4dd18 100644 --- a/src/action.rs +++ b/src/action.rs @@ -7,7 +7,7 @@ use log::{debug, info}; use serde::{Deserialize, Serialize}; use crate::{ - project::Project, + project::{Project, State}, qemu, vdrive::{VirtualDriveBuilder, VirtualDriveError}, }; @@ -28,10 +28,10 @@ impl PreAction { &["dummy", "pwd", "cargo_fetch"] } - pub fn execute(&self, project: &Project, state: &Path) -> Result<(), ActionError> { + pub fn execute(&self, project: &Project, state: &State) -> Result<(), ActionError> { debug!("Plan::execute: {:#?}", self); match self { - Self::Dummy => dummy(state), + Self::Dummy => dummy(), Self::Pwd => pwd(project), Self::CargoFetch => cargo_fetch(project, state), } @@ -51,16 +51,16 @@ impl PostAction { &["dummy", "pwd"] } - pub fn execute(&self, project: &Project, state: &Path) -> Result<(), ActionError> { + pub fn execute(&self, project: &Project, _state: &State) -> Result<(), ActionError> { debug!("Plan::execute: {:#?}", self); match self { - Self::Dummy => dummy(state), + Self::Dummy => dummy(), Self::Pwd => pwd(project), } } } -fn dummy(_state: &Path) -> Result<(), ActionError> { +fn dummy() -> Result<(), ActionError> { println!("dummy action"); Ok(()) } @@ -70,8 +70,8 @@ fn pwd(project: &Project) -> Result<(), ActionError> { Ok(()) } -fn cargo_fetch(project: &Project, state: &Path) -> Result<(), ActionError> { - let cargo_home = state.join("dependencies"); // FIXME: hardcoded pathname +fn cargo_fetch(project: &Project, state: &State) -> Result<(), ActionError> { + let cargo_home = state.statedir().join("dependencies"); // FIXME: hardcoded pathname if !cargo_home.exists() { std::fs::create_dir(&cargo_home).map_err(|e| ActionError::Mkdir(cargo_home.clone(), e))?; } diff --git a/src/project.rs b/src/project.rs index 658d075..8ffc03d 100644 --- a/src/project.rs +++ b/src/project.rs @@ -178,6 +178,11 @@ impl State { Ok(()) } + /// Return state directory. + pub fn statedir(&self) -> &Path { + &self.statedir + } + /// Return artifacts directory for project. pub fn artifactsdir(&self) -> PathBuf { self.statedir.join("artifacts") @@ -62,7 +62,7 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> { debug!("Executing pre-plan steps"); for action in project.pre_plan() { - action.execute(project, statedir)?; + action.execute(project, &state)?; } debug!("Executing CI run"); @@ -141,7 +141,7 @@ fn cmd_run(config: &EffectiveConfig, run: &RunCommand) -> Result<(), RunError> { debug!("Executing post-plan steps"); for action in project.post_plan() { - action.execute(project, statedir)?; + action.execute(project, &state)?; } if is_git(project.source()) { diff --git a/src/util.rs b/src/util.rs index ef7baee..a9ecfe2 100644 --- a/src/util.rs +++ b/src/util.rs @@ -38,7 +38,7 @@ pub fn recreate_dir(dirname: &Path) -> Result<(), UtilError> { if dirname.exists() { std::fs::remove_dir_all(dirname).map_err(|e| UtilError::RemoveDir(dirname.into(), e))?; } - mkdir(&dirname)?; + mkdir(dirname)?; Ok(()) } |