summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-09-02 14:49:55 +0300
committerLars Wirzenius <liw@liw.fi>2023-09-02 14:49:55 +0300
commit5aebdae47b6554eb58a7152fd346d18104e8a31d (patch)
tree502c8248a5ab77497d1b27b88c1ff619bcd52897
parentdcf990d1f1871c3f6d0f7be8eeab7e48570d9196 (diff)
downloadambient-run-5aebdae47b6554eb58a7152fd346d18104e8a31d.tar.gz
feat: provide dependencies to build VM
Sponsored-by: author
-rw-r--r--ambient-run.md28
-rw-r--r--src/bin/ambient-run.rs3
-rw-r--r--src/project.rs14
-rw-r--r--src/qemu.rs15
4 files changed, 54 insertions, 6 deletions
diff --git a/ambient-run.md b/ambient-run.md
index 82eccab..76fca3f 100644
--- a/ambient-run.md
+++ b/ambient-run.md
@@ -167,6 +167,7 @@ shell: |
image: /my/image.qcow2
artifact: null
artifact_max_size: null
+dependencies: null
~~~
### Show per-build configuration
@@ -317,6 +318,33 @@ artifact_max_size: 1
~~~
### Build is given dependencies
+
+_Requirement:_ The build is provided with its dependencies.
+
+_Justification:_ Without its dependencies, a project can't build.
+
+_Stakeholder:_ Lars.
+
+~~~scenario
+given an installed ambient-run
+given file dep-project.yaml
+given file foo/README.md from dep-project.yaml
+given file foo-deps/library.file from dep-project.yaml
+given image file image.qcow2 specified for test suite
+when I run ambient-run build dep-project.yaml --log foo.log
+then file foo.log contains "/workspace/deps/library.file"
+~~~
+
+
+~~~{#dep-project.yaml .file .yaml}
+source: foo
+shell: |
+ #!/bin/bash
+ find /workspace -type f
+image: image.qcow2
+dependencies: foo-deps
+~~~
+
### Cache is persistent between builds
### Build gets the resources is demands
diff --git a/src/bin/ambient-run.rs b/src/bin/ambient-run.rs
index 37054c2..dbe7bfa 100644
--- a/src/bin/ambient-run.rs
+++ b/src/bin/ambient-run.rs
@@ -217,7 +217,8 @@ impl BuildCommand {
.with_shell(project.shell())
.with_source(&project.source())
.with_artifact(project.artifact())
- .with_artifact_max_size(project.artifact_max_size());
+ .with_artifact_max_size(project.artifact_max_size())
+ .with_dependencies(project.dependencies());
if let Some(log) = &self.log {
qemu = qemu.with_log(log);
}
diff --git a/src/project.rs b/src/project.rs
index 76f42dc..c9b2c38 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
/// Per-project build instructions.
-#[derive(Debug, Deserialize, Serialize)]
+#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Project {
#[serde(skip)]
filename: PathBuf,
@@ -14,6 +14,7 @@ pub struct Project {
image: PathBuf,
artifact: Option<PathBuf>,
artifact_max_size: Option<u64>,
+ dependencies: Option<PathBuf>,
}
impl Project {
@@ -43,10 +44,8 @@ impl Project {
let mut project = Self {
filename: filename.into(),
source: PathBuf::from("."),
- shell: "".into(),
image,
- artifact: None,
- artifact_max_size: None,
+ ..Default::default()
};
project.add_from(filename)?;
if project.shell.is_empty() {
@@ -74,6 +73,7 @@ impl Project {
}
self.artifact = snippet.artifact;
self.artifact_max_size = snippet.artifact_max_size;
+ self.dependencies = snippet.dependencies;
Ok(())
}
@@ -106,6 +106,11 @@ impl Project {
pub fn artifact_max_size(&self) -> Option<u64> {
self.artifact_max_size.clone()
}
+
+ /// Dependencies directory.
+ pub fn dependencies(&self) -> &Option<PathBuf> {
+ &self.dependencies
+ }
}
#[derive(Debug, Deserialize)]
@@ -116,6 +121,7 @@ struct ProjectSnippet {
image: Option<PathBuf>,
artifact: Option<PathBuf>,
artifact_max_size: Option<u64>,
+ dependencies: Option<PathBuf>,
}
/// Possible errors from configuration file handling.
diff --git a/src/qemu.rs b/src/qemu.rs
index 4c6efff..2853e52 100644
--- a/src/qemu.rs
+++ b/src/qemu.rs
@@ -20,6 +20,7 @@ pub struct Qemu {
shell: Option<String>,
artifact: Option<PathBuf>,
artifact_max_xize: u64,
+ dependencies: Option<PathBuf>,
}
impl Qemu {
@@ -63,6 +64,12 @@ impl Qemu {
self
}
+ /// Set directory where dependencies are.
+ pub fn with_dependencies(mut self, dirname: &Option<PathBuf>) -> Self {
+ self.dependencies = dirname.clone();
+ self
+ }
+
/// Run QEMU in the specified way.
pub fn run(&self) -> Result<(), QemuError> {
eprintln!("qemu run");
@@ -94,7 +101,13 @@ impl Qemu {
Self::create_tar_with_size(tmp.path().join("cache"), empty.path(), MAX_OUTPUT_SIZE)?;
eprintln!("deps drive");
- let deps_drive = Self::create_tar(tmp.path().join("deps"), empty.path())?;
+ let deps_drive = if let Some(dirname) = &self.dependencies {
+ eprintln!("deps {}", dirname.display());
+ Self::create_tar(tmp.path().join("deps"), dirname)?
+ } else {
+ eprintln!("no deps");
+ Self::create_tar(tmp.path().join("deps"), empty.path())?
+ };
eprintln!("script");
let script = empty.path().join("ambient-script");