Skip to content

Commit

Permalink
Added a new method to CodegenFileSystem, mark_generated_dir, to h…
Browse files Browse the repository at this point in the history
…elp with marking the output of `ldw` during codegen. Without marking these files they will not persist after codegen is complete.
  • Loading branch information
mjoerussell committed Jan 29, 2025
1 parent f63609a commit f53f256
Show file tree
Hide file tree
Showing 9 changed files with 7,729 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ class AnalyseSumTypes extends Visitor {
terminalDefinitions.add(name);
}
break;
case Out.Discriminator.PrimitiveType:
break;
default:
throw new Error('Not yet implemented: sum type discriminators on product/enum leaf types');
throw new Error(`Not yet implemented: sum type discriminators on ${definition.type.discriminator}`);
}
});
}
Expand Down
19 changes: 19 additions & 0 deletions crates/infra/utils/src/codegen/file_system.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Borrow;
use std::collections::HashSet;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -60,6 +61,24 @@ impl CodegenFileSystem {
};
}

/// Mark all files in the specified directory as generated files.
pub fn mark_generated_dir(&mut self, dir_path: impl AsRef<Path>) -> Result<()> {
let dir_path = dir_path.as_ref();

if dir_path.strip_repo_root().is_err() {
bail!("Generated directory is outside repository: {dir_path:?}");
}

for file_path in FileWalker::from_directory(dir_path).find_all().unwrap() {
self.mark_generated_file(file_path)?;
}

Ok(())
}

/// Mark (register) a single file as a generated file. Any file not marked this way will be deleted by
/// `CodegenFileSystem` after codegen is completed. It is an error to mark the same file as generated
/// twice.
pub fn mark_generated_file(&mut self, file_path: impl AsRef<Path>) -> Result<()> {
let file_path = file_path.as_ref();

Expand Down
9 changes: 5 additions & 4 deletions crates/solidity/outputs/cargo/crate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ fn main() -> Result<()> {
render_built_ins,
)?;

let ldw_output_dir = crate_path.join("src/generated/ldw/");

Command::new("ts-node")
.current_dir(Path::repo_path("crates/codegen/ldw"))
.args(["-P", "./tsconfig.json"])
Expand All @@ -38,13 +40,12 @@ fn main() -> Result<()> {
.to_str()
.unwrap(),
])
.args([
"--out-dir",
crate_path.join("src/generated/ldw/").to_str().unwrap(),
])
.args(["--out-dir", ldw_output_dir.to_str().unwrap()])
.args(["--language", "rust"])
.args(["--name", "l0::generated"])
.run();

fs.mark_generated_dir(ldw_output_dir)?;

Ok(())
}

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

Loading

0 comments on commit f53f256

Please sign in to comment.