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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// 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.
// @dart = 2.8
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/depfile.dart';
import 'package:flutter_tools/src/build_system/targets/assets.dart';
import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/devfs.dart';
import '../../../src/common.dart';
import '../../../src/context.dart';
void main() {
Environment environment;
FileSystem fileSystem;
setUp(() {
fileSystem = MemoryFileSystem.test();
environment = Environment.test(
fileSystem.currentDirectory,
processManager: FakeProcessManager.any(),
artifacts: Artifacts.test(),
fileSystem: fileSystem,
logger: BufferLogger.test(),
platform: FakePlatform(),
);
fileSystem.file(environment.buildDir.childFile('app.dill')).createSync(recursive: true);
fileSystem.file('packages/flutter_tools/lib/src/build_system/targets/assets.dart')
.createSync(recursive: true);
fileSystem.file('assets/foo/bar.png')
.createSync(recursive: true);
fileSystem.file('assets/wildcard/#bar.png')
.createSync(recursive: true);
fileSystem.file('.packages')
.createSync();
fileSystem.file('pubspec.yaml')
..createSync()
..writeAsStringSync('''
name: example
flutter:
assets:
- assets/foo/bar.png
- assets/wildcard/
''');
});
testUsingContext('includes LICENSE file inputs in dependencies', () async {
fileSystem.file('.packages')
.writeAsStringSync('foo:file:///bar/lib');
fileSystem.file('bar/LICENSE')
..createSync(recursive: true)
..writeAsStringSync('THIS IS A LICENSE');
await const CopyAssets().build(environment);
final File depfile = environment.buildDir.childFile('flutter_assets.d');
expect(depfile, exists);
final DepfileService depfileService = DepfileService(
logger: BufferLogger.test(),
fileSystem: fileSystem,
);
final Depfile dependencies = depfileService.parse(depfile);
expect(
dependencies.inputs.firstWhere((File file) => file.path == '/bar/LICENSE', orElse: () => null),
isNotNull,
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Copies files to correct asset directory', () async {
await const CopyAssets().build(environment);
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/AssetManifest.json'), exists);
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/FontManifest.json'), exists);
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/NOTICES.Z'), exists);
// See https://github.com/flutter/flutter/issues/35293
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/foo/bar.png'), exists);
// See https://github.com/flutter/flutter/issues/46163
expect(fileSystem.file('${environment.buildDir.path}/flutter_assets/assets/wildcard/%23bar.png'), exists);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Throws exception if pubspec contains missing files', () async {
fileSystem.file('pubspec.yaml')
..createSync()
..writeAsStringSync('''
name: example
flutter:
assets:
- assets/foo/bar2.png
''');
expect(() async => const CopyAssets().build(environment), throwsException);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testWithoutContext('processSkSLBundle returns null if there is no path '
'to the bundle', () {
expect(processSkSLBundle(
null,
targetPlatform: TargetPlatform.android,
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
engineVersion: null,
), isNull);
});
testWithoutContext('processSkSLBundle throws exception if bundle file is '
'missing', () {
expect(() => processSkSLBundle(
'does_not_exist.sksl',
targetPlatform: TargetPlatform.android,
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
engineVersion: null,
), throwsException);
});
testWithoutContext('processSkSLBundle throws exception if the bundle is not '
'valid JSON', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
fileSystem.file('bundle.sksl').writeAsStringSync('{');
expect(() => processSkSLBundle(
'bundle.sksl',
targetPlatform: TargetPlatform.android,
fileSystem: fileSystem,
logger: logger,
engineVersion: null,
), throwsException);
expect(logger.errorText, contains('was not a JSON object'));
});
testWithoutContext('processSkSLBundle throws exception if the bundle is not '
'a JSON object', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
fileSystem.file('bundle.sksl').writeAsStringSync('[]');
expect(() => processSkSLBundle(
'bundle.sksl',
targetPlatform: TargetPlatform.android,
fileSystem: fileSystem,
logger: logger,
engineVersion: null,
), throwsException);
expect(logger.errorText, contains('was not a JSON object'));
});
testWithoutContext('processSkSLBundle throws an exception if the engine '
'revision is different', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
fileSystem.file('bundle.sksl').writeAsStringSync(json.encode(
<String, String>{
'engineRevision': '1'
}
));
expect(() => processSkSLBundle(
'bundle.sksl',
targetPlatform: TargetPlatform.android,
fileSystem: fileSystem,
logger: logger,
engineVersion: '2',
), throwsException);
expect(logger.errorText, contains('Expected Flutter 1, but found 2'));
});
testWithoutContext('processSkSLBundle warns if the bundle target platform is '
'different from the current target', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
fileSystem.file('bundle.sksl').writeAsStringSync(json.encode(
<String, Object>{
'engineRevision': '2',
'platform': 'fuchsia-arm64',
'data': <String, Object>{}
}
));
final DevFSContent content = processSkSLBundle(
'bundle.sksl',
targetPlatform: TargetPlatform.android,
fileSystem: fileSystem,
logger: logger,
engineVersion: '2',
);
expect(await content.contentsAsBytes(), utf8.encode('{"data":{}}'));
expect(logger.errorText, contains('This may lead to less efficient shader caching'));
});
testWithoutContext('processSkSLBundle does not warn and produces bundle', () async {
final FileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
fileSystem.file('bundle.sksl').writeAsStringSync(json.encode(
<String, Object>{
'engineRevision': '2',
'platform': 'android',
'data': <String, Object>{}
}
));
final DevFSContent content = processSkSLBundle(
'bundle.sksl',
targetPlatform: TargetPlatform.android,
fileSystem: fileSystem,
logger: logger,
engineVersion: '2',
);
expect(await content.contentsAsBytes(), utf8.encode('{"data":{}}'));
expect(logger.errorText, isEmpty);
});
}