diff --git a/tools/tailor/crates/tailor-core/src/imagedep.rs b/tools/tailor/crates/tailor-core/src/imagedep.rs index a7ba40ebe8..895b239411 100644 --- a/tools/tailor/crates/tailor-core/src/imagedep.rs +++ b/tools/tailor/crates/tailor-core/src/imagedep.rs @@ -21,7 +21,8 @@ use tailor_config::{BaseSource, OutputFormat, render_image}; use crate::{ domain::{Cell, Target}, error::CoreError, - orchestrator::{cells, published_artifact_name}, + orchestrator::{cells, cells_selected, published_artifact_name}, + selector::Selector, }; /// The dependency-closed set of `selected` images: `selected` plus every workspace image reachable @@ -297,17 +298,7 @@ fn resolve_producer( members: &[Arc], ) -> Result<(String, Cell), CoreError> { let image_name = consumer.target.name().to_owned(); - let producer = members.iter().find(|t| t.name() == image).ok_or_else(|| { - CoreError::UnknownDependencyImage { - image: image_name.clone(), - dependency: image.to_owned(), - known: members - .iter() - .map(|t| t.name()) - .collect::>() - .join(", "), - } - })?; + let producer = dependency_target(&image_name, image, members)?; let producer_cells = cells(producer)?; let format = resolve_output(&image_name, image, output, &producer_cells)?; @@ -332,10 +323,27 @@ fn resolve_producer( } } -/// The `(producer image name, producer cell slug)` pairs that `consumer` requires — one per -/// `base: { image }` and per declared `inputs:` entry. The scheduler unions these into each -/// producer's build set so a dependency is always built even when a `-s/--cell` selection would -/// otherwise exclude it (or the producer lacks the selected axis entirely). +fn dependency_target<'a>( + image: &str, + dependency: &str, + members: &'a [Arc], +) -> Result<&'a Arc, CoreError> { + members + .iter() + .find(|target| target.name() == dependency) + .ok_or_else(|| CoreError::UnknownDependencyImage { + image: image.to_owned(), + dependency: dependency.to_owned(), + known: members + .iter() + .map(|t| t.name()) + .collect::>() + .join(", "), + }) +} + +/// Required producer cells: paired base/input cells and all enabled `dependsOn` cells. +/// These are scheduled independently of the consumer's CLI filters. pub fn required_producers( consumer: &Cell, members: &[Arc], @@ -355,6 +363,12 @@ pub fn required_producers( resolve_producer(consumer, &spec.image, spec.output, &spec.cell, members)?; required.push((producer, matched.slug.as_ref().to_owned())); } + for name in &consumer.target.definition.depends_on { + let prerequisite = dependency_target(consumer.target.name(), name, members)?; + for cell in cells_selected(prerequisite, &Selector::default())? { + required.push((name.clone(), cell.slug.to_string())); + } + } Ok(required) } @@ -881,4 +895,27 @@ mod tests { ); } } + + #[test] + fn order_only_prerequisites_select_all_enabled_cells() { + let tmp = TempDir::new().unwrap(); + let prerequisite = producer(tmp.path(), "prerequisite", true); + fs::create_dir(prerequisite.dir.join("by-arch")).unwrap(); + fs::write(prerequisite.dir.join("by-arch/arm64.yaml"), "skip: true\n").unwrap(); + let consumer = target( + tmp.path(), + "consumer", + "name: consumer\ndependsOn: [prerequisite]\nbase: { path: ./base.img }\nconfig: {}\n", + ); + let members = vec![prerequisite, Arc::clone(&consumer)]; + let cell = cells(&consumer).unwrap().remove(0); + + assert_eq!( + required_producers(&cell, &members).unwrap(), + [( + "prerequisite".to_owned(), + "prerequisite_amd64_cosi".to_owned() + )] + ); + } } diff --git a/tools/tailor/crates/tailor/src/run.rs b/tools/tailor/crates/tailor/src/run.rs index fff51e9559..75ffa085a0 100644 --- a/tools/tailor/crates/tailor/src/run.rs +++ b/tools/tailor/crates/tailor/src/run.rs @@ -1465,16 +1465,21 @@ async fn build( // drops (or errors on) a producer's paired cell (`inter-image-dependencies.md` §4). let requested: BTreeSet = targets.iter().map(|t| t.name().to_owned()).collect(); let mut required: BTreeMap> = BTreeMap::new(); + let mut scheduled_targets = Vec::new(); for node in ordered.iter().rev() { let apply_selector = requested.contains(node.name()); let node_cells = select_node_cells(node, &selection, apply_selector, required.get(node.name()))?; + if !node_cells.is_empty() { + scheduled_targets.push(Arc::clone(node)); + } for cell in &node_cells { for (producer, slug) in imagedep::required_producers(cell, &all_members)? { required.entry(producer).or_default().insert(slug); } } } + scheduled_targets.reverse(); let build_selection = BuildSelection { selector: &selection, requested, @@ -1501,7 +1506,7 @@ async fn build( .get_or_insert_with(Runtime::default) .build_dir_base = Some(output_dir.join(TAILOR_STATE_DIR).join(BUILD_DIR)); } - let signing = signing_requirements(&targets, tool.signing.as_ref())?; + let signing = signing_requirements(&scheduled_targets, tool.signing.as_ref())?; ensure_signing_preview(&tool, &signing)?; // Build one signer per required profile (a shared CA per build); `signer_for` resolves a cell to // its signer via the image name (meta/docs/2026-06-29-signing.md §6). Empty when nothing signs. diff --git a/tools/tailor/crates/tailor/tests/cli.rs b/tools/tailor/crates/tailor/tests/cli.rs index 56b33b8710..45e28349a3 100644 --- a/tools/tailor/crates/tailor/tests/cli.rs +++ b/tools/tailor/crates/tailor/tests/cli.rs @@ -10,10 +10,14 @@ //! list append, `$set`/`$replace`/`$remove`/`$include`, parameter interpolation, base override, //! rpm sources, opaque IC passthrough). -use std::path::PathBuf; +use std::{ + fs, + path::{Path, PathBuf}, +}; use assert_cmd::Command; use predicates::prelude::*; +use tempfile::TempDir; fn fixtures() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures") @@ -109,6 +113,116 @@ fn build_rejects_an_unknown_positional_with_a_clear_error() { )); } +fn order_only_workspace() -> TempDir { + let tmp = TempDir::new().unwrap(); + fs::write( + tmp.path().join("tailor.yaml"), + "schemaVersion: 1\ntoolchains:\n default: ic\n entries:\n - name: ic\n container: registry.example/ic\n", + ) + .unwrap(); + for (name, definition) in [ + ( + "foundation", + "skip: true\nmatrix:\n arch: [amd64, arm64]\n", + ), + ("prepare", "dependsOn: [foundation]\n"), + ( + "consumer", + "dependsOn: [prepare, foundation]\nmatrix:\n channel: [stable, edge]\n", + ), + ] { + let dir = tmp.path().join(name); + fs::create_dir(&dir).unwrap(); + fs::write( + dir.join("image.yaml"), + format!("name: {name}\n{definition}base: {{ path: ./base.img }}\nconfig: {{}}\n"), + ) + .unwrap(); + } + tmp +} + +fn dry_run_in(dir: &Path, args: &[&str]) -> String { + let output = tailor() + .current_dir(dir) + .args(["build", "--dry-run"]) + .args(args) + .assert() + .success() + .get_output() + .stdout + .clone(); + String::from_utf8(output).unwrap() +} + +#[test] +fn depends_on_builds_transitive_prerequisites_before_a_selected_consumer_once() { + let ws = order_only_workspace(); + for args in [ + vec!["consumer", "-s", "channel=stable"], + vec!["consumer_stable_amd64_cosi"], + ] { + let output = dry_run_in(ws.path(), &args); + assert!(output.contains("4 cell(s) (dry-run)"), "{output}"); + assert_eq!(output.matches("docker run").count(), 4, "{output}"); + let foundation = output.find("foundation_amd64_cosi.cosi").unwrap(); + let arm = output.find("foundation_arm64_cosi.cosi").unwrap(); + let prepare = output.find("prepare_amd64_cosi.cosi").unwrap(); + let consumer = output.find("consumer_stable_amd64_cosi.cosi").unwrap(); + assert!( + foundation < prepare && arm < prepare && prepare < consumer, + "{output}" + ); + assert!(!output.contains("consumer_edge_amd64_cosi"), "{output}"); + } +} + +#[test] +fn depends_on_keeps_a_prerequisites_signing_profile() { + let ws = order_only_workspace(); + let manifest = ws.path().join("tailor.yaml"); + let original = fs::read_to_string(&manifest).unwrap(); + fs::write( + manifest, + format!( + "{original}previewFeatures: [signing]\nsigning:\n default: test-ca\n profiles:\n test-ca:\n backend: local-test-ca\n" + ), + ) + .unwrap(); + let image = ws.path().join("prepare/image.yaml"); + let original = fs::read_to_string(&image).unwrap(); + fs::write(image, format!("{original}signing: true\n")).unwrap(); + + let output = dry_run_in(ws.path(), &["consumer_stable_amd64_cosi"]); + assert!( + output.contains("# prepare_amd64_cosi — signed 3-pass"), + "{output}" + ); + assert_eq!(output.matches("— signed 3-pass").count(), 1, "{output}"); +} + +#[test] +fn depends_on_also_builds_prerequisites_of_an_input_producer() { + let ws = order_only_workspace(); + let image = ws.path().join("consumer/image.yaml"); + let original = fs::read_to_string(&image).unwrap(); + fs::write( + image, + original.replace( + "dependsOn: [prepare, foundation]", + "inputs:\n - name: payload\n image: prepare", + ), + ) + .unwrap(); + + let output = dry_run_in(ws.path(), &["consumer_stable_amd64_cosi"]); + assert!(output.contains("4 cell(s) (dry-run)"), "{output}"); + let foundation = output.find("foundation_arm64_cosi.cosi").unwrap(); + let prepare = output.find("prepare_amd64_cosi.cosi").unwrap(); + let consumer = output.find("consumer_stable_amd64_cosi.cosi").unwrap(); + assert!(foundation < prepare && prepare < consumer, "{output}"); +} + // ───────────────────────────── standalone: built-in default toolchain ───────────────────────────── #[test] fn standalone_image_builds_without_a_manifest() { diff --git a/tools/tailor/docs/reference/image-yaml.md b/tools/tailor/docs/reference/image-yaml.md index f15b7c95a7..fa066ec1f9 100644 --- a/tools/tailor/docs/reference/image-yaml.md +++ b/tools/tailor/docs/reference/image-yaml.md @@ -230,8 +230,10 @@ extension; tailor derives the extension (and appends `.zst` if that output is co optional only when the producer declares a single output. `dependsOn: [, …]` declares an **order-only** dependency: the listed images build first, but -they contribute nothing to this image's fingerprint. Use it when an image must run after another but -references none of its output. (An `image` base or input already implies the edge — don't restate it.) +they contribute nothing to this image's fingerprint. Their enabled cells build without the +consumer's axis/slug filters, including for `tailor build `; fragment-skipped cells +stay excluded. Use it when an image must run after another but references none of its output. +(An `image` base or input already implies the edge — don't restate it.) ### Embedding an artifact with `inputs:`