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

import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
10
import 'package:flutter_devicelab/framework/ios.dart';
11 12 13 14 15 16 17
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;

Future<void> main() async {
  await task(() async {
    try {
      bool foundProjectName = false;
18
      bool bitcode = false;
19
      await runProjectTest((FlutterProject flutterProject) async {
20
        section('Build app with with --obfuscate');
21 22 23 24 25 26 27 28
        await inDirectory(flutterProject.rootPath, () async {
          await flutter('build', options: <String>[
            'ios',
            '--release',
            '--obfuscate',
            '--split-debug-info=foo/',
          ]);
        });
29
        final String outputAppPath = path.join(
30
          flutterProject.rootPath,
31
          'build/ios/iphoneos/Runner.app',
32
        );
33 34 35 36 37 38 39
        final String outputAppFramework = path.join(
          flutterProject.rootPath,
          outputAppPath,
          'Frameworks/App.framework/App',
        );
        if (!File(outputAppFramework).existsSync()) {
          fail('Failed to produce expected output at $outputAppFramework');
40 41
        }

42 43
        section('Validate obfuscation');

44 45 46 47 48
        // Verify that an identifier from the Dart project code is not present
        // in the compiled binary.
        await inDirectory(flutterProject.rootPath, () async {
          final String response = await eval(
            'grep',
49
            <String>[flutterProject.name, outputAppFramework],
50 51 52 53 54 55
            canFail: true,
          );
          if (response.trim().contains('matches')) {
            foundProjectName = true;
          }
        });
56 57 58 59 60 61 62 63 64 65 66 67 68

        section('Validate bitcode');

        final String outputFlutterFramework = path.join(
          flutterProject.rootPath,
          outputAppPath,
          'Frameworks/Flutter.framework/Flutter',
        );

        if (!File(outputFlutterFramework).existsSync()) {
          fail('Failed to produce expected output at $outputFlutterFramework');
        }
        bitcode = await containsBitcode(outputFlutterFramework);
69
      });
70

71 72 73
      if (foundProjectName) {
        return TaskResult.failure('Found project name in obfuscated dart library');
      }
74 75 76 77 78 79 80
      // Archiving should contain a bitcode blob, but not building in release.
      // This mimics Xcode behavior and present a developer from having to install a
      // 300+MB app to test devices.
      if (bitcode) {
        return TaskResult.failure('Bitcode present in Flutter.framework');
      }

81 82 83 84 85 86 87 88
      return TaskResult.success(null);
    } on TaskResult catch (taskResult) {
      return taskResult;
    } catch (e) {
      return TaskResult.failure(e.toString());
    }
  });
}