mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
feat: refactor IosProject and MacOSProject to extends XcodeBasedProject to share common (#87930)
This commit is contained in:
parent
9e9ca69808
commit
047d35d8ba
@ -20,21 +20,36 @@ import 'template.dart';
|
|||||||
/// Represents an Xcode-based sub-project.
|
/// Represents an Xcode-based sub-project.
|
||||||
///
|
///
|
||||||
/// This defines interfaces common to iOS and macOS projects.
|
/// 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.
|
/// The parent of this project.
|
||||||
FlutterProject get parent;
|
FlutterProject get parent;
|
||||||
|
|
||||||
/// Whether the subproject (either iOS or macOS) exists in the Flutter project.
|
Directory get hostAppRoot;
|
||||||
bool existsSync();
|
|
||||||
|
/// 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.
|
/// 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].
|
/// 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.
|
/// 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
|
/// Contains definitions for FLUTTER_ROOT, LOCAL_ENGINE, and more flags for
|
||||||
/// the Xcode build.
|
/// the Xcode build.
|
||||||
@ -50,20 +65,20 @@ abstract class XcodeBasedProject {
|
|||||||
File get generatedEnvironmentVariableExportScript;
|
File get generatedEnvironmentVariableExportScript;
|
||||||
|
|
||||||
/// The CocoaPods 'Podfile'.
|
/// The CocoaPods 'Podfile'.
|
||||||
File get podfile;
|
File get podfile => hostAppRoot.childFile('Podfile');
|
||||||
|
|
||||||
/// The CocoaPods 'Podfile.lock'.
|
/// The CocoaPods 'Podfile.lock'.
|
||||||
File get podfileLock;
|
File get podfileLock => hostAppRoot.childFile('Podfile.lock');
|
||||||
|
|
||||||
/// The CocoaPods 'Manifest.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.
|
/// Represents the iOS sub-project of a Flutter project.
|
||||||
///
|
///
|
||||||
/// Instances will reflect the contents of the `ios/` sub-folder of
|
/// Instances will reflect the contents of the `ios/` sub-folder of
|
||||||
/// Flutter applications and the `.ios/` sub-folder of Flutter module projects.
|
/// 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);
|
IosProject.fromFlutter(this.parent);
|
||||||
|
|
||||||
@override
|
@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 final RegExp _productBundleIdPattern = RegExp(r'''^\s*PRODUCT_BUNDLE_IDENTIFIER\s*=\s*(["']?)(.*?)\1;\s*$''');
|
||||||
static const String _productBundleIdVariable = r'$(PRODUCT_BUNDLE_IDENTIFIER)';
|
static const String _productBundleIdVariable = r'$(PRODUCT_BUNDLE_IDENTIFIER)';
|
||||||
static const String _hostAppProjectName = 'Runner';
|
|
||||||
|
|
||||||
Directory get ephemeralModuleDirectory => parent.directory.childDirectory('.ios');
|
Directory get ephemeralModuleDirectory => parent.directory.childDirectory('.ios');
|
||||||
Directory get _editableDirectory => parent.directory.childDirectory('ios');
|
Directory get _editableDirectory => parent.directory.childDirectory('ios');
|
||||||
|
|
||||||
/// This parent folder of `Runner.xcodeproj`.
|
/// This parent folder of `Runner.xcodeproj`.
|
||||||
|
@override
|
||||||
Directory get hostAppRoot {
|
Directory get hostAppRoot {
|
||||||
if (!isModule || _editableDirectory.existsSync()) {
|
if (!isModule || _editableDirectory.existsSync()) {
|
||||||
return _editableDirectory;
|
return _editableDirectory;
|
||||||
@ -110,42 +125,10 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
|||||||
@override
|
@override
|
||||||
File get generatedEnvironmentVariableExportScript => _flutterLibRoot.childDirectory('Flutter').childFile('flutter_export_environment.sh');
|
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');
|
File get appFrameworkInfoPlist => _flutterLibRoot.childDirectory('Flutter').childFile('AppFrameworkInfo.plist');
|
||||||
|
|
||||||
Directory get symlinks => _flutterLibRoot.childDirectory('.symlinks');
|
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?
|
/// Do all plugins support arm64 simulators to run natively on an ARM Mac?
|
||||||
Future<bool> pluginsSupportArmSimulator() async {
|
Future<bool> pluginsSupportArmSimulator() async {
|
||||||
final Directory podXcodeProject = hostAppRoot
|
final Directory podXcodeProject = hostAppRoot
|
||||||
@ -249,9 +232,9 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (productName == null) {
|
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.
|
/// 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
|
? _flutterLibRoot
|
||||||
.childDirectory('Flutter')
|
.childDirectory('Flutter')
|
||||||
.childDirectory('FlutterPluginRegistrant')
|
.childDirectory('FlutterPluginRegistrant')
|
||||||
: hostAppRoot.childDirectory(_hostAppProjectName);
|
: hostAppRoot.childDirectory(XcodeBasedProject._hostAppProjectName);
|
||||||
}
|
}
|
||||||
|
|
||||||
File get pluginRegistrantHeader {
|
File get pluginRegistrantHeader {
|
||||||
@ -493,7 +476,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The macOS sub project.
|
/// The macOS sub project.
|
||||||
class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
class MacOSProject extends XcodeBasedProject {
|
||||||
MacOSProject.fromFlutter(this.parent);
|
MacOSProject.fromFlutter(this.parent);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -502,17 +485,16 @@ class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
|||||||
@override
|
@override
|
||||||
String get pluginConfigKey => MacOSPlugin.kConfigKey;
|
String get pluginConfigKey => MacOSPlugin.kConfigKey;
|
||||||
|
|
||||||
static const String _hostAppProjectName = 'Runner';
|
@override
|
||||||
|
bool existsSync() => hostAppRoot.existsSync();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool existsSync() => _macOSDirectory.existsSync();
|
Directory get hostAppRoot => parent.directory.childDirectory('macos');
|
||||||
|
|
||||||
Directory get _macOSDirectory => parent.directory.childDirectory('macos');
|
|
||||||
|
|
||||||
/// The directory in the project that is managed by Flutter. As much as
|
/// The directory in the project that is managed by Flutter. As much as
|
||||||
/// possible, files that are edited by Flutter tooling after initial project
|
/// possible, files that are edited by Flutter tooling after initial project
|
||||||
/// creation should live here.
|
/// 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
|
/// The subdirectory of [managedDirectory] that contains files that are
|
||||||
/// generated on the fly. All generated files that are not intended to be
|
/// generated on the fly. All generated files that are not intended to be
|
||||||
@ -536,24 +518,6 @@ class MacOSProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
|||||||
@override
|
@override
|
||||||
File get generatedEnvironmentVariableExportScript => ephemeralDirectory.childFile('flutter_export_environment.sh');
|
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.
|
/// 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
|
/// Ideally this will be replaced in the future with inspection of the Runner
|
||||||
|
Loading…
Reference in New Issue
Block a user