diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d29633e414dc2..782384db2b520 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest if: ${{ github.repository == 'flutter/flutter' }} steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b - name: ./bin/flutter test --coverage run: pushd packages/flutter;../../bin/flutter test --coverage -j 1;popd - name: upload coverage diff --git a/.github/workflows/easy-cp.yml b/.github/workflows/easy-cp.yml index 62caf93cc7580..36300f09eab84 100644 --- a/.github/workflows/easy-cp.yml +++ b/.github/workflows/easy-cp.yml @@ -30,7 +30,7 @@ jobs: run: | echo "COMMIT_SHA=$(echo ${{ github.event.pull_request.merge_commit_sha }})" >> $GITHUB_ENV - name: Checkout Flutter Repo - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b with: repository: flutteractionsbot/flutter path: flutter diff --git a/.github/workflows/minimal.yml b/.github/workflows/minimal.yml index c20c33e816f66..ade82e4918869 100644 --- a/.github/workflows/minimal.yml +++ b/.github/workflows/minimal.yml @@ -18,7 +18,7 @@ jobs: pull-requests: write steps: - name: Checkout Flutter Repo - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b with: repository: flutter/flutter token: ${{ github.token }} diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 61cf485b52c46..4842a632dd886 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -23,7 +23,7 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 + uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b with: persist-credentials: false diff --git a/packages/flutter_tools/lib/src/ios/migrations/uiapplicationmain_deprecation_migration.dart b/packages/flutter_tools/lib/src/ios/migrations/uiapplicationmain_deprecation_migration.dart new file mode 100644 index 0000000000000..c2fbbcf541721 --- /dev/null +++ b/packages/flutter_tools/lib/src/ios/migrations/uiapplicationmain_deprecation_migration.dart @@ -0,0 +1,51 @@ +// 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 '../../base/file_system.dart'; +import '../../base/project_migrator.dart'; +import '../../xcode_project.dart'; + +const String _appDelegateFileBefore = r''' +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { +'''; + +const String _appDelegateFileAfter = r''' +@main +@objc class AppDelegate: FlutterAppDelegate { +'''; + +/// Replace the deprecated `@UIApplicationMain` attribute with `@main`. +/// +/// See: +/// https://github.com/apple/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md +class UIApplicationmMainDeprecationMigration extends ProjectMigrator { + UIApplicationmMainDeprecationMigration( + IosProject project, + super.logger, + ) : _appDelegateSwift = project.appDelegateSwift; + + final File _appDelegateSwift; + + @override + Future migrate() async { + // Skip this migration if the project uses Objective-C. + if (!_appDelegateSwift.existsSync()) { + return true; + } + + // Migrate the ios/Runner/AppDelegate.swift file. + final String original = _appDelegateSwift.readAsStringSync(); + final String migrated = original.replaceFirst(_appDelegateFileBefore, _appDelegateFileAfter); + if (original == migrated) { + return true; + } + + logger.printStatus( + 'ios/Runner/AppDelegate.swift does not use the @main attribute, updating.', + ); + _appDelegateSwift.writeAsStringSync(migrated); + return true; + } +} diff --git a/packages/flutter_tools/lib/src/xcode_project.dart b/packages/flutter_tools/lib/src/xcode_project.dart index 16defd560f476..9852592fa7e60 100644 --- a/packages/flutter_tools/lib/src/xcode_project.dart +++ b/packages/flutter_tools/lib/src/xcode_project.dart @@ -178,15 +178,15 @@ class IosProject extends XcodeBasedProject { File get appFrameworkInfoPlist => _flutterLibRoot.childDirectory('Flutter').childFile('AppFrameworkInfo.plist'); + /// The 'AppDelegate.swift' file of the host app. This file might not exist if the app project uses Objective-C. + File get appDelegateSwift => _editableDirectory.childDirectory('Runner').childFile('AppDelegate.swift'); + File get infoPlist => _editableDirectory.childDirectory('Runner').childFile('Info.plist'); Directory get symlinks => _flutterLibRoot.childDirectory('.symlinks'); - /// True, if the app project is using swift. - bool get isSwift { - final File appDelegateSwift = _editableDirectory.childDirectory('Runner').childFile('AppDelegate.swift'); - return appDelegateSwift.existsSync(); - } + /// True if the app project uses Swift. + bool get isSwift => appDelegateSwift.existsSync(); /// Do all plugins support arm64 simulators to run natively on an ARM Mac? Future pluginsSupportArmSimulator() async { diff --git a/packages/flutter_tools/templates/app_shared/ios-swift.tmpl/Runner/AppDelegate.swift b/packages/flutter_tools/templates/app_shared/ios-swift.tmpl/Runner/AppDelegate.swift index 9074fee9290db..626664468b891 100644 --- a/packages/flutter_tools/templates/app_shared/ios-swift.tmpl/Runner/AppDelegate.swift +++ b/packages/flutter_tools/templates/app_shared/ios-swift.tmpl/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import Flutter import UIKit -@UIApplicationMain +@main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication,