mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-12 08:11:02 +00:00
multiple resolc fixes and improvements (#151)
- Error out early on compiler invocations with invalid base path or include path flags. - Do not error out if no files and no errors were produced. This aligns resolc closer to sloc. - Add a CLI test with an involved fixture containing multiple contract remappings to properly testing the standard JSON path. - Fixes input normalization in the Wasm version. Co-authored-by: Cyrill Leutwiler <cyrill@parity.io>
This commit is contained in:
committed by
GitHub
parent
b78b2b2af9
commit
06f43083c3
@@ -9,6 +9,8 @@ pub mod soljson_compiler;
|
||||
pub mod standard_json;
|
||||
pub mod version;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use semver::VersionReq;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -29,6 +31,13 @@ pub const FIRST_VIA_IR_VERSION: semver::Version = semver::Version::new(0, 8, 13)
|
||||
|
||||
/// The last supported version of `solc`.
|
||||
pub const LAST_SUPPORTED_VERSION: semver::Version = semver::Version::new(0, 8, 28);
|
||||
/// `--base-path` was introduced in 0.6.9 <https://github.com/ethereum/solidity/releases/tag/v0.6.9>
|
||||
pub static FIRST_SUPPORTS_BASE_PATH: Lazy<VersionReq> =
|
||||
Lazy::new(|| VersionReq::parse(">=0.6.9").unwrap());
|
||||
|
||||
/// `--include-path` was introduced in 0.8.8 <https://github.com/ethereum/solidity/releases/tag/v0.8.8>
|
||||
pub static FIRST_SUPPORTS_INCLUDE_PATH: Lazy<VersionReq> =
|
||||
Lazy::new(|| VersionReq::parse(">=0.8.8").unwrap());
|
||||
|
||||
/// The Solidity compiler.
|
||||
pub trait Compiler {
|
||||
|
||||
@@ -11,6 +11,7 @@ use crate::solc::standard_json::output::Output as StandardJsonOutput;
|
||||
use crate::solc::version::Version;
|
||||
|
||||
use super::Compiler;
|
||||
use crate::solc::{FIRST_SUPPORTS_BASE_PATH, FIRST_SUPPORTS_INCLUDE_PATH};
|
||||
|
||||
/// The Solidity compiler.
|
||||
pub struct SolcCompiler {
|
||||
@@ -58,10 +59,23 @@ impl Compiler for SolcCompiler {
|
||||
command.stdout(std::process::Stdio::piped());
|
||||
command.arg("--standard-json");
|
||||
|
||||
if let Some(base_path) = base_path {
|
||||
command.arg("--base-path");
|
||||
command.arg(base_path);
|
||||
if let Some(base_path) = &base_path {
|
||||
if !FIRST_SUPPORTS_BASE_PATH.matches(&version.default) {
|
||||
anyhow::bail!(
|
||||
"--base-path not supported this version {} of solc",
|
||||
&version.default
|
||||
);
|
||||
}
|
||||
command.arg("--base-path").arg(base_path);
|
||||
}
|
||||
|
||||
if !include_paths.is_empty() && !FIRST_SUPPORTS_INCLUDE_PATH.matches(&version.default) {
|
||||
anyhow::bail!(
|
||||
"--include-path not supported this version {} of solc",
|
||||
&version.default
|
||||
);
|
||||
}
|
||||
|
||||
for include_path in include_paths.into_iter() {
|
||||
command.arg("--include-path");
|
||||
command.arg(include_path);
|
||||
|
||||
@@ -35,6 +35,7 @@ impl Compiler for SoljsonCompiler {
|
||||
_allow_paths: Option<String>,
|
||||
) -> anyhow::Result<StandardJsonOutput> {
|
||||
let version = self.version()?;
|
||||
input.normalize(&version.default);
|
||||
let suppressed_warnings = input.suppressed_warnings.take().unwrap_or_default();
|
||||
|
||||
let input_json = serde_json::to_string(&input).expect("Always valid");
|
||||
|
||||
@@ -24,9 +24,8 @@ use crate::yul::parser::statement::object::Object;
|
||||
use self::contract::Contract;
|
||||
use self::error::Error as SolcStandardJsonOutputError;
|
||||
use self::source::Source;
|
||||
|
||||
/// The `solc --standard-json` output.
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
pub struct Output {
|
||||
/// The file-contract hashmap.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
@@ -64,15 +63,12 @@ impl Output {
|
||||
|
||||
let files = match self.contracts.as_ref() {
|
||||
Some(files) => files,
|
||||
None => {
|
||||
anyhow::bail!(
|
||||
"{}",
|
||||
self.errors
|
||||
.as_ref()
|
||||
.map(|errors| serde_json::to_string_pretty(errors).expect("Always valid"))
|
||||
.unwrap_or_else(|| "Unknown project assembling error".to_owned())
|
||||
);
|
||||
}
|
||||
None => match &self.errors {
|
||||
Some(errors) if errors.iter().any(|e| e.severity == "error") => {
|
||||
anyhow::bail!(serde_json::to_string_pretty(errors).expect("Always valid"));
|
||||
}
|
||||
_ => &BTreeMap::new(),
|
||||
},
|
||||
};
|
||||
let mut project_contracts = BTreeMap::new();
|
||||
|
||||
@@ -159,7 +155,6 @@ impl Output {
|
||||
messages.extend(polkavm_messages);
|
||||
}
|
||||
}
|
||||
|
||||
self.errors = match self.errors.take() {
|
||||
Some(mut errors) => {
|
||||
errors.extend(messages);
|
||||
|
||||
Reference in New Issue
Block a user