// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import '../artifacts.dart'; import '../base/config.dart'; import '../base/file_system.dart'; import '../base/version.dart'; import '../build_info.dart'; import '../ios/xcodeproj.dart'; import '../macos/swift_packages.dart'; import '../platform_plugins.dart'; import '../project.dart'; /// Encapsulates platform-specific values for Darwin targets ([ios] and [macos]). /// /// This includes details like binary names, artifact locations, and deployment versions. enum FlutterDarwinPlatform { ios( binaryName: 'Flutter', targetPlatform: TargetPlatform.ios, swiftPackagePlatform: SwiftPackagePlatform.ios, artifactName: 'ios', artifactZip: 'artifacts.zip', xcframeworkArtifact: Artifact.flutterXcframework, sdks: [XcodeSdk.IPhoneOS, XcodeSdk.IPhoneSimulator], ), macos( binaryName: 'FlutterMacOS', targetPlatform: TargetPlatform.darwin, swiftPackagePlatform: SwiftPackagePlatform.macos, artifactName: 'darwin-x64', artifactZip: 'framework.zip', xcframeworkArtifact: Artifact.flutterMacOSXcframework, sdks: [XcodeSdk.MacOSX], ); const FlutterDarwinPlatform({ required this.binaryName, required this.targetPlatform, required this.swiftPackagePlatform, required String artifactName, required this.artifactZip, required this.xcframeworkArtifact, required this.sdks, }) : _artifactName = artifactName; /// The name of the binary file within the [xcframeworkArtifact]. final String binaryName; /// The corresponding [TargetPlatform] for the [FlutterDarwinPlatform]. final TargetPlatform targetPlatform; /// The corresponding [SwiftPackagePlatform] for the [FlutterDarwinPlatform]. final SwiftPackagePlatform swiftPackagePlatform; /// The name of the directory for the artifacts for the platform in the cache. final String _artifactName; /// The name of the zip file the xcframework artifacts are located in. final String artifactZip; /// The [Artifact] for the xcframework for the platform. final Artifact xcframeworkArtifact; /// A list of supported [XcodeSdk]. final List sdks; String get pluginConfigKey { return switch (this) { ios => IOSPlugin.kConfigKey, macos => MacOSPlugin.kConfigKey, }; } /// Minimum supported version for the platform. Version deploymentTarget() { return switch (this) { ios => Version(13, 0, null), macos => Version(10, 15, null), }; } /// Artifact name for the platform and [mode]. /// /// e.g. (`ios`, `ios-profile`, `ios-release`, `darwin-x64`, `darwin-x64-profile`, /// `darwin-x64-release`). String artifactName(BuildMode mode) { return mode == BuildMode.debug ? _artifactName : '$_artifactName-${mode.cliName}'; } /// Minimum supported Swift package version for the platform. SwiftPackageSupportedPlatform get supportedPackagePlatform { return SwiftPackageSupportedPlatform( platform: swiftPackagePlatform, version: deploymentTarget(), ); } /// Framework name with the `.framework` extension. /// /// e.g. (`Flutter.framework`, `FlutterMacOS.framework`). String get frameworkName => '$binaryName.framework'; /// Framework name with the `.xcframework` extension. /// /// e.g. (`Flutter.xcframework`, `FlutterMacOS.xcframework`). String get xcframeworkName => '$binaryName.xcframework'; /// Returns corresponding [FlutterDarwinPlatform] for the [targetPlatform]. static FlutterDarwinPlatform? fromTargetPlatform(TargetPlatform targetPlatform) { for (final FlutterDarwinPlatform darwinPlatform in FlutterDarwinPlatform.values) { if (targetPlatform == darwinPlatform.targetPlatform) { return darwinPlatform; } } return null; } /// Returns [FlutterDarwinPlatform] that matches the [name]. Returns null if no match is found. static FlutterDarwinPlatform? fromName(String name) { for (final FlutterDarwinPlatform darwinPlatform in FlutterDarwinPlatform.values) { if (name == darwinPlatform.name) { return darwinPlatform; } } return null; } /// Returns corresponding [XcodeBasedProject] for the platform. XcodeBasedProject xcodeProject(FlutterProject project) { return switch (this) { ios => project.ios, macos => project.macos, }; } /// Returns the corresponding build directory for the platform. String buildDirectory({Config? config, FileSystem? fileSystem}) { switch (this) { case FlutterDarwinPlatform.ios: return getIosBuildDirectory(config: config, fileSystem: fileSystem); case FlutterDarwinPlatform.macos: return getMacOSBuildDirectory(config: config, fileSystem: fileSystem); } } }