-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `dump` xtask * Dump before building in xtask `build`
- Loading branch information
Showing
4 changed files
with
53 additions
and
38 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod build; | ||
pub mod dump; |
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,43 @@ | ||
use fuel_core::schema::build_schema; | ||
use std::{ | ||
env, | ||
fs::{self, File}, | ||
io::Write, | ||
path::PathBuf, | ||
}; | ||
use structopt::StructOpt; | ||
|
||
// stored in the root of the workspace | ||
const SCHEMA_URL: &str = "../assets/schema.sdl"; | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub struct DumpCommand {} | ||
|
||
pub fn dump_schema() -> Result<(), Box<dyn std::error::Error>> { | ||
let assets = env::var("CARGO_MANIFEST_DIR") | ||
.map(PathBuf::from) | ||
.map(|f| { | ||
let f = f.as_path().join(SCHEMA_URL); | ||
let dir = f.parent().expect("Failed to read assets dir"); | ||
fs::create_dir_all(dir).expect("Failed to create assets dir"); | ||
|
||
f | ||
}) | ||
.expect("Failed to fetch assets path"); | ||
|
||
File::create(&assets) | ||
.and_then(|mut f| { | ||
f.write_all(build_schema().finish().sdl().as_bytes())?; | ||
f.sync_all() | ||
}) | ||
.expect("Failed to write SDL schema to temporary file"); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// ensures that latest schema is always committed | ||
#[test] | ||
fn is_latest_schema_committed() { | ||
let current_content = fs::read(SCHEMA_URL).unwrap(); | ||
assert_eq!(current_content, build_schema().finish().sdl().as_bytes()); | ||
} |
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