@@ -155,26 +155,25 @@ pub fn encode_contract_publish(
155155}
156156
157157pub fn setup_session_with_deployment (
158- manifest_path : & PathBuf ,
158+ manifest : & ProjectManifest ,
159159 deployment : & DeploymentSpecification ,
160160 contracts_asts : Option < HashMap < QualifiedContractIdentifier , ContractAST > > ,
161161) -> (
162162 Session ,
163163 BTreeMap < QualifiedContractIdentifier , Result < ExecutionResult , Vec < Diagnostic > > > ,
164164) {
165- let mut session = initiate_session_from_deployment ( & manifest_path ) ;
165+ let mut session = initiate_session_from_deployment ( & manifest ) ;
166166 update_session_with_genesis_accounts ( & mut session, deployment) ;
167167 let results =
168168 update_session_with_contracts_executions ( & mut session, deployment, contracts_asts) ;
169169 ( session, results)
170170}
171171
172- pub fn initiate_session_from_deployment ( manifest_path : & PathBuf ) -> Session {
173- let mut manifest = ProjectManifest :: from_path ( manifest_path) ;
172+ pub fn initiate_session_from_deployment ( manifest : & ProjectManifest ) -> Session {
174173 let mut settings = SessionSettings :: default ( ) ;
175174 settings
176175 . include_boot_contracts
177- . append ( & mut manifest. project . boot_contracts ) ;
176+ . append ( & mut manifest. project . boot_contracts . clone ( ) ) ;
178177 settings. repl_settings = manifest. repl_settings . clone ( ) ;
179178 settings. disk_cache_enabled = true ;
180179 let session = Session :: new ( settings) ;
@@ -319,11 +318,10 @@ pub fn update_session_with_contracts_analyses(
319318}
320319
321320pub fn get_absolute_deployment_path (
322- manifest_path : & PathBuf ,
321+ manifest : & ProjectManifest ,
323322 relative_deployment_path : & str ,
324323) -> PathBuf {
325- let mut base_path = manifest_path. clone ( ) ;
326- base_path. pop ( ) ;
324+ let mut base_path = manifest. get_project_root_dir ( ) ;
327325 let path = match PathBuf :: from_str ( relative_deployment_path) {
328326 Ok ( path) => path,
329327 Err ( _e) => {
@@ -335,11 +333,10 @@ pub fn get_absolute_deployment_path(
335333}
336334
337335pub fn get_default_deployment_path (
338- manifest_path : & PathBuf ,
336+ manifest : & ProjectManifest ,
339337 network : & Option < StacksNetwork > ,
340338) -> PathBuf {
341- let mut deployment_path = manifest_path. clone ( ) ;
342- deployment_path. pop ( ) ;
339+ let mut deployment_path = manifest. get_project_root_dir ( ) ;
343340 deployment_path. push ( "deployments" ) ;
344341 let file_path = match network {
345342 None => "default.test-plan.yaml" ,
@@ -352,7 +349,7 @@ pub fn get_default_deployment_path(
352349}
353350
354351pub fn read_or_default_to_generated_deployment (
355- manifest_path : & PathBuf ,
352+ manifest : & ProjectManifest ,
356353 network : & Option < StacksNetwork > ,
357354) -> Result <
358355 (
@@ -361,14 +358,14 @@ pub fn read_or_default_to_generated_deployment(
361358 ) ,
362359 String ,
363360> {
364- let default_deployment_file_path = get_default_deployment_path ( manifest_path , network) ;
361+ let default_deployment_file_path = get_default_deployment_path ( & manifest , network) ;
365362 let ( deployment, artifacts) = if default_deployment_file_path. exists ( ) {
366363 (
367- load_deployment ( manifest_path , & default_deployment_file_path) ?,
364+ load_deployment ( manifest , & default_deployment_file_path) ?,
368365 None ,
369366 )
370367 } else {
371- let ( deployment, artifacts) = generate_default_deployment ( manifest_path , network) ?;
368+ let ( deployment, artifacts) = generate_default_deployment ( manifest , network) ?;
372369 ( deployment, Some ( artifacts) )
373370 } ;
374371 Ok ( ( deployment, artifacts) )
@@ -407,13 +404,13 @@ pub enum TransactionStatus {
407404}
408405
409406pub fn apply_on_chain_deployment (
410- manifest_path : & PathBuf ,
407+ manifest : & ProjectManifest ,
411408 deployment : DeploymentSpecification ,
412409 deployment_event_tx : Sender < DeploymentEvent > ,
413410 deployment_command_rx : Receiver < DeploymentCommand > ,
414411 fetch_initial_nonces : bool ,
415412) {
416- let chain_config = ChainConfig :: from_manifest_path ( & manifest_path , & deployment. network ) ;
413+ let chain_config = ChainConfig :: from_manifest_path ( & manifest . path , & deployment. network ) ;
417414 let delay_between_checks: u64 = 10 ;
418415 // Load deployers, deployment_fee_rate
419416 // Check fee, balances and deployers
@@ -431,7 +428,7 @@ pub fn apply_on_chain_deployment(
431428 for ( _, account) in chain_config. accounts . iter ( ) {
432429 accounts_cached_nonces. insert ( account. address . clone ( ) , 0 ) ;
433430 }
434- }
431+ }
435432 }
436433
437434 for ( _, account) in chain_config. accounts . iter ( ) {
@@ -584,10 +581,9 @@ pub fn apply_on_chain_deployment(
584581 let _ = deployment_event_tx. send ( DeploymentEvent :: ProtocolDeployed ) ;
585582}
586583
587- pub fn check_deployments ( manifest_path : & PathBuf ) -> Result < ( ) , String > {
588- let mut base_path = manifest_path. clone ( ) ;
589- base_path. pop ( ) ;
590- let files = get_deployments_files ( manifest_path) ?;
584+ pub fn check_deployments ( manifest : & ProjectManifest ) -> Result < ( ) , String > {
585+ let mut base_path = manifest. get_project_root_dir ( ) ;
586+ let files = get_deployments_files ( manifest) ?;
591587 for ( path, relative_path) in files. into_iter ( ) {
592588 let _spec = match DeploymentSpecification :: from_config_file ( & path, & base_path) {
593589 Ok ( spec) => spec,
@@ -602,22 +598,21 @@ pub fn check_deployments(manifest_path: &PathBuf) -> Result<(), String> {
602598}
603599
604600pub fn load_deployment_if_exists (
605- manifest_path : & PathBuf ,
601+ manifest : & ProjectManifest ,
606602 network : & Option < StacksNetwork > ,
607603) -> Option < Result < DeploymentSpecification , String > > {
608- let default_deployment_path = get_default_deployment_path ( manifest_path , network) ;
604+ let default_deployment_path = get_default_deployment_path ( manifest , network) ;
609605 if !default_deployment_path. exists ( ) {
610606 return None ;
611607 }
612- Some ( load_deployment ( manifest_path , & default_deployment_path) )
608+ Some ( load_deployment ( manifest , & default_deployment_path) )
613609}
614610
615611pub fn load_deployment (
616- manifest_path : & PathBuf ,
612+ manifest : & ProjectManifest ,
617613 deployment_plan_path : & PathBuf ,
618614) -> Result < DeploymentSpecification , String > {
619- let mut base_path = manifest_path. clone ( ) ;
620- base_path. pop ( ) ;
615+ let base_path = manifest. get_project_root_dir ( ) ;
621616 let spec = match DeploymentSpecification :: from_config_file ( & deployment_plan_path, & base_path) {
622617 Ok ( spec) => spec,
623618 Err ( msg) => {
@@ -632,16 +627,15 @@ pub fn load_deployment(
632627 Ok ( spec)
633628}
634629
635- fn get_deployments_files ( manifest_path : & PathBuf ) -> Result < Vec < ( PathBuf , String ) > , String > {
636- let mut hooks_home = manifest_path. clone ( ) ;
637- hooks_home. pop ( ) ;
638- let suffix_len = hooks_home. to_str ( ) . unwrap ( ) . len ( ) + 1 ;
639- hooks_home. push ( "deployments" ) ;
640- let paths = match fs:: read_dir ( & hooks_home) {
630+ fn get_deployments_files ( manifest : & ProjectManifest ) -> Result < Vec < ( PathBuf , String ) > , String > {
631+ let mut project_dir = manifest. get_project_root_dir ( ) ;
632+ let suffix_len = project_dir. to_str ( ) . unwrap ( ) . len ( ) + 1 ;
633+ project_dir. push ( "deployments" ) ;
634+ let paths = match fs:: read_dir ( & project_dir) {
641635 Ok ( paths) => paths,
642636 Err ( _) => return Ok ( vec ! [ ] ) ,
643637 } ;
644- let mut hook_paths = vec ! [ ] ;
638+ let mut plans_paths = vec ! [ ] ;
645639 for path in paths {
646640 let file = path. unwrap ( ) . path ( ) ;
647641 let is_extension_valid = file
@@ -652,11 +646,11 @@ fn get_deployments_files(manifest_path: &PathBuf) -> Result<Vec<(PathBuf, String
652646 if let Some ( true ) = is_extension_valid {
653647 let relative_path = file. clone ( ) ;
654648 let ( _, relative_path) = relative_path. to_str ( ) . unwrap ( ) . split_at ( suffix_len) ;
655- hook_paths . push ( ( file, relative_path. to_string ( ) ) ) ;
649+ plans_paths . push ( ( file, relative_path. to_string ( ) ) ) ;
656650 }
657651 }
658652
659- Ok ( hook_paths )
653+ Ok ( plans_paths )
660654}
661655
662656pub fn write_deployment (
@@ -714,11 +708,10 @@ pub fn write_deployment(
714708}
715709
716710pub fn generate_default_deployment (
717- manifest_path : & PathBuf ,
711+ manifest : & ProjectManifest ,
718712 network : & Option < StacksNetwork > ,
719713) -> Result < ( DeploymentSpecification , DeploymentGenerationArtifacts ) , String > {
720- let mut project_config = ProjectManifest :: from_path ( & manifest_path) ;
721- let chain_config = ChainConfig :: from_manifest_path ( & manifest_path, & network) ;
714+ let chain_config = ChainConfig :: from_manifest_path ( & manifest. path , & network) ;
722715
723716 let node = match network {
724717 None => None ,
@@ -760,27 +753,25 @@ pub fn generate_default_deployment(
760753 let mut requirements_deps = HashMap :: new ( ) ;
761754
762755 let mut settings = SessionSettings :: default ( ) ;
763- let parser_version = project_config . repl_settings . parser_version ;
764- settings. repl_settings = project_config . repl_settings . clone ( ) ;
756+ let parser_version = manifest . repl_settings . parser_version ;
757+ settings. repl_settings = manifest . repl_settings . clone ( ) ;
765758 let session = Session :: new ( settings. clone ( ) ) ;
766759 let mut boot_contracts_asts = session. get_boot_contracts_asts ( ) ;
767760 requirements_asts. append ( & mut boot_contracts_asts) ;
768761
769762 // Only handle requirements in test environments
770- if project_config . project . requirements . is_some ( ) {
771- let default_cache_path = match PathBuf :: from_str ( & project_config . project . cache_dir ) {
763+ if let Some ( ref requirements ) = manifest . project . requirements {
764+ let default_cache_path = match PathBuf :: from_str ( & manifest . project . cache_dir ) {
772765 Ok ( path) => path,
773766 Err ( _) => return Err ( "unable to get default cache path" . to_string ( ) ) ,
774767 } ;
775768 let mut contracts = HashMap :: new ( ) ;
776769
777- let requirements = project_config. project . requirements . take ( ) . unwrap ( ) ;
778-
779770 // Load all the requirements
780771 // Some requirements are explicitly listed, some are discovered as we compute the ASTs.
781772 let mut queue = VecDeque :: new ( ) ;
782773
783- for requirement in requirements. into_iter ( ) {
774+ for requirement in requirements. iter ( ) {
784775 let contract_id = match QualifiedContractIdentifier :: parse ( & requirement. contract_id ) {
785776 Ok ( contract_id) => contract_id,
786777 Err ( _e) => {
@@ -810,10 +801,8 @@ pub fn generate_default_deployment(
810801 Some ( default_cache_path. clone ( ) ) ,
811802 ) ?;
812803
813- let path = if project_config. project . cache_dir_relative {
814- let mut manifest_dir = manifest_path. clone ( ) ;
815- manifest_dir. pop ( ) ;
816- let manifest_dir = format ! ( "{}" , manifest_dir. display( ) ) ;
804+ let path = if manifest. project . cache_dir_relative {
805+ let manifest_dir = format ! ( "{}" , manifest. get_project_root_dir( ) . display( ) ) ;
817806 let absolute_path = format ! ( "{}" , path. display( ) ) ;
818807 absolute_path[ ( manifest_dir. len ( ) + 1 ) ..] . to_string ( )
819808 } else {
@@ -901,7 +890,7 @@ pub fn generate_default_deployment(
901890
902891 let mut contracts = HashMap :: new ( ) ;
903892
904- for ( name, config) in project_config . contracts . iter ( ) {
893+ for ( name, config) in manifest . contracts . iter ( ) {
905894 let contract = match ContractName :: try_from ( name. to_string ( ) ) {
906895 Ok ( res) => res,
907896 Err ( _) => return Err ( format ! ( "unable to use {} as a valid contract name" , name) ) ,
@@ -934,8 +923,7 @@ pub fn generate_default_deployment(
934923 }
935924 } ;
936925
937- let mut path = manifest_path. clone ( ) ;
938- path. pop ( ) ;
926+ let mut path = manifest. get_project_root_dir ( ) ;
939927 path. push ( & config. path ) ;
940928 let source = match std:: fs:: read_to_string ( & path) {
941929 Ok ( code) => code,
@@ -1066,7 +1054,7 @@ pub fn generate_default_deployment(
10661054 genesis : if network. is_none ( ) {
10671055 Some ( GenesisSpecification {
10681056 wallets,
1069- contracts : project_config . project . boot_contracts . clone ( ) ,
1057+ contracts : manifest . project . boot_contracts . clone ( ) ,
10701058 } )
10711059 } else {
10721060 None
0 commit comments