-
Notifications
You must be signed in to change notification settings - Fork 142
[hermes] Add package/target/root resolution #3005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joshlf
wants to merge
1
commit into
G9611b9a3ca0254d8ba488d591e6a21980cca3d29
Choose a base branch
from
Gb7f1abf97eed8a035dbcaf7b0363b5890baaec05
base: G9611b9a3ca0254d8ba488d591e6a21980cca3d29
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,44 +1,55 @@ | ||
| mod errors; | ||
| mod parse; | ||
| mod resolve; | ||
| mod transform; | ||
| mod ui_test_shim; | ||
|
|
||
| use std::{env, path::PathBuf, process::exit}; | ||
| use std::{env, process::exit}; | ||
|
|
||
| use clap::Parser; | ||
|
|
||
| /// Hermes: A Literate Verification Toolchain | ||
| #[derive(Parser, Debug)] | ||
| #[command(name = "hermes", version, about, long_about = None)] | ||
| struct Cli { | ||
| #[command(flatten)] | ||
| resolve: resolve::Args, | ||
| } | ||
|
|
||
| fn main() { | ||
| if env::var("HERMES_UI_TEST_MODE").is_ok() { | ||
| ui_test_shim::run(); | ||
| return; | ||
| } | ||
|
|
||
| let args: Vec<String> = env::args().collect(); | ||
| if args.len() < 2 { | ||
| eprintln!("Usage: hermes <file.rs>"); | ||
| exit(1); | ||
| } | ||
| let args = Cli::parse(); | ||
|
|
||
| let file_path = PathBuf::from(&args[1]); | ||
| // TODO: Better error handling than `.unwrap()`. | ||
| let roots = resolve::resolve_roots(&args.resolve).unwrap(); | ||
|
|
||
| // TODO: From each root, parse and walk referenced modules. | ||
| let mut has_errors = false; | ||
| let mut edits = Vec::new(); | ||
| let res = parse::read_file_and_visit_hermes_items(&file_path, |_src, res| { | ||
| if let Err(e) = res { | ||
| has_errors = true; | ||
| eprint!("{:?}", miette::Report::new(e)); | ||
| } else if let Ok(item) = res { | ||
| transform::append_edits(&item, &mut edits); | ||
| for (package, kind, path) in roots { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| let mut edits = Vec::new(); | ||
| let res = parse::read_file_and_visit_hermes_items(path.as_std_path(), |_src, res| { | ||
| if let Err(e) = res { | ||
| has_errors = true; | ||
| eprint!("{:?}", miette::Report::new(e)); | ||
| } else if let Ok(item) = res { | ||
| transform::append_edits(&item, &mut edits); | ||
| } | ||
| }); | ||
|
|
||
| let source = res.unwrap_or_else(|e| { | ||
| eprintln!("Error parsing file: {}", e); | ||
| exit(1); | ||
| }); | ||
|
|
||
| if has_errors { | ||
| exit(1); | ||
| } | ||
| }); | ||
|
|
||
| let source = res.unwrap_or_else(|e| { | ||
| eprintln!("Error parsing file: {}", e); | ||
| exit(1); | ||
| }); | ||
|
|
||
| if has_errors { | ||
| exit(1); | ||
| let mut source = source.into_bytes(); | ||
| transform::apply_edits(&mut source, &edits); | ||
| } | ||
|
|
||
| let mut source = source.into_bytes(); | ||
| transform::apply_edits(&mut source, &edits); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in the
TODOcomment, using.unwrap()here can cause the program to panic ifresolve_rootsreturns an error. It would be more user-friendly to handle the error gracefully and print a descriptive message instead of panicking. Sinceanyhowis a dependency, you can useunwrap_or_elseto achieve this.