Skip to content

Commit

Permalink
fix cairo file metadata for contracts and models
Browse files Browse the repository at this point in the history
  • Loading branch information
remybar committed Jul 15, 2024
1 parent 307653b commit 6e26334
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use cairo_lang_starknet_classes::contract_class::ContractClass;
use cairo_lang_utils::UpcastMut;
use camino::Utf8PathBuf;
use convert_case::{Case, Casing};
use dojo_world::contracts::naming;
use dojo_world::contracts::naming::{self};
use dojo_world::manifest::{
AbiFormat, Class, ComputedValueEntrypoint, DojoContract, DojoModel, Manifest, ManifestMethods,
ABIS_DIR, BASE_CONTRACT_TAG, BASE_DIR, BASE_QUALIFIED_PATH, CONTRACTS_DIR, MANIFESTS_DIR,
Expand Down Expand Up @@ -553,7 +553,25 @@ fn save_expanded_source_file(
contract_basename: &str,
contract_tag: &str,
) -> anyhow::Result<()> {
if let Ok(file_id) = db.module_main_file(module_id) {
if let Ok(files) = db.module_files(module_id) {
let contract_name = naming::get_name_from_tag(contract_tag);

// search among all the module files (real and virtual), the one named with
// the contract/model name. This is the file containing the Cairo code generated
// from Dojo plugins.
let res = files.iter().filter(|f| f.file_name(db).eq(&contract_name)).collect::<Vec<_>>();

let file_id = if res.is_empty() {
// if there is no virtual file with the name of the contract/model, just use the main
// module file
match db.module_main_file(module_id) {
Ok(f) => f,
Err(_) => return Err(anyhow!("failed to get source file: {contract_tag}")),

Check warning on line 569 in crates/dojo-lang/src/compiler.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo-lang/src/compiler.rs#L569

Added line #L569 was not covered by tests
}
} else {
*res[0]
};

if let Some(file_content) = db.file_content(file_id) {
let src_file_name = format!("{contract_basename}.cairo");

Expand Down

0 comments on commit 6e26334

Please sign in to comment.