@@ -497,6 +497,7 @@ fn ensure_init(
497497 app : & App ,
498498 project_dir : PathBuf ,
499499 target : Target ,
500+ noninteractive : bool ,
500501) -> Result < ( ) > {
501502 if !project_dir. exists ( ) {
502503 crate :: error:: bail!(
@@ -527,32 +528,83 @@ fn ensure_init(
527528 }
528529 #[ cfg( target_os = "macos" ) ]
529530 Target :: Ios => {
530- let pbxproj_contents = read_to_string (
531- project_dir
532- . join ( format ! ( "{}.xcodeproj" , app. name( ) ) )
533- . join ( "project.pbxproj" ) ,
534- )
535- . fs_context (
536- "missing project.pbxproj file in the Xcode project directory" ,
537- project_dir
538- . join ( format ! ( "{}.xcodeproj" , app. name( ) ) )
539- . join ( "project.pbxproj" ) ,
540- ) ?;
541-
542- if !( pbxproj_contents. contains ( ios:: LIB_OUTPUT_FILE_NAME )
543- || pbxproj_contents. contains ( & format ! ( "lib{}.a" , app. lib_name( ) ) ) )
544- {
545- project_outdated_reasons
546- . push ( "you have modified your [lib.name] or [package.name] in the Cargo.toml file" ) ;
531+ let xcodeproj_path = crate :: helpers:: fs:: find_in_directory ( & project_dir, "*.xcodeproj" )
532+ . with_context ( || format ! ( "failed to locate xcodeproj in {}" , project_dir. display( ) ) ) ?;
533+
534+ let xcodeproj_name = xcodeproj_path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
535+ if xcodeproj_name != app. name ( ) {
536+ let rename_targets = vec ! [
537+ // first rename the entitlements
538+ (
539+ format!( "{xcodeproj_name}_iOS/{xcodeproj_name}_iOS.entitlements" ) ,
540+ format!( "{xcodeproj_name}_iOS/{}_iOS.entitlements" , app. name( ) ) ,
541+ ) ,
542+ // then the scheme folder
543+ (
544+ format!( "{xcodeproj_name}_iOS" ) ,
545+ format!( "{}_iOS" , app. name( ) ) ,
546+ ) ,
547+ (
548+ format!( "{xcodeproj_name}.xcodeproj" ) ,
549+ format!( "{}.xcodeproj" , app. name( ) ) ,
550+ ) ,
551+ ] ;
552+ let rename_info = rename_targets
553+ . iter ( )
554+ . map ( |( from, to) | format ! ( "- {from} to {to}" ) )
555+ . collect :: < Vec < _ > > ( )
556+ . join ( "\n " ) ;
557+ log:: error!(
558+ "you have modified your package name from {current_project_name} to {new_project_name}\n We need to apply the name change to the Xcode project, renaming:\n {rename_info}" ,
559+ new_project_name = app. name( ) ,
560+ current_project_name = xcodeproj_name,
561+ ) ;
562+ if noninteractive {
563+ project_outdated_reasons
564+ . push ( "you have modified your [lib.name] or [package.name] in the Cargo.toml file" ) ;
565+ } else {
566+ let confirm = crate :: helpers:: prompts:: confirm (
567+ "Do you want to apply the name change to the Xcode project?" ,
568+ Some ( true ) ,
569+ )
570+ . unwrap_or_default ( ) ;
571+ if confirm {
572+ for ( from, to) in rename_targets {
573+ std:: fs:: rename ( project_dir. join ( & from) , project_dir. join ( & to) )
574+ . with_context ( || format ! ( "failed to rename {from} to {to}" ) ) ?;
575+ }
576+
577+ // update scheme name in pbxproj
578+ // identifier / product name are synchronized by the dev/build commands
579+ let pbxproj_path =
580+ project_dir. join ( format ! ( "{}.xcodeproj/project.pbxproj" , app. name( ) ) ) ;
581+ let pbxproj_contents = std:: fs:: read_to_string ( & pbxproj_path)
582+ . with_context ( || format ! ( "failed to read {}" , pbxproj_path. display( ) ) ) ?;
583+ std:: fs:: write (
584+ & pbxproj_path,
585+ pbxproj_contents. replace (
586+ & format ! ( "{xcodeproj_name}_iOS" ) ,
587+ & format ! ( "{}_iOS" , app. name( ) ) ,
588+ ) ,
589+ )
590+ . with_context ( || format ! ( "failed to write {}" , pbxproj_path. display( ) ) ) ?;
591+ } else {
592+ project_outdated_reasons
593+ . push ( "you have modified your [lib.name] or [package.name] in the Cargo.toml file" ) ;
594+ }
595+ }
547596 }
597+
598+ // note: pbxproj is synchronied by the dev/build commands
548599 }
549600 }
550601
551602 if !project_outdated_reasons. is_empty ( ) {
552603 let reason = project_outdated_reasons. join ( " and " ) ;
553604 crate :: error:: bail!(
554- "{} project directory is outdated because {reason}. Please run `tauri {} init` and try again." ,
605+ "{} project directory is outdated because {reason}. Please delete {}, run `tauri {} init` and try again." ,
555606 target. ide_name( ) ,
607+ project_dir. display( ) ,
556608 target. command_name( ) ,
557609 )
558610 }
0 commit comments