git.delta.rocks / jrsonnet / refs/commits / ca5174b8c4a4

difftreelog

feat prefetch command

Yaroslav Bolyukin2023-07-09parent: #eee08d5.patch.diff
in: trunk

3 files changed

modifiedcmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth
120 "--json",120 "--json",
121 // "--show-trace",121 // "--show-trace",
122 "--no-link",122 "--no-link",
123 "--option",
124 "log-lines",
125 "200",
123 ])126 ])
124 .comparg("--out-link", &built)127 .comparg("--out-link", &built)
125 .arg(128 .arg(
modifiedcmds/fleet/src/command.rsdiffbeforeafterboth
254 NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for a machine to build ") => {254 NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for a machine to build ") => {
255 // Useless repeating notification about build255 // Useless repeating notification about build
256 }256 }
257 NixLog::Start { text, level: 3, typ: 111, .. } if text.starts_with("resolved derivation: ") => {257 NixLog::Start { text, level: 3, typ: 111, .. } if text.starts_with("resolved derivation: ") => {
258 // CA resolved258 // CA resolved
259 }259 }
260 NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for lock on ") => {
261 // Concurrent build of the same message
262 }
260 NixLog::Stop { .. } => {},263 NixLog::Stop { .. } => {},
261 NixLog::Result { .. } => {},264 NixLog::Result { .. } => {},
262 _ => warn!("unknown log: {:?}", log)265 _ => warn!("unknown log: {:?}", log)
modifiedcmds/fleet/src/main.rsdiffbeforeafterboth
55
6mod fleetdata;6mod fleetdata;
77
8use std::ffi::OsString;
8use std::io;9use std::io;
910
10use anyhow::{anyhow, Result};11use anyhow::{anyhow, bail, Result};
11use clap::Parser;12use clap::Parser;
1213
13use cmds::{build_systems::BuildSystems, info::Info, secrets::Secrets};14use cmds::{build_systems::BuildSystems, info::Info, secrets::Secrets};
14use host::{Config, FleetOpts};15use host::{Config, FleetOpts};
16use tokio::fs;
17use tokio::process::Command;
15use tracing::{info, metadata::LevelFilter};18use tracing::{info, metadata::LevelFilter};
16use tracing_subscriber::EnvFilter;19use tracing_subscriber::EnvFilter;
20
21#[derive(Parser)]
22struct Prefetch {}
23impl Prefetch {
24 async fn run(&self, config: &Config) -> Result<()> {
25 let mut prefetch_dir = config.directory.to_path_buf();
26 prefetch_dir.push("prefetch");
27 if !prefetch_dir.is_dir() {
28 info!("nothing to prefetch: no prefetch directory");
29 return Ok(());
30 }
31 for entry in std::fs::read_dir(&prefetch_dir)? {
32 let entry = entry?;
33 if !entry.metadata()?.is_file() {
34 bail!("only files should exist in prefetch directory");
35 }
36 info!("prefetching {:?}", entry.file_name());
37 let mut path = OsString::new();
38 path.push("file://");
39 path.push(entry.path());
40 let status = Command::new("nix-prefetch-url").arg(path).status().await?;
41 if !status.success() {
42 bail!("failed with {status}");
43 }
44 }
45 Ok(())
46 }
47}
1748
18#[derive(Parser)]49#[derive(Parser)]
19enum Opts {50enum Opts {
22 /// Secret management53 /// Secret management
23 #[clap(subcommand)]54 #[clap(subcommand)]
24 Secrets(Secrets),55 Secrets(Secrets),
56 /// Upload prefetch directory to the nix store
57 Prefetch(Prefetch),
25 /// Config parsing58 /// Config parsing
26 Info(Info),59 Info(Info),
27}60}
40 Opts::BuildSystems(c) => c.run(config).await?,73 Opts::BuildSystems(c) => c.run(config).await?,
41 Opts::Secrets(s) => s.run(config).await?,74 Opts::Secrets(s) => s.run(config).await?,
42 Opts::Info(i) => i.run(config).await?,75 Opts::Info(i) => i.run(config).await?,
76 Opts::Prefetch(p) => p.run(config).await?,
43 };77 };
44 Ok(())78 Ok(())
45}79}