@@ -26,7 +26,7 @@ use move_command_line_common::{
26
26
use move_compiler:: {
27
27
compiled_unit:: AnnotatedCompiledUnit ,
28
28
diagnostics:: { Diagnostics , FilesSourceText } ,
29
- shared:: NumericalAddress ,
29
+ shared:: { NumberFormat , NumericalAddress } ,
30
30
FullyCompiledProgram ,
31
31
} ;
32
32
use move_core_types:: {
@@ -221,7 +221,7 @@ pub trait MoveTestAdapter<'a>: Sized {
221
221
let state = self . compiled_state ( ) ;
222
222
let ( modules, warnings_opt) = match syntax {
223
223
SyntaxChoice :: Source => {
224
- let ( units, warnings_opt) = compile_source_units ( state, data. path ( ) ) ?;
224
+ let ( units, warnings_opt) = compile_source_units ( state, data. path ( ) , None ) ?;
225
225
let modules = units
226
226
. into_iter ( )
227
227
. map ( |unit| match unit {
@@ -283,7 +283,8 @@ pub trait MoveTestAdapter<'a>: Sized {
283
283
let state = self . compiled_state ( ) ;
284
284
let ( script, warning_opt) = match syntax {
285
285
SyntaxChoice :: Source => {
286
- let ( mut units, warning_opt) = compile_source_units ( state, data. path ( ) ) ?;
286
+ let ( mut units, warning_opt) =
287
+ compile_source_units ( state, data. path ( ) , None ) ?;
287
288
let len = units. len ( ) ;
288
289
if len != 1 {
289
290
panic ! ( "Invalid input. Expected 1 compiled unit but got {}" , len)
@@ -540,6 +541,7 @@ impl<'a> CompiledState<'a> {
540
541
pub fn compile_source_units (
541
542
state : & CompiledState ,
542
543
file_name : impl AsRef < Path > ,
544
+ package_name : Option < String > ,
543
545
) -> Result < ( Vec < AnnotatedCompiledUnit > , Option < String > ) > {
544
546
fn rendered_diags ( files : & FilesSourceText , diags : Diagnostics ) -> Option < String > {
545
547
if diags. is_empty ( ) {
@@ -555,10 +557,20 @@ pub fn compile_source_units(
555
557
}
556
558
557
559
use move_compiler:: PASS_COMPILATION ;
560
+ let mut named_address_mapping = state. named_address_mapping . clone ( ) ;
561
+ if let Some ( package_name) = package_name {
562
+ // When a package_name is specified, create a fresh mapping for it by
563
+ // zero-ing the address for an existing mapping. Required for upgrading
564
+ // (i.e, re-publishing) an existing named package.
565
+ named_address_mapping. insert (
566
+ package_name,
567
+ NumericalAddress :: new ( AccountAddress :: ZERO . into_bytes ( ) , NumberFormat :: Hex ) ,
568
+ ) ;
569
+ } ;
558
570
let ( mut files, comments_and_compiler_res) = move_compiler:: Compiler :: from_files (
559
571
vec ! [ file_name. as_ref( ) . to_str( ) . unwrap( ) . to_owned( ) ] ,
560
572
state. source_files ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ,
561
- state . named_address_mapping . clone ( ) ,
573
+ named_address_mapping,
562
574
)
563
575
. set_pre_compiled_lib_opt ( state. pre_compiled_deps )
564
576
. set_flags ( move_compiler:: Flags :: empty ( ) . set_sources_shadow_deps ( true ) )
0 commit comments