summaryrefslogtreecommitdiffstats
path: root/src/commands/build.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-02-04 15:52:02 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-02-06 11:54:23 +0100
commitefe07be74cf1ae704cb73b0f20c28b33aa46c217 (patch)
tree2c7b1686fc2878b79d82708bd2335c713326299d /src/commands/build.rs
parent8a4ef5e6c0126037412794699d5f80540ffd4802 (diff)
Rewrite package organizational structure using DAG
This patch reimplements the package orchestration functionality to rely on a DAG rather than a tree. A / \ B E / \ \ C D F Before this change, the structure the packages were organized in for a build was a tree. That did work reasonable well for initial development of butido, because this is a simple case and the implementation is rather simple, too. But, packages and their dependencies are not always organized in a tree. Most of the time, they are organized in a DAG: .-> C -, / \ D > A \ / `-> B -ยด This is a real-world example: A could be a common crypto-library that I do not want to name here. B and C could be libraries that use the said crypto-library and D could be a program that use B and C. Because said crypto-library builds rather long, building it twice and throwing one result away is a no-go. A DAG as organizational structure makes that issue go away entirely. Also, we can later implement checks whether the DAG contains multiple versions of the same library, if that is undesireable. The change itself is rather big, frankly because it is a non-trivial change the replace the whole data structure and its handling in the orchestrator code. First of all, we introduce the "daggy" library, which provides the DAG implementation on top of the popular "petgraph" library. The package `Tree` datastructure was replaced by a package `Dag` datastructure. This type implements the heavy-lifting that is needed to load a package and all its dependencies from the `Repository` object. The `JobTree` was also reimplemented, but as `daggy::Dag` provides a convenient `map()` function, its implementation which transforms the package `Dag` into a job `Dag` is rather trivial. `crate::job::Dag` then provides the convenience `iter()` function to iterate over all elements in the DAG and providing a `JobDefinition` object for each node. The topology in which we traverse the DAG is not an issue, as we need to create tasks for all `JobDefinition`s anyways, so we do not care about traversal topology at all. The `crate::package::Package` type got an `Hash` implementation, which is necessary to keep track of the mappings while reading the DAG from the repository. The implementation does not create the edges between the nodes in the DAG right when inserting, but afterwards. To keep track of the `daggy::NodeIndex`es, it keeps a mapping Package -> NodeIndex in a Hashmap. Thus, `Package` must implement `std::hash::Hash` Signed-off-by: Matthias Beyer <mail@beyermatthias.de> Tested-by: Matthias Beyer <mail@beyermatthias.de> squash! Reimplement as DAG
Diffstat (limited to 'src/commands/build.rs')
-rw-r--r--src/commands/build.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/commands/build.rs b/src/commands/build.rs
index b1d3e58..f5c9b5a 100644
--- a/src/commands/build.rs
+++ b/src/commands/build.rs
@@ -38,7 +38,7 @@ use crate::orchestrator::OrchestratorSetup;
use crate::package::PackageName;
use crate::package::PackageVersion;
use crate::package::Shebang;
-use crate::package::Tree;
+use crate::package::Dag;
use crate::repository::Repository;
use crate::schema;
use crate::source::SourceCache;
@@ -195,15 +195,12 @@ pub async fn build(
r.map(RwLock::new).map(Arc::new).map(|store| (store, p))?
};
- let tree = {
+ let dag = {
let bar_tree_building = progressbars.bar();
bar_tree_building.set_length(max_packages);
-
- let mut tree = Tree::default();
- tree.add_package(package.clone(), &repo, bar_tree_building.clone())?;
-
- bar_tree_building.finish_with_message("Finished loading Tree");
- tree
+ let dag = Dag::for_root_package(package.clone(), &repo, bar_tree_building.clone())?;
+ bar_tree_building.finish_with_message("Finished loading Dag");
+ dag
};
let source_cache = SourceCache::new(config.source_cache_root().clone());
@@ -212,7 +209,7 @@ pub async fn build(
warn!("No hash verification will be performed");
} else {
crate::commands::source::verify_impl(
- tree.all_packages().into_iter(),
+ dag.all_packages().into_iter(),
&source_cache,
&progressbars,
)
@@ -223,7 +220,7 @@ pub async fn build(
if matches.is_present("no_lint") {
warn!("No script linting will be performed!");
} else if let Some(linter) = crate::ui::find_linter_command(repo_root, config)? {
- let all_packages = tree.all_packages();
+ let all_packages = dag.all_packages();
let bar = progressbars.bar();
bar.set_length(all_packages.len() as u64);
bar.set_message("Linting package scripts...");
@@ -234,7 +231,7 @@ pub async fn build(
warn!("No linter set in configuration, no script linting will be performed!");
} // linting
- tree.all_packages()
+ dag.all_packages()
.into_iter()
.map(|pkg| {
if let Some(allowlist) = pkg.allowed_images() {
@@ -304,7 +301,7 @@ pub async fn build(
trace!("Setting up job sets");
let resources: Vec<JobResource> = additional_env.into_iter().map(JobResource::from).collect();
- let jobtree = crate::job::Tree::from_package_tree(tree, shebang, image_name, phases.clone(), resources);
+ let jobdag = crate::job::Dag::from_package_dag(dag, shebang, image_name, phases.clone(), resources);
trace!("Setting up job sets finished successfully");
trace!("Setting up Orchestrator");
@@ -322,7 +319,7 @@ pub async fn build(
} else {
None
})
- .jobtree(jobtree)
+ .jobdag(jobdag)
.config(config)
.build()
.setup()