Skip to content

Commit

Permalink
Reinstated save_ref command, accepted prog gen signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
ginty committed Jul 25, 2024
1 parent 4aa41db commit 3eace9f
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 375 deletions.
44 changes: 6 additions & 38 deletions rust/origen/cli/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ fn main() -> Result<()> {
commands::env::add_helps(&mut helps);
commands::generate::add_helps(&mut helps);
commands::target::add_helps(&mut helps);
commands::save_ref::add_helps(&mut helps);
} else {
commands::new::add_helps(&mut helps);
}
Expand Down Expand Up @@ -474,6 +475,7 @@ fn main() -> Result<()> {
app = commands::app::add_commands(app, &helps, app_cmds.as_ref().unwrap(), &extensions)?;
app = commands::env::add_commands(app, &helps, &extensions)?;
app = commands::generate::add_commands(app, &helps, &extensions)?;
app = commands::save_ref::add_commands(app, &helps, &extensions)?;

// /************************************************************************************/
// let new_help = "Generate a new block, flow, pattern, etc. for your application";
Expand Down Expand Up @@ -765,40 +767,6 @@ fn main() -> Result<()> {
// .action(SetArg)
// .value_name("MODE"),
// ),
// );

// /************************************************************************************/
// let save_ref_help = "Save a reference version of the given file, this will be automatically checked for differences the next time it is generated";
// origen_commands.push(CommandHelp {
// name: "save_ref".to_string(),
// help: save_ref_help.to_string(),
// shortcut: None,
// });
// app = app.subcommand(
// Command::new("save_ref")
// .about(save_ref_help)
// .arg(
// Arg::new("files")
// .help("The name of the file(s) to be saved")
// .action(SetArg)
// .value_name("FILES")
// .multiple(true)
// .required_unless_one(&["new", "changed"]),
// )
// .arg(
// Arg::new("new")
// .long("new")
// .required(false)
// .action(SetArgTrue)
// .help("Update all NEW file references from the last generate run"),
// )
// .arg(
// Arg::new("changed")
// .long("changed")
// .required(false)
// .action(SetArgTrue)
// .help("Update all CHANGED file references from the last generate run"),
// ),
// );
} else {
app = commands::new::add_commands(app, &helps, &extensions)?;
Expand Down Expand Up @@ -1181,10 +1149,10 @@ fn main() -> Result<()> {
// let matches = matches.subcommand_matches("mode").unwrap();
// commands::mode::run(matches.get_one::<&str>("mode").map(|s| *s));
// }
// Some("save_ref") => {
// let matches = matches.subcommand_matches("save_ref").unwrap();
// commands::save_ref::run(matches);
// }
Some(commands::save_ref::BASE_CMD) => {
let matches = matches.subcommand_matches(commands::save_ref::BASE_CMD).unwrap();
commands::save_ref::run(matches)?;
}
Some(commands::plugin::BASE_CMD) => run_cmd_match_case!(plugin),
Some(commands::plugins::BASE_CMD) => commands::plugins::run(matches.subcommand_matches(commands::plugins::BASE_CMD).unwrap(), plugins.as_ref())?,
Some(invalid_cmd) => {
Expand Down
2 changes: 1 addition & 1 deletion rust/origen/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod interactive;
// pub mod mode;
pub mod new;
// pub mod proj;
// pub mod save_ref;
pub mod save_ref;
pub mod target;
// pub mod mailer;
pub mod credentials;
Expand Down
50 changes: 40 additions & 10 deletions rust/origen/cli/src/commands/save_ref.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,67 @@
use origen_metal::framework::reference_files;
use std::path::Path;

pub fn run(matches: &clap::ArgMatches) {
let mut exit_code = 0;
use origen_metal::framework::reference_files;
use crate::commands::_prelude::*;

pub const BASE_CMD: &'static str = "save_ref";

gen_core_cmd_funcs!(
BASE_CMD,
"Save a reference version of the given file, this will be automatically checked for differences the next time it is generated",
{ |cmd: App<'a>| {
cmd
.arg(
Arg::new("files")
.help("The name of the file(s) to be saved")
.action(SetArg)
.value_name("FILES")
.multiple(true)
.required_unless_one(&["new", "changed"]),
)
.arg(
Arg::new("new")
.long("new")
.required(false)
.action(SetArgTrue)
.help("Update all NEW file references from the last generate run"),
)
.arg(
Arg::new("changed")
.long("changed")
.required(false)
.action(SetArgTrue)
.help("Update all CHANGED file references from the last generate run"),
)
}}
);


pub fn run(matches: &clap::ArgMatches) -> Result<()> {
let new = matches.contains_id("new");
let changed = matches.contains_id("changed");
let files = matches.get_many::<String>("files");

if new {
if let Err(e) = reference_files::apply_all_new_refs() {
log_error!("Something went wrong saving the NEW references - {}", e);
exit_code = 1;
bail!("Something went wrong saving the NEW references - {}", e);
}
}

if changed {
if let Err(e) = reference_files::apply_all_changed_refs() {
log_error!(
bail!(
"Something went wrong updating the CHANGED references - {}",
e
);
exit_code = 1;
}
}

if let Some(files) = files {
for key in files {
if let Err(e) = reference_files::apply_ref(Path::new(key)) {
log_error!("Could not save '{}' - {}", key, e);
exit_code = 1;
bail!("Could not save '{}' - {}", key, e);
}
}
}
std::process::exit(exit_code);
Ok(())
}
6 changes: 3 additions & 3 deletions rust/origen/cli/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use std::collections::HashMap;
use origen_metal::indexmap::IndexMap;

pub use extensions::{Extensions, ExtensionTOML, Extension};
pub use plugins::{Plugins, Plugin};
pub use plugins::Plugins;
pub use aux_cmds::AuxCmds;
pub use app_cmds::AppCmds;
pub use helps::{CmdHelps, CmdHelp, CmdSrc};
use std::{env};
use std::env;

use clap::{App};
use clap::App;
use clap::Command as ClapCommand;
use clap::Arg as ClapArg;
use origen::{Result, in_app_invocation};
Expand Down
2 changes: 1 addition & 1 deletion rust/origen/src/core/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ pub trait TesterAPI: std::fmt::Debug + Interceptor + TesterID + TesterAPIClone {
/// A default implementation is given since some testers may only support prog gen
/// and not patgen and vice versa, in that case they will return an empty vector.
fn render_program(&mut self) -> crate::Result<(Vec<PathBuf>, Model)> {
origen_metal::prog_gen::render_program(self.id_prog_gen(), &self.output_dir()?)
origen_metal::prog_gen::render_program(self.id_prog_gen(), &self.output_dir()?.join("test_program"))
}

/// The tester should implement this to return a differ instance which is configured
Expand Down
2 changes: 1 addition & 1 deletion rust/origen_metal/src/prog_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ pub fn trace_error<T: Attrs>(node: &Node<T>, error: crate::Error) -> crate::Resu
pub fn render_program(tester: SupportedTester, output_dir: &Path) -> crate::Result<(Vec<PathBuf>, Model)> {
match tester {
SupportedTester::V93KSMT7 => advantest::smt7::render(output_dir),
_ => unimplemented!("Tester {:?} is not yet supported for render_program", tester),
_ => Ok((vec![], Model::new(tester))),
}
}
Loading

0 comments on commit 3eace9f

Please sign in to comment.