|
| 1 | +use anyhow::{bail, Result}; |
| 2 | +use std::env; |
| 3 | +use std::path::{Path, PathBuf}; |
| 4 | + |
| 5 | +pub fn docs_path(phase_paths: &[PathBuf]) -> PathBuf { |
| 6 | + phase_paths |
| 7 | + .get(0) |
| 8 | + .expect("at least one path") |
| 9 | + .parent() |
| 10 | + .expect("drop file") |
| 11 | + .join("../docs.md") |
| 12 | +} |
| 13 | + |
| 14 | +pub fn snapshot() -> Result<Vec<PathBuf>> { |
| 15 | + let root = repo_root()?; |
| 16 | + let snapshot = root.join("phases/snapshot/witx"); |
| 17 | + let paths = vec![snapshot.join("wasi_snapshot_preview1.witx")]; |
| 18 | + ensure_exists(&paths)?; |
| 19 | + Ok(paths) |
| 20 | +} |
| 21 | + |
| 22 | +pub fn ephemeral() -> Result<Vec<PathBuf>> { |
| 23 | + let root = repo_root()?; |
| 24 | + let ephemeral = root.join("phases/ephemeral/witx"); |
| 25 | + let paths = vec![ |
| 26 | + ephemeral.join("wasi_ephemeral_args.witx"), |
| 27 | + ephemeral.join("wasi_ephemeral_clock.witx"), |
| 28 | + ephemeral.join("wasi_ephemeral_environ.witx"), |
| 29 | + ephemeral.join("wasi_ephemeral_fd.witx"), |
| 30 | + ephemeral.join("wasi_ephemeral_path.witx"), |
| 31 | + ephemeral.join("wasi_ephemeral_poll.witx"), |
| 32 | + ephemeral.join("wasi_ephemeral_proc.witx"), |
| 33 | + ephemeral.join("wasi_ephemeral_random.witx"), |
| 34 | + ephemeral.join("wasi_ephemeral_sched.witx"), |
| 35 | + ephemeral.join("wasi_ephemeral_sock.witx"), |
| 36 | + ]; |
| 37 | + ensure_exists(&paths)?; |
| 38 | + Ok(paths) |
| 39 | +} |
| 40 | + |
| 41 | +pub mod old { |
| 42 | + use super::*; |
| 43 | + pub fn snapshot_0() -> Result<Vec<PathBuf>> { |
| 44 | + let root = repo_root()?; |
| 45 | + let snapshot_0 = root.join("phases/old/snapshot_0/witx"); |
| 46 | + let paths = vec![snapshot_0.join("wasi_unstable.witx")]; |
| 47 | + ensure_exists(&paths)?; |
| 48 | + Ok(paths) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +fn repo_root() -> Result<PathBuf> { |
| 53 | + let repo_root = if let Ok(e) = env::var("WASI_REPO") { |
| 54 | + PathBuf::from(e) |
| 55 | + } else { |
| 56 | + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..") |
| 57 | + }; |
| 58 | + if repo_root.exists() { |
| 59 | + Ok(repo_root) |
| 60 | + } else { |
| 61 | + bail!("could not find WASI repo root - try setting WASI_REPO env variable") |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +fn ensure_exists(paths: &[PathBuf]) -> Result<()> { |
| 66 | + for p in paths.iter() { |
| 67 | + if !p.exists() { |
| 68 | + bail!( |
| 69 | + "{} does not exist - is WASI_REPO set to repository root?", |
| 70 | + Path::display(p) |
| 71 | + ) |
| 72 | + } |
| 73 | + } |
| 74 | + Ok(()) |
| 75 | +} |
0 commit comments