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 5 6
// 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';
7
import '../cache.dart';
8
import '../flutter_plugins.dart';
9
import '../globals_null_migrated.dart' as globals;
10 11 12 13
import '../project.dart';

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

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