Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtask: Add function to get the test_data directory #18

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
28 changes: 23 additions & 5 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,29 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use clap::{Parser, Subcommand};
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;
use std::{env, fs};

/// Get the path of the root directory of the repo.
///
/// This assumes the currently-running executable is `<repo>/target/release/xtask`.
fn repo_root() -> Result<PathBuf> {
let current_exe = env::current_exe()?;
Ok(current_exe
.parent()
.and_then(|p| p.parent())
.and_then(|p| p.parent())
.context("xtask is not in expected location")?
.to_owned())
}

/// Get the path of the `test_data` directory.
fn test_data_dir() -> Result<PathBuf> {
Ok(repo_root()?.join("test_data"))
}

struct DiskParams {
path: PathBuf,
Expand Down Expand Up @@ -39,9 +57,9 @@ impl DiskParams {
}

fn create_test_data() -> Result<()> {
let dir = Path::new("test_data");
let dir = test_data_dir()?;
if !dir.exists() {
fs::create_dir(dir)?;
fs::create_dir(&dir)?;
}

let path = dir.join("test_disk1.bin");
Expand Down