Skip to content

Commit

Permalink
removed BuildConfig::Default
Browse files Browse the repository at this point in the history
  • Loading branch information
mdgeorge4153 committed Mar 8, 2025
1 parent 7521848 commit eeee9fd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion crates/sui-json-rpc-tests/tests/balance_changes_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn test_dry_run_publish_with_mocked_coin() -> Result<(), anyhow::Error> {
move_package::package_hooks::register_package_hooks(Box::new(SuiPackageHooks));
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.extend(["tests", "data", "dummy_modules_publish"]);
let compiled_package = BuildConfig::default().build(&path)?;
let compiled_package = BuildConfig::new_for_testing().build(&path)?;
let compiled_modules_bytes = compiled_package
.get_package_base64(false)
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-json-rpc-tests/tests/rpc_server_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ async fn test_get_total_supply() -> Result<(), anyhow::Error> {
// Publish test coin package
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.extend(["tests", "data", "dummy_modules_publish"]);
let compiled_package = BuildConfig::default().build(&path)?;
let compiled_package = BuildConfig::new_for_testing().build(&path)?;
let compiled_modules_bytes =
compiled_package.get_package_base64(/* with_unpublished_deps */ false);
let dependencies = compiled_package.get_dependency_storage_package_ids();
Expand Down
47 changes: 20 additions & 27 deletions crates/sui-move-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use move_package::{
package_hooks::{PackageHooks, PackageIdentifier},
resolution::{dependency_graph::DependencyGraph, resolution_graph::ResolvedGraph},
source_package::parsed_manifest::{Dependencies, PackageName},
BuildConfig as MoveBuildConfig,
BuildConfig as MoveBuildConfig, LintFlag,
};
use move_package::{
source_package::parsed_manifest::OnChainInfo, source_package::parsed_manifest::SourceManifest,
Expand Down Expand Up @@ -110,17 +110,26 @@ pub struct BuildConfig {
impl BuildConfig {
pub fn new_for_testing() -> Self {
move_package::package_hooks::register_package_hooks(Box::new(SuiPackageHooks));
let mut build_config: Self = Default::default();

// Note: in the future, consider changing this to dependencies on the local system
// packages:
let implicit_dependencies = Dependencies::new();
let install_dir = tempfile::tempdir().unwrap().into_path();
let lock_file = install_dir.join("Move.lock");
build_config.config.install_dir = Some(install_dir);
build_config.config.lock_file = Some(lock_file);
build_config
.config
.lint_flag
.set(move_compiler::linters::LintLevel::None);
build_config.config.silence_warnings = true;
build_config
let config = MoveBuildConfig {
default_flavor: Some(move_compiler::editions::Flavor::Sui),
implicit_dependencies,
lock_file: Some(install_dir.join("Move.lock")),
install_dir: Some(install_dir),
lint_flag: LintFlag::LEVEL_NONE,
silence_warnings: true,
..MoveBuildConfig::default()
};
BuildConfig {
config,
run_bytecode_verifier: true,
print_diags_to_stderr: false,
chain_id: None,
}
}

pub fn new_for_testing_replace_addresses<I, S>(dep_original_addresses: I) -> Self
Expand Down Expand Up @@ -700,22 +709,6 @@ impl CompiledPackage {
}
}

impl Default for BuildConfig {
fn default() -> Self {
let config = MoveBuildConfig {
default_flavor: Some(move_compiler::editions::Flavor::Sui),
implicit_dependencies: Dependencies::new(),
..MoveBuildConfig::default()
};
BuildConfig {
config,
run_bytecode_verifier: true,
print_diags_to_stderr: false,
chain_id: None,
}
}
}

impl GetModule for CompiledPackage {
type Error = anyhow::Error;
// TODO: return ref here for better efficiency? Borrow checker + all_modules_map() make it hard to do this
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn init_static_initializers(_args: TokenStream, item: TokenStream) -> TokenS

register_package_hooks(Box::new(SuiPackageHooks {}));
let mut path = PathBuf::from(env!("SIMTEST_STATIC_INIT_MOVE"));
let mut build_config = BuildConfig::default();
let mut build_config = BuildConfig::new_for_testing();

build_config.config.install_dir = Some(TempDir::new().unwrap().into_path());
let _all_module_bytes = build_config
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-rosetta/tests/custom_coins/test_coin_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sui_json_rpc_types::{
SuiTransactionBlockResponse, SuiTransactionBlockResponseOptions,
};
use sui_keys::keystore::{AccountKeystore, Keystore};
use sui_move_build::BuildConfig as MoveBuildConfig;
use sui_move_build::BuildConfig;

use sui_sdk::SuiClient;
use sui_types::base_types::{ObjectID, ObjectRef, SuiAddress};
Expand Down Expand Up @@ -135,7 +135,7 @@ pub async fn init_package(
) -> Result<InitRet> {
let path_buf = base::reroot_path(Some(path))?;

let move_build_config = MoveBuildConfig::default();
let move_build_config = BuildConfig::new_for_testing();
let compiled_modules = move_build_config.build(path_buf.as_path())?;
let modules_bytes = compiled_modules.get_package_bytes(false);

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-source-validation/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ async fn successful_verification_with_bytecode_dep() -> anyhow::Result<()> {
let pkg_path = copy_published_package(&tempdir, "b", b_ref.0.into()).await?;

move_package::package_hooks::register_package_hooks(Box::new(SuiPackageHooks));
BuildConfig::default().build(&pkg_path).unwrap();
BuildConfig::new_for_testing().build(&pkg_path).unwrap();

fs::remove_dir_all(pkg_path.join("sources"))?;
};
Expand Down
6 changes: 3 additions & 3 deletions crates/sui/src/client_ptb/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use move_core_types::parsing::{
use move_core_types::{
account_address::AccountAddress, annotated_value::MoveTypeLayout, ident_str,
};
use move_package::BuildConfig;
use move_package::BuildConfig as MoveBuildConfig;
use std::{collections::BTreeMap, path::Path};
use sui_json::{is_receiving_argument, primitive_type};
use sui_json_rpc_types::{SuiObjectData, SuiObjectDataOptions, SuiRawData};
Expand Down Expand Up @@ -932,7 +932,7 @@ impl<'a> PTBBuilder<'a> {
}
ParsedPTBCommand::Publish(sp!(pkg_loc, package_path)) => {
let chain_id = self.reader.get_chain_identifier().await.ok();
let build_config = BuildConfig::default();
let build_config = MoveBuildConfig::default();
let package_path = Path::new(&package_path);
let build_config = resolve_lock_file_path(build_config.clone(), Some(package_path))
.map_err(|e| err!(pkg_loc, "{e}"))?;
Expand Down Expand Up @@ -1000,7 +1000,7 @@ impl<'a> PTBBuilder<'a> {
.await?;

let chain_id = self.reader.get_chain_identifier().await.ok();
let build_config = BuildConfig::default();
let build_config = MoveBuildConfig::default();
let package_path = Path::new(&package_path);
let build_config = resolve_lock_file_path(build_config.clone(), Some(package_path))
.map_err(|e| err!(path_loc, "{e}"))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/sui/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4256,7 +4256,7 @@ async fn test_tree_shaking_package_with_bytecode_deps() -> Result<(), anyhow::Er
}
move_package::package_hooks::register_package_hooks(Box::new(SuiPackageHooks));
// now build the package which will create the build folder and a new Move.lock file
BuildConfig::default().build(&package_path).unwrap();
BuildConfig::new_for_testing().build(&package_path).unwrap();
fs::remove_dir_all(package_path.join("sources"))?;

let (package_f_id, _) = test
Expand Down

0 comments on commit eeee9fd

Please sign in to comment.