cocoapod_utils.dart 1.81 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7 8
import '../base/fingerprint.dart';
import '../build_info.dart';
9
import '../cache.dart';
10
import '../flutter_plugins.dart';
11
import '../globals.dart' as globals;
12 13 14 15
import '../project.dart';

/// For a given build, determines whether dependencies have changed since the
/// last call to processPods, then calls processPods with that information.
16 17 18
Future<void> processPodsIfNeeded(
  XcodeBasedProject xcodeProject,
  String buildDirectory,
19
  BuildMode buildMode) async {
20 21
  final FlutterProject project = xcodeProject.parent;
  // Ensure that the plugin list is up to date, since hasPlugins relies on it.
22
  await refreshPluginsList(project, macOSPlatform: project.macos.existsSync());
23 24 25 26 27 28
  if (!(hasPlugins(project) || (project.isModule && xcodeProject.podfile.existsSync()))) {
    return;
  }
  // If the Xcode project, Podfile, or generated xcconfig have changed since
  // last run, pods should be updated.
  final Fingerprinter fingerprinter = Fingerprinter(
29
    fingerprintPath: globals.fs.path.join(buildDirectory, 'pod_inputs.fingerprint'),
30 31 32 33
    paths: <String>[
      xcodeProject.xcodeProjectInfoFile.path,
      xcodeProject.podfile.path,
      xcodeProject.generatedXcodePropertiesFile.path,
34 35 36 37 38 39 40
      globals.fs.path.join(
        Cache.flutterRoot,
        'packages',
        'flutter_tools',
        'bin',
        'podhelper.rb',
      ),
41
    ],
42 43
    fileSystem: globals.fs,
    logger: globals.logger,
44 45
  );

46
  final bool didPodInstall = await globals.cocoaPods.processPods(
47
    xcodeProject: xcodeProject,
48
    buildMode: buildMode,
49
    dependenciesChanged: !fingerprinter.doesFingerprintMatch(),
50 51
  );
  if (didPodInstall) {
52
    fingerprinter.writeFingerprint();
53 54
  }
}