build_macos_config_only_test.dart 2.71 KB
Newer Older
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
// 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';
import 'test_utils.dart';

void main() {
  test('flutter build macOS --config only updates generated xcconfig file without performing build', () async {
    final String workingDirectory = fileSystem.path.join(
      getFlutterRoot(),
      'dev',
      'integration_tests',
      'flutter_gallery',
    );
    final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');

    await processManager.run(<String>[
      flutterBin,
      ...getLocalEngineArguments(),
      'clean',
    ], workingDirectory: workingDirectory);
    final List<String> buildCommand = <String>[
      flutterBin,
      ...getLocalEngineArguments(),
      'build',
      'macos',
      '--config-only',
      '--release',
      '--obfuscate',
      '--split-debug-info=info',
    ];
    final ProcessResult firstRunResult = await processManager.run(buildCommand, workingDirectory: workingDirectory);

    printOnFailure('Output of flutter build macOS:');
    final String firstRunStdout = firstRunResult.stdout.toString();
    printOnFailure('First run stdout: $firstRunStdout');
    printOnFailure('First run stderr: ${firstRunResult.stderr}');

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

    final File generatedConfig = fileSystem.file(fileSystem.path.join(
      workingDirectory,
      'macos',
      'Flutter',
      'ephemeral',
      'Flutter-Generated.xcconfig',
    ));

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

    // file that only exists if app was fully built.
    final File frameworkPlist = fileSystem.file(fileSystem.path.join(
      workingDirectory,
      'build',
      'macos',
      'Build',
      'Products',
      'Release',
      'App.framework',
      'Resources',
      'Info.plist'
    ));

    expect(frameworkPlist, isNot(exists));

    // 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');
    printOnFailure('Second run stderr: ${secondRunResult.stderr}');

    expect(secondRunResult.exitCode, 0);
  }, skip: !platform.isMacOS); // [intended] macOS builds only work on macos.
}