mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
remove clap from svd2repl
This commit is contained in:
parent
df96605531
commit
e2d941e3b4
3 changed files with 10 additions and 90 deletions
|
|
@ -1,51 +0,0 @@
|
||||||
use std::env;
|
|
||||||
use std::error::Error;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
struct IgnoredError {}
|
|
||||||
|
|
||||||
impl<E> From<E> for IgnoredError
|
|
||||||
where
|
|
||||||
E: Error,
|
|
||||||
{
|
|
||||||
fn from(_: E) -> IgnoredError {
|
|
||||||
IgnoredError {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
||||||
|
|
||||||
File::create(out_dir.join("commit-info.txt"))
|
|
||||||
.unwrap()
|
|
||||||
.write_all(commit_info().as_bytes())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn commit_info() -> String {
|
|
||||||
match (commit_hash(), commit_date()) {
|
|
||||||
(Ok(hash), Ok(date)) => format!(" ({} {})", hash.trim(), date.trim()),
|
|
||||||
_ => String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn commit_hash() -> Result<String, IgnoredError> {
|
|
||||||
Ok(String::from_utf8(
|
|
||||||
Command::new("git")
|
|
||||||
.args(&["rev-parse", "--short", "HEAD"])
|
|
||||||
.output()?
|
|
||||||
.stdout,
|
|
||||||
)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn commit_date() -> Result<String, IgnoredError> {
|
|
||||||
Ok(String::from_utf8(
|
|
||||||
Command::new("git")
|
|
||||||
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
|
|
||||||
.output()?
|
|
||||||
.stdout,
|
|
||||||
)?)
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +1,17 @@
|
||||||
mod generate;
|
mod generate;
|
||||||
|
|
||||||
use anyhow::Context;
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
use clap::{App, Arg};
|
if std::env::args().count() != 3 {
|
||||||
use std::fs::File;
|
println!("Usage: svd2repl <input SVD> <output repl>");
|
||||||
use std::io::{Read, Write};
|
return Ok(())
|
||||||
|
}
|
||||||
|
let svd_filename = std::env::args().nth(1).ok_or("Must specify SVD input filename")?;
|
||||||
|
let generated_filename = std::env::args().nth(2).ok_or("Must specify destination utralib filename")?;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
let src_file = std::fs::File::open(svd_filename).expect("couldn't open src file");
|
||||||
let matches = App::new("svd2repl")
|
let mut dest_file = std::fs::File::create(generated_filename).expect("couldn't open dest file");
|
||||||
.about("Generate a Renode Platform description from SVD files")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("input")
|
|
||||||
.help("Input SVD file")
|
|
||||||
.short("i")
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("FILE"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("output")
|
|
||||||
.help("Output .repl file or directory")
|
|
||||||
.short("o")
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("FILE"),
|
|
||||||
)
|
|
||||||
.version(concat!(
|
|
||||||
env!("CARGO_PKG_VERSION"),
|
|
||||||
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
|
|
||||||
))
|
|
||||||
.get_matches();
|
|
||||||
|
|
||||||
let src: Box<dyn Read> = match matches.value_of("input") {
|
generate::generate(src_file, &mut dest_file)?;
|
||||||
Some(file) => Box::new(File::open(file).context("Cannot open the SVD file")?),
|
|
||||||
None => Box::new(std::io::stdin()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut dest: Box<dyn Write> = match matches.value_of("output") {
|
|
||||||
None => Box::new(std::io::stdout()),
|
|
||||||
Some(path) => Box::new(File::create(path).context("Cannot open destination file")?),
|
|
||||||
};
|
|
||||||
|
|
||||||
generate::generate(src, &mut dest).context("Cannot generate output file")?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -919,9 +919,7 @@ fn renode_image(
|
||||||
"-p",
|
"-p",
|
||||||
"svd2repl",
|
"svd2repl",
|
||||||
"--",
|
"--",
|
||||||
"-i",
|
|
||||||
"utralib/renode/renode.svd",
|
"utralib/renode/renode.svd",
|
||||||
"-o",
|
|
||||||
"emulation/soc/betrusted-soc.repl",
|
"emulation/soc/betrusted-soc.repl",
|
||||||
])
|
])
|
||||||
.status()?;
|
.status()?;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue