@@ -48,6 +48,7 @@ pub struct UnpackOptions {
4848 pub output_directory : PathBuf ,
4949 pub env_name : String ,
5050 pub shell : Option < ShellEnum > ,
51+ pub allow_incompatible_target : bool ,
5152}
5253
5354/// Unpack a pixi environment.
@@ -62,7 +63,7 @@ pub async fn unpack(options: UnpackOptions) -> Result<()> {
6263 . await
6364 . map_err ( |e| anyhow ! ( "Could not unarchive: {}" , e) ) ?;
6465
65- validate_metadata_file ( unpack_dir. join ( PIXI_PACK_METADATA_PATH ) ) . await ?;
66+ validate_metadata_file ( unpack_dir. join ( PIXI_PACK_METADATA_PATH ) , options . allow_incompatible_target ) . await ?;
6667
6768 // HACK: The `Installer` and `Preparer` created below (in `install_pypi_packages`),
6869 // will utilize rayon for parallelism. By using rayon
@@ -139,7 +140,7 @@ async fn collect_packages_in_subdir(subdir: PathBuf) -> Result<FxHashMap<String,
139140 Ok ( conda_packages)
140141}
141142
142- async fn validate_metadata_file ( metadata_file : PathBuf ) -> Result < ( ) > {
143+ async fn validate_metadata_file ( metadata_file : PathBuf , allow_incompatible_target : bool ) -> Result < ( ) > {
143144 let metadata_contents = fs:: read_to_string ( & metadata_file)
144145 . await
145146 . map_err ( |e| anyhow ! ( "Could not read metadata file: {}" , e) ) ?;
@@ -150,7 +151,12 @@ async fn validate_metadata_file(metadata_file: PathBuf) -> Result<()> {
150151 anyhow:: bail!( "Unsupported pixi-pack version: {}" , metadata. version) ;
151152 }
152153 if metadata. platform != Platform :: current ( ) {
153- anyhow:: bail!( "The pack was created for a different platform" ) ;
154+ if allow_incompatible_target {
155+ tracing:: warn!( "The pack was created for a different platform, continuing because of flag --allow-incompatible-target" )
156+ }
157+ else {
158+ anyhow:: bail!( "The pack was created for a different platform, if you still wish to continue, use --allow-incompatible-target" ) ;
159+ }
154160 }
155161
156162 tracing:: debug!( "pack metadata: {:?}" , metadata) ;
@@ -461,7 +467,7 @@ mod tests {
461467 #[ tokio:: test]
462468 async fn test_metadata_file_valid ( metadata_file : NamedTempFile ) {
463469 assert ! (
464- validate_metadata_file( metadata_file. path( ) . to_path_buf( ) )
470+ validate_metadata_file( metadata_file. path( ) . to_path_buf( ) , false )
465471 . await
466472 . is_ok( )
467473 )
@@ -471,7 +477,7 @@ mod tests {
471477 #[ tokio:: test]
472478 async fn test_metadata_file_empty ( ) {
473479 assert ! (
474- validate_metadata_file( NamedTempFile :: new( ) . unwrap( ) . path( ) . to_path_buf( ) )
480+ validate_metadata_file( NamedTempFile :: new( ) . unwrap( ) . path( ) . to_path_buf( ) , false )
475481 . await
476482 . is_err( )
477483 )
@@ -480,15 +486,15 @@ mod tests {
480486 #[ rstest]
481487 #[ tokio:: test]
482488 async fn test_metadata_file_non_existent ( ) {
483- assert ! ( validate_metadata_file( PathBuf :: new( ) ) . await . is_err( ) )
489+ assert ! ( validate_metadata_file( PathBuf :: new( ) , false ) . await . is_err( ) )
484490 }
485491
486492 #[ rstest]
487493 #[ tokio:: test]
488494 async fn test_metadata_file_invalid_version (
489495 #[ with( "v0" . to_string( ) ) ] metadata_file : NamedTempFile ,
490496 ) {
491- let result = validate_metadata_file ( metadata_file. path ( ) . to_path_buf ( ) ) . await ;
497+ let result = validate_metadata_file ( metadata_file. path ( ) . to_path_buf ( ) , false ) . await ;
492498 let error = result. unwrap_err ( ) ;
493499 assert_eq ! ( error. to_string( ) , "Unsupported pixi-pack version: v0" ) ;
494500 }
@@ -499,11 +505,21 @@ mod tests {
499505 #[ with( DEFAULT_PIXI_PACK_VERSION . to_string( ) , other_platform( ) ) ]
500506 metadata_file : NamedTempFile ,
501507 ) {
502- let result = validate_metadata_file ( metadata_file. path ( ) . to_path_buf ( ) ) . await ;
508+ let result = validate_metadata_file ( metadata_file. path ( ) . to_path_buf ( ) , false ) . await ;
503509 let error = result. unwrap_err ( ) ;
504510 assert_eq ! (
505511 error. to_string( ) ,
506- "The pack was created for a different platform"
512+ "The pack was created for a different platform, if you still wish to continue, use --allow-incompatible-target"
513+ ) ;
514+ }
515+ #[ rstest]
516+ #[ tokio:: test]
517+ async fn test_metadata_file_wrong_platform_with_flag (
518+ #[ with( DEFAULT_PIXI_PACK_VERSION . to_string( ) , other_platform( ) ) ]
519+ metadata_file : NamedTempFile ,
520+ ) {
521+ assert ! ( validate_metadata_file( metadata_file. path( ) . to_path_buf( ) , true ) . await
522+ . is_ok( )
507523 ) ;
508524 }
509525}
0 commit comments