From da36090a05574dce8b6e0cdfe2d4075b50d10d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Tr=C4=85tnowiecki?= Date: Wed, 2 Oct 2024 01:21:01 +0200 Subject: [PATCH] Fix dep version for corelib --- extensions/scarb-doc/src/metadata/compilation.rs | 6 ++++-- extensions/scarb-snforge-test-collector/src/metadata.rs | 8 +++++--- scarb/src/compiler/db.rs | 8 ++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/extensions/scarb-doc/src/metadata/compilation.rs b/extensions/scarb-doc/src/metadata/compilation.rs index 74570dc45..fbcbf5b71 100644 --- a/extensions/scarb-doc/src/metadata/compilation.rs +++ b/extensions/scarb-doc/src/metadata/compilation.rs @@ -152,7 +152,9 @@ fn get_crate_settings_for_package( .iter() .find(|package| package.name == compilation_unit_metadata_component.name) .map(|package| package.version.clone()); - + let version = (dependency.name == *CORELIB_CRATE_NAME) + .then_some(version) + .flatten(); (dependency.name.clone(), DependencySettings { version }) }) }) @@ -162,7 +164,7 @@ fn get_crate_settings_for_package( dependencies.insert( package.name.clone(), DependencySettings { - version: Some(package.version.clone()), + version: (package.name != *CORELIB_CRATE_NAME).then_some(package.version.clone()), }, ); diff --git a/extensions/scarb-snforge-test-collector/src/metadata.rs b/extensions/scarb-snforge-test-collector/src/metadata.rs index 292274e5b..9d0131b89 100644 --- a/extensions/scarb-snforge-test-collector/src/metadata.rs +++ b/extensions/scarb-snforge-test-collector/src/metadata.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, ensure, Context, Result}; use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; use cairo_lang_filesystem::db::{ - CrateSettings, DependencySettings, Edition, ExperimentalFeaturesConfig, + CrateSettings, DependencySettings, Edition, ExperimentalFeaturesConfig, CORELIB_CRATE_NAME, }; use cairo_lang_project::AllCratesConfig; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; @@ -249,7 +249,9 @@ fn get_crate_settings_for_package( .iter() .find(|package| package.name == compilation_unit_metadata_component.name) .map(|package| package.version.clone()); - + let version = (dependency.name == *CORELIB_CRATE_NAME) + .then_some(version) + .flatten(); (dependency.name.clone(), DependencySettings { version }) }) }) @@ -259,7 +261,7 @@ fn get_crate_settings_for_package( dependencies.insert( package.name.clone(), DependencySettings { - version: Some(package.version.clone()), + version: (package.name != *CORELIB_CRATE_NAME).then_some(package.version.clone()), }, ); diff --git a/scarb/src/compiler/db.rs b/scarb/src/compiler/db.rs index 196ee109a..cf9384529 100644 --- a/scarb/src/compiler/db.rs +++ b/scarb/src/compiler/db.rs @@ -6,6 +6,7 @@ use cairo_lang_defs::ids::ModuleId; use cairo_lang_defs::plugin::MacroPlugin; use cairo_lang_filesystem::db::{ AsFilesGroupMut, CrateSettings, DependencySettings, FilesGroup, FilesGroupEx, + CORELIB_CRATE_NAME, }; use cairo_lang_filesystem::ids::{CrateLongId, Directory}; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; @@ -174,7 +175,9 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { ( compilation_unit_component.package.id.name.to_string(), DependencySettings { - version: Some(compilation_unit_component.package.id.version.clone()), + version: (compilation_unit_component.package.id.name.to_string() + != *CORELIB_CRATE_NAME) + .then_some(compilation_unit_component.package.id.version.clone()), }, ) }) @@ -184,7 +187,8 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { dependencies.insert( component.package.id.name.to_string(), DependencySettings { - version: Some(component.package.id.version.clone()), + version: (component.package.id.name.to_string() != *CORELIB_CRATE_NAME) + .then_some(component.package.id.version.clone()), }, );