Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update manifest structure #2153

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions bin/sozo/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fs;
use anyhow::{Context, Result};
use camino::Utf8PathBuf;
use clap::Args;
use dojo_world::manifest::{ABIS_DIR, BASE_DIR, MANIFESTS_DIR};
use dojo_world::manifest::{BASE_DIR, MANIFESTS_DIR};
use scarb::core::Config;
use scarb::ops;
use tracing::trace;
Expand All @@ -28,7 +28,7 @@ impl CleanArgs {
/// * `profile_dir` - The directory where the profile files are located.
pub fn clean_manifests(profile_dir: &Utf8PathBuf) -> Result<()> {
trace!(?profile_dir, "Cleaning manifests.");
let dirs = vec![profile_dir.join(BASE_DIR), profile_dir.join(ABIS_DIR).join(BASE_DIR)];
let dirs = vec![profile_dir.join(BASE_DIR)];

for d in dirs {
if d.exists() {
Expand Down Expand Up @@ -96,6 +96,8 @@ impl CleanArgs {
#[cfg(test)]
mod tests {
use dojo_test_utils::compiler;
use dojo_world::manifest::DEPLOYMENT_DIR;
use dojo_world::metadata::ABIS_DIR;
use scarb::compiler::Profile;

use super::*;
Expand Down Expand Up @@ -147,11 +149,11 @@ mod tests {
);
assert!(
fs::read_dir(dev_manifests_abis_base_dir).is_err(),
"Expected 'manifests/dev/abis/base' to be empty"
"Expected 'manifests/dev/base/abis' to be empty"
);
assert!(
fs::read_dir(&dev_manifests_abis_depl_dir).is_ok(),
"Expected 'manifests/dev/abis/deployments' to not be empty"
"Expected 'manifests/dev/deployment/abis' to not be empty"
);

// we expect release profile to be not affected
Expand All @@ -161,7 +163,7 @@ mod tests {
);
assert!(
fs::read_dir(release_manifests_abis_base_dir).is_ok(),
"Expected 'manifests/release/abis/base' to be non empty"
"Expected 'manifests/release/base/abis' to be non empty"
);

assert!(dev_manifest_toml.exists(), "Expected 'manifest.toml' to exist");
Expand All @@ -172,7 +174,7 @@ mod tests {

assert!(
fs::read_dir(&dev_manifests_abis_depl_dir).is_err(),
"Expected 'manifests/dev/abis/deployments' to be empty"
"Expected 'manifests/dev/deployment/abis' to be empty"
);
assert!(!dev_manifest_toml.exists(), "Expected 'manifest.toml' to not exist");
assert!(!dev_manifest_json.exists(), "Expected 'manifest.json' to not exist");
Expand Down Expand Up @@ -200,18 +202,19 @@ mod tests {
let target_dev_dir = temp_project_dir.join("target").join(dev_profile_name);
let target_release_dir = temp_project_dir.join("target").join(release_profile_name);

let dev_manifests_dir = temp_project_dir.join("manifests").join(dev_profile_name);
let release_manifests_dir = temp_project_dir.join("manifests").join(release_profile_name);
let dev_manifests_dir = temp_project_dir.join(MANIFESTS_DIR).join(dev_profile_name);
let release_manifests_dir = temp_project_dir.join(MANIFESTS_DIR).join(release_profile_name);

let dev_manifests_base_dir = dev_manifests_dir.join("base");
let dev_manifests_abis_base_dir = dev_manifests_dir.join("abis").join("base");
let release_manifests_base_dir = release_manifests_dir.join("base");
let release_manifests_abis_base_dir = release_manifests_dir.join("abis").join("base");
let dev_manifests_base_dir = dev_manifests_dir.join(BASE_DIR);
let dev_manifests_abis_base_dir = dev_manifests_base_dir.join(ABIS_DIR);
let release_manifests_base_dir = release_manifests_dir.join(BASE_DIR);
let release_manifests_abis_base_dir = release_manifests_base_dir.join(ABIS_DIR);

let dev_manifests_abis_depl_dir = dev_manifests_dir.join("abis").join("deployments");
let dev_manifests_deploy_dir = dev_manifests_dir.join(DEPLOYMENT_DIR);
let dev_manifests_abis_depl_dir = dev_manifests_deploy_dir.join(ABIS_DIR);

let dev_manifest_toml = dev_manifests_dir.join("manifest").with_extension("toml");
let dev_manifest_json = dev_manifests_dir.join("manifest").with_extension("json");
let dev_manifest_toml = dev_manifests_deploy_dir.join("manifest").with_extension("toml");
let dev_manifest_json = dev_manifests_deploy_dir.join("manifest").with_extension("json");

assert!(fs::read_dir(target_dev_dir).is_err(), "Expected 'target/dev' to be empty");
assert!(fs::read_dir(target_release_dir).is_err(), "Expected 'target/release' to be empty");
Expand All @@ -222,11 +225,11 @@ mod tests {
);
assert!(
fs::read_dir(dev_manifests_abis_base_dir).is_err(),
"Expected 'manifests/dev/abis/base' to be empty"
"Expected 'manifests/dev/base/abis' to be empty"
);
assert!(
fs::read_dir(&dev_manifests_abis_depl_dir).is_ok(),
"Expected 'manifests/dev/abis/deployments' to not be empty"
"Expected 'manifests/dev/deployment/abis' to not be empty"
);

assert!(
Expand All @@ -235,7 +238,7 @@ mod tests {
);
assert!(
fs::read_dir(release_manifests_abis_base_dir).is_err(),
"Expected 'manifests/release/abis/base' to be empty"
"Expected 'manifests/release/base/abis' to be empty"
);

assert!(dev_manifest_toml.exists(), "Expected 'manifest.toml' to exist");
Expand All @@ -246,7 +249,7 @@ mod tests {

assert!(
fs::read_dir(&dev_manifests_abis_depl_dir).is_err(),
"Expected 'manifests/dev/abis/deployments' to be empty"
"Expected 'manifests/dev/deployment/abis' to be empty"
);
assert!(!dev_manifest_toml.exists(), "Expected 'manifest.toml' to not exist");
assert!(!dev_manifest_json.exists(), "Expected 'manifest.json' to not exist");
Expand Down
4 changes: 3 additions & 1 deletion bin/sozo/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ impl MigrateArgs {
None
};

let profile_name =
ws.current_profile().expect("Scarb profile expected to be defined.").to_string();
let manifest_dir = ws.manifest_path().parent().unwrap().to_path_buf();
if !manifest_dir.join(MANIFESTS_DIR).exists() {
if !manifest_dir.join(MANIFESTS_DIR).join(profile_name).exists() {
return Err(anyhow!("Build project using `sozo build` first"));
}

Expand Down
4 changes: 2 additions & 2 deletions crates/benches/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{anyhow, bail, Context, Ok, Result};
use clap::Parser;
use dojo_lang::compiler::DojoCompiler;
use dojo_lang::plugin::CairoPluginRepository;
use dojo_world::manifest::{DeploymentManifest, DEPLOYMENTS_DIR, MANIFESTS_DIR};
use dojo_world::manifest::{DeploymentManifest, DEPLOYMENT_DIR, MANIFESTS_DIR};
use futures::executor::block_on;
use katana_runner::KatanaRunner;
use scarb::compiler::CompilerRepository;
Expand Down Expand Up @@ -97,7 +97,7 @@ async fn prepare_migration_args(args: SozoArgs) -> Result<Felt> {
let manifest_dir = manifest_path.parent().unwrap();

let manifest = DeploymentManifest::load_from_path(
&manifest_dir.join(MANIFESTS_DIR).join("dev").join(DEPLOYMENTS_DIR).with_extension("toml"),
&manifest_dir.join(MANIFESTS_DIR).join("dev").join(DEPLOYMENT_DIR).with_extension("toml"),
)
.expect("failed to load manifest");

Expand Down
20 changes: 11 additions & 9 deletions crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ fn update_files(
) -> anyhow::Result<()> {
let profile_name =
ws.current_profile().expect("Scarb profile expected to be defined.").to_string();
let profile_dir = Utf8PathBuf::new().join(MANIFESTS_DIR).join(profile_name);
let relative_manifest_dir = Utf8PathBuf::new().join(MANIFESTS_DIR).join(profile_name);

lambda-0x marked this conversation as resolved.
Show resolved Hide resolved
// relative path to manifests and abi
let base_manifests_dir = Utf8PathBuf::new().join(relative_manifest_dir).join(BASE_DIR);
let base_abis_dir = Utf8PathBuf::new().join(&base_manifests_dir).join(ABIS_DIR);

let relative_manifests_dir = Utf8PathBuf::new().join(&profile_dir).join(BASE_DIR);
let relative_abis_dir = Utf8PathBuf::new().join(&profile_dir).join(ABIS_DIR).join(BASE_DIR);
let manifest_dir = ws.manifest_path().parent().unwrap().to_path_buf();

fn get_compiled_artifact_from_map<'a>(
Expand All @@ -247,8 +249,8 @@ fn update_files(
let (hash, class) = get_compiled_artifact_from_map(&compiled_artifacts, qualified_path)?;
let filename = naming::get_filename_from_tag(tag);
write_manifest_and_abi(
&relative_manifests_dir,
&relative_abis_dir,
&base_manifests_dir,
&base_abis_dir,
&manifest_dir,
&mut Manifest::new(
// abi path will be written by `write_manifest`
Expand Down Expand Up @@ -334,8 +336,8 @@ fn update_files(

for (_, (manifest, class, module_id)) in contracts.iter_mut() {
write_manifest_and_abi(
&relative_manifests_dir.join(CONTRACTS_DIR),
&relative_abis_dir.join(CONTRACTS_DIR),
&base_manifests_dir.join(CONTRACTS_DIR),
&base_abis_dir.join(CONTRACTS_DIR),
&manifest_dir,
manifest,
&class.abi,
Expand All @@ -360,8 +362,8 @@ fn update_files(

for (_, (manifest, class, module_id)) in models.iter_mut() {
write_manifest_and_abi(
&relative_manifests_dir.join(MODELS_DIR),
&relative_abis_dir.join(MODELS_DIR),
&base_manifests_dir.join(MODELS_DIR),
&base_abis_dir.join(MODELS_DIR),
&manifest_dir,
manifest,
&class.abi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind = "DojoContract"
class_hash = "0x7468fbf6e47eb66fd898a4a68bbe801560fdd42b0d6909ec4f75fb38c613702"
original_class_hash = "0x7468fbf6e47eb66fd898a4a68bbe801560fdd42b0d6909ec4f75fb38c613702"
base_class_hash = "0x0"
abi = "manifests/dev/abis/base/contracts/ccf-cairo_v240-8d921297.json"
abi = "manifests/dev/base/abis/contracts/ccf-cairo_v240-8d921297.json"
reads = []
writes = []
computed = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind = "DojoContract"
class_hash = "0x4bbfcdc8d95ecfa332201e21f615e98b4d12e08f77d176761e32bb34e3bc333"
original_class_hash = "0x4bbfcdc8d95ecfa332201e21f615e98b4d12e08f77d176761e32bb34e3bc333"
base_class_hash = "0x0"
abi = "manifests/dev/abis/base/contracts/ccf-cairo_v260-465ec7fe.json"
abi = "manifests/dev/base/abis/contracts/ccf-cairo_v260-465ec7fe.json"
reads = []
writes = []
computed = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x22f3e55b61d86c2ac5239fa3b3b8761f26b9a5c0b5f61ddbd5d756ced498b46"
original_class_hash = "0x22f3e55b61d86c2ac5239fa3b3b8761f26b9a5c0b5f61ddbd5d756ced498b46"
abi = "manifests/dev/abis/base/dojo-base.json"
abi = "manifests/dev/base/abis/dojo-base.json"
tag = "dojo-base"
manifest_name = "dojo-base"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x1498dd1197805ec05d37da956d0fc568023a4c25578b0523b4f4f0d0e4f16c2"
original_class_hash = "0x1498dd1197805ec05d37da956d0fc568023a4c25578b0523b4f4f0d0e4f16c2"
abi = "manifests/dev/abis/base/dojo-world.json"
abi = "manifests/dev/base/abis/dojo-world.json"
tag = "dojo-world"
manifest_name = "dojo-world"
2 changes: 1 addition & 1 deletion crates/dojo-world/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ pub const WORLD_QUALIFIED_PATH: &str = "dojo::world::world";
pub const BASE_QUALIFIED_PATH: &str = "dojo::base::base";

pub const MANIFESTS_DIR: &str = "manifests";
pub const DEPLOYMENT_DIR: &str = "deployment";
pub const TARGET_DIR: &str = "target";
pub const BASE_DIR: &str = "base";
pub const OVERLAYS_DIR: &str = "overlays";
pub const DEPLOYMENTS_DIR: &str = "deployments";
pub const ABIS_DIR: &str = "abis";

pub const CONTRACTS_DIR: &str = "contracts";
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo-world/src/metadata_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async fn get_full_dojo_metadata_from_workspace() {
let manifest_dir = manifest_dir.join(MANIFESTS_DIR).join(profile.as_str());
let target_dir = ws.target_dir().path_existent().unwrap();
let target_dir = target_dir.join(profile.as_str());
let abis_dir = manifest_dir.join(ABIS_DIR).join(BASE_DIR);
let abis_dir = manifest_dir.join(BASE_DIR).join(ABIS_DIR);

let dojo_metadata =
dojo_metadata_from_workspace(&ws).expect("No current package with dojo metadata found.");
Expand Down
25 changes: 14 additions & 11 deletions crates/sozo/ops/src/migration/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use dojo_world::contracts::{cairo_utils, WorldContract};
use dojo_world::manifest::{
AbiFormat, BaseManifest, DeploymentManifest, DojoContract, DojoModel, Manifest,
ManifestMethods, WorldContract as ManifestWorldContract, WorldMetadata, ABIS_DIR, BASE_DIR,
DEPLOYMENTS_DIR, MANIFESTS_DIR,
DEPLOYMENT_DIR, MANIFESTS_DIR,
};
use dojo_world::metadata::{dojo_metadata_from_workspace, ResourceMetadata};
use dojo_world::migration::class::ClassMigration;
Expand Down Expand Up @@ -807,8 +807,10 @@ pub async fn update_manifests_and_abis(
let ui = ws.config().ui();
ui.print_step(5, "✨", "Updating manifests...");

let deployed_path = manifest_dir.join("manifest").with_extension("toml");
let deployed_path_json = manifest_dir.join("manifest").with_extension("json");
let deployment_dir = manifest_dir.join(DEPLOYMENT_DIR);

let deployed_path = deployment_dir.join("manifest").with_extension("toml");
let deployed_path_json = deployment_dir.join("manifest").with_extension("json");

let mut local_manifest: DeploymentManifest = local_manifest.into();

Expand Down Expand Up @@ -862,7 +864,7 @@ pub async fn update_manifests_and_abis(
}
});

// copy abi files from `abi/base` to `abi/deployments/{chain_id}` and update abi path in
// copy abi files from `base/abi` to `deployment/abi` and update abi path in
// local_manifest
update_manifest_abis(&mut local_manifest, manifest_dir, profile_name).await;

Expand All @@ -887,25 +889,26 @@ async fn update_manifest_abis(
) where
T: ManifestMethods,
{
// manifests/dev/abis/base/contract/dojo-world.json -> abis/base/contract/dojo-world.json
let base_relative_path = manifest.inner.abi().unwrap().to_path().unwrap();

// manifests/dev/base/abis/contract/contract.json -> abis/contract/contract.json
let base_relative_path = base_relative_path
.strip_prefix(Utf8PathBuf::new().join(MANIFESTS_DIR).join(profile_name))
.unwrap();

// abis/base/dojo-world.json -> dojo-world.json
// base/abis/contract/contract.json -> contract/contract.json
let stripped_path = base_relative_path
.strip_prefix(Utf8PathBuf::new().join(ABIS_DIR).join(BASE_DIR))
.strip_prefix(Utf8PathBuf::new().join(BASE_DIR).join(ABIS_DIR))
.unwrap();

// abis/deployments/dojo-world.json
// deployment/abis/dojo-world.json
let deployed_relative_path =
Utf8PathBuf::new().join(ABIS_DIR).join(DEPLOYMENTS_DIR).join(stripped_path);
Utf8PathBuf::new().join(DEPLOYMENT_DIR).join(ABIS_DIR).join(stripped_path);

// <manifest_dir>/abis/base/dojo-world.json
// <manifest_dir>/base/abis/dojo-world.json
let full_base_path = manifest_dir.join(base_relative_path);

// <manifest_dir>/abis/deployments/dojo-world.json
// <manifest_dir>/deployment/abis/dojo-world.json
let full_deployed_path = manifest_dir.join(deployed_relative_path.clone());

fs::create_dir_all(full_deployed_path.parent().unwrap())
Expand Down
1 change: 0 additions & 1 deletion crates/torii/core/src/sql_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ async fn test_load_from_remote() {
SqliteConnectOptions::from_str("sqlite::memory:").unwrap().create_if_missing(true);
let pool = SqlitePoolOptions::new().max_connections(5).connect_with(options).await.unwrap();
sqlx::migrate!("../migrations").run(&pool).await.unwrap();

let source_project_dir = Utf8PathBuf::from("../../../examples/spawn-and-move/");
let dojo_core_path = Utf8PathBuf::from("../../dojo-core");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind = "DojoContract"
class_hash = "0x7b394d087b5cf4f3b740253c591138bf98d177ef0d9b5c00b0477a145f3fb75"
original_class_hash = "0x7b394d087b5cf4f3b740253c591138bf98d177ef0d9b5c00b0477a145f3fb75"
base_class_hash = "0x0"
abi = "manifests/dev/abis/base/contracts/dojo_examples-actions-40b6994c.json"
abi = "manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json"
reads = []
writes = []
computed = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind = "DojoContract"
class_hash = "0x6a55b3f612b0bc5e55603d805c188c0220aa53017fd2f690abe8bad50867ef2"
original_class_hash = "0x6a55b3f612b0bc5e55603d805c188c0220aa53017fd2f690abe8bad50867ef2"
base_class_hash = "0x0"
abi = "manifests/dev/abis/base/contracts/dojo_examples-mock_token-31599eb2.json"
abi = "manifests/dev/base/abis/contracts/dojo_examples-mock_token-31599eb2.json"
reads = []
writes = []
computed = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind = "DojoContract"
class_hash = "0x3a61e2fafaee0ca4ed5166fbb417270563b4d8518cd1e086733cc346e8ea6b9"
original_class_hash = "0x3a61e2fafaee0ca4ed5166fbb417270563b4d8518cd1e086733cc346e8ea6b9"
base_class_hash = "0x0"
abi = "manifests/dev/abis/base/contracts/dojo_examples-others-61de2c18.json"
abi = "manifests/dev/base/abis/contracts/dojo_examples-others-61de2c18.json"
reads = []
writes = []
computed = []
Expand Down
2 changes: 1 addition & 1 deletion examples/spawn-and-move/manifests/dev/base/dojo-base.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x22f3e55b61d86c2ac5239fa3b3b8761f26b9a5c0b5f61ddbd5d756ced498b46"
original_class_hash = "0x22f3e55b61d86c2ac5239fa3b3b8761f26b9a5c0b5f61ddbd5d756ced498b46"
abi = "manifests/dev/abis/base/dojo-base.json"
abi = "manifests/dev/base/abis/dojo-base.json"
tag = "dojo-base"
manifest_name = "dojo-base"
2 changes: 1 addition & 1 deletion examples/spawn-and-move/manifests/dev/base/dojo-world.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind = "Class"
class_hash = "0x1498dd1197805ec05d37da956d0fc568023a4c25578b0523b4f4f0d0e4f16c2"
original_class_hash = "0x1498dd1197805ec05d37da956d0fc568023a4c25578b0523b4f4f0d0e4f16c2"
abi = "manifests/dev/abis/base/dojo-world.json"
abi = "manifests/dev/base/abis/dojo-world.json"
tag = "dojo-world"
manifest_name = "dojo-world"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x1ba185f6f09a7a73f32e6e1d6767c182abe5635d3107c79b64dfdb9f25b3c3a"
original_class_hash = "0x1ba185f6f09a7a73f32e6e1d6767c182abe5635d3107c79b64dfdb9f25b3c3a"
abi = "manifests/dev/abis/base/models/dojo_examples-ContractInitialized-376b7bd6.json"
abi = "manifests/dev/base/abis/models/dojo_examples-ContractInitialized-376b7bd6.json"
tag = "dojo_examples-ContractInitialized"
manifest_name = "dojo_examples-ContractInitialized-376b7bd6"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x6d9703c6df6af6f097cfdd2e7f838f4fd2b2f2ae27bf27e76065ffb903f9c9b"
original_class_hash = "0x6d9703c6df6af6f097cfdd2e7f838f4fd2b2f2ae27bf27e76065ffb903f9c9b"
abi = "manifests/dev/abis/base/models/dojo_examples-Message-1bb1d226.json"
abi = "manifests/dev/base/abis/models/dojo_examples-Message-1bb1d226.json"
tag = "dojo_examples-Message"
manifest_name = "dojo_examples-Message-1bb1d226"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind = "DojoModel"
class_hash = "0x637d1d7966a14967047e31f3512c694e32b4d6a6dda4afe4b225a8b6f8f3519"
original_class_hash = "0x637d1d7966a14967047e31f3512c694e32b4d6a6dda4afe4b225a8b6f8f3519"
abi = "manifests/dev/abis/base/models/dojo_examples-MockToken-38903c7c.json"
abi = "manifests/dev/base/abis/models/dojo_examples-MockToken-38903c7c.json"
tag = "dojo_examples-MockToken"
manifest_name = "dojo_examples-MockToken-38903c7c"

Expand Down
Loading
Loading