-
Notifications
You must be signed in to change notification settings - Fork 3
Implement a compile context/subcommand for standalone compilation mode
#239
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
elle-j
wants to merge
29
commits into
main
Choose a base branch
from
lj/compile-context
base: main
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
Show all changes
29 commits
Select commit
Hold shift + click to select a range
60154e0
Compute and add bytecode hashes to the report.
elle-j d97c8b4
Update hash type to fixed-size byte array.
elle-j 1b8113b
Remove leftover clone.
elle-j 2312786
Hex decode the bytecode string prior to hashing.
elle-j e442719
Add additional comment to info field.
elle-j 88b26b5
Implement the Compile context/subcommand.
elle-j e30302b
Implement driver and reporter for the compile subcommand.
elle-j 0d7fdca
Refactor runner_event macros to improve readability and maintainability.
elle-j 27a7bbb
Implement CLI reporting for standalone compile mode.
elle-j d9f5363
Fix clippy.
elle-j dc5077f
Merge branch 'main' into lj/compile-context
elle-j b884fa9
Key compilation information in report by mode.
elle-j 5934bdb
Prepare multi-mode support.
elle-j 4481128
Add compatibility check for pragma solidity version.
elle-j 921c187
Minor docs and structure update.
elle-j 28d1cbc
Move compilation reports onto the MetadataFileReport.
elle-j fe0cc4b
Remove build_label from context for now.
elle-j aa8f68a
Share pre-link comp events between execution and standalone contexts.
elle-j 3edf5f9
Remove unnecessary ignore check for compilation.
elle-j 8706916
Update terminology from "standalone" to "pre-link".
elle-j 6c680ff
Update match cases in cached compiler.
elle-j 8246f3c
Merge branch 'main' into lj/compile-context
elle-j ab8346a
Share orchestration logic between tests and compilations.
elle-j 361247c
Merge branch 'main' into lj/compile-context
elle-j 856d62e
Merge branch 'main' into lj/compile-context
elle-j 7c46dcd
Enable cache invalidation.
elle-j 4b84f27
Don't panic clearing the cache if the cache directory does not exit.
elle-j b382150
Fix clippy.
elle-j eb3aad9
Update naming.
elle-j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use std::{fmt::Display, path::PathBuf, str::FromStr}; | ||
|
|
||
| use anyhow::Context as _; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub enum ParsedCompilationSpecifier { | ||
| /// All of the contracts in the file should be compiled. | ||
| FileOrDirectory { | ||
| /// The path of the metadata file containing the contracts or the references to the contracts. | ||
| metadata_or_directory_file_path: PathBuf, | ||
| }, | ||
| } | ||
|
|
||
| impl Display for ParsedCompilationSpecifier { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| ParsedCompilationSpecifier::FileOrDirectory { | ||
| metadata_or_directory_file_path, | ||
| } => { | ||
| write!(f, "{}", metadata_or_directory_file_path.display()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for ParsedCompilationSpecifier { | ||
| type Err = anyhow::Error; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| let path = PathBuf::from(s) | ||
| .canonicalize() | ||
| .context("Failed to canonicalize the path of the contracts")?; | ||
|
|
||
| Ok(Self::FileOrDirectory { | ||
| metadata_or_directory_file_path: path, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl From<ParsedCompilationSpecifier> for String { | ||
| fn from(value: ParsedCompilationSpecifier) -> Self { | ||
| value.to_string() | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<String> for ParsedCompilationSpecifier { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: String) -> Result<Self, Self::Error> { | ||
| value.parse() | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&str> for ParsedCompilationSpecifier { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
| value.parse() | ||
| } | ||
| } | ||
|
|
||
| impl Serialize for ParsedCompilationSpecifier { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::Serializer, | ||
| { | ||
| self.to_string().serialize(serializer) | ||
| } | ||
| } | ||
|
|
||
| impl<'de> Deserialize<'de> for ParsedCompilationSpecifier { | ||
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| { | ||
| let string = String::deserialize(deserializer)?; | ||
| string.parse().map_err(serde::de::Error::custom) | ||
| } | ||
| } | ||
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
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| use anyhow::{Context as _, Result}; | ||
| use revive_dt_report::CompilationReporter; | ||
| use tracing::error; | ||
|
|
||
| use crate::helpers::{CachedCompiler, CompilationDefinition}; | ||
|
|
||
| /// The compilation driver. | ||
| pub struct Driver<'a> { | ||
| /// The definition of the compilation that the driver is instructed to execute. | ||
| compilation_definition: &'a CompilationDefinition<'a>, | ||
| } | ||
|
|
||
| impl<'a> Driver<'a> { | ||
| /// Creates a new driver. | ||
| pub fn new(compilation_definition: &'a CompilationDefinition<'a>) -> Self { | ||
| Self { | ||
| compilation_definition, | ||
| } | ||
| } | ||
|
|
||
| /// Compiles all contracts specified by the [`CompilationDefinition`]. | ||
| pub async fn compile_all(&self, cached_compiler: &CachedCompiler<'a>) -> Result<()> { | ||
| cached_compiler | ||
| .compile_contracts( | ||
| self.compilation_definition.metadata, | ||
| self.compilation_definition.metadata_file_path, | ||
| self.compilation_definition.mode.clone(), | ||
| None, | ||
| self.compilation_definition.compiler.as_ref(), | ||
| self.compilation_definition.compiler_identifier, | ||
| None, | ||
| &CompilationReporter::PreLink(&self.compilation_definition.reporter), | ||
| ) | ||
| .await | ||
| .inspect_err(|err| error!(?err, "Compilation failed")) | ||
| .context("Failed to produce the compiled contracts")?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } |
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.
Why do we need this file rather than the
TestSpecifier? They seem to be functionally the same but the test specifier seems to be more permissive in what it allows us to point to.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.
Grouped my response here to some related comments such as that ☝️ one.
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.
We discussed this and I agree with you that your approach here is better. Will mark this as resolved.