@@ -692,4 +692,114 @@ void main() {
692
692
);
693
693
}
694
694
}, skip: ! platform.isMacOS); // [intended] Swift Package Manager only works on macos.
695
+
696
+ test ('Migrated app builds after Swift Package Manager is turned off' , () async {
697
+ final Directory workingDirectory = fileSystem.systemTempDirectory
698
+ .createTempSync ('swift_package_manager_turned_off.' );
699
+ final String workingDirectoryPath = workingDirectory.path;
700
+ try {
701
+ await SwiftPackageManagerUtils .enableSwiftPackageManager (
702
+ flutterBin,
703
+ workingDirectoryPath,
704
+ );
705
+
706
+ // Create an app with a plugin and Swift Package Manager integration.
707
+ final String appDirectoryPath = await SwiftPackageManagerUtils .createApp (
708
+ flutterBin,
709
+ workingDirectoryPath,
710
+ iosLanguage: 'swift' ,
711
+ platform: 'ios' ,
712
+ usesSwiftPackageManager: true ,
713
+ options: < String > ['--platforms=ios' ],
714
+ );
715
+
716
+ final SwiftPackageManagerPlugin integrationTestPlugin =
717
+ SwiftPackageManagerUtils .integrationTestPlugin ('ios' );
718
+
719
+ SwiftPackageManagerUtils .addDependency (
720
+ appDirectoryPath: appDirectoryPath,
721
+ plugin: integrationTestPlugin,
722
+ );
723
+
724
+ // Build the app.
725
+ await SwiftPackageManagerUtils .buildApp (
726
+ flutterBin,
727
+ appDirectoryPath,
728
+ options: < String > ['ios' , '--config-only' , '-v' ],
729
+ );
730
+
731
+ // The app should have SwiftPM integration.
732
+ final File xcodeProjectFile = fileSystem
733
+ .directory (appDirectoryPath)
734
+ .childDirectory ('ios' )
735
+ .childDirectory ('Runner.xcodeproj' )
736
+ .childFile ('project.pbxproj' );
737
+ final File generatedManifestFile = fileSystem
738
+ .directory (appDirectoryPath)
739
+ .childDirectory ('ios' )
740
+ .childDirectory ('Flutter' )
741
+ .childDirectory ('ephemeral' )
742
+ .childDirectory ('Packages' )
743
+ .childDirectory ('FlutterGeneratedPluginSwiftPackage' )
744
+ .childFile ('Package.swift' );
745
+ final Directory cocoaPodsPluginFramework = fileSystem
746
+ .directory (appDirectoryPath)
747
+ .childDirectory ('build' )
748
+ .childDirectory ('ios' )
749
+ .childDirectory ('iphoneos' )
750
+ .childDirectory ('Runner.app' )
751
+ .childDirectory ('Frameworks' )
752
+ .childDirectory ('${integrationTestPlugin .pluginName }.framework' );
753
+
754
+ expect (xcodeProjectFile.existsSync (), isTrue);
755
+ expect (generatedManifestFile.existsSync (), isTrue);
756
+ expect (cocoaPodsPluginFramework.existsSync (), isFalse);
757
+
758
+ String xcodeProject = xcodeProjectFile.readAsStringSync ();
759
+ String generatedManifest = generatedManifestFile.readAsStringSync ();
760
+ final String generatedSwiftDependency = '''
761
+ dependencies: [
762
+ .package(name: "integration_test", path: "${integrationTestPlugin .swiftPackagePlatformPath }")
763
+ ],
764
+ ''' ;
765
+
766
+ expect (xcodeProject.contains ('FlutterGeneratedPluginSwiftPackage' ), isTrue);
767
+ expect (generatedManifest.contains (generatedSwiftDependency), isTrue);
768
+
769
+ // Disable Swift Package Manager and do a clean re-build of the app.
770
+ // The build should succeed.
771
+ await SwiftPackageManagerUtils .disableSwiftPackageManager (
772
+ flutterBin,
773
+ workingDirectoryPath,
774
+ );
775
+
776
+ await SwiftPackageManagerUtils .cleanApp (flutterBin, appDirectoryPath);
777
+
778
+ await SwiftPackageManagerUtils .buildApp (
779
+ flutterBin,
780
+ appDirectoryPath,
781
+ options: < String > ['ios' , '-v' ],
782
+ );
783
+
784
+ // The app should still have SwiftPM integration,
785
+ // but the plugin should be added using CocoaPods.
786
+ expect (xcodeProjectFile.existsSync (), isTrue);
787
+ expect (generatedManifestFile.existsSync (), isTrue);
788
+
789
+ xcodeProject = xcodeProjectFile.readAsStringSync ();
790
+ generatedManifest = generatedManifestFile.readAsStringSync ();
791
+ const String emptyDependencies = 'dependencies: [\n \n ],\n ' ;
792
+
793
+ expect (xcodeProject.contains ('FlutterGeneratedPluginSwiftPackage' ), isTrue);
794
+ expect (generatedManifest.contains ('integration_test' ), isFalse);
795
+ expect (generatedManifest.contains (emptyDependencies), isTrue);
796
+ expect (cocoaPodsPluginFramework.existsSync (), isTrue);
797
+ } finally {
798
+ await SwiftPackageManagerUtils .disableSwiftPackageManager (flutterBin, workingDirectoryPath);
799
+ ErrorHandlingFileSystem .deleteIfExists (
800
+ workingDirectory,
801
+ recursive: true ,
802
+ );
803
+ }
804
+ }, skip: ! platform.isMacOS); // [intended] Swift Package Manager only works on macos.
695
805
}
0 commit comments