diff --git a/crossdev-stages/src/cli/mod.rs b/crossdev-stages/src/cli/mod.rs index 42cf21d2..528e4efa 100644 --- a/crossdev-stages/src/cli/mod.rs +++ b/crossdev-stages/src/cli/mod.rs @@ -193,6 +193,16 @@ pub enum SandboxCmd { #[arg(long)] gcc_version: Option, }, + /// Sync the ebuild tree and update the sandbox's own packages. + Update { + /// Sandbox name (default: most-recently-modified). + #[arg(long)] + name: Option, + /// Update installed packages without syncing the tree first. + #[arg(long)] + no_sync: bool, + }, + /// Open an interactive shell in a sandbox. Enter { #[arg(long)] @@ -373,6 +383,19 @@ pub enum MaintCmd { pub enum StoreCmd { /// List crossdev prefixes in the workspace store. List, + /// Rebuild a board's cached binary packages against the current tree. + Update { + /// Board name. + #[arg(long)] + board: String, + /// Sandbox name (default: most-recently-modified). + #[arg(long)] + sandbox: Option, + /// Update the packages without syncing the tree first. + #[arg(long)] + no_sync: bool, + }, + /// Show prefixes no current board would build into. Gc { /// Delete instead of just listing. diff --git a/crossdev-stages/src/cli/sandbox.rs b/crossdev-stages/src/cli/sandbox.rs index c7fedc46..008f6c42 100644 --- a/crossdev-stages/src/cli/sandbox.rs +++ b/crossdev-stages/src/cli/sandbox.rs @@ -58,6 +58,20 @@ pub async fn run( ) .await?; } + SandboxCmd::Update { name, no_sync } => { + let dir = ws.resolve_sandbox(name.as_deref())?; + let sb = sandbox::Sandbox::open(dir)?; + let runner = sb.runner(); + let portage = crate::portage::Portage::new(&runner); + if !no_sync { + tracing::info!("Syncing the ebuild tree..."); + portage.webrsync()?; + portage.getuto()?; + } + tracing::info!("Updating the sandbox's own packages..."); + portage.update_world()?; + println!("Sandbox {} updated.", sb.dir.file_name().unwrap_or_default()); + } SandboxCmd::Enter { name } => { let dir = ws.resolve_sandbox(name.as_deref())?; let sb = sandbox::Sandbox::open(dir)?; diff --git a/crossdev-stages/src/cli/store.rs b/crossdev-stages/src/cli/store.rs index 86a9878c..434abf9c 100644 --- a/crossdev-stages/src/cli/store.rs +++ b/crossdev-stages/src/cli/store.rs @@ -11,9 +11,76 @@ pub fn run(ws: &Workspace, boards_root: &Utf8Path, cmd: StoreCmd) -> Result<()> match cmd { StoreCmd::List => list(ws), StoreCmd::Gc { force } => gc(ws, boards_root, force), + StoreCmd::Update { + board, + sandbox, + no_sync, + } => update(ws, boards_root, &board, sandbox.as_deref(), no_sync), } } +/// Bring a board's cached binary packages up to date against the current tree. +/// +/// The cache is what makes the next image build fast, and it goes stale the +/// moment the ebuild tree moves. Doing this on its own means the staleness is +/// paid for deliberately, once, instead of turning up inside a build that was +/// supposed to be quick. +fn update( + ws: &Workspace, + boards_root: &Utf8Path, + board_name: &str, + sandbox: Option<&str>, + no_sync: bool, +) -> Result<()> { + let board = crate::board::load(boards_root, board_name)?; + let sb = crate::sandbox::Sandbox::open(ws.resolve_sandbox(sandbox)?)?; + let target = crate::target::Target::open(ws.resolve_target_for_arch( + None, + &board.arch, + board.rootfs_provider.name(), + )?)?; + + let defaults_root = boards_root.parent().unwrap_or(boards_root).join("defaults"); + let board_dir = boards_root.join(board_name); + let packages = crate::package_list::merge( + crate::package_list::read_required(&defaults_root.join("target-packages.txt"))?, + crate::package_list::read_optional(&board_dir.join("target-packages.txt"))?, + ); + if packages.is_empty() { + println!("{board_name} declares no target packages."); + return Ok(()); + } + + let binpkgs_dir = ws + .binpkgs_dir() + .join(board.chost()) + .join(crate::cflags::binpkg_key(&board)); + std::fs::create_dir_all(&binpkgs_dir)?; + + let runner = sb + .runner_for_board(ws, &board.arch, &board)? + .with_target(&target.dir) + .with_binpkgs(&binpkgs_dir); + let portage = crate::portage::Portage::new(&runner); + + if !no_sync { + tracing::info!("Syncing the ebuild tree..."); + portage.webrsync()?; + } + crate::binpkg_meta::report( + &binpkgs_dir, + &ws.store_dir().join(store_key( + &board.chost(), + &crate::cflags::toolchain_key(&board), + &sb.gcc_spec_for(&board, None)?, + )), + )?; + + tracing::info!("Updating {board_name}'s target packages..."); + portage.cross_update(&board.chost(), &crate::package_list::atoms(&packages))?; + Ok(()) +} + fn list(ws: &Workspace) -> Result<()> { let entries = walk_store(ws); let binpkgs = walk_binpkgs(ws); diff --git a/crossdev-stages/src/portage.rs b/crossdev-stages/src/portage.rs index 6bb19dde..3688bd17 100644 --- a/crossdev-stages/src/portage.rs +++ b/crossdev-stages/src/portage.rs @@ -307,6 +307,28 @@ impl<'a> Portage<'a> { self.run_emerge("emerge -b -k -e @world") } + /// Bring the world set up to date: newer versions, changed USE, and the + /// dependencies that follow from either. `--keep-going` because one + /// package failing to build is not a reason to leave the other ninety + /// un-updated, and the log of what failed is printed either way. + pub fn update_world(&self) -> Result<()> { + self.run_emerge("emerge -b -k -uDN --keep-going --with-bdeps=y @world") + } + + /// Bring a set of packages up to date without touching the rest. + pub fn update(&self, packages: &[&str]) -> Result<()> { + let pkgs = packages.join(" "); + self.run_emerge(&format!("emerge -b -k -uDN --keep-going {pkgs}")) + } + + /// Same, cross-emerged into the target stage. + pub fn cross_update(&self, chost: &str, packages: &[&str]) -> Result<()> { + let pkgs = packages.join(" "); + self.run_emerge(&format!( + "ROOT=/target {chost}-emerge -b -k -uDN --keep-going {pkgs}" + )) + } + /// Cross-emerge packages into the target stage (mounted at `/target`). /// Uses `{chost}-emerge` which crossdev installs. pub fn cross_emerge(&self, chost: &str, packages: &[&str]) -> Result<()> {