build_ios_config_only_test.dart 2.76 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';

import '../src/common.dart';
10
import 'test_utils.dart';
11 12 13

void main() {
  test('flutter build ios --config only updates generated xcconfig file without performing build', () async {
14 15 16 17 18 19
    final String workingDirectory = fileSystem.path.join(
      getFlutterRoot(),
      'dev',
      'integration_tests',
      'flutter_gallery',
    );
20
    final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
21

22
    await processManager.run(<String>[
23
      flutterBin,
24
      ...getLocalEngineArguments(),
25
      'clean',
26
    ], workingDirectory: workingDirectory);
27
    final List<String> buildCommand = <String>[
28
      flutterBin,
29
      ...getLocalEngineArguments(),
30 31 32 33 34 35 36
      'build',
      'ios',
      '--config-only',
      '--release',
      '--obfuscate',
      '--split-debug-info=info',
      '--no-codesign',
37 38
    ];
    final ProcessResult firstRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
39

40
    printOnFailure('Output of flutter build ios:');
41 42
    final String firstRunStdout = firstRunResult.stdout.toString();
    printOnFailure('First run stdout: $firstRunStdout');
43
    printOnFailure('First run stderr: ${firstRunResult.stderr}');
44

45 46
    expect(firstRunResult.exitCode, 0);
    expect(firstRunStdout, contains('Running pod install'));
47

48 49 50 51 52 53
    final File generatedConfig = fileSystem.file(fileSystem.path.join(
      workingDirectory,
      'ios',
      'Flutter',
      'Generated.xcconfig',
    ));
54 55 56

    // Config is updated if command succeeded.
    expect(generatedConfig, exists);
57
    expect(generatedConfig.readAsStringSync(), contains('DART_OBFUSCATION=true'));
58 59

    // file that only exists if app was fully built.
60 61 62 63 64 65 66 67
    final File frameworkPlist = fileSystem.file(fileSystem.path.join(
      workingDirectory,
      'build',
      'ios',
      'iphoneos',
      'Runner.app',
      'AppFrameworkInfo.plist',
    ));
68 69

    expect(frameworkPlist, isNot(exists));
70 71 72 73 74

    // Run again with no changes.
    final ProcessResult secondRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);
    final String secondRunStdout = secondRunResult.stdout.toString();
    printOnFailure('Second run stdout: $secondRunStdout');
75
    printOnFailure('Second run stderr: ${secondRunResult.stderr}');
76 77 78 79

    expect(secondRunResult.exitCode, 0);
    // Do not run "pod install" when nothing changes.
    expect(secondRunStdout, isNot(contains('pod install')));
80
  }, skip: !platform.isMacOS); // [intended] iOS builds only work on macos.
81
}