Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-0x committed Jun 3, 2024
1 parent d9c4f4f commit 2975876
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bin/sozo/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cairo_lang_starknet::starknet_plugin_suite;
use cairo_lang_test_plugin::test_plugin_suite;
use cairo_lang_test_runner::{CompiledTestRunner, RunProfilerConfig, TestCompiler, TestRunConfig};
use clap::Args;
use dojo_lang::compiler::{collect_core_crate_ids, collect_external_crate_ids, Props};
use dojo_lang::compiler::{collect_core_crate_ids, collect_crate_ids, Props};
use dojo_lang::plugin::dojo_plugin_suite;
use dojo_lang::scarb_internal::crates_config_for_compilation_unit;
use scarb::compiler::helpers::collect_main_crate_ids;
Expand Down Expand Up @@ -101,7 +101,7 @@ impl TestArgs {
}

if let Some(external_contracts) = props.build_external_contracts {
main_crate_ids.extend(collect_external_crate_ids(&db, external_contracts));
main_crate_ids.extend(collect_crate_ids(&db, external_contracts));

Check warning on line 104 in bin/sozo/src/commands/test.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/test.rs#L104

Added line #L104 was not covered by tests
}

let config = TestRunConfig {
Expand Down
27 changes: 20 additions & 7 deletions crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub struct DojoCompiler;
#[serde(rename_all = "kebab-case")]
pub struct Props {
pub build_external_contracts: Option<Vec<ContractSelector>>,
pub skip_migration: Option<Vec<ContractSelector>>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -157,7 +158,14 @@ impl Compiler for DojoCompiler {
compiled_classes.insert(contract_full_path.into(), (class_hash, class.abi));
}

update_manifest(db, ws, &main_crate_ids, compiled_classes, props.build_external_contracts)?;
update_manifest(
db,
ws,
&main_crate_ids,
compiled_classes,
props.build_external_contracts,
props.skip_migration,
)?;
Ok(())
}
}
Expand Down Expand Up @@ -220,11 +228,8 @@ pub fn collect_core_crate_ids(db: &RootDatabase) -> Vec<CrateId> {
.collect::<Vec<_>>()
}

pub fn collect_external_crate_ids(
db: &RootDatabase,
external_contracts: Vec<ContractSelector>,
) -> Vec<CrateId> {
external_contracts
pub fn collect_crate_ids(db: &RootDatabase, contracts: Vec<ContractSelector>) -> Vec<CrateId> {
contracts
.iter()
.map(|selector| selector.package().into())
.unique()
Expand All @@ -238,6 +243,7 @@ fn update_manifest(
crate_ids: &[CrateId],
compiled_artifacts: HashMap<SmolStr, (FieldElement, Option<abi::Contract>)>,
external_contracts: Option<Vec<ContractSelector>>,
skip_migration: Option<Vec<ContractSelector>>,
) -> anyhow::Result<()> {
let profile_name =
ws.current_profile().expect("Scarb profile expected to be defined.").to_string();
Expand Down Expand Up @@ -288,10 +294,17 @@ fn update_manifest(
let mut computed = BTreeMap::new();

if let Some(external_contracts) = external_contracts {
let external_crate_ids = collect_external_crate_ids(db, external_contracts);
let external_crate_ids = collect_crate_ids(db, external_contracts);
crate_ids.extend(external_crate_ids);
}

if let Some(skip_contracts) = skip_migration {
let skip_crate_ids = collect_crate_ids(db, skip_contracts);

// remove crate_ids present in `skip_crate_ids`
crate_ids.retain(|id| !skip_crate_ids.contains(id))
}

for crate_id in crate_ids {
for module_id in db.crate_modules(crate_id).as_ref() {
let file_infos = db.module_generated_file_infos(*module_id).unwrap_or_default();
Expand Down
1 change: 1 addition & 0 deletions examples/spawn-and-move/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dojo = { path = "../../crates/dojo-core" }

[[target.dojo]]
build-external-contracts = [ ]
skip-migration = [ ]

[tool.dojo.world]
description = "example world"
Expand Down

0 comments on commit 2975876

Please sign in to comment.