linux_test.dart 7.03 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
7
import 'package:flutter_tools/src/artifacts.dart';
8
import 'package:flutter_tools/src/base/logger.dart';
9
import 'package:flutter_tools/src/base/file_system.dart';
10
import 'package:flutter_tools/src/build_info.dart';
11
import 'package:flutter_tools/src/build_system/build_system.dart';
12
import 'package:flutter_tools/src/build_system/targets/assets.dart';
13
import 'package:flutter_tools/src/build_system/targets/common.dart';
14
import 'package:flutter_tools/src/build_system/targets/linux.dart';
15
import 'package:flutter_tools/src/convert.dart';
16

17
import '../../../src/common.dart';
18
import '../../../src/context.dart';
19 20

void main() {
21 22
  testWithoutContext('Copies files to correct cache directory, excluding unrelated code', () async {
    final FileSystem fileSystem = MemoryFileSystem.test();
23 24
    final Artifacts artifacts = Artifacts.test();
    setUpCacheDirectory(fileSystem, artifacts);
25 26 27 28 29 30

    final Environment testEnvironment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kBuildMode: 'debug',
      },
31
      artifacts: artifacts,
32 33 34 35 36 37 38 39
      processManager: FakeProcessManager.any(),
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
    );
    testEnvironment.buildDir.createSync(recursive: true);

    await const UnpackLinux().build(testEnvironment);

40
    expect(fileSystem.file('linux/flutter/ephemeral/libflutter_linux_gtk.so'), exists);
41 42 43 44 45 46

    final String headersPath = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
    expect(fileSystem.file('linux/flutter/ephemeral/$headersPath/foo.h'), exists);

    final String icuDataPath = artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_x64);
    expect(fileSystem.file('linux/flutter/ephemeral/$icuDataPath'), exists);
47
    expect(fileSystem.file('linux/flutter/ephemeral/unrelated-stuff'), isNot(exists));
48
  });
49

50 51
  // Only required for the test below that still depends on the context.
  FileSystem fileSystem;
52
  setUp(() {
53
    fileSystem = MemoryFileSystem.test();
54
  });
55

56 57 58 59 60 61
  testUsingContext('DebugBundleLinuxAssets copies artifacts to out directory', () async {
    final Environment testEnvironment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kBuildMode: 'debug',
      },
62 63 64
      inputs: <String, String>{
        kBundleSkSLPath: 'bundle.sksl',
      },
65
      artifacts: Artifacts.test(),
66 67 68
      processManager: FakeProcessManager.any(),
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
69
      engineVersion: '2',
70
    );
71

72
    testEnvironment.buildDir.createSync(recursive: true);
73 74

    // Create input files.
75
    testEnvironment.buildDir.childFile('app.dill').createSync();
76 77 78 79 80 81 82 83 84
    fileSystem.file('bundle.sksl').writeAsStringSync(json.encode(
      <String, Object>{
        'engineRevision': '2',
        'platform': 'ios',
        'data': <String, Object>{
          'A': 'B',
        }
      }
    ));
85

86 87
    await const DebugBundleLinuxAssets().build(testEnvironment);
    final Directory output = testEnvironment.outputDir
88 89
      .childDirectory('flutter_assets');

90 91
    expect(output.childFile('kernel_blob.bin'), exists);
    expect(output.childFile('AssetManifest.json'), exists);
92 93 94 95
    // SkSL
    expect(output.childFile('io.flutter.shaders.json'), exists);
    expect(output.childFile('io.flutter.shaders.json').readAsStringSync(), '{"data":{"A":"B"}}');

96 97 98 99 100
    // No bundled fonts
    expect(output.childFile('FontManifest.json'), isNot(exists));
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
101 102 103 104 105 106 107 108
  });

  testUsingContext('ProfileBundleLinuxAssets copies artifacts to out directory', () async {
    final Environment testEnvironment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kBuildMode: 'profile',
      },
109
      artifacts: Artifacts.test(),
110 111 112 113 114 115 116 117 118 119
      processManager: FakeProcessManager.any(),
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
    );

    testEnvironment.buildDir.createSync(recursive: true);

    // Create input files.
    testEnvironment.buildDir.childFile('app.so').createSync();

120
    await const LinuxAotBundle(AotElfProfile(TargetPlatform.linux_x64)).build(testEnvironment);
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    await const ProfileBundleLinuxAssets().build(testEnvironment);
    final Directory libDir = testEnvironment.outputDir
      .childDirectory('lib');
    final Directory assetsDir = testEnvironment.outputDir
      .childDirectory('flutter_assets');

    expect(libDir.childFile('libapp.so'), exists);
    expect(assetsDir.childFile('AssetManifest.json'), exists);
    // No bundled fonts
    expect(assetsDir.childFile('FontManifest.json'), isNot(exists));
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
  });

  testUsingContext('ReleaseBundleLinuxAssets copies artifacts to out directory', () async {
    final Environment testEnvironment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kBuildMode: 'release',
      },
142
      artifacts: Artifacts.test(),
143 144 145 146 147 148 149 150 151 152
      processManager: FakeProcessManager.any(),
      fileSystem: fileSystem,
      logger: BufferLogger.test(),
    );

    testEnvironment.buildDir.createSync(recursive: true);

    // Create input files.
    testEnvironment.buildDir.childFile('app.so').createSync();

153
    await const LinuxAotBundle(AotElfRelease(TargetPlatform.linux_x64)).build(testEnvironment);
154 155 156 157 158 159 160 161 162 163 164 165 166
    await const ReleaseBundleLinuxAssets().build(testEnvironment);
    final Directory libDir = testEnvironment.outputDir
      .childDirectory('lib');
    final Directory assetsDir = testEnvironment.outputDir
      .childDirectory('flutter_assets');

    expect(libDir.childFile('libapp.so'), exists);
    expect(assetsDir.childFile('AssetManifest.json'), exists);
    // No bundled fonts
    expect(assetsDir.childFile('FontManifest.json'), isNot(exists));
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => FakeProcessManager.any(),
167 168 169
  });
}

170 171 172 173 174 175 176 177 178
void setUpCacheDirectory(FileSystem fileSystem, Artifacts artifacts) {
  final String desktopPath = artifacts.getArtifactPath(Artifact.linuxDesktopPath, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
  fileSystem.file('$desktopPath/unrelated-stuff').createSync(recursive: true);
  fileSystem.file('$desktopPath/libflutter_linux_gtk.so').createSync(recursive: true);

  final String headersPath = artifacts.getArtifactPath(Artifact.linuxHeaders, platform: TargetPlatform.linux_x64, mode: BuildMode.debug);
  fileSystem.file('$headersPath/foo.h').createSync(recursive: true);

  fileSystem.file(artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.linux_x64)).createSync();
179
  fileSystem.file('packages/flutter_tools/lib/src/build_system/targets/linux.dart').createSync(recursive: true);
180
}