From 8a80fa0f39a63189bc6d6e5be04189d9ac929e74 Mon Sep 17 00:00:00 2001 From: elfedy Date: Fri, 11 Oct 2024 14:59:10 -0300 Subject: [PATCH] Rename solc version to something better --- crates/compilers/src/compilers/zksolc/mod.rs | 25 +++++++------------ .../compilers/src/zksync/compile/project.rs | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/compilers/src/compilers/zksolc/mod.rs b/crates/compilers/src/compilers/zksolc/mod.rs index cf78674c..153b76da 100644 --- a/crates/compilers/src/compilers/zksolc/mod.rs +++ b/crates/compilers/src/compilers/zksolc/mod.rs @@ -188,7 +188,7 @@ impl ZkSolcCompiler { /// Version metadata. Will include `zksync_version` if compiler is zksync solc. #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] -pub struct SolcVersion { +pub struct SolcVersionInfo { /// The solc compiler version (e.g: 0.8.20) pub version: Version, /// The full zksync solc compiler version (e.g: 0.8.20-1.0.1) @@ -196,7 +196,7 @@ pub struct SolcVersion { } /// Given a solc path, get both the solc semver and optional zkSync version. -pub fn get_solc_type_and_version(path: &Path) -> Result { +pub fn get_solc_version_info(path: &Path) -> Result { let mut cmd = Command::new(path); cmd.arg("--version").stdin(Stdio::piped()).stderr(Stdio::piped()).stdout(Stdio::piped()); debug!(?cmd, "getting Solc versions"); @@ -226,7 +226,7 @@ pub fn get_solc_type_and_version(path: &Path) -> Result } }); - Ok(SolcVersion { version, zksync_version }) + Ok(SolcVersionInfo { version, zksync_version }) } /// Abstraction over `zksolc` command line utility @@ -249,7 +249,7 @@ pub struct ZkSolc { /// Value for --solc arg pub solc: Option, /// Version data for solc - pub solc_version: SolcVersion, + pub solc_version_info: SolcVersionInfo, } impl ZkSolc { @@ -257,14 +257,14 @@ impl ZkSolc { pub fn new(path: PathBuf, solc: Option) -> Result { let default_solc_path = PathBuf::from("solc"); let solc_path = solc.as_ref().unwrap_or(&default_solc_path); - let solc_version = get_solc_type_and_version(solc_path)?; + let solc_version_info = get_solc_version_info(solc_path)?; Ok(Self { zksolc: path, base_path: None, allow_paths: Default::default(), include_paths: Default::default(), solc, - solc_version, + solc_version_info, }) } @@ -289,13 +289,6 @@ impl ZkSolc { Ok(version) } - pub fn set_solc_path(&mut self, path: PathBuf) -> Result<()> { - let solc_version = get_solc_type_and_version(&path)?; - self.solc = Some(path); - self.solc_version = solc_version; - Ok(()) - } - /// Sets zksolc's base path pub fn with_base_path(mut self, base_path: impl Into) -> Self { self.base_path = Some(base_path.into()); @@ -312,7 +305,7 @@ impl ZkSolc { let mut compiler_output: CompilerOutput = serde_json::from_str(output)?; // Add zksync version so that there's some way to identify if zksync solc was used // by looking at build info - compiler_output.zksync_solc_version = self.solc_version.zksync_version.clone(); + compiler_output.zksync_solc_version = self.solc_version_info.zksync_version.clone(); Ok(compiler_output) } @@ -704,7 +697,7 @@ mod tests { fn get_solc_type_and_version_works_for_zksync_solc() { let zksolc = zksolc(); let solc = zksolc.solc.unwrap(); - let solc_v = get_solc_type_and_version(&solc).unwrap(); + let solc_v = get_solc_version_info(&solc).unwrap(); let zksync_v = solc_v.zksync_version.unwrap(); let prerelease = Version::parse(zksync_v.pre.as_str()).unwrap(); assert_eq!(solc_v.version.minor, 8); @@ -714,7 +707,7 @@ mod tests { #[test] fn get_solc_type_and_version_works_for_vanilla_solc() { let solc = vanilla_solc(); - let solc_v = get_solc_type_and_version(&solc.solc).unwrap(); + let solc_v = get_solc_version_info(&solc.solc).unwrap(); assert_eq!(solc_v.version.minor, 8); assert!(solc_v.zksync_version.is_none()); } diff --git a/crates/compilers/src/zksync/compile/project.rs b/crates/compilers/src/zksync/compile/project.rs index aae61b91..d44f2fb4 100644 --- a/crates/compilers/src/zksync/compile/project.rs +++ b/crates/compilers/src/zksync/compile/project.rs @@ -378,7 +378,7 @@ fn compile_sequential( let zksolc = zksolc_compiler.zksolc(&input)?; let (compiler_name, version) = - if let Some(zk_version) = zksolc.solc_version.zksync_version.as_ref() { + if let Some(zk_version) = zksolc.solc_version_info.zksync_version.as_ref() { ("zksolc and ZKsync solc".to_string(), zk_version.clone()) } else { (input.compiler_name().to_string(), input.version().clone())