ios_content_validation_test.dart 2.29 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
import 'dart:io';

7 8
import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
9
import 'package:flutter_devicelab/framework/task_result.dart';
10 11 12 13 14 15 16
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;

Future<void> main() async {
  await task(() async {
    try {
      await runProjectTest((FlutterProject flutterProject) async {
17 18 19 20 21 22 23 24
        section('Archive');

        await inDirectory(flutterProject.rootPath, () async {
          await flutter('build', options: <String>[
            'xcarchive',
          ]);
        });

25
        final String archivePath = path.join(
26 27 28 29 30
          flutterProject.rootPath,
          'build',
          'ios',
          'archive',
          'Runner.xcarchive',
31 32
        );

33 34 35
        final String products = path.join(archivePath, 'Products');

        checkDirectoryExists(products);
36 37 38 39 40 41

        checkDirectoryExists(path.join(
          archivePath,
          'dSYMs',
          'Runner.app.dSYM',
        ));
42 43 44 45 46
        final Directory applications = Directory(path.join(products, 'Applications'));

        final Directory appBundle = applications
            .listSync()
            .whereType<Directory>()
47
            .singleWhere((Directory directory) => path.extension(directory.path) == '.app');
48 49 50 51 52 53 54 55

        final String flutterFramework = path.join(
          appBundle.path,
          'Frameworks',
          'Flutter.framework',
          'Flutter',
        );
        // Exits 0 only if codesigned.
56 57
        final Future<String> flutterCodesign =
            eval('xcrun', <String>['codesign', '--verify', flutterFramework]);
58 59 60 61 62 63 64

        final String appFramework = path.join(
          appBundle.path,
          'Frameworks',
          'App.framework',
          'App',
        );
65 66 67 68
        final Future<String> appCodesign =
            eval('xcrun', <String>['codesign', '--verify', appFramework]);
        await flutterCodesign;
        await appCodesign;
69
      });
70

71 72 73 74 75 76 77 78
      return TaskResult.success(null);
    } on TaskResult catch (taskResult) {
      return taskResult;
    } catch (e) {
      return TaskResult.failure(e.toString());
    }
  });
}