diff --git a/packages/flutter_tools/lib/src/xcode_project.dart b/packages/flutter_tools/lib/src/xcode_project.dart index 36d49401789..dd483246342 100644 --- a/packages/flutter_tools/lib/src/xcode_project.dart +++ b/packages/flutter_tools/lib/src/xcode_project.dart @@ -20,21 +20,36 @@ import 'template.dart'; /// Represents an Xcode-based sub-project. /// /// This defines interfaces common to iOS and macOS projects. -abstract class XcodeBasedProject { +abstract class XcodeBasedProject extends FlutterProjectPlatform { + static const String _hostAppProjectName = 'Runner'; + /// The parent of this project. FlutterProject get parent; - /// Whether the subproject (either iOS or macOS) exists in the Flutter project. - bool existsSync(); + Directory get hostAppRoot; + + /// The default 'Info.plist' file of the host app. The developer can change this location in Xcode. + File get defaultHostInfoPlist => hostAppRoot.childDirectory(_hostAppProjectName).childFile('Info.plist'); /// The Xcode project (.xcodeproj directory) of the host app. - Directory get xcodeProject; + Directory get xcodeProject => hostAppRoot.childDirectory('$_hostAppProjectName.xcodeproj'); /// The 'project.pbxproj' file of [xcodeProject]. - File get xcodeProjectInfoFile; + File get xcodeProjectInfoFile => xcodeProject.childFile('project.pbxproj'); + + File get xcodeProjectWorkspaceData => + xcodeProject + .childDirectory('project.xcworkspace') + .childFile('contents.xcworkspacedata'); /// The Xcode workspace (.xcworkspace directory) of the host app. - Directory get xcodeWorkspace; + Directory get xcodeWorkspace => hostAppRoot.childDirectory('$_hostAppProjectName.xcworkspace'); + + /// Xcode workspace shared data directory for the host app. + Directory get xcodeWorkspaceSharedData => xcodeWorkspace.childDirectory('xcshareddata'); + + /// Xcode workspace shared workspace settings file for the host app. + File get xcodeWorkspaceSharedSettings => xcodeWorkspaceSharedData.childFile('WorkspaceSettings.xcsettings'); /// Contains definitions for FLUTTER_ROOT, LOCAL_ENGINE, and more flags for /// the Xcode build. @@ -50,20 +65,20 @@ abstract class XcodeBasedProject { File get generatedEnvironmentVariableExportScript; /// The CocoaPods 'Podfile'. - File get podfile; + File get podfile => hostAppRoot.childFile('Podfile'); /// The CocoaPods 'Podfile.lock'. - File get podfileLock; + File get podfileLock => hostAppRoot.childFile('Podfile.lock'); /// The CocoaPods 'Manifest.lock'. - File get podManifestLock; + File get podManifestLock => hostAppRoot.childDirectory('Pods').childFile('Manifest.lock'); } /// Represents the iOS sub-project of a Flutter project. /// /// Instances will reflect the contents of the `ios/` sub-folder of /// Flutter applications and the `.ios/` sub-folder of Flutter module projects. -class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { +class IosProject extends XcodeBasedProject { IosProject.fromFlutter(this.parent); @override @@ -74,12 +89,12 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { static final RegExp _productBundleIdPattern = RegExp(r'''^\s*PRODUCT_BUNDLE_IDENTIFIER\s*=\s*(["']?)(.*?)\1;\s*$'''); static const String _productBundleIdVariable = r'$(PRODUCT_BUNDLE_IDENTIFIER)'; - static const String _hostAppProjectName = 'Runner'; Directory get ephemeralModuleDirectory => parent.directory.childDirectory('.ios'); Directory get _editableDirectory => parent.directory.childDirectory('ios'); /// This parent folder of `Runner.xcodeproj`. + @override Directory get hostAppRoot { if (!isModule || _editableDirectory.existsSync()) { return _editableDirectory; @@ -110,42 +125,10 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { @override File get generatedEnvironmentVariableExportScript => _flutterLibRoot.childDirectory('Flutter').childFile('flutter_export_environment.sh'); - @override - File get podfile => hostAppRoot.childFile('Podfile'); - - @override - File get podfileLock => hostAppRoot.childFile('Podfile.lock'); - - @override - File get podManifestLock => hostAppRoot.childDirectory('Pods').childFile('Manifest.lock'); - - /// The default 'Info.plist' file of the host app. The developer can change this location in Xcode. - File get defaultHostInfoPlist => hostAppRoot.childDirectory(_hostAppProjectName).childFile('Info.plist'); - File get appFrameworkInfoPlist => _flutterLibRoot.childDirectory('Flutter').childFile('AppFrameworkInfo.plist'); Directory get symlinks => _flutterLibRoot.childDirectory('.symlinks'); - @override - Directory get xcodeProject => hostAppRoot.childDirectory('$_hostAppProjectName.xcodeproj'); - - @override - File get xcodeProjectInfoFile => xcodeProject.childFile('project.pbxproj'); - - File get xcodeProjectWorkspaceData => - xcodeProject - .childDirectory('project.xcworkspace') - .childFile('contents.xcworkspacedata'); - - @override - Directory get xcodeWorkspace => hostAppRoot.childDirectory('$_hostAppProjectName.xcworkspace'); - - /// Xcode workspace shared data directory for the host app. - Directory get xcodeWorkspaceSharedData => xcodeWorkspace.childDirectory('xcshareddata'); - - /// Xcode workspace shared workspace settings file for the host app. - File get xcodeWorkspaceSharedSettings => xcodeWorkspaceSharedData.childFile('WorkspaceSettings.xcsettings'); - /// Do all plugins support arm64 simulators to run natively on an ARM Mac? Future pluginsSupportArmSimulator() async { final Directory podXcodeProject = hostAppRoot @@ -249,9 +232,9 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { } } if (productName == null) { - globals.printTrace('FULL_PRODUCT_NAME not present, defaulting to $_hostAppProjectName'); + globals.printTrace('FULL_PRODUCT_NAME not present, defaulting to ${XcodeBasedProject._hostAppProjectName}'); } - return productName ?? '$_hostAppProjectName.app'; + return productName ?? '${XcodeBasedProject._hostAppProjectName}.app'; } /// The build settings for the host app of this project, as a detached map. @@ -451,7 +434,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { ? _flutterLibRoot .childDirectory('Flutter') .childDirectory('FlutterPluginRegistrant') - : hostAppRoot.childDirectory(_hostAppProjectName); + : hostAppRoot.childDirectory(XcodeBasedProject._hostAppProjectName); } File get pluginRegistrantHeader { @@ -493,7 +476,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { } /// The macOS sub project. -class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject { +class MacOSProject extends XcodeBasedProject { MacOSProject.fromFlutter(this.parent); @override @@ -502,17 +485,16 @@ class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject { @override String get pluginConfigKey => MacOSPlugin.kConfigKey; - static const String _hostAppProjectName = 'Runner'; + @override + bool existsSync() => hostAppRoot.existsSync(); @override - bool existsSync() => _macOSDirectory.existsSync(); - - Directory get _macOSDirectory => parent.directory.childDirectory('macos'); + Directory get hostAppRoot => parent.directory.childDirectory('macos'); /// The directory in the project that is managed by Flutter. As much as /// possible, files that are edited by Flutter tooling after initial project /// creation should live here. - Directory get managedDirectory => _macOSDirectory.childDirectory('Flutter'); + Directory get managedDirectory => hostAppRoot.childDirectory('Flutter'); /// The subdirectory of [managedDirectory] that contains files that are /// generated on the fly. All generated files that are not intended to be @@ -536,24 +518,6 @@ class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject { @override File get generatedEnvironmentVariableExportScript => ephemeralDirectory.childFile('flutter_export_environment.sh'); - @override - File get podfile => _macOSDirectory.childFile('Podfile'); - - @override - File get podfileLock => _macOSDirectory.childFile('Podfile.lock'); - - @override - File get podManifestLock => _macOSDirectory.childDirectory('Pods').childFile('Manifest.lock'); - - @override - Directory get xcodeProject => _macOSDirectory.childDirectory('$_hostAppProjectName.xcodeproj'); - - @override - File get xcodeProjectInfoFile => xcodeProject.childFile('project.pbxproj'); - - @override - Directory get xcodeWorkspace => _macOSDirectory.childDirectory('$_hostAppProjectName.xcworkspace'); - /// The file where the Xcode build will write the name of the built app. /// /// Ideally this will be replaced in the future with inspection of the Runner