native_ui_tests_ios32.dart 3.17 KB
Newer Older
1 2 3 4
// 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.

5 6
// @dart = 2.8

7 8
import 'dart:io';

9
import 'package:flutter_devicelab/framework/devices.dart';
10
import 'package:flutter_devicelab/framework/framework.dart';
11
import 'package:flutter_devicelab/framework/host_agent.dart';
12 13
import 'package:flutter_devicelab/framework/task_result.dart';
import 'package:flutter_devicelab/framework/utils.dart';
14
import 'package:path/path.dart' as path;
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

Future<void> main() async {
  deviceOperatingSystem = DeviceOperatingSystem.ios;

  await task(() async {
    final String projectDirectory = '${flutterDirectory.path}/dev/integration_tests/flutter_gallery';

    await inDirectory(projectDirectory, () async {
      section('Build clean');

      await flutter('clean');

      section('Build gallery app');

      await flutter(
        'build',
        options: <String>[
          'ios',
          '-v',
          '--release',
          '--config-only',
        ],
      );
    });

    section('Run platform unit tests');
41

42
    final Device device = await devices.workingDevice;
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
    final Map<String, String> environment = Platform.environment;
    // If not running on CI, inject the Flutter team code signing properties.
    final String developmentTeam = environment['FLUTTER_XCODE_DEVELOPMENT_TEAM'] ?? 'S8QB4VV633';
    final String codeSignStyle = environment['FLUTTER_XCODE_CODE_SIGN_STYLE'];
    final String provisioningProfile = environment['FLUTTER_XCODE_PROVISIONING_PROFILE_SPECIFIER'];

    final String resultBundleTemp = Directory.systemTemp.createTempSync('flutter_native_ui_tests_ios32_xcresult.').path;
    final String resultBundlePath = path.join(resultBundleTemp, 'result');
    final int testResultExit = await exec(
      'xcodebuild',
      <String>[
        '-workspace',
        'Runner.xcworkspace',
        '-scheme',
        'Runner',
        '-configuration',
        'Release',
        '-destination',
        'id=${device.deviceId}',
        '-resultBundlePath',
        resultBundlePath,
        'test',
        'COMPILER_INDEX_STORE_ENABLE=NO',
        'DEVELOPMENT_TEAM=$developmentTeam',
        if (codeSignStyle != null)
          'CODE_SIGN_STYLE=$codeSignStyle',
        if (provisioningProfile != null)
          'PROVISIONING_PROFILE_SPECIFIER=$provisioningProfile',
      ],
      workingDirectory: path.join(projectDirectory, 'ios'),
      canFail: true,
    );

    if (testResultExit != 0) {
      final Directory dumpDirectory = hostAgent.dumpDirectory;
      if (dumpDirectory != null) {
        // Zip the test results to the artifacts directory for upload.
        final String zipPath = path.join(dumpDirectory.path,
            'native_ui_tests_ios32-${DateTime.now().toLocal().toIso8601String()}.zip');
        await exec(
          'zip',
          <String>[
            '-r',
            '-9',
            zipPath,
            'result.xcresult',
          ],
          workingDirectory: resultBundleTemp,
          canFail: true, // Best effort to get the logs.
        );
      }

      return TaskResult.failure('Platform unit tests failed');
    }
97 98 99 100

    return TaskResult.success(null);
  });
}