-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Flix
committed
Sep 3, 2023
1 parent
8e85ac7
commit aa59098
Showing
7 changed files
with
301 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[alias] | ||
xtask = "run --package xtask -- " | ||
|
||
[env] | ||
CARGO_WORKSPACE_DIR = { value = "", relative = true } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[workspace] | ||
members = ["crates/*"] | ||
members = ["crates/*", "xtask"] | ||
resolver = "2" | ||
|
||
[profile.dev.build-override] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
edition = "2021" | ||
name = "xtask" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
clap = { version = "4.4.2", features = ["derive"] } | ||
color-eyre = "0.6.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# XTask | ||
|
||
This is a pattern to manage common use-cases like testing multiple features. | ||
It is a simple CLI tool that works kind of similar to a `Makefile` and executes certain tasks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//! XTask CLI tool. | ||
#![allow(clippy::expect_used, clippy::print_stdout)] | ||
|
||
use std::{env, ffi::OsStr, path::PathBuf, process::Command, str::FromStr}; | ||
|
||
use clap::Parser; | ||
use color_eyre::{eyre::bail, Result}; | ||
|
||
/// XTask pattern helper CLI tool. | ||
#[derive(Debug, Parser)] | ||
#[command(about)] | ||
enum Cli { | ||
/// Test command: run all tests with different feature selections. | ||
Test, | ||
} | ||
|
||
impl Cli { | ||
/// Run the CLI. | ||
pub fn run(self) -> Result<()> { | ||
match self { | ||
Self::Test => Self::run_test()?, | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Run the test sub-command. | ||
fn run_test() -> Result<()> { | ||
let workspace_path = PathBuf::from_str(&env::var("CARGO_WORKSPACE_DIR")?)?; | ||
|
||
// Run all tests and doc-tests with default features. | ||
let mut command = Command::new("cargo"); | ||
command.args(["test", "--workspace"]).current_dir(&workspace_path); | ||
run_command(command)?; | ||
|
||
// Run R4 tests. | ||
let mut command = Command::new("cargo"); | ||
command | ||
.args([ | ||
"test", | ||
"--workspace", | ||
"--no-default-features", | ||
"--features", | ||
"r4b,builders,client", | ||
]) | ||
.current_dir(&workspace_path); | ||
run_command(command)?; | ||
|
||
// Make sure the models compile without builders in all FHIR versions. | ||
let mut command = Command::new("cargo"); | ||
command.args(["check", "-p", "fhir-model", "--no-default-features", "--features", "r4b"]); | ||
run_command(command)?; | ||
let mut command = Command::new("cargo"); | ||
command.args(["check", "-p", "fhir-model", "--no-default-features", "--features", "r5"]); | ||
run_command(command)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
/// Print out the command being run and then run it, checking its exit code | ||
/// afterwards. | ||
fn run_command(mut command: Command) -> Result<()> { | ||
println!( | ||
"Running {} {}", | ||
command.get_program().to_string_lossy(), | ||
command.get_args().map(OsStr::to_string_lossy).collect::<Vec<_>>().join(" ") | ||
); | ||
|
||
let exit_code = command.spawn()?.wait()?; | ||
if !exit_code.success() { | ||
bail!("Command failed!"); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
color_eyre::install()?; | ||
let cli = Cli::parse(); | ||
cli.run()?; | ||
Ok(()) | ||
} |