Skip to content
Closed
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
23 changes: 23 additions & 0 deletions crossdev-stages/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ pub enum SandboxCmd {
#[arg(long)]
gcc_version: Option<String>,
},
/// Sync the ebuild tree and update the sandbox's own packages.
Update {
/// Sandbox name (default: most-recently-modified).
#[arg(long)]
name: Option<String>,
/// Update installed packages without syncing the tree first.
#[arg(long)]
no_sync: bool,
},

/// Open an interactive shell in a sandbox.
Enter {
#[arg(long)]
Expand Down Expand Up @@ -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<String>,
/// 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.
Expand Down
14 changes: 14 additions & 0 deletions crossdev-stages/src/cli/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
67 changes: 67 additions & 0 deletions crossdev-stages/src/cli/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions crossdev-stages/src/portage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down
Loading