blob: ebf6fcf2b3e4f59ff9734b8c497601e700206fe1 [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001// Copyright 2014 The Flutter Authors. All rights reserved.
Michael Goderbauercd8434d2017-02-16 23:10:11 -08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alexander Aprelevc5750cd2017-08-31 13:35:55 -07005import 'package:meta/meta.dart';
Jonah Williamsad9476d2020-01-14 16:47:34 -08006import 'package:platform/platform.dart';
7import 'package:process/process.dart';
Alexander Aprelevc5750cd2017-08-31 13:35:55 -07008
Michael Goderbauercd8434d2017-02-16 23:10:11 -08009import 'base/file_system.dart';
Stanislav Baranov393f9272018-08-16 08:43:41 -070010import 'base/utils.dart';
Michael Goderbauercd8434d2017-02-16 23:10:11 -080011import 'build_info.dart';
Jonah Williamsad9476d2020-01-14 16:47:34 -080012import 'cache.dart';
Alexander Aprelevfe005982018-02-16 09:20:23 -080013import 'dart/sdk.dart';
Jonah Williamsee7a37f2020-01-06 11:04:20 -080014import 'globals.dart' as globals;
Michael Goderbauercd8434d2017-02-16 23:10:11 -080015
16enum Artifact {
Jonah Williamse91b98a2019-07-11 16:53:17 -070017 /// The tool which compiles a dart kernel file into native code.
Michael Goderbauercd8434d2017-02-16 23:10:11 -080018 genSnapshot,
Jonah Williamse91b98a2019-07-11 16:53:17 -070019 /// The flutter tester binary.
Jason Simmonse7f13612017-03-29 16:30:41 -070020 flutterTester,
Michael Goderbauercd8434d2017-02-16 23:10:11 -080021 snapshotDart,
22 flutterFramework,
Jonah Williamse91b98a2019-07-11 16:53:17 -070023 /// The framework directory of the macOS desktop.
Jonah Williams7f959d82019-04-22 13:51:00 -070024 flutterMacOSFramework,
Michael Goderbauerd579d582017-03-02 10:57:27 -080025 vmSnapshotData,
Alexander Aprelevc5750cd2017-08-31 13:35:55 -070026 isolateSnapshotData,
27 platformKernelDill,
28 platformLibrariesJson,
29 flutterPatchedSdkPath,
30 frontendServerSnapshotForEngineDartSdk,
Jonah Williamscc51ad52019-11-07 20:13:02 -080031 /// The root directory of the dart SDK.
Alexander Aprelevfe005982018-02-16 09:20:23 -080032 engineDartSdkPath,
Jonah Williamse91b98a2019-07-11 16:53:17 -070033 /// The dart binary used to execute any of the required snapshots.
Keerti Parthasarathy02633942018-03-06 14:41:50 -080034 engineDartBinary,
Jonah Williamse91b98a2019-07-11 16:53:17 -070035 /// The dart snapshot of the dart2js compiler.
Jonah Williams9bc56562019-02-14 22:42:30 -080036 dart2jsSnapshot,
Jonah Williamse91b98a2019-07-11 16:53:17 -070037 /// The dart snapshot of the dartdev compiler.
Jonah Williamsda600ba2019-05-29 22:46:28 -070038 dartdevcSnapshot,
Jonah Williamse91b98a2019-07-11 16:53:17 -070039 /// The dart snpashot of the kernel worker compiler.
Jonah Williams9bc56562019-02-14 22:42:30 -080040 kernelWorkerSnapshot,
Jonah Williamse91b98a2019-07-11 16:53:17 -070041 /// The root of the web implementation of the dart SDK.
Jonah Williams44b22c72019-03-25 18:47:37 -070042 flutterWebSdk,
Jonah Williams79a985f2019-10-22 20:35:05 -070043 /// The summary dill for the dartdevc target.
44 webPlatformKernelDill,
Christopher Fujino102ab1e2019-07-15 09:22:29 -070045 iosDeploy,
Christopher Fujino102ab1e2019-07-15 09:22:29 -070046 idevicesyslog,
47 idevicescreenshot,
48 ideviceinstaller,
49 iproxy,
Jonah Williamse91b98a2019-07-11 16:53:17 -070050 /// The root of the Linux desktop sources.
51 linuxDesktopPath,
52 /// The root of the Windows desktop sources.
53 windowsDesktopPath,
54 /// The root of the sky_engine package
55 skyEnginePath,
Jonah Williams2ab46992019-07-31 16:19:22 -070056 /// The location of the macOS engine podspec file.
57 flutterMacOSPodspec,
Zachary Anderson0dfabb22019-10-28 09:38:08 -070058
59 // Fuchsia artifacts from the engine prebuilts.
60 fuchsiaKernelCompiler,
Zachary Anderson05226d22019-11-21 12:55:39 -080061 fuchsiaFlutterRunner,
Dan Field525855d2020-01-21 16:53:02 -080062
63 /// Tools related to subsetting or icon font files.
64 fontSubset,
65 constFinder,
Michael Goderbauercd8434d2017-02-16 23:10:11 -080066}
67
Alexandre Ardhuin5169ab52019-02-21 09:27:07 +010068String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) {
Dan Field525855d2020-01-21 16:53:02 -080069 final String exe = platform == TargetPlatform.windows_x64 ? '.exe' : '';
Michael Goderbauercd8434d2017-02-16 23:10:11 -080070 switch (artifact) {
Michael Goderbauercd8434d2017-02-16 23:10:11 -080071 case Artifact.genSnapshot:
Alexander Aprelev70b32e82017-12-22 14:58:53 -080072 return 'gen_snapshot';
Jason Simmonse7f13612017-03-29 16:30:41 -070073 case Artifact.flutterTester:
Dan Field525855d2020-01-21 16:53:02 -080074 return 'flutter_tester$exe';
Michael Goderbauercd8434d2017-02-16 23:10:11 -080075 case Artifact.snapshotDart:
76 return 'snapshot.dart';
77 case Artifact.flutterFramework:
78 return 'Flutter.framework';
Jonah Williams7f959d82019-04-22 13:51:00 -070079 case Artifact.flutterMacOSFramework:
80 return 'FlutterMacOS.framework';
Michael Goderbauerd579d582017-03-02 10:57:27 -080081 case Artifact.vmSnapshotData:
82 return 'vm_isolate_snapshot.bin';
83 case Artifact.isolateSnapshotData:
84 return 'isolate_snapshot.bin';
Alexander Aprelevc5750cd2017-08-31 13:35:55 -070085 case Artifact.platformKernelDill:
Siva426d6b02018-01-04 10:39:02 -080086 return 'platform_strong.dill';
Alexander Aprelevc5750cd2017-08-31 13:35:55 -070087 case Artifact.platformLibrariesJson:
88 return 'libraries.json';
89 case Artifact.flutterPatchedSdkPath:
90 assert(false, 'No filename for sdk path, should not be invoked');
91 return null;
Jonah Williams44b22c72019-03-25 18:47:37 -070092 case Artifact.flutterWebSdk:
93 assert(false, 'No filename for web sdk path, should not be invoked');
94 return null;
Alexander Aprelevfe005982018-02-16 09:20:23 -080095 case Artifact.engineDartSdkPath:
96 return 'dart-sdk';
Alexander Aprelevc5750cd2017-08-31 13:35:55 -070097 case Artifact.frontendServerSnapshotForEngineDartSdk:
98 return 'frontend_server.dart.snapshot';
Keerti Parthasarathy02633942018-03-06 14:41:50 -080099 case Artifact.engineDartBinary:
Dan Field525855d2020-01-21 16:53:02 -0800100 return 'dart$exe';
Jonah Williams9bc56562019-02-14 22:42:30 -0800101 case Artifact.dart2jsSnapshot:
Jonah Williams44b22c72019-03-25 18:47:37 -0700102 return 'dart2js.dart.snapshot';
Jonah Williamsda600ba2019-05-29 22:46:28 -0700103 case Artifact.dartdevcSnapshot:
104 return 'dartdevc.dart.snapshot';
Jonah Williams9bc56562019-02-14 22:42:30 -0800105 case Artifact.kernelWorkerSnapshot:
Jonah Williams44b22c72019-03-25 18:47:37 -0700106 return 'kernel_worker.dart.snapshot';
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700107 case Artifact.iosDeploy:
108 return 'ios-deploy';
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700109 case Artifact.idevicesyslog:
110 return 'idevicesyslog';
111 case Artifact.idevicescreenshot:
112 return 'idevicescreenshot';
113 case Artifact.ideviceinstaller:
114 return 'ideviceinstaller';
115 case Artifact.iproxy:
116 return 'iproxy';
Jonah Williamse91b98a2019-07-11 16:53:17 -0700117 case Artifact.linuxDesktopPath:
Jonah Williamse91b98a2019-07-11 16:53:17 -0700118 return '';
119 case Artifact.windowsDesktopPath:
Jonah Williamse91b98a2019-07-11 16:53:17 -0700120 return '';
121 case Artifact.skyEnginePath:
122 return 'sky_engine';
Jonah Williams2ab46992019-07-31 16:19:22 -0700123 case Artifact.flutterMacOSPodspec:
124 return 'FlutterMacOS.podspec';
Jonah Williams79a985f2019-10-22 20:35:05 -0700125 case Artifact.webPlatformKernelDill:
126 return 'flutter_ddc_sdk.dill';
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700127 case Artifact.fuchsiaKernelCompiler:
128 return 'kernel_compiler.snapshot';
Zachary Anderson05226d22019-11-21 12:55:39 -0800129 case Artifact.fuchsiaFlutterRunner:
130 final String jitOrAot = mode.isJit ? '_jit' : '_aot';
131 final String productOrNo = mode.isRelease ? '_product' : '';
132 return 'flutter$jitOrAot${productOrNo}_runner-0.far';
Dan Field525855d2020-01-21 16:53:02 -0800133 case Artifact.fontSubset:
134 return 'font-subset$exe';
135 case Artifact.constFinder:
136 return 'const_finder.dart.snapshot';
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800137 }
138 assert(false, 'Invalid artifact $artifact.');
139 return null;
140}
141
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700142class EngineBuildPaths {
Alexandre Ardhuinef276ff2019-01-29 21:47:16 +0100143 const EngineBuildPaths({
144 @required this.targetEngine,
145 @required this.hostEngine,
146 }) : assert(targetEngine != null),
147 assert(hostEngine != null);
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700148
149 final String targetEngine;
150 final String hostEngine;
151}
152
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800153// Manages the engine artifacts of Flutter.
154abstract class Artifacts {
Todd Volkert8d11f5c2018-03-28 10:58:28 -0700155 static LocalEngineArtifacts getLocalEngine(String engineSrcPath, EngineBuildPaths engineBuildPaths) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800156 return LocalEngineArtifacts(
157 engineSrcPath,
158 engineBuildPaths.targetEngine,
159 engineBuildPaths.hostEngine,
160 cache: globals.cache,
161 fileSystem: globals.fs,
162 processManager: globals.processManager,
163 platform: globals.platform,
164 );
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800165 }
166
167 // Returns the requested [artifact] for the [platform] and [mode] combination.
Alexander Aprelevd7759082019-04-15 21:02:20 -0700168 String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode });
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800169
170 // Returns which set of engine artifacts is currently used for the [platform]
171 // and [mode] combination.
Alexandre Ardhuin5169ab52019-02-21 09:27:07 +0100172 String getEngineType(TargetPlatform platform, [ BuildMode mode ]);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800173}
174
Jonah Williams7a487b22019-09-27 18:54:24 -0700175
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800176/// Manages the engine artifacts downloaded to the local cache.
177class CachedArtifacts extends Artifacts {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800178 CachedArtifacts({
179 @required FileSystem fileSystem,
180 @required Platform platform,
181 @required Cache cache,
182 }) : _fileSystem = fileSystem,
183 _platform = platform,
184 _cache = cache;
185
186 final FileSystem _fileSystem;
187 final Platform _platform;
188 final Cache _cache;
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800189
190 @override
Alexander Aprelevd7759082019-04-15 21:02:20 -0700191 String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800192 switch (platform) {
193 case TargetPlatform.android_arm:
Jason Simmonsd5149d42018-02-01 15:14:48 -0800194 case TargetPlatform.android_arm64:
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800195 case TargetPlatform.android_x64:
196 case TargetPlatform.android_x86:
197 return _getAndroidArtifactPath(artifact, platform, mode);
198 case TargetPlatform.ios:
199 return _getIosArtifactPath(artifact, platform, mode);
200 case TargetPlatform.darwin_x64:
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700201 return _getDarwinArtifactPath(artifact, platform, mode);
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700202 case TargetPlatform.fuchsia_arm64:
203 case TargetPlatform.fuchsia_x64:
204 return _getFuchsiaArtifactPath(artifact, platform, mode);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800205 case TargetPlatform.linux_x64:
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700206 case TargetPlatform.windows_x64:
Konstantin Scheglov38970f52018-04-10 09:37:16 -0700207 case TargetPlatform.tester:
Jonah Williams83986ac2019-06-03 23:19:42 -0700208 case TargetPlatform.web_javascript:
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700209 default: // could be null, but that can't be specified as a case.
Jonah Williamsad9476d2020-01-14 16:47:34 -0800210 return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform), mode);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800211 }
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800212 }
213
214 @override
Alexandre Ardhuin5169ab52019-02-21 09:27:07 +0100215 String getEngineType(TargetPlatform platform, [ BuildMode mode ]) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800216 return _fileSystem.path.basename(_getEngineArtifactsPath(platform, mode));
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800217 }
218
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700219 String _getDarwinArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
220 // When platform is null, a generic host platform artifact is being requested
221 // and not the gen_snapshot for darwin as a target platform.
222 if (platform != null && artifact == Artifact.genSnapshot) {
223 final String engineDir = _getEngineArtifactsPath(platform, mode);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800224 return _fileSystem.path.join(engineDir, _artifactToFileName(artifact));
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700225 }
Jonah Williamsad9476d2020-01-14 16:47:34 -0800226 return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform), mode);
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700227 }
228
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800229 String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
Chris Bracken7a093162017-03-03 17:50:46 -0800230 final String engineDir = _getEngineArtifactsPath(platform, mode);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800231 switch (artifact) {
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700232 case Artifact.frontendServerSnapshotForEngineDartSdk:
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800233 assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
Jonah Williamsad9476d2020-01-14 16:47:34 -0800234 return _fileSystem.path.join(engineDir, _artifactToFileName(artifact));
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800235 case Artifact.genSnapshot:
236 assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
Chris Bracken7a093162017-03-03 17:50:46 -0800237 final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
Jonah Williamsad9476d2020-01-14 16:47:34 -0800238 return _fileSystem.path.join(engineDir, hostPlatform, _artifactToFileName(artifact));
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800239 default:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700240 return _getHostArtifactPath(artifact, platform, mode);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800241 }
242 }
243
244 String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800245 switch (artifact) {
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800246 case Artifact.genSnapshot:
247 case Artifact.snapshotDart:
248 case Artifact.flutterFramework:
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700249 case Artifact.frontendServerSnapshotForEngineDartSdk:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700250 final String artifactFileName = _artifactToFileName(artifact);
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700251 final String engineDir = _getEngineArtifactsPath(platform, mode);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800252 return _fileSystem.path.join(engineDir, artifactFileName);
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700253 case Artifact.idevicescreenshot:
254 case Artifact.idevicesyslog:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700255 final String artifactFileName = _artifactToFileName(artifact);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800256 return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path;
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700257 case Artifact.iosDeploy:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700258 final String artifactFileName = _artifactToFileName(artifact);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800259 return _cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path;
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700260 case Artifact.ideviceinstaller:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700261 final String artifactFileName = _artifactToFileName(artifact);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800262 return _cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path;
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700263 case Artifact.iproxy:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700264 final String artifactFileName = _artifactToFileName(artifact);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800265 return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path;
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800266 default:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700267 return _getHostArtifactPath(artifact, platform, mode);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800268 }
269 }
270
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700271 String _getFuchsiaArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800272 final String root = _fileSystem.path.join(
273 _cache.getArtifactDirectory('flutter_runner').path,
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700274 'flutter',
275 fuchsiaArchForTargetPlatform(platform),
Zachary Anderson05226d22019-11-21 12:55:39 -0800276 mode.isRelease ? 'release' : mode.toString(),
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700277 );
Zachary Anderson05226d22019-11-21 12:55:39 -0800278 final String runtime = mode.isJit ? 'jit' : 'aot';
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700279 switch (artifact) {
Zachary Anderson05226d22019-11-21 12:55:39 -0800280 case Artifact.genSnapshot:
281 final String genSnapshot = mode.isRelease ? 'gen_snapshot_product' : 'gen_snapshot';
Jonah Williamsad9476d2020-01-14 16:47:34 -0800282 return _fileSystem.path.join(root, runtime, 'dart_binaries', genSnapshot);
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700283 case Artifact.flutterPatchedSdkPath:
284 const String artifactFileName = 'flutter_runner_patched_sdk';
Jonah Williamsad9476d2020-01-14 16:47:34 -0800285 return _fileSystem.path.join(root, runtime, artifactFileName);
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700286 case Artifact.platformKernelDill:
287 final String artifactFileName = _artifactToFileName(artifact, platform, mode);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800288 return _fileSystem.path.join(root, runtime, 'flutter_runner_patched_sdk', artifactFileName);
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700289 case Artifact.fuchsiaKernelCompiler:
290 final String artifactFileName = _artifactToFileName(artifact, platform, mode);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800291 return _fileSystem.path.join(root, runtime, 'dart_binaries', artifactFileName);
Zachary Anderson05226d22019-11-21 12:55:39 -0800292 case Artifact.fuchsiaFlutterRunner:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700293 final String artifactFileName = _artifactToFileName(artifact, platform, mode);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800294 return _fileSystem.path.join(root, runtime, artifactFileName);
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700295 default:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700296 return _getHostArtifactPath(artifact, platform, mode);
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700297 }
298 }
299
Alexander Aprelevd7759082019-04-15 21:02:20 -0700300 String _getFlutterPatchedSdkPath(BuildMode mode) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800301 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
302 return _fileSystem.path.join(engineArtifactsPath, 'common',
Alexander Aprelevd7759082019-04-15 21:02:20 -0700303 mode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700304 }
305
Jonah Williams44b22c72019-03-25 18:47:37 -0700306 String _getFlutterWebSdkPath() {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800307 return _cache.getWebSdkDirectory().path;
Jonah Williams44b22c72019-03-25 18:47:37 -0700308 }
309
Stanislav Baranovc799c2f2018-09-20 13:12:38 -0700310 String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700311 assert(platform != null);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800312 switch (artifact) {
Michael Goderbauer906103d2017-03-08 13:33:06 -0800313 case Artifact.genSnapshot:
314 // For script snapshots any gen_snapshot binary will do. Returning gen_snapshot for
315 // android_arm in profile mode because it is available on all supported host platforms.
316 return _getAndroidArtifactPath(artifact, TargetPlatform.android_arm, BuildMode.profile);
Jason Simmonse7f13612017-03-29 16:30:41 -0700317 case Artifact.flutterTester:
Michael Goderbauerd579d582017-03-02 10:57:27 -0800318 case Artifact.vmSnapshotData:
319 case Artifact.isolateSnapshotData:
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700320 case Artifact.frontendServerSnapshotForEngineDartSdk:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800321 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
Chris Bracken7a093162017-03-03 17:50:46 -0800322 final String platformDirName = getNameForTargetPlatform(platform);
Jonah Williamsad9476d2020-01-14 16:47:34 -0800323 return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode));
Alexander Aprelevfe005982018-02-16 09:20:23 -0800324 case Artifact.engineDartSdkPath:
325 return dartSdkPath;
Keerti Parthasarathy02633942018-03-06 14:41:50 -0800326 case Artifact.engineDartBinary:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800327 return _fileSystem.path.join(dartSdkPath, 'bin', _artifactToFileName(artifact, platform));
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700328 case Artifact.platformKernelDill:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800329 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), _artifactToFileName(artifact));
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700330 case Artifact.platformLibrariesJson:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800331 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', _artifactToFileName(artifact));
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700332 case Artifact.flutterPatchedSdkPath:
Alexander Aprelevd7759082019-04-15 21:02:20 -0700333 return _getFlutterPatchedSdkPath(mode);
Jonah Williams44b22c72019-03-25 18:47:37 -0700334 case Artifact.flutterWebSdk:
335 return _getFlutterWebSdkPath();
Jonah Williams79a985f2019-10-22 20:35:05 -0700336 case Artifact.webPlatformKernelDill:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800337 return _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact));
Jonah Williams9bc56562019-02-14 22:42:30 -0800338 case Artifact.dart2jsSnapshot:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800339 return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
Jonah Williamsda600ba2019-05-29 22:46:28 -0700340 case Artifact.dartdevcSnapshot:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800341 return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
Jonah Williams9bc56562019-02-14 22:42:30 -0800342 case Artifact.kernelWorkerSnapshot:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800343 return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
Jonah Williams7f959d82019-04-22 13:51:00 -0700344 case Artifact.flutterMacOSFramework:
Jonah Williamse91b98a2019-07-11 16:53:17 -0700345 case Artifact.linuxDesktopPath:
346 case Artifact.windowsDesktopPath:
Jonah Williams2ab46992019-07-31 16:19:22 -0700347 case Artifact.flutterMacOSPodspec:
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700348 // TODO(jonahwilliams): remove once debug desktop artifacts are uploaded
349 // under a separate directory from the host artifacts.
350 // https://github.com/flutter/flutter/issues/38935
351 String platformDirName = getNameForTargetPlatform(platform);
352 if (mode == BuildMode.profile || mode == BuildMode.release) {
353 platformDirName = '$platformDirName-${getNameForBuildMode(mode)}';
354 }
Jonah Williamsad9476d2020-01-14 16:47:34 -0800355 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
356 return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode));
Jonah Williamse91b98a2019-07-11 16:53:17 -0700357 case Artifact.skyEnginePath:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800358 final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
359 return _fileSystem.path.join(dartPackageDirectory.path, _artifactToFileName(artifact));
Dan Field525855d2020-01-21 16:53:02 -0800360 case Artifact.fontSubset:
361 case Artifact.constFinder:
Dan Field4b8efad2020-02-04 20:34:24 -0800362 return _cache.getArtifactDirectory('engine')
363 .childDirectory(getNameForTargetPlatform(platform))
364 .childFile(_artifactToFileName(artifact, platform, mode))
365 .path;
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800366 default:
367 assert(false, 'Artifact $artifact not available for platform $platform.');
368 return null;
369 }
370 }
371
Alexandre Ardhuin5169ab52019-02-21 09:27:07 +0100372 String _getEngineArtifactsPath(TargetPlatform platform, [ BuildMode mode ]) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800373 final String engineDir = _cache.getArtifactDirectory('engine').path;
Chris Bracken7a093162017-03-03 17:50:46 -0800374 final String platformName = getNameForTargetPlatform(platform);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800375 switch (platform) {
376 case TargetPlatform.linux_x64:
377 case TargetPlatform.darwin_x64:
Michael Goderbauerd579d582017-03-02 10:57:27 -0800378 case TargetPlatform.windows_x64:
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700379 // TODO(jonahwilliams): remove once debug desktop artifacts are uploaded
380 // under a separate directory from the host artifacts.
381 // https://github.com/flutter/flutter/issues/38935
382 if (mode == BuildMode.debug || mode == null) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800383 return _fileSystem.path.join(engineDir, platformName);
Jonah Williamsb2d19d22019-08-23 08:46:24 -0700384 }
385 final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode), '-')}' : '';
Jonah Williamsad9476d2020-01-14 16:47:34 -0800386 return _fileSystem.path.join(engineDir, platformName + suffix);
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700387 case TargetPlatform.fuchsia_arm64:
388 case TargetPlatform.fuchsia_x64:
Konstantin Scheglov38970f52018-04-10 09:37:16 -0700389 case TargetPlatform.tester:
Jonah Williams83986ac2019-06-03 23:19:42 -0700390 case TargetPlatform.web_javascript:
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800391 assert(mode == null, 'Platform $platform does not support different build modes.');
Jonah Williamsad9476d2020-01-14 16:47:34 -0800392 return _fileSystem.path.join(engineDir, platformName);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800393 case TargetPlatform.ios:
394 case TargetPlatform.android_arm:
Jason Simmonsd5149d42018-02-01 15:14:48 -0800395 case TargetPlatform.android_arm64:
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800396 case TargetPlatform.android_x64:
397 case TargetPlatform.android_x86:
398 assert(mode != null, 'Need to specify a build mode for platform $platform.');
Stanislav Baranov393f9272018-08-16 08:43:41 -0700399 final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode), '-')}' : '';
Jonah Williamsad9476d2020-01-14 16:47:34 -0800400 return _fileSystem.path.join(engineDir, platformName + suffix);
Jonah Williamsdf3505c2019-11-19 11:26:07 -0800401 case TargetPlatform.android:
402 assert(false, 'cannot use TargetPlatform.android to look up artifacts');
403 return null;
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800404 }
405 assert(false, 'Invalid platform $platform.');
406 return null;
407 }
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800408}
409
Jonah Williamsad9476d2020-01-14 16:47:34 -0800410TargetPlatform _currentHostPlatform(Platform platform) {
411 if (platform.isMacOS) {
412 return TargetPlatform.darwin_x64;
413 }
414 if (platform.isLinux) {
415 return TargetPlatform.linux_x64;
416 }
417 if (platform.isWindows) {
418 return TargetPlatform.windows_x64;
419 }
420 throw UnimplementedError('Host OS not supported.');
421}
422
423HostPlatform _currentHostPlatformAsHost(Platform platform) {
424 if (platform.isMacOS) {
425 return HostPlatform.darwin_x64;
426 }
427 if (platform.isLinux) {
428 return HostPlatform.linux_x64;
429 }
430 if (platform.isWindows) {
431 return HostPlatform.windows_x64;
432 }
433 throw UnimplementedError('Host OS not supported.');
434}
435
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800436/// Manages the artifacts of a locally built engine.
437class LocalEngineArtifacts extends Artifacts {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800438 LocalEngineArtifacts(
439 this._engineSrcPath,
440 this.engineOutPath,
441 this._hostEngineOutPath, {
442 @required FileSystem fileSystem,
443 @required Cache cache,
444 @required ProcessManager processManager,
445 @required Platform platform,
446 }) : _fileSystem = fileSystem,
447 _cache = cache,
448 _processManager = processManager,
449 _platform = platform;
Alexandre Ardhuin2ea1d812018-10-04 07:28:07 +0200450
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800451 final String _engineSrcPath;
452 final String engineOutPath; // TODO(goderbauer): This should be private.
Alexandre Ardhuinc7408be2019-06-25 19:39:34 +0200453 final String _hostEngineOutPath;
Jonah Williamsad9476d2020-01-14 16:47:34 -0800454 final FileSystem _fileSystem;
455 final Cache _cache;
456 final ProcessManager _processManager;
457 final Platform _platform;
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800458
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800459 @override
Alexander Aprelevd7759082019-04-15 21:02:20 -0700460 String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800461 platform ??= _currentHostPlatform(_platform);
Zachary Anderson05226d22019-11-21 12:55:39 -0800462 final String artifactFileName = _artifactToFileName(artifact, platform, mode);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800463 switch (artifact) {
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800464 case Artifact.snapshotDart:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800465 return _fileSystem.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', artifactFileName);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800466 case Artifact.genSnapshot:
Jason Simmons22ccb742017-07-27 14:22:21 -0700467 return _genSnapshotPath();
Jason Simmonse7f13612017-03-29 16:30:41 -0700468 case Artifact.flutterTester:
469 return _flutterTesterPath(platform);
Michael Goderbauerd579d582017-03-02 10:57:27 -0800470 case Artifact.isolateSnapshotData:
471 case Artifact.vmSnapshotData:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800472 return _fileSystem.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName);
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700473 case Artifact.platformKernelDill:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700474 if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800475 return _fileSystem.path.join(engineOutPath, 'flutter_runner_patched_sdk', artifactFileName);
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700476 }
Jonah Williamsad9476d2020-01-14 16:47:34 -0800477 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), artifactFileName);
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700478 case Artifact.platformLibrariesJson:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800479 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800480 case Artifact.flutterFramework:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800481 return _fileSystem.path.join(engineOutPath, artifactFileName);
Jonah Williams7f959d82019-04-22 13:51:00 -0700482 case Artifact.flutterMacOSFramework:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800483 return _fileSystem.path.join(engineOutPath, artifactFileName);
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700484 case Artifact.flutterPatchedSdkPath:
Alexander Aprelevd7759082019-04-15 21:02:20 -0700485 // When using local engine always use [BuildMode.debug] regardless of
486 // what was specified in [mode] argument because local engine will
487 // have only one flutter_patched_sdk in standard location, that
488 // is happen to be what debug(non-release) mode is using.
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700489 if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800490 return _fileSystem.path.join(engineOutPath, 'flutter_runner_patched_sdk');
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700491 }
Alexander Aprelevd7759082019-04-15 21:02:20 -0700492 return _getFlutterPatchedSdkPath(BuildMode.debug);
Jonah Williams44b22c72019-03-25 18:47:37 -0700493 case Artifact.flutterWebSdk:
494 return _getFlutterWebSdkPath();
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700495 case Artifact.frontendServerSnapshotForEngineDartSdk:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800496 return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName);
Alexander Aprelevfe005982018-02-16 09:20:23 -0800497 case Artifact.engineDartSdkPath:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800498 return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk');
Keerti Parthasarathy02633942018-03-06 14:41:50 -0800499 case Artifact.engineDartBinary:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800500 return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', artifactFileName);
Jonah Williams9bc56562019-02-14 22:42:30 -0800501 case Artifact.dart2jsSnapshot:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800502 return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName);
Jonah Williamsda600ba2019-05-29 22:46:28 -0700503 case Artifact.dartdevcSnapshot:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800504 return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', artifactFileName);
Jonah Williams9bc56562019-02-14 22:42:30 -0800505 case Artifact.kernelWorkerSnapshot:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800506 return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName);
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700507 case Artifact.idevicescreenshot:
508 case Artifact.idevicesyslog:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800509 return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path;
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700510 case Artifact.ideviceinstaller:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800511 return _cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path;
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700512 case Artifact.iosDeploy:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800513 return _cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path;
Christopher Fujino102ab1e2019-07-15 09:22:29 -0700514 case Artifact.iproxy:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800515 return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path;
Jonah Williamse91b98a2019-07-11 16:53:17 -0700516 case Artifact.linuxDesktopPath:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800517 return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
Jonah Williamse91b98a2019-07-11 16:53:17 -0700518 case Artifact.windowsDesktopPath:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800519 return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
Jonah Williamse91b98a2019-07-11 16:53:17 -0700520 case Artifact.skyEnginePath:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800521 return _fileSystem.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName);
Jonah Williams2ab46992019-07-31 16:19:22 -0700522 case Artifact.flutterMacOSPodspec:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800523 return _fileSystem.path.join(_hostEngineOutPath, _artifactToFileName(artifact));
Jonah Williams79a985f2019-10-22 20:35:05 -0700524 case Artifact.webPlatformKernelDill:
Jonah Williamsad9476d2020-01-14 16:47:34 -0800525 return _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact));
Zachary Anderson0dfabb22019-10-28 09:38:08 -0700526 case Artifact.fuchsiaKernelCompiler:
Zachary Andersond0d8e6e2019-10-30 14:11:18 -0700527 final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
Zachary Anderson05226d22019-11-21 12:55:39 -0800528 final String modeName = mode.isRelease ? 'release' : mode.toString();
529 final String dartBinaries = 'dart_binaries-$modeName-$hostPlatform';
Jonah Williamsad9476d2020-01-14 16:47:34 -0800530 return _fileSystem.path.join(engineOutPath, 'host_bundle', dartBinaries, 'kernel_compiler.dart.snapshot');
Zachary Anderson05226d22019-11-21 12:55:39 -0800531 case Artifact.fuchsiaFlutterRunner:
532 final String jitOrAot = mode.isJit ? '_jit' : '_aot';
533 final String productOrNo = mode.isRelease ? '_product' : '';
Jonah Williamsad9476d2020-01-14 16:47:34 -0800534 return _fileSystem.path.join(engineOutPath, 'flutter$jitOrAot${productOrNo}_runner-0.far');
Dan Field525855d2020-01-21 16:53:02 -0800535 case Artifact.fontSubset:
536 return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
537 case Artifact.constFinder:
538 return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800539 }
540 assert(false, 'Invalid artifact $artifact.');
541 return null;
542 }
543
544 @override
Alexandre Ardhuin5169ab52019-02-21 09:27:07 +0100545 String getEngineType(TargetPlatform platform, [ BuildMode mode ]) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800546 return _fileSystem.path.basename(engineOutPath);
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800547 }
548
Alexander Aprelevd7759082019-04-15 21:02:20 -0700549 String _getFlutterPatchedSdkPath(BuildMode buildMode) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800550 return _fileSystem.path.join(engineOutPath,
Alexander Aprelevd7759082019-04-15 21:02:20 -0700551 buildMode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
Alexander Aprelevc5750cd2017-08-31 13:35:55 -0700552 }
553
Jonah Williams44b22c72019-03-25 18:47:37 -0700554 String _getFlutterWebSdkPath() {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800555 return _fileSystem.path.join(engineOutPath, 'flutter_web_sdk');
Jonah Williams44b22c72019-03-25 18:47:37 -0700556 }
557
Jason Simmons22ccb742017-07-27 14:22:21 -0700558 String _genSnapshotPath() {
Liam Appelbe0cd0c662019-08-06 08:45:08 -0700559 const List<String> clangDirs = <String>['.', 'clang_x64', 'clang_x86', 'clang_i386'];
Jason Simmons22ccb742017-07-27 14:22:21 -0700560 final String genSnapshotName = _artifactToFileName(Artifact.genSnapshot);
Alexandre Ardhuin4f9b6cf2020-01-07 16:32:04 +0100561 for (final String clangDir in clangDirs) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800562 final String genSnapshotPath = _fileSystem.path.join(engineOutPath, clangDir, genSnapshotName);
563 if (_processManager.canRun(genSnapshotPath)) {
Jason Simmons22ccb742017-07-27 14:22:21 -0700564 return genSnapshotPath;
Zachary Andersone2340c62019-09-13 14:51:35 -0700565 }
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800566 }
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200567 throw Exception('Unable to find $genSnapshotName');
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800568 }
569
Jason Simmonse7f13612017-03-29 16:30:41 -0700570 String _flutterTesterPath(TargetPlatform platform) {
Jonah Williamsad9476d2020-01-14 16:47:34 -0800571 final HostPlatform hostPlatform = _currentHostPlatformAsHost(_platform);
572 if (hostPlatform == HostPlatform.linux_x64) {
573 return _fileSystem.path.join(engineOutPath, _artifactToFileName(Artifact.flutterTester));
574 } else if (hostPlatform == HostPlatform.darwin_x64) {
575 return _fileSystem.path.join(engineOutPath, 'flutter_tester');
576 } else if (hostPlatform == HostPlatform.windows_x64) {
577 return _fileSystem.path.join(engineOutPath, 'flutter_tester.exe');
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800578 }
Alexandre Ardhuind927c932018-09-12 08:29:29 +0200579 throw Exception('Unsupported platform $platform.');
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800580 }
Michael Goderbauercd8434d2017-02-16 23:10:11 -0800581}
Jonah Williamsc9ca7c42018-10-16 14:27:22 -0700582
583/// An implementation of [Artifacts] that provides individual overrides.
584///
585/// If an artifact is not provided, the lookup delegates to the parent.
Jonah Williamsc9ca7c42018-10-16 14:27:22 -0700586class OverrideArtifacts implements Artifacts {
587 /// Creates a new [OverrideArtifacts].
588 ///
589 /// [parent] must be provided.
590 OverrideArtifacts({
591 @required this.parent,
592 this.frontendServer,
Jonah Williams81c7af32018-11-06 14:36:35 -0800593 this.engineDartBinary,
Jonah Williamsa226c0f2018-11-30 16:18:18 -0800594 this.platformKernelDill,
595 this.flutterPatchedSdk,
Jonah Williamsc9ca7c42018-10-16 14:27:22 -0700596 }) : assert(parent != null);
597
598 final Artifacts parent;
599 final File frontendServer;
Jonah Williams81c7af32018-11-06 14:36:35 -0800600 final File engineDartBinary;
Jonah Williamsa226c0f2018-11-30 16:18:18 -0800601 final File platformKernelDill;
602 final File flutterPatchedSdk;
Jonah Williamsc9ca7c42018-10-16 14:27:22 -0700603
604 @override
Alexander Aprelevd7759082019-04-15 21:02:20 -0700605 String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
Jonah Williamsc9ca7c42018-10-16 14:27:22 -0700606 if (artifact == Artifact.frontendServerSnapshotForEngineDartSdk && frontendServer != null) {
607 return frontendServer.path;
608 }
Jonah Williams81c7af32018-11-06 14:36:35 -0800609 if (artifact == Artifact.engineDartBinary && engineDartBinary != null) {
610 return engineDartBinary.path;
611 }
Jonah Williamsa226c0f2018-11-30 16:18:18 -0800612 if (artifact == Artifact.platformKernelDill && platformKernelDill != null) {
613 return platformKernelDill.path;
614 }
615 if (artifact == Artifact.flutterPatchedSdkPath && flutterPatchedSdk != null) {
616 return flutterPatchedSdk.path;
617 }
Alexander Aprelevd7759082019-04-15 21:02:20 -0700618 return parent.getArtifactPath(artifact, platform: platform, mode: mode);
Jonah Williamsc9ca7c42018-10-16 14:27:22 -0700619 }
620
621 @override
Alexandre Ardhuin5169ab52019-02-21 09:27:07 +0100622 String getEngineType(TargetPlatform platform, [ BuildMode mode ]) => parent.getEngineType(platform, mode);
Jonah Williamsc9ca7c42018-10-16 14:27:22 -0700623}