forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartifacts.dart
More file actions
287 lines (264 loc) · 10.9 KB
/
artifacts.dart
File metadata and controls
287 lines (264 loc) · 10.9 KB
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Copyright 2017 The Chromium 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 'base/context.dart';
import 'base/file_system.dart';
import 'base/platform.dart';
import 'build_info.dart';
import 'globals.dart';
enum Artifact {
chromiumDebugKeyStore,
classesDexJar,
icudtlDat,
libskyShellSo,
dartIoEntriesTxt,
dartVmEntryPointsTxt,
dartVmEntryPointsAndroidTxt,
genSnapshot,
skyShell,
skySnapshot,
snapshotDart,
flutterFramework,
vmSnapshotData,
isolateSnapshotData
}
String _artifactToFileName(Artifact artifact) {
switch (artifact) {
case Artifact.chromiumDebugKeyStore:
return 'chromium-debug.keystore';
case Artifact.classesDexJar:
return 'classes.dex.jar';
case Artifact.icudtlDat:
return 'icudtl.dat';
case Artifact.libskyShellSo:
return 'libsky_shell.so';
case Artifact.dartIoEntriesTxt:
return 'dart_io_entries.txt';
case Artifact.dartVmEntryPointsTxt:
return 'dart_vm_entry_points.txt';
case Artifact.dartVmEntryPointsAndroidTxt:
return 'dart_vm_entry_points_android.txt';
case Artifact.genSnapshot:
return 'gen_snapshot';
case Artifact.skySnapshot:
return 'sky_snapshot';
case Artifact.skyShell:
return 'sky_shell';
case Artifact.snapshotDart:
return 'snapshot.dart';
case Artifact.flutterFramework:
return 'Flutter.framework';
case Artifact.vmSnapshotData:
return 'vm_isolate_snapshot.bin';
case Artifact.isolateSnapshotData:
return 'isolate_snapshot.bin';
}
assert(false, 'Invalid artifact $artifact.');
return null;
}
// Manages the engine artifacts of Flutter.
abstract class Artifacts {
static Artifacts get instance => context[Artifacts];
static void useLocalEngine(String engineSrcPath, String engineOutPath) {
context.setVariable(Artifacts, new LocalEngineArtifacts(engineSrcPath, engineOutPath));
}
// Returns the requested [artifact] for the [platform] and [mode] combination.
String getArtifactPath(Artifact artifact, [TargetPlatform platform, BuildMode mode]);
// Returns which set of engine artifacts is currently used for the [platform]
// and [mode] combination.
String getEngineType(TargetPlatform platform, [BuildMode mode]);
}
/// Manages the engine artifacts downloaded to the local cache.
class CachedArtifacts extends Artifacts {
@override
String getArtifactPath(Artifact artifact, [TargetPlatform platform, BuildMode mode]) {
platform ??= _currentHostPlatform;
switch (platform) {
case TargetPlatform.android_arm:
case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
return _getAndroidArtifactPath(artifact, platform, mode);
case TargetPlatform.ios:
return _getIosArtifactPath(artifact, platform, mode);
case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64:
case TargetPlatform.windows_x64:
assert(mode == null, 'Platform $platform does not support different build modes.');
return _getHostArtifactPath(artifact, platform);
}
assert(false, 'Invalid platform $platform.');
return null;
}
@override
String getEngineType(TargetPlatform platform, [BuildMode mode]){
return fs.path.basename(_getEngineArtifactsPath(platform, mode));
}
String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
String engineDir = _getEngineArtifactsPath(platform, mode);
switch (artifact) {
case Artifact.chromiumDebugKeyStore:
case Artifact.classesDexJar:
case Artifact.icudtlDat:
case Artifact.libskyShellSo:
return fs.path.join(engineDir, _artifactToFileName(artifact));
case Artifact.dartIoEntriesTxt:
case Artifact.dartVmEntryPointsTxt:
case Artifact.dartVmEntryPointsAndroidTxt:
assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
return fs.path.join(engineDir, _artifactToFileName(artifact));
case Artifact.genSnapshot:
assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
return fs.path.join(engineDir, hostPlatform, _artifactToFileName(artifact));
default:
assert(false, 'Artifact $artifact not available for platform $platform.');
return null;
}
}
String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
String engineDir = _getEngineArtifactsPath(platform, mode);
switch (artifact) {
case Artifact.dartIoEntriesTxt:
case Artifact.dartVmEntryPointsTxt:
case Artifact.genSnapshot:
case Artifact.snapshotDart:
case Artifact.flutterFramework:
return fs.path.join(engineDir, _artifactToFileName(artifact));
default:
assert(false, 'Artifact $artifact not available for platform $platform.');
return null;
}
}
String _getHostArtifactPath(Artifact artifact, TargetPlatform platform) {
switch (artifact) {
case Artifact.skyShell:
case Artifact.skySnapshot:
if (platform == TargetPlatform.windows_x64)
throw new UnimplementedError('Artifact $artifact not available on platfrom $platform.');
continue returnResourcePath;
case Artifact.genSnapshot:
case Artifact.vmSnapshotData:
case Artifact.isolateSnapshotData:
if (platform != TargetPlatform.windows_x64)
throw new UnimplementedError('Artifact $artifact not available on platfrom $platform.');
continue returnResourcePath;
returnResourcePath:
case Artifact.icudtlDat:
String engineArtifactsPath = cache.getArtifactDirectory('engine').path;
String platformDirName = getNameForTargetPlatform(platform);
return fs.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact));
default:
assert(false, 'Artifact $artifact not available for platform $platform.');
return null;
}
assert(false, 'Artifact $artifact not available for platform $platform.');
return null;
}
String _getEngineArtifactsPath(TargetPlatform platform, [BuildMode mode]) {
String engineDir = cache.getArtifactDirectory('engine').path;
String platformName = getNameForTargetPlatform(platform);
switch (platform) {
case TargetPlatform.linux_x64:
case TargetPlatform.darwin_x64:
case TargetPlatform.windows_x64:
assert(mode == null, 'Platform $platform does not support different build modes.');
return fs.path.join(engineDir, platformName);
case TargetPlatform.ios:
case TargetPlatform.android_arm:
case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
assert(mode != null, 'Need to specify a build mode for platform $platform.');
String suffix = mode != BuildMode.debug ? '-${getModeName(mode)}' : '';
return fs.path.join(engineDir, platformName + suffix);
}
assert(false, 'Invalid platform $platform.');
return null;
}
TargetPlatform get _currentHostPlatform {
if (platform.isMacOS)
return TargetPlatform.darwin_x64;
if (platform.isLinux)
return TargetPlatform.linux_x64;
if (platform.isWindows)
return TargetPlatform.windows_x64;
throw new UnimplementedError('Host OS not supported.');
}
}
/// Manages the artifacts of a locally built engine.
class LocalEngineArtifacts extends Artifacts {
final String _engineSrcPath;
final String engineOutPath; // TODO(goderbauer): This should be private.
LocalEngineArtifacts(this._engineSrcPath, this.engineOutPath);
@override
String getArtifactPath(Artifact artifact, [TargetPlatform platform, BuildMode mode]) {
switch (artifact) {
case Artifact.chromiumDebugKeyStore:
return fs.path.join(_engineSrcPath, 'build', 'android', 'ant', _artifactToFileName(artifact));
case Artifact.dartIoEntriesTxt:
return fs.path.join(_engineSrcPath, 'dart', 'runtime', 'bin', _artifactToFileName(artifact));
case Artifact.dartVmEntryPointsTxt:
case Artifact.dartVmEntryPointsAndroidTxt:
return fs.path.join(_engineSrcPath, 'flutter', 'runtime', _artifactToFileName(artifact));
case Artifact.snapshotDart:
return fs.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', _artifactToFileName(artifact));
case Artifact.classesDexJar:
return fs.path.join(engineOutPath, 'gen', 'flutter', 'shell', 'platform', 'android', 'android', _artifactToFileName(artifact));
case Artifact.libskyShellSo:
String abi = _getAbiDirectory(platform);
return fs.path.join(engineOutPath, 'gen', 'flutter', 'shell', 'platform', 'android', 'android', fs.path.join('android', 'libs', abi, _artifactToFileName(artifact)));
case Artifact.genSnapshot:
return _genSnapshotPath(platform);
case Artifact.skyShell:
return _skyShellPath(platform);
case Artifact.skySnapshot:
return _skySnapshotPath();
case Artifact.isolateSnapshotData:
case Artifact.vmSnapshotData:
return fs.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', _artifactToFileName(artifact));
case Artifact.icudtlDat:
case Artifact.flutterFramework:
return fs.path.join(engineOutPath, _artifactToFileName(artifact));
}
assert(false, 'Invalid artifact $artifact.');
return null;
}
@override
String getEngineType(TargetPlatform platform, [BuildMode mode]) {
return fs.path.basename(engineOutPath);
}
String _genSnapshotPath(TargetPlatform platform) {
String clang;
if (platform == TargetPlatform.ios) {
clang = 'clang_x64';
} else {
clang = getCurrentHostPlatform() == HostPlatform.darwin_x64 ? 'clang_i386' : 'clang_x86';
}
return fs.path.join(engineOutPath, clang, _artifactToFileName(Artifact.genSnapshot));
}
String _skySnapshotPath() {
String clangPath = fs.path.join(engineOutPath, 'clang_x64', _artifactToFileName(Artifact.skySnapshot));
if (fs.isFileSync(clangPath))
return clangPath;
return fs.path.join(engineOutPath, _artifactToFileName(Artifact.skySnapshot));
}
String _skyShellPath(TargetPlatform platform) {
if (getCurrentHostPlatform() == HostPlatform.linux_x64) {
return fs.path.join(engineOutPath, _artifactToFileName(Artifact.skyShell));
} else if (getCurrentHostPlatform() == HostPlatform.darwin_x64) {
return fs.path.join(engineOutPath, 'SkyShell.app', 'Contents', 'MacOS', 'SkyShell');
}
throw new Exception('Unsupported platform $platform.');
}
String _getAbiDirectory(TargetPlatform platform) {
switch (platform) {
case TargetPlatform.android_arm:
return 'armeabi-v7a';
case TargetPlatform.android_x64:
return 'x86_64';
case TargetPlatform.android_x86:
return 'x86';
default:
throw new Exception('Unsupported platform $platform.');
}
}
}