Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[package] Use topological sorting from omicron-zone-package #4816

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ omicron-package = { path = "package" }
omicron-rpaths = { path = "rpaths" }
omicron-sled-agent = { path = "sled-agent" }
omicron-test-utils = { path = "test-utils" }
omicron-zone-package = "0.9.1"
omicron-zone-package = "0.10.1"
oxide-client = { path = "clients/oxide-client" }
oxide-vpc = { git = "https://github.com/oxidecomputer/opte", rev = "4e6e6ab6379fa4bc40f5d0c7340b9f35c45ad6e4", features = [ "api", "std" ] }
once_cell = "1.19.0"
Expand Down Expand Up @@ -378,7 +378,6 @@ tokio-tungstenite = "0.20"
tokio-util = { version = "0.7.10", features = ["io", "io-util"] }
toml = "0.8.8"
toml_edit = "0.21.0"
topological-sort = "0.2.2"
tough = { version = "0.16.0", features = [ "http" ] }
trust-dns-client = "0.22"
trust-dns-proto = "0.22"
Expand Down
1 change: 0 additions & 1 deletion package/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ tar.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = [ "full" ] }
toml.workspace = true
topological-sort.workspace = true
walkdir.workspace = true
omicron-workspace-hack.workspace = true

Expand Down
59 changes: 9 additions & 50 deletions package/src/bin/omicron-package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ async fn do_for_all_rust_packages(
let (release_pkgs, debug_pkgs): (Vec<_>, _) = config
.package_config
.packages_to_build(&config.target)
.0
.into_iter()
.filter_map(|(name, pkg)| match &pkg.source {
PackageSource::Local { rust: Some(rust_pkg), .. } => {
Expand Down Expand Up @@ -463,63 +464,19 @@ async fn get_package(
}

async fn do_package(config: &Config, output_directory: &Path) -> Result<()> {
use topological_sort::TopologicalSort;

create_dir_all(&output_directory)
.map_err(|err| anyhow!("Cannot create output directory: {}", err))?;

let ui = ProgressUI::new();

do_build(&config).await?;

let mut all_packages = config
.package_config
.packages_to_build(&config.target)
.into_iter()
.map(|(package_name, package)| {
(package.get_output_file(package_name), (package_name, package))
})
.collect::<std::collections::BTreeMap<_, _>>();

let mut outputs = TopologicalSort::<String>::new();
for (package_output, (_, package)) in &all_packages {
match &package.source {
PackageSource::Local { .. }
| PackageSource::Prebuilt { .. }
| PackageSource::Manual => {
// Skip intermediate leaf packages; if necessary they'll be
// added to the dependency graph by whatever composite package
// actually depends on them.
if !matches!(
package.output,
PackageOutput::Zone { intermediate_only: true }
) {
outputs.insert(package_output);
}
}
PackageSource::Composite { packages: deps } => {
for dep in deps {
outputs.add_dependency(dep, package_output);
}
}
}
}

while !outputs.is_empty() {
let batch = outputs.pop_all();
assert!(
!batch.is_empty() || outputs.is_empty(),
"cyclic dependency in package manifest!"
);

let packages = batch.into_iter().map(|output| {
all_packages
.remove(&output)
.expect("package should've already been handled.")
});
let packages = config.package_config.packages_to_build(&config.target);

let ui_refs = vec![ui.clone(); packages.len()];
let pkg_stream = stream::iter(packages)
let package_iter = packages.build_order();
for batch in package_iter {
let ui_refs = vec![ui.clone(); batch.len()];
let pkg_stream = stream::iter(batch)
.zip(stream::iter(ui_refs))
.map(Ok::<_, anyhow::Error>)
.try_for_each_concurrent(
Expand Down Expand Up @@ -553,6 +510,7 @@ async fn do_stamp(
let (_name, package) = config
.package_config
.packages_to_deploy(&config.target)
.0
.into_iter()
.find(|(name, _pkg)| name.as_str() == package_name)
.ok_or_else(|| anyhow!("Package {package_name} not found"))?;
Expand All @@ -574,7 +532,7 @@ async fn do_unpack(
})?;

// Copy all packages to the install location in parallel.
let packages = config.package_config.packages_to_deploy(&config.target);
let packages = config.package_config.packages_to_deploy(&config.target).0;

packages.par_iter().try_for_each(
|(package_name, package)| -> Result<()> {
Expand Down Expand Up @@ -704,6 +662,7 @@ fn uninstall_all_packages(config: &Config) {
for (_, package) in config
.package_config
.packages_to_deploy(&config.target)
.0
.into_iter()
.filter(|(_, package)| matches!(package.output, PackageOutput::Tarball))
{
Expand Down
Loading