File size: 3,998 Bytes
a4ff84b
 
 
 
 
 
 
 
 
b0336a8
a4ff84b
b0336a8
a4ff84b
 
 
 
 
 
b0336a8
 
 
a4ff84b
b0336a8
 
 
 
 
 
 
 
a4ff84b
b0336a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4ff84b
 
b0336a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4ff84b
 
 
 
 
b0336a8
 
 
a4ff84b
 
 
 
 
b0336a8
 
 
 
 
 
 
a4ff84b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// 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/fingerprint.dart';
import '../build_info.dart';
import '../cache.dart';
import '../flutter_plugins.dart';
import '../globals.dart' as globals;
import '../plugins.dart';
import '../project.dart';
import 'swift_package_manager.dart';

/// For a given build, determines whether dependencies have changed since the
/// last call to processPods, then calls processPods with that information.
Future<void> processPodsIfNeeded(
  XcodeBasedProject xcodeProject,
  String buildDirectory,
  BuildMode buildMode, {
  bool forceCocoaPodsOnly = false,
}) async {
  final FlutterProject project = xcodeProject.parent;

  // When using Swift Package Manager, the Podfile may not exist so if there
  // isn't a Podfile, skip processing pods.
  if (xcodeProject.usesSwiftPackageManager &&
      !xcodeProject.podfile.existsSync() &&
      !forceCocoaPodsOnly) {
    return;
  }
  // Ensure that the plugin list is up to date, since hasPlugins relies on it.
  await refreshPluginsList(
    project,
    iosPlatform: project.ios.existsSync(),
    macOSPlatform: project.macos.existsSync(),
    forceCocoaPodsOnly: forceCocoaPodsOnly,

    // TODO(matanlurey): As-per discussion on https://github.com/flutter/flutter/pull/157393
    //  we'll assume that iOS/MacOS builds do not use or rely on the `.flutter-plugins` legacy
    //  file being generated. A better long-term fix would be not to have a call to refreshPluginsList
    //  at all, and instead have it implicitly run by the FlutterCommand instead. See
    //  https://github.com/flutter/flutter/issues/157391 for details.
    generateLegacyPlugins: false,
  );

  // If there are no plugins and if the project is a not module with an existing
  // podfile, skip processing pods
  if (!hasPlugins(project) && !(project.isModule && xcodeProject.podfile.existsSync())) {
    return;
  }

  // If forcing the use of only CocoaPods, but the project is using Swift
  // Package Manager, print a warning that CocoaPods will be used.
  if (forceCocoaPodsOnly && xcodeProject.usesSwiftPackageManager) {
    globals.logger.printWarning(
      'Swift Package Manager does not yet support this command. '
      'CocoaPods will be used instead.',
    );

    // If CocoaPods has been deintegrated, add it back.
    if (!xcodeProject.podfile.existsSync()) {
      await globals.cocoaPods?.setupPodfile(xcodeProject);
    }

    // Generate an empty Swift Package Manager manifest to invalidate fingerprinter
    final SwiftPackageManager swiftPackageManager = SwiftPackageManager(
      fileSystem: globals.localFileSystem,
      templateRenderer: globals.templateRenderer,
    );
    final SupportedPlatform platform =
        xcodeProject is IosProject ? SupportedPlatform.ios : SupportedPlatform.macos;

    await swiftPackageManager.generatePluginsSwiftPackage(const <Plugin>[], platform, xcodeProject);
  }

  // If the Xcode project, Podfile, generated plugin Swift Package, or podhelper
  // have changed since last run, pods should be updated.
  final Fingerprinter fingerprinter = Fingerprinter(
    fingerprintPath: globals.fs.path.join(buildDirectory, 'pod_inputs.fingerprint'),
    paths: <String>[
      xcodeProject.xcodeProjectInfoFile.path,
      xcodeProject.podfile.path,
      if (xcodeProject.flutterPluginSwiftPackageManifest.existsSync())
        xcodeProject.flutterPluginSwiftPackageManifest.path,
      globals.fs.path.join(Cache.flutterRoot!, 'packages', 'flutter_tools', 'bin', 'podhelper.rb'),
    ],
    fileSystem: globals.fs,
    logger: globals.logger,
  );

  final bool didPodInstall =
      await globals.cocoaPods?.processPods(
        xcodeProject: xcodeProject,
        buildMode: buildMode,
        dependenciesChanged: !fingerprinter.doesFingerprintMatch(),
      ) ??
      false;
  if (didPodInstall) {
    fingerprinter.writeFingerprint();
  }
}