Skip to content

Commit

Permalink
chore(avm): delete generated dir (#7741)
Browse files Browse the repository at this point in the history
Use `-y` if you want to avoid the prompt.
  • Loading branch information
fcarreiro authored Aug 2, 2024
1 parent ef4217f commit f875e1e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
86 changes: 86 additions & 0 deletions bb-pilcom/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bb-pilcom/bb-pil-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ rand = "0.8.5"
powdr-ast = { path = "../powdr/ast" }
handlebars = { version = "5.1.2", features = ["string_helpers"] }
serde_json = "1.0.120"
dialoguer = "0.11.0"
7 changes: 7 additions & 0 deletions bb-pilcom/bb-pil-backend/src/file_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ impl BBFiles {
}
}

pub fn remove_generated_dir(&self) {
let path = Path::new(&self.base_dir);
if path.exists() {
std::fs::remove_dir_all(path).unwrap();
}
}

pub fn write_file(&self, folder: Option<&str>, filename: &str, contents: &str) {
// attempt to create dir
let base_path = Path::new(&self.base_dir).join(folder.unwrap_or(""));
Expand Down
17 changes: 17 additions & 0 deletions bb-pilcom/bb-pil-backend/src/vm_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use dialoguer::Confirm;

use itertools::Itertools;
use powdr_ast::analyzed::Analyzed;
use powdr_number::FieldElement;

Expand Down Expand Up @@ -56,6 +59,7 @@ pub fn analyzed_to_cpp<F: FieldElement>(
witness: &[String],
public: &[String],
vm_name: &str,
delete_dir: bool,
) {
// Extract public inputs information.
let mut public_inputs: Vec<(String, usize)> = public
Expand All @@ -70,6 +74,17 @@ pub fn analyzed_to_cpp<F: FieldElement>(
let witness = &sort_cols(witness);

let mut bb_files = BBFiles::default(&snake_case(&vm_name));
// Pass `-y` as parameter if you want to skip the confirmation prompt.
let confirmation = delete_dir
|| Confirm::new()
.with_prompt(format!("Going to remove: {}. OK?", bb_files.base_dir))
.default(true)
.interact()
.unwrap();
if confirmation {
println!("Removing generated directory: {}", bb_files.base_dir);
bb_files.remove_generated_dir();
}

// Inlining step to remove the intermediate poly definitions
let mut analyzed_identities = analyzed.identities_with_inlined_intermediate_polynomials();
Expand Down Expand Up @@ -169,6 +184,8 @@ pub fn analyzed_to_cpp<F: FieldElement>(
// ----------------------- Create the Prover files -----------------------
bb_files.create_prover_cpp(vm_name, &inverses);
bb_files.create_prover_hpp(vm_name);

println!("Done with generation.");
}

/// Get all col names
Expand Down
6 changes: 6 additions & 0 deletions bb-pilcom/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ struct Cli {
/// BBerg: Name of the output file for bberg
#[arg(long)]
name: Option<String>,

/// Delete the output directory if it already exists
#[arg(short, long)]
#[arg(default_value_t = false)]
yes: bool,
}

fn extract_col_name(cols: Vec<&(Symbol, Option<FunctionValueDefinition>)>) -> Vec<String> {
Expand Down Expand Up @@ -47,6 +52,7 @@ fn main() -> Result<(), io::Error> {
&extract_col_name(witness),
&extract_col_name(public),
&name,
args.yes,
);
Ok(())
}

0 comments on commit f875e1e

Please sign in to comment.