From 949fdb7aa4ea29e36669035bc9b375f62a387db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 17 Jul 2024 12:32:17 -0400 Subject: [PATCH] Generate VERSION_BREAKS in a separate module for tests --- crates/codegen/testing/src/common.rs | 37 ++++++++++++++++++ crates/codegen/testing/src/lib.rs | 5 +++ crates/solidity/outputs/cargo/tests/build.rs | 6 +++ .../outputs/cargo/tests/src/generated/mod.rs | 39 +++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 crates/solidity/outputs/cargo/tests/src/generated/mod.rs diff --git a/crates/codegen/testing/src/common.rs b/crates/codegen/testing/src/common.rs index 50ae8e1e7..bc551ccb0 100644 --- a/crates/codegen/testing/src/common.rs +++ b/crates/codegen/testing/src/common.rs @@ -126,3 +126,40 @@ pub(crate) fn generate_unit_test_file( fs.write_file(unit_test_file_path, contents) } + +pub(crate) fn generate_version_breaks( + language: &Language, + input_dir: &Path, + output_dir: &Path, +) -> Result<()> { + let mut fs = CodegenFileSystem::new(input_dir)?; + + let version_breaks = language.collect_breaking_versions(); + let version_breaks_len = version_breaks.len(); + let version_breaks_str = version_breaks + .iter() + .fold(String::new(), |mut buffer, version| { + writeln!( + buffer, + "Version::new({}, {}, {}),", + version.major, version.minor, version.patch + ) + .unwrap(); + buffer + }); + + let contents = format!( + " + use semver::Version; + + pub const VERSION_BREAKS: [Version; {version_breaks_len}] = [ + {version_breaks_str} + ]; + ", + ); + + let mod_file_path = output_dir.join("mod.rs"); + fs.write_file(mod_file_path, contents)?; + + Ok(()) +} diff --git a/crates/codegen/testing/src/lib.rs b/crates/codegen/testing/src/lib.rs index cae1c0fbc..9399d7419 100644 --- a/crates/codegen/testing/src/lib.rs +++ b/crates/codegen/testing/src/lib.rs @@ -7,12 +7,14 @@ use std::path::Path; use anyhow::Result; use codegen_language_definition::model::Language; +use common::generate_version_breaks; use crate::bindings_assertions::generate_bindings_assertions_tests; use crate::bindings_output::generate_bindings_output_tests; use crate::cst_output::generate_cst_output_tests; pub trait TestingGeneratorExtensions { + fn generate_version_breaks(&self, lang_def_dir: &Path, output_dir: &Path) -> Result<()>; fn generate_bindings_assertions_tests( &self, sources_dir: &Path, @@ -24,6 +26,9 @@ pub trait TestingGeneratorExtensions { } impl TestingGeneratorExtensions for Language { + fn generate_version_breaks(&self, lang_def_dir: &Path, output_dir: &Path) -> Result<()> { + generate_version_breaks(self, lang_def_dir, output_dir) + } fn generate_bindings_assertions_tests(&self, data_dir: &Path, output_dir: &Path) -> Result<()> { generate_bindings_assertions_tests(self, data_dir, output_dir) } diff --git a/crates/solidity/outputs/cargo/tests/build.rs b/crates/solidity/outputs/cargo/tests/build.rs index cb74333f4..8f5c982af 100644 --- a/crates/solidity/outputs/cargo/tests/build.rs +++ b/crates/solidity/outputs/cargo/tests/build.rs @@ -5,9 +5,15 @@ use solidity_language::SolidityDefinition; fn main() -> Result<()> { let lang_def = SolidityDefinition::create(); + let lang_def_crate = CargoWorkspace::locate_source_crate("solidity_language")?; let snapshots_crate = CargoWorkspace::locate_source_crate("solidity_testing_snapshots")?; let tests_crate = CargoWorkspace::locate_source_crate("solidity_cargo_tests")?; + lang_def.generate_version_breaks( + &lang_def_crate.join("src"), + &tests_crate.join("src/generated"), + )?; + lang_def.generate_bindings_assertions_tests( &snapshots_crate.join("bindings_assertions"), &tests_crate.join("src/bindings_assertions/generated"), diff --git a/crates/solidity/outputs/cargo/tests/src/generated/mod.rs b/crates/solidity/outputs/cargo/tests/src/generated/mod.rs new file mode 100644 index 000000000..7d0e2e9f9 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/generated/mod.rs @@ -0,0 +1,39 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +use semver::Version; + +pub const VERSION_BREAKS: [Version; 33] = [ + Version::new(0, 4, 11), + Version::new(0, 4, 12), + Version::new(0, 4, 14), + Version::new(0, 4, 16), + Version::new(0, 4, 21), + Version::new(0, 4, 22), + Version::new(0, 4, 25), + Version::new(0, 5, 0), + Version::new(0, 5, 3), + Version::new(0, 5, 5), + Version::new(0, 5, 8), + Version::new(0, 5, 10), + Version::new(0, 5, 12), + Version::new(0, 5, 14), + Version::new(0, 6, 0), + Version::new(0, 6, 2), + Version::new(0, 6, 5), + Version::new(0, 6, 7), + Version::new(0, 6, 8), + Version::new(0, 6, 11), + Version::new(0, 7, 0), + Version::new(0, 7, 1), + Version::new(0, 7, 4), + Version::new(0, 8, 0), + Version::new(0, 8, 4), + Version::new(0, 8, 7), + Version::new(0, 8, 8), + Version::new(0, 8, 10), + Version::new(0, 8, 13), + Version::new(0, 8, 18), + Version::new(0, 8, 19), + Version::new(0, 8, 22), + Version::new(0, 8, 24), +];