1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:file/memory.dart';
6import 'package:meta/meta.dart';
7import 'package:process/process.dart';
8
9import 'base/common.dart';
10import 'base/file_system.dart';
11import 'base/os.dart';
12import 'base/platform.dart';
13import 'base/user_messages.dart';
14import 'base/utils.dart';
15import 'build_info.dart';
16import 'cache.dart';
17import 'globals.dart' as globals;
18
19enum Artifact {
20 /// The tool which compiles a dart kernel file into native code.
21 genSnapshot,
22 /// The flutter tester binary.
23 flutterTester,
24 flutterFramework,
25 flutterFrameworkDsym,
26 flutterXcframework,
27 /// The framework directory of the macOS desktop.
28 flutterMacOSFramework,
29 flutterMacOSFrameworkDsym,
30 flutterMacOSXcframework,
31 vmSnapshotData,
32 isolateSnapshotData,
33 icuData,
34 platformKernelDill,
35 platformLibrariesJson,
36 flutterPatchedSdkPath,
37
38 /// The root directory of the dart SDK.
39 engineDartSdkPath,
40 /// The dart binary used to execute any of the required snapshots.
41 engineDartBinary,
42 /// The dart binary for running aot snapshots
43 engineDartAotRuntime,
44 /// The snapshot of frontend_server compiler.
45 frontendServerSnapshotForEngineDartSdk,
46 /// The dart snapshot of the dart2js compiler.
47 dart2jsSnapshot,
48 /// The dart snapshot of the dart2wasm compiler.
49 dart2wasmSnapshot,
50
51 /// The root of the Linux desktop sources.
52 linuxDesktopPath,
53 // The root of the cpp headers for Linux desktop.
54 linuxHeaders,
55 /// The root of the Windows desktop sources.
56 windowsDesktopPath,
57 /// The root of the cpp client code for Windows desktop.
58 windowsCppClientWrapper,
59
60 /// The root of the sky_engine package.
61 skyEnginePath,
62
63 // Fuchsia artifacts from the engine prebuilts.
64 fuchsiaKernelCompiler,
65 fuchsiaFlutterRunner,
66
67 /// Tools related to subsetting or icon font files.
68 fontSubset,
69 constFinder,
70
71 /// The location of file generators.
72 flutterToolsFileGenerators,
73
74 /// Pre-built desktop debug app.
75 flutterPreviewDevice,
76}
77
78/// A subset of [Artifact]s that are platform and build mode independent
79enum HostArtifact {
80 /// The root of the web implementation of the dart SDK.
81 flutterWebSdk,
82 /// The libraries JSON file for web release builds.
83 flutterWebLibrariesJson,
84
85 // The flutter.js bootstrapping file provided by the engine.
86 flutterJsDirectory,
87
88 /// Folder that contains platform dill files for the web sdk.
89 webPlatformKernelFolder,
90
91 /// The summary dill for the dartdevc target.
92 webPlatformDDCKernelDill,
93 /// The summary dill with null safety enabled for the dartdevc target.g
94 webPlatformDDCSoundKernelDill,
95 /// The summary dill for the dartdevc target.
96 webPlatformDart2JSKernelDill,
97 /// The summary dill with null safety enabled for the dartdevc target.
98 webPlatformDart2JSSoundKernelDill,
99
100 /// The precompiled SDKs and sourcemaps for web debug builds with the AMD module system.
101 // TODO(markzipan): delete these when DDC's AMD module system is deprecated, https://github.com/flutter/flutter/issues/142060.
102 webPrecompiledAmdSdk,
103 webPrecompiledAmdSdkSourcemaps,
104 webPrecompiledAmdCanvaskitSdk,
105 webPrecompiledAmdCanvaskitSdkSourcemaps,
106 webPrecompiledAmdCanvaskitAndHtmlSdk,
107 webPrecompiledAmdCanvaskitAndHtmlSdkSourcemaps,
108 webPrecompiledAmdSoundSdk,
109 webPrecompiledAmdSoundSdkSourcemaps,
110 webPrecompiledAmdCanvaskitSoundSdk,
111 webPrecompiledAmdCanvaskitSoundSdkSourcemaps,
112 webPrecompiledAmdCanvaskitAndHtmlSoundSdk,
113 webPrecompiledAmdCanvaskitAndHtmlSoundSdkSourcemaps,
114
115 /// The precompiled SDKs and sourcemaps for web debug builds with the DDC module system.
116 webPrecompiledDdcSdk,
117 webPrecompiledDdcSdkSourcemaps,
118 webPrecompiledDdcCanvaskitSdk,
119 webPrecompiledDdcCanvaskitSdkSourcemaps,
120 webPrecompiledDdcCanvaskitAndHtmlSdk,
121 webPrecompiledDdcCanvaskitAndHtmlSdkSourcemaps,
122 webPrecompiledDdcSoundSdk,
123 webPrecompiledDdcSoundSdkSourcemaps,
124 webPrecompiledDdcCanvaskitSoundSdk,
125 webPrecompiledDdcCanvaskitSoundSdkSourcemaps,
126 webPrecompiledDdcCanvaskitAndHtmlSoundSdk,
127 webPrecompiledDdcCanvaskitAndHtmlSoundSdkSourcemaps,
128
129 iosDeploy,
130 idevicesyslog,
131 idevicescreenshot,
132 iproxy,
133
134 /// The root of the sky_engine package.
135 skyEnginePath,
136
137 // The Impeller shader compiler.
138 impellerc,
139 // The Impeller Scene 3D model importer.
140 scenec,
141 // Impeller's tessellation library.
142 libtessellator,
143}
144
145// TODO(knopp): Remove once darwin artifacts are universal and moved out of darwin-x64
146String _enginePlatformDirectoryName(TargetPlatform platform) {
147 if (platform == TargetPlatform.darwin) {
148 return 'darwin-x64';
149 }
150 return getNameForTargetPlatform(platform);
151}
152
153// Remove android target platform type.
154TargetPlatform? _mapTargetPlatform(TargetPlatform? targetPlatform) {
155 switch (targetPlatform) {
156 case TargetPlatform.android:
157 return TargetPlatform.android_arm64;
158 case TargetPlatform.ios:
159 case TargetPlatform.darwin:
160 case TargetPlatform.linux_x64:
161 case TargetPlatform.linux_arm64:
162 case TargetPlatform.windows_x64:
163 case TargetPlatform.windows_arm64:
164 case TargetPlatform.fuchsia_arm64:
165 case TargetPlatform.fuchsia_x64:
166 case TargetPlatform.tester:
167 case TargetPlatform.web_javascript:
168 case TargetPlatform.android_arm:
169 case TargetPlatform.android_arm64:
170 case TargetPlatform.android_x64:
171 case TargetPlatform.android_x86:
172 case null:
173 return targetPlatform;
174 }
175}
176
177String? _artifactToFileName(Artifact artifact, Platform hostPlatform, [ BuildMode? mode ]) {
178 final String exe = hostPlatform.isWindows ? '.exe' : '';
179 switch (artifact) {
180 case Artifact.genSnapshot:
181 return 'gen_snapshot';
182 case Artifact.flutterTester:
183 return 'flutter_tester$exe';
184 case Artifact.flutterFramework:
185 return 'Flutter.framework';
186 case Artifact.flutterFrameworkDsym:
187 return 'Flutter.framework.dSYM';
188 case Artifact.flutterXcframework:
189 return 'Flutter.xcframework';
190 case Artifact.flutterMacOSFramework:
191 return 'FlutterMacOS.framework';
192 case Artifact.flutterMacOSFrameworkDsym:
193 return 'FlutterMacOS.framework.dSYM';
194 case Artifact.flutterMacOSXcframework:
195 return 'FlutterMacOS.xcframework';
196 case Artifact.vmSnapshotData:
197 return 'vm_isolate_snapshot.bin';
198 case Artifact.isolateSnapshotData:
199 return 'isolate_snapshot.bin';
200 case Artifact.icuData:
201 return 'icudtl.dat';
202 case Artifact.platformKernelDill:
203 return 'platform_strong.dill';
204 case Artifact.platformLibrariesJson:
205 return 'libraries.json';
206 case Artifact.flutterPatchedSdkPath:
207 assert(false, 'No filename for sdk path, should not be invoked');
208 return null;
209 case Artifact.engineDartSdkPath:
210 return 'dart-sdk';
211 case Artifact.engineDartBinary:
212 return 'dart$exe';
213 case Artifact.engineDartAotRuntime:
214 return 'dartaotruntime$exe';
215 case Artifact.dart2jsSnapshot:
216 return 'dart2js.dart.snapshot';
217 case Artifact.dart2wasmSnapshot:
218 return 'dart2wasm_product.snapshot';
219 case Artifact.frontendServerSnapshotForEngineDartSdk:
220 return 'frontend_server_aot.dart.snapshot';
221 case Artifact.linuxDesktopPath:
222 return '';
223 case Artifact.linuxHeaders:
224 return 'flutter_linux';
225 case Artifact.windowsCppClientWrapper:
226 return 'cpp_client_wrapper';
227 case Artifact.windowsDesktopPath:
228 return '';
229 case Artifact.skyEnginePath:
230 return 'sky_engine';
231 case Artifact.fuchsiaKernelCompiler:
232 return 'kernel_compiler.snapshot';
233 case Artifact.fuchsiaFlutterRunner:
234 final String jitOrAot = mode!.isJit ? '_jit' : '_aot';
235 final String productOrNo = mode.isRelease ? '_product' : '';
236 return 'flutter$jitOrAot${productOrNo}_runner-0.far';
237 case Artifact.fontSubset:
238 return 'font-subset$exe';
239 case Artifact.constFinder:
240 return 'const_finder.dart.snapshot';
241 case Artifact.flutterToolsFileGenerators:
242 return '';
243 case Artifact.flutterPreviewDevice:
244 return 'flutter_preview$exe';
245 }
246}
247
248String _hostArtifactToFileName(HostArtifact artifact, Platform platform) {
249 final String exe = platform.isWindows ? '.exe' : '';
250 String dll = '.so';
251 if (platform.isWindows) {
252 dll = '.dll';
253 } else if (platform.isMacOS) {
254 dll = '.dylib';
255 }
256 switch (artifact) {
257 case HostArtifact.flutterWebSdk:
258 return '';
259 case HostArtifact.flutterJsDirectory:
260 return 'flutter_js';
261 case HostArtifact.iosDeploy:
262 return 'ios-deploy';
263 case HostArtifact.idevicesyslog:
264 return 'idevicesyslog';
265 case HostArtifact.idevicescreenshot:
266 return 'idevicescreenshot';
267 case HostArtifact.iproxy:
268 return 'iproxy';
269 case HostArtifact.skyEnginePath:
270 return 'sky_engine';
271 case HostArtifact.webPlatformKernelFolder:
272 return 'kernel';
273 case HostArtifact.webPlatformDDCKernelDill:
274 return 'ddc_outline.dill';
275 case HostArtifact.webPlatformDDCSoundKernelDill:
276 return 'ddc_outline_sound.dill';
277 case HostArtifact.webPlatformDart2JSKernelDill:
278 return 'dart2js_platform_unsound.dill';
279 case HostArtifact.webPlatformDart2JSSoundKernelDill:
280 return 'dart2js_platform.dill';
281 case HostArtifact.flutterWebLibrariesJson:
282 return 'libraries.json';
283 case HostArtifact.webPrecompiledAmdSdk:
284 case HostArtifact.webPrecompiledAmdCanvaskitSdk:
285 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdk:
286 case HostArtifact.webPrecompiledAmdSoundSdk:
287 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdk:
288 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdk:
289 case HostArtifact.webPrecompiledDdcSdk:
290 case HostArtifact.webPrecompiledDdcCanvaskitSdk:
291 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdk:
292 case HostArtifact.webPrecompiledDdcSoundSdk:
293 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdk:
294 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdk:
295 return 'dart_sdk.js';
296 case HostArtifact.webPrecompiledAmdSdkSourcemaps:
297 case HostArtifact.webPrecompiledAmdCanvaskitSdkSourcemaps:
298 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdkSourcemaps:
299 case HostArtifact.webPrecompiledAmdSoundSdkSourcemaps:
300 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdkSourcemaps:
301 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdkSourcemaps:
302 case HostArtifact.webPrecompiledDdcSdkSourcemaps:
303 case HostArtifact.webPrecompiledDdcCanvaskitSdkSourcemaps:
304 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdkSourcemaps:
305 case HostArtifact.webPrecompiledDdcSoundSdkSourcemaps:
306 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdkSourcemaps:
307 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdkSourcemaps:
308 return 'dart_sdk.js.map';
309 case HostArtifact.impellerc:
310 return 'impellerc$exe';
311 case HostArtifact.scenec:
312 return 'scenec$exe';
313 case HostArtifact.libtessellator:
314 return 'libtessellator$dll';
315 }
316}
317
318class EngineBuildPaths {
319 const EngineBuildPaths({
320 required this.targetEngine,
321 required this.hostEngine,
322 required this.webSdk,
323 });
324
325 final String? targetEngine;
326 final String? hostEngine;
327 final String? webSdk;
328}
329
330/// Information about a local engine build (i.e. `--local-engine[-host]=...`).
331///
332/// See https://github.com/flutter/flutter/blob/main/docs/tool/README.md#using-a-locally-built-engine-with-the-flutter-tool
333/// for more information about local engine builds.
334class LocalEngineInfo {
335 /// Creates a reference to a local engine build.
336 ///
337 /// The [targetOutPath] and [hostOutPath] are assumed to be resolvable
338 /// paths to the built engine artifacts for the target (device) and host
339 /// (build) platforms, respectively.
340 const LocalEngineInfo({
341 required this.targetOutPath,
342 required this.hostOutPath,
343 });
344
345 /// The path to the engine artifacts for the target (device) platform.
346 ///
347 /// For example, if the target platform is Android debug, this would be a path
348 /// like `/path/to/engine/src/out/android_debug_unopt`. To retrieve just the
349 /// name (platform), see [localTargetName].
350 final String targetOutPath;
351
352 /// The path to the engine artifacts for the host (build) platform.
353 ///
354 /// For example, if the host platform is debug, this would be a path like
355 /// `/path/to/engine/src/out/host_debug_unopt`. To retrieve just the name
356 /// (platform), see [localHostName].
357 final String hostOutPath;
358
359 /// The name of the target (device) platform, i.e. `android_debug_unopt`.
360 String get localTargetName => globals.fs.path.basename(targetOutPath);
361
362 /// The name of the host (build) platform, e.g. `host_debug_unopt`.
363 String get localHostName => globals.fs.path.basename(hostOutPath);
364}
365
366// Manages the engine artifacts of Flutter.
367abstract class Artifacts {
368 /// A test-specific implementation of artifacts that returns stable paths for
369 /// all artifacts.
370 ///
371 /// If a [fileSystem] is not provided, creates a new [MemoryFileSystem] instance.
372 ///
373 /// Creates a [LocalEngineArtifacts] if `localEngine` is non-null
374 @visibleForTesting
375 factory Artifacts.test({FileSystem? fileSystem}) {
376 return _TestArtifacts(fileSystem ?? MemoryFileSystem.test());
377 }
378
379 /// A test-specific implementation of artifacts that returns stable paths for
380 /// all artifacts, and uses a local engine.
381 ///
382 /// If a [fileSystem] is not provided, creates a new [MemoryFileSystem] instance.
383 @visibleForTesting
384 factory Artifacts.testLocalEngine({
385 required String localEngine,
386 required String localEngineHost,
387 FileSystem? fileSystem,
388 }) {
389 return _TestLocalEngine(
390 localEngine, localEngineHost, fileSystem ?? MemoryFileSystem.test());
391 }
392
393 static Artifacts getLocalEngine(EngineBuildPaths engineBuildPaths) {
394 Artifacts artifacts = CachedArtifacts(
395 fileSystem: globals.fs,
396 platform: globals.platform,
397 cache: globals.cache,
398 operatingSystemUtils: globals.os
399 );
400 if (engineBuildPaths.hostEngine != null && engineBuildPaths.targetEngine != null) {
401 artifacts = CachedLocalEngineArtifacts(
402 engineBuildPaths.hostEngine!,
403 engineOutPath: engineBuildPaths.targetEngine!,
404 cache: globals.cache,
405 fileSystem: globals.fs,
406 processManager: globals.processManager,
407 platform: globals.platform,
408 operatingSystemUtils: globals.os,
409 parent: artifacts,
410 );
411 }
412 if (engineBuildPaths.webSdk != null) {
413 artifacts = CachedLocalWebSdkArtifacts(
414 parent: artifacts,
415 webSdkPath: engineBuildPaths.webSdk!,
416 fileSystem: globals.fs,
417 platform: globals.platform,
418 operatingSystemUtils: globals.os
419 );
420 }
421 return artifacts;
422 }
423
424 /// Returns the requested [artifact] for the [platform], [mode], and [environmentType] combination.
425 String getArtifactPath(
426 Artifact artifact, {
427 TargetPlatform? platform,
428 BuildMode? mode,
429 EnvironmentType? environmentType,
430 });
431
432 /// Retrieve a host specific artifact that does not depend on the
433 /// current build mode or environment.
434 FileSystemEntity getHostArtifact(
435 HostArtifact artifact,
436 );
437
438 // Returns which set of engine artifacts is currently used for the [platform]
439 // and [mode] combination.
440 String getEngineType(TargetPlatform platform, [ BuildMode? mode ]);
441
442 /// Whether these artifacts correspond to a non-versioned local engine.
443 bool get isLocalEngine;
444
445 /// If these artifacts are bound to a local engine build, returns info about
446 /// the location and name of the local engine, otherwise returns null.
447 LocalEngineInfo? get localEngineInfo;
448}
449
450/// Manages the engine artifacts downloaded to the local cache.
451class CachedArtifacts implements Artifacts {
452 CachedArtifacts({
453 required FileSystem fileSystem,
454 required Platform platform,
455 required Cache cache,
456 required OperatingSystemUtils operatingSystemUtils,
457 }) : _fileSystem = fileSystem,
458 _platform = platform,
459 _cache = cache,
460 _operatingSystemUtils = operatingSystemUtils;
461
462 final FileSystem _fileSystem;
463 final Platform _platform;
464 final Cache _cache;
465 final OperatingSystemUtils _operatingSystemUtils;
466
467 @override
468 LocalEngineInfo? get localEngineInfo => null;
469
470 @override
471 FileSystemEntity getHostArtifact(
472 HostArtifact artifact,
473 ) {
474 switch (artifact) {
475 case HostArtifact.flutterWebSdk:
476 final String path = _getFlutterWebSdkPath();
477 return _fileSystem.directory(path);
478 case HostArtifact.flutterWebLibrariesJson:
479 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), _hostArtifactToFileName(artifact, _platform));
480 return _fileSystem.file(path);
481 case HostArtifact.flutterJsDirectory:
482 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'flutter_js');
483 return _fileSystem.directory(path);
484 case HostArtifact.webPlatformKernelFolder:
485 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel');
486 return _fileSystem.file(path);
487 case HostArtifact.webPlatformDDCKernelDill:
488 case HostArtifact.webPlatformDDCSoundKernelDill:
489 case HostArtifact.webPlatformDart2JSKernelDill:
490 case HostArtifact.webPlatformDart2JSSoundKernelDill:
491 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _hostArtifactToFileName(artifact, _platform));
492 return _fileSystem.file(path);
493 case HostArtifact.webPrecompiledAmdSdk:
494 case HostArtifact.webPrecompiledAmdSdkSourcemaps:
495 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd', _hostArtifactToFileName(artifact, _platform));
496 return _fileSystem.file(path);
497 case HostArtifact.webPrecompiledAmdCanvaskitSdk:
498 case HostArtifact.webPrecompiledAmdCanvaskitSdkSourcemaps:
499 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit', _hostArtifactToFileName(artifact, _platform));
500 return _fileSystem.file(path);
501 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdk:
502 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdkSourcemaps:
503 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
504 return _fileSystem.file(path);
505 case HostArtifact.webPrecompiledAmdSoundSdk:
506 case HostArtifact.webPrecompiledAmdSoundSdkSourcemaps:
507 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-sound', _hostArtifactToFileName(artifact, _platform));
508 return _fileSystem.file(path);
509 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdk:
510 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdkSourcemaps:
511 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-sound', _hostArtifactToFileName(artifact, _platform));
512 return _fileSystem.file(path);
513 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdk:
514 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdkSourcemaps:
515 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html-sound', _hostArtifactToFileName(artifact, _platform));
516 return _fileSystem.file(path);
517 case HostArtifact.webPrecompiledDdcSdk:
518 case HostArtifact.webPrecompiledDdcSdkSourcemaps:
519 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc', _hostArtifactToFileName(artifact, _platform));
520 return _fileSystem.file(path);
521 case HostArtifact.webPrecompiledDdcCanvaskitSdk:
522 case HostArtifact.webPrecompiledDdcCanvaskitSdkSourcemaps:
523 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit', _hostArtifactToFileName(artifact, _platform));
524 return _fileSystem.file(path);
525 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdk:
526 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdkSourcemaps:
527 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
528 return _fileSystem.file(path);
529 case HostArtifact.webPrecompiledDdcSoundSdk:
530 case HostArtifact.webPrecompiledDdcSoundSdkSourcemaps:
531 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-sound', _hostArtifactToFileName(artifact, _platform));
532 return _fileSystem.file(path);
533 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdk:
534 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdkSourcemaps:
535 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-sound', _hostArtifactToFileName(artifact, _platform));
536 return _fileSystem.file(path);
537 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdk:
538 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdkSourcemaps:
539 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-html-sound', _hostArtifactToFileName(artifact, _platform));
540 return _fileSystem.file(path);
541 case HostArtifact.idevicesyslog:
542 case HostArtifact.idevicescreenshot:
543 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
544 return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName);
545 case HostArtifact.skyEnginePath:
546 final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
547 final String path = _fileSystem.path.join(dartPackageDirectory.path, _hostArtifactToFileName(artifact, _platform));
548 return _fileSystem.directory(path);
549 case HostArtifact.iosDeploy:
550 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
551 return _cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName);
552 case HostArtifact.iproxy:
553 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
554 return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName);
555 case HostArtifact.impellerc:
556 case HostArtifact.scenec:
557 case HostArtifact.libtessellator:
558 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
559 final String engineDir = _getEngineArtifactsPath(_currentHostPlatform(_platform, _operatingSystemUtils))!;
560 return _fileSystem.file(_fileSystem.path.join(engineDir, artifactFileName));
561 }
562 }
563
564 @override
565 String getArtifactPath(
566 Artifact artifact, {
567 TargetPlatform? platform,
568 BuildMode? mode,
569 EnvironmentType? environmentType,
570 }) {
571 platform = _mapTargetPlatform(platform);
572 switch (platform) {
573 case TargetPlatform.android:
574 case TargetPlatform.android_arm:
575 case TargetPlatform.android_arm64:
576 case TargetPlatform.android_x64:
577 case TargetPlatform.android_x86:
578 assert(platform != TargetPlatform.android);
579 return _getAndroidArtifactPath(artifact, platform!, mode!);
580 case TargetPlatform.ios:
581 return _getIosArtifactPath(artifact, platform!, mode, environmentType);
582 case TargetPlatform.darwin:
583 case TargetPlatform.linux_x64:
584 case TargetPlatform.linux_arm64:
585 case TargetPlatform.windows_x64:
586 case TargetPlatform.windows_arm64:
587 return _getDesktopArtifactPath(artifact, platform!, mode);
588 case TargetPlatform.fuchsia_arm64:
589 case TargetPlatform.fuchsia_x64:
590 return _getFuchsiaArtifactPath(artifact, platform!, mode!);
591 case TargetPlatform.tester:
592 case TargetPlatform.web_javascript:
593 case null:
594 return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform, _operatingSystemUtils), mode);
595 }
596 }
597
598 @override
599 String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) {
600 return _fileSystem.path.basename(_getEngineArtifactsPath(platform, mode)!);
601 }
602
603 String _getDesktopArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode? mode) {
604 // When platform is null, a generic host platform artifact is being requested
605 // and not the gen_snapshot for darwin as a target platform.
606 final String engineDir = _getEngineArtifactsPath(platform, mode)!;
607 switch (artifact) {
608 case Artifact.genSnapshot:
609 return _fileSystem.path.join(engineDir, _artifactToFileName(artifact, _platform));
610 case Artifact.engineDartSdkPath:
611 case Artifact.engineDartBinary:
612 case Artifact.engineDartAotRuntime:
613 case Artifact.dart2jsSnapshot:
614 case Artifact.dart2wasmSnapshot:
615 case Artifact.frontendServerSnapshotForEngineDartSdk:
616 case Artifact.constFinder:
617 case Artifact.flutterFramework:
618 case Artifact.flutterFrameworkDsym:
619 case Artifact.flutterMacOSFramework:
620 return _getMacOSFrameworkPath(engineDir, _fileSystem, _platform);
621 case Artifact.flutterMacOSFrameworkDsym:
622 return _getMacOSFrameworkDsymPath(engineDir, _fileSystem, _platform);
623 case Artifact.flutterMacOSXcframework:
624 case Artifact.flutterPatchedSdkPath:
625 case Artifact.flutterTester:
626 case Artifact.flutterXcframework:
627 case Artifact.fontSubset:
628 case Artifact.fuchsiaFlutterRunner:
629 case Artifact.fuchsiaKernelCompiler:
630 case Artifact.icuData:
631 case Artifact.isolateSnapshotData:
632 case Artifact.linuxDesktopPath:
633 case Artifact.linuxHeaders:
634 case Artifact.platformKernelDill:
635 case Artifact.platformLibrariesJson:
636 case Artifact.skyEnginePath:
637 case Artifact.vmSnapshotData:
638 case Artifact.windowsCppClientWrapper:
639 case Artifact.windowsDesktopPath:
640 case Artifact.flutterToolsFileGenerators:
641 case Artifact.flutterPreviewDevice:
642 return _getHostArtifactPath(artifact, platform, mode);
643 }
644 }
645
646 String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
647 final String engineDir = _getEngineArtifactsPath(platform, mode)!;
648 switch (artifact) {
649 case Artifact.genSnapshot:
650 assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
651
652 // TODO(cbracken): Build Android gen_snapshot as Arm64 binary to run
653 // natively on Apple Silicon. See:
654 // https://github.com/flutter/flutter/issues/152281
655 HostPlatform hostPlatform = getCurrentHostPlatform();
656 if (hostPlatform == HostPlatform.darwin_arm64) {
657 hostPlatform = HostPlatform.darwin_x64;
658 }
659
660 final String hostPlatformName = getNameForHostPlatform(hostPlatform);
661 return _fileSystem.path.join(engineDir, hostPlatformName, _artifactToFileName(artifact, _platform));
662 case Artifact.engineDartSdkPath:
663 case Artifact.engineDartBinary:
664 case Artifact.engineDartAotRuntime:
665 case Artifact.dart2jsSnapshot:
666 case Artifact.dart2wasmSnapshot:
667 case Artifact.frontendServerSnapshotForEngineDartSdk:
668 case Artifact.constFinder:
669 case Artifact.flutterFramework:
670 case Artifact.flutterFrameworkDsym:
671 case Artifact.flutterMacOSFramework:
672 case Artifact.flutterMacOSFrameworkDsym:
673 case Artifact.flutterMacOSXcframework:
674 case Artifact.flutterPatchedSdkPath:
675 case Artifact.flutterTester:
676 case Artifact.flutterXcframework:
677 case Artifact.fontSubset:
678 case Artifact.fuchsiaFlutterRunner:
679 case Artifact.fuchsiaKernelCompiler:
680 case Artifact.icuData:
681 case Artifact.isolateSnapshotData:
682 case Artifact.linuxDesktopPath:
683 case Artifact.linuxHeaders:
684 case Artifact.platformKernelDill:
685 case Artifact.platformLibrariesJson:
686 case Artifact.skyEnginePath:
687 case Artifact.vmSnapshotData:
688 case Artifact.windowsCppClientWrapper:
689 case Artifact.windowsDesktopPath:
690 case Artifact.flutterToolsFileGenerators:
691 case Artifact.flutterPreviewDevice:
692 return _getHostArtifactPath(artifact, platform, mode);
693 }
694 }
695
696 String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode? mode, EnvironmentType? environmentType) {
697 switch (artifact) {
698 case Artifact.genSnapshot:
699 case Artifact.flutterXcframework:
700 final String artifactFileName = _artifactToFileName(artifact, _platform)!;
701 final String engineDir = _getEngineArtifactsPath(platform, mode)!;
702 return _fileSystem.path.join(engineDir, artifactFileName);
703 case Artifact.flutterFramework:
704 final String engineDir = _getEngineArtifactsPath(platform, mode)!;
705 return _getIosFrameworkPath(engineDir, environmentType, _fileSystem, _platform);
706 case Artifact.flutterFrameworkDsym:
707 final String engineDir = _getEngineArtifactsPath(platform, mode)!;
708 return _getIosFrameworkDsymPath(engineDir, environmentType, _fileSystem, _platform);
709 case Artifact.engineDartSdkPath:
710 case Artifact.engineDartBinary:
711 case Artifact.engineDartAotRuntime:
712 case Artifact.dart2jsSnapshot:
713 case Artifact.dart2wasmSnapshot:
714 case Artifact.frontendServerSnapshotForEngineDartSdk:
715 case Artifact.constFinder:
716 case Artifact.flutterMacOSFramework:
717 case Artifact.flutterMacOSFrameworkDsym:
718 case Artifact.flutterMacOSXcframework:
719 case Artifact.flutterPatchedSdkPath:
720 case Artifact.flutterTester:
721 case Artifact.fontSubset:
722 case Artifact.fuchsiaFlutterRunner:
723 case Artifact.fuchsiaKernelCompiler:
724 case Artifact.icuData:
725 case Artifact.isolateSnapshotData:
726 case Artifact.linuxDesktopPath:
727 case Artifact.linuxHeaders:
728 case Artifact.platformKernelDill:
729 case Artifact.platformLibrariesJson:
730 case Artifact.skyEnginePath:
731 case Artifact.vmSnapshotData:
732 case Artifact.windowsCppClientWrapper:
733 case Artifact.windowsDesktopPath:
734 case Artifact.flutterToolsFileGenerators:
735 case Artifact.flutterPreviewDevice:
736 return _getHostArtifactPath(artifact, platform, mode);
737 }
738 }
739
740 String _getFuchsiaArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
741 final String root = _fileSystem.path.join(
742 _cache.getArtifactDirectory('flutter_runner').path,
743 'flutter',
744 platform.fuchsiaArchForTargetPlatform,
745 mode.isRelease ? 'release' : mode.toString(),
746 );
747 final String runtime = mode.isJit ? 'jit' : 'aot';
748 switch (artifact) {
749 case Artifact.genSnapshot:
750 final String genSnapshot = mode.isRelease ? 'gen_snapshot_product' : 'gen_snapshot';
751 return _fileSystem.path.join(root, runtime, 'dart_binaries', genSnapshot);
752 case Artifact.flutterPatchedSdkPath:
753 const String artifactFileName = 'flutter_runner_patched_sdk';
754 return _fileSystem.path.join(root, runtime, artifactFileName);
755 case Artifact.platformKernelDill:
756 final String artifactFileName = _artifactToFileName(artifact, _platform, mode)!;
757 return _fileSystem.path.join(root, runtime, 'flutter_runner_patched_sdk', artifactFileName);
758 case Artifact.fuchsiaKernelCompiler:
759 final String artifactFileName = _artifactToFileName(artifact, _platform, mode)!;
760 return _fileSystem.path.join(root, runtime, 'dart_binaries', artifactFileName);
761 case Artifact.fuchsiaFlutterRunner:
762 final String artifactFileName = _artifactToFileName(artifact, _platform, mode)!;
763 return _fileSystem.path.join(root, runtime, artifactFileName);
764 case Artifact.constFinder:
765 case Artifact.flutterFramework:
766 case Artifact.flutterFrameworkDsym:
767 case Artifact.flutterMacOSFramework:
768 case Artifact.flutterMacOSFrameworkDsym:
769 case Artifact.flutterMacOSXcframework:
770 case Artifact.flutterTester:
771 case Artifact.flutterXcframework:
772 case Artifact.fontSubset:
773 case Artifact.engineDartSdkPath:
774 case Artifact.engineDartBinary:
775 case Artifact.engineDartAotRuntime:
776 case Artifact.dart2jsSnapshot:
777 case Artifact.dart2wasmSnapshot:
778 case Artifact.frontendServerSnapshotForEngineDartSdk:
779 case Artifact.icuData:
780 case Artifact.isolateSnapshotData:
781 case Artifact.linuxDesktopPath:
782 case Artifact.linuxHeaders:
783 case Artifact.platformLibrariesJson:
784 case Artifact.skyEnginePath:
785 case Artifact.vmSnapshotData:
786 case Artifact.windowsCppClientWrapper:
787 case Artifact.windowsDesktopPath:
788 case Artifact.flutterToolsFileGenerators:
789 case Artifact.flutterPreviewDevice:
790 return _getHostArtifactPath(artifact, platform, mode);
791 }
792 }
793
794 String _getFlutterPatchedSdkPath(BuildMode? mode) {
795 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
796 return _fileSystem.path.join(engineArtifactsPath, 'common',
797 mode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
798 }
799
800 String _getFlutterWebSdkPath() {
801 return _cache.getWebSdkDirectory().path;
802 }
803
804 String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode? mode) {
805 switch (artifact) {
806 case Artifact.genSnapshot:
807 // For script snapshots any gen_snapshot binary will do. Returning gen_snapshot for
808 // android_arm in profile mode because it is available on all supported host platforms.
809 return _getAndroidArtifactPath(artifact, TargetPlatform.android_arm, BuildMode.profile);
810 case Artifact.dart2jsSnapshot:
811 case Artifact.dart2wasmSnapshot:
812 case Artifact.frontendServerSnapshotForEngineDartSdk:
813 return _fileSystem.path.join(
814 _dartSdkPath(_cache), 'bin', 'snapshots',
815 _artifactToFileName(artifact, _platform),
816 );
817 case Artifact.flutterTester:
818 case Artifact.vmSnapshotData:
819 case Artifact.isolateSnapshotData:
820 case Artifact.icuData:
821 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
822 final String platformDirName = _enginePlatformDirectoryName(platform);
823 return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, _platform, mode));
824 case Artifact.platformKernelDill:
825 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), _artifactToFileName(artifact, _platform));
826 case Artifact.platformLibrariesJson:
827 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', _artifactToFileName(artifact, _platform));
828 case Artifact.flutterPatchedSdkPath:
829 return _getFlutterPatchedSdkPath(mode);
830 case Artifact.engineDartSdkPath:
831 return _dartSdkPath(_cache);
832 case Artifact.engineDartBinary:
833 case Artifact.engineDartAotRuntime:
834 return _fileSystem.path.join(_dartSdkPath(_cache), 'bin', _artifactToFileName(artifact, _platform));
835 case Artifact.flutterMacOSFramework:
836 String platformDirName = _enginePlatformDirectoryName(platform);
837 if (mode == BuildMode.profile || mode == BuildMode.release) {
838 platformDirName = '$platformDirName-${mode!.cliName}';
839 }
840 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
841 return _getMacOSFrameworkPath(_fileSystem.path.join(engineArtifactsPath, platformDirName), _fileSystem, _platform);
842 case Artifact.flutterMacOSFrameworkDsym:
843 String platformDirName = _enginePlatformDirectoryName(platform);
844 if (mode == BuildMode.profile || mode == BuildMode.release) {
845 platformDirName = '$platformDirName-${mode!.cliName}';
846 }
847 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
848 return _getMacOSFrameworkDsymPath(_fileSystem.path.join(engineArtifactsPath, platformDirName), _fileSystem, _platform);
849 case Artifact.flutterMacOSXcframework:
850 case Artifact.linuxDesktopPath:
851 case Artifact.windowsDesktopPath:
852 case Artifact.linuxHeaders:
853 // TODO(zanderso): remove once debug desktop artifacts are uploaded
854 // under a separate directory from the host artifacts.
855 // https://github.com/flutter/flutter/issues/38935
856 String platformDirName = _enginePlatformDirectoryName(platform);
857 if (mode == BuildMode.profile || mode == BuildMode.release) {
858 platformDirName = '$platformDirName-${mode!.cliName}';
859 }
860 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
861 return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, _platform, mode));
862 case Artifact.windowsCppClientWrapper:
863 final String platformDirName = _enginePlatformDirectoryName(platform);
864 final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
865 return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, _platform, mode));
866 case Artifact.skyEnginePath:
867 final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
868 return _fileSystem.path.join(dartPackageDirectory.path, _artifactToFileName(artifact, _platform));
869 case Artifact.fontSubset:
870 case Artifact.constFinder:
871 return _cache.getArtifactDirectory('engine')
872 .childDirectory(_enginePlatformDirectoryName(platform))
873 .childFile(_artifactToFileName(artifact, _platform, mode)!)
874 .path;
875 case Artifact.flutterFramework:
876 case Artifact.flutterFrameworkDsym:
877 case Artifact.flutterXcframework:
878 case Artifact.fuchsiaFlutterRunner:
879 case Artifact.fuchsiaKernelCompiler:
880 throw StateError('Artifact $artifact not available for platform $platform.');
881 case Artifact.flutterToolsFileGenerators:
882 return _getFileGeneratorsPath();
883 case Artifact.flutterPreviewDevice:
884 assert(platform == TargetPlatform.windows_x64);
885 return _cache.getArtifactDirectory('flutter_preview').childFile('flutter_preview.exe').path;
886 }
887 }
888
889 String? _getEngineArtifactsPath(TargetPlatform platform, [ BuildMode? mode ]) {
890 final String engineDir = _cache.getArtifactDirectory('engine').path;
891 final String platformName = _enginePlatformDirectoryName(platform);
892 switch (platform) {
893 case TargetPlatform.linux_x64:
894 case TargetPlatform.linux_arm64:
895 case TargetPlatform.darwin:
896 case TargetPlatform.windows_x64:
897 case TargetPlatform.windows_arm64:
898 // TODO(zanderso): remove once debug desktop artifacts are uploaded
899 // under a separate directory from the host artifacts.
900 // https://github.com/flutter/flutter/issues/38935
901 if (mode == BuildMode.debug || mode == null) {
902 return _fileSystem.path.join(engineDir, platformName);
903 }
904 final String suffix = mode != BuildMode.debug ? '-${kebabCase(mode.cliName)}' : '';
905 return _fileSystem.path.join(engineDir, platformName + suffix);
906 case TargetPlatform.fuchsia_arm64:
907 case TargetPlatform.fuchsia_x64:
908 case TargetPlatform.tester:
909 case TargetPlatform.web_javascript:
910 assert(mode == null, 'Platform $platform does not support different build modes.');
911 return _fileSystem.path.join(engineDir, platformName);
912 case TargetPlatform.ios:
913 case TargetPlatform.android_arm:
914 case TargetPlatform.android_arm64:
915 case TargetPlatform.android_x64:
916 case TargetPlatform.android_x86:
917 assert(mode != null, 'Need to specify a build mode for platform $platform.');
918 final String suffix = mode != BuildMode.debug ? '-${kebabCase(mode!.cliName)}' : '';
919 return _fileSystem.path.join(engineDir, platformName + suffix);
920 case TargetPlatform.android:
921 assert(false, 'cannot use TargetPlatform.android to look up artifacts');
922 return null;
923 }
924 }
925
926 @override
927 bool get isLocalEngine => false;
928}
929
930TargetPlatform _currentHostPlatform(Platform platform, OperatingSystemUtils operatingSystemUtils) {
931 if (platform.isMacOS) {
932 return TargetPlatform.darwin;
933 }
934 if (platform.isLinux) {
935 return operatingSystemUtils.hostPlatform == HostPlatform.linux_x64 ?
936 TargetPlatform.linux_x64 : TargetPlatform.linux_arm64;
937 }
938 if (platform.isWindows) {
939 return operatingSystemUtils.hostPlatform == HostPlatform.windows_arm64 ?
940 TargetPlatform.windows_arm64 : TargetPlatform.windows_x64;
941 }
942 throw UnimplementedError('Host OS not supported.');
943}
944
945/// Returns the Flutter.xcframework platform directory for the specified environment type.
946///
947/// `Flutter.xcframework` contains target environment/architecture-specific
948/// subdirectories containing the appropriate `Flutter.framework` and
949/// `dSYMs/Flutter.framework.dSYMs` bundles for that target architecture.
950Directory _getIosFlutterFrameworkPlatformDirectory(
951 String engineDirectory,
952 EnvironmentType? environmentType,
953 FileSystem fileSystem,
954 Platform hostPlatform) {
955 final Directory xcframeworkDirectory = fileSystem
956 .directory(engineDirectory)
957 .childDirectory(_artifactToFileName(Artifact.flutterXcframework, hostPlatform)!);
958
959 if (!xcframeworkDirectory.existsSync()) {
960 throwToolExit('No xcframework found at ${xcframeworkDirectory.path}. Try running "flutter precache --ios".');
961 }
962 for (final Directory platformDirectory in xcframeworkDirectory.listSync().whereType<Directory>()) {
963 if (!platformDirectory.basename.startsWith('ios-')) {
964 continue;
965 }
966 // ios-x86_64-simulator, ios-arm64_x86_64-simulator, or ios-arm64.
967 final bool simulatorDirectory = platformDirectory.basename.endsWith('-simulator');
968 if ((environmentType == EnvironmentType.simulator && simulatorDirectory) ||
969 (environmentType == EnvironmentType.physical && !simulatorDirectory)) {
970 return platformDirectory;
971 }
972 }
973 throwToolExit('No iOS frameworks found in ${xcframeworkDirectory.path}');
974}
975
976/// Returns the path to Flutter.framework.
977String _getIosFrameworkPath(
978 String engineDirectory,
979 EnvironmentType? environmentType,
980 FileSystem fileSystem,
981 Platform hostPlatform) {
982 final Directory platformDir = _getIosFlutterFrameworkPlatformDirectory(
983 engineDirectory,
984 environmentType,
985 fileSystem,
986 hostPlatform,
987 );
988 return platformDir
989 .childDirectory(_artifactToFileName(Artifact.flutterFramework, hostPlatform)!)
990 .path;
991}
992
993/// Returns the path to Flutter.framework.dSYM.
994String _getIosFrameworkDsymPath(
995 String engineDirectory,
996 EnvironmentType? environmentType,
997 FileSystem fileSystem,
998 Platform hostPlatform) {
999 final Directory platformDir = _getIosFlutterFrameworkPlatformDirectory(
1000 engineDirectory,
1001 environmentType,
1002 fileSystem,
1003 hostPlatform,
1004 );
1005 return platformDir
1006 .childDirectory('dSYMs')
1007 .childDirectory(_artifactToFileName(Artifact.flutterFrameworkDsym, hostPlatform)!)
1008 .path;
1009}
1010
1011/// Returns the Flutter.xcframework platform directory for the specified environment type.
1012///
1013/// `FlutterMacOS.xcframework` contains target environment/architecture-specific
1014/// subdirectories containing the appropriate `FlutterMacOS.framework` and
1015/// `FlutterMacOS.framework.dSYM` bundles for that target architecture. At present,
1016/// there is only one such directory: `macos-arm64_x86_64`.
1017Directory _getMacOSFrameworkPlatformDirectory(
1018 String engineDirectory,
1019 FileSystem fileSystem,
1020 Platform hostPlatform,
1021) {
1022 final Directory xcframeworkDirectory = fileSystem
1023 .directory(engineDirectory)
1024 .childDirectory(_artifactToFileName(Artifact.flutterMacOSXcframework, hostPlatform)!);
1025
1026 if (!xcframeworkDirectory.existsSync()) {
1027 throwToolExit('No xcframework found at ${xcframeworkDirectory.path}. Try running "flutter precache --macos".');
1028 }
1029 final Directory? platformDirectory = xcframeworkDirectory
1030 .listSync()
1031 .whereType<Directory>()
1032 .where((Directory platformDirectory) =>
1033 platformDirectory.basename.startsWith('macos-'))
1034 .firstOrNull;
1035 if (platformDirectory == null) {
1036 throwToolExit('No macOS frameworks found in ${xcframeworkDirectory.path}');
1037 }
1038 return platformDirectory;
1039}
1040
1041/// Returns the path to `FlutterMacOS.framework`.
1042String _getMacOSFrameworkPath(
1043 String engineDirectory,
1044 FileSystem fileSystem,
1045 Platform hostPlatform,
1046) {
1047 final Directory platformDirectory = _getMacOSFrameworkPlatformDirectory(engineDirectory, fileSystem, hostPlatform);
1048 return platformDirectory
1049 .childDirectory(_artifactToFileName(Artifact.flutterMacOSFramework, hostPlatform)!)
1050 .path;
1051}
1052
1053/// Returns the path to `FlutterMacOS.framework`.
1054String _getMacOSFrameworkDsymPath(
1055 String engineDirectory,
1056 FileSystem fileSystem,
1057 Platform hostPlatform,
1058) {
1059 final Directory platformDirectory = _getMacOSFrameworkPlatformDirectory(engineDirectory, fileSystem, hostPlatform);
1060 return platformDirectory
1061 .childDirectory('dSYMs')
1062 .childDirectory(_artifactToFileName(Artifact.flutterMacOSFrameworkDsym, hostPlatform)!)
1063 .path;
1064}
1065
1066/// Manages the artifacts of a locally built engine.
1067class CachedLocalEngineArtifacts implements Artifacts {
1068 CachedLocalEngineArtifacts(
1069 this._hostEngineOutPath, {
1070 required String engineOutPath,
1071 required FileSystem fileSystem,
1072 required Cache cache,
1073 required ProcessManager processManager,
1074 required Platform platform,
1075 required OperatingSystemUtils operatingSystemUtils,
1076 Artifacts? parent,
1077 }) : _fileSystem = fileSystem,
1078 localEngineInfo =
1079 LocalEngineInfo(
1080 targetOutPath: engineOutPath,
1081 hostOutPath: _hostEngineOutPath,
1082 ),
1083 _cache = cache,
1084 _processManager = processManager,
1085 _platform = platform,
1086 _operatingSystemUtils = operatingSystemUtils,
1087 _backupCache = parent ??
1088 CachedArtifacts(
1089 fileSystem: fileSystem,
1090 platform: platform,
1091 cache: cache,
1092 operatingSystemUtils: operatingSystemUtils
1093 );
1094
1095 @override
1096 final LocalEngineInfo localEngineInfo;
1097
1098 final String _hostEngineOutPath;
1099 final FileSystem _fileSystem;
1100 final Cache _cache;
1101 final ProcessManager _processManager;
1102 final Platform _platform;
1103 final OperatingSystemUtils _operatingSystemUtils;
1104 final Artifacts _backupCache;
1105
1106 @override
1107 FileSystemEntity getHostArtifact(
1108 HostArtifact artifact,
1109 ) {
1110 switch (artifact) {
1111 case HostArtifact.flutterWebSdk:
1112 final String path = _getFlutterWebSdkPath();
1113 return _fileSystem.directory(path);
1114 case HostArtifact.flutterWebLibrariesJson:
1115 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), _hostArtifactToFileName(artifact, _platform));
1116 return _fileSystem.file(path);
1117 case HostArtifact.flutterJsDirectory:
1118 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'flutter_js');
1119 return _fileSystem.directory(path);
1120 case HostArtifact.webPlatformKernelFolder:
1121 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel');
1122 return _fileSystem.file(path);
1123 case HostArtifact.webPlatformDDCKernelDill:
1124 case HostArtifact.webPlatformDDCSoundKernelDill:
1125 case HostArtifact.webPlatformDart2JSKernelDill:
1126 case HostArtifact.webPlatformDart2JSSoundKernelDill:
1127 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _hostArtifactToFileName(artifact, _platform));
1128 return _fileSystem.file(path);
1129 case HostArtifact.webPrecompiledAmdSdk:
1130 case HostArtifact.webPrecompiledAmdSdkSourcemaps:
1131 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd', _hostArtifactToFileName(artifact, _platform));
1132 return _fileSystem.file(path);
1133 case HostArtifact.webPrecompiledAmdCanvaskitSdk:
1134 case HostArtifact.webPrecompiledAmdCanvaskitSdkSourcemaps:
1135 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit', _hostArtifactToFileName(artifact, _platform));
1136 return _fileSystem.file(path);
1137 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdk:
1138 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdkSourcemaps:
1139 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
1140 return _fileSystem.file(path);
1141 case HostArtifact.webPrecompiledAmdSoundSdk:
1142 case HostArtifact.webPrecompiledAmdSoundSdkSourcemaps:
1143 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-sound', _hostArtifactToFileName(artifact, _platform));
1144 return _fileSystem.file(path);
1145 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdk:
1146 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdkSourcemaps:
1147 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-sound', _hostArtifactToFileName(artifact, _platform));
1148 return _fileSystem.file(path);
1149 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdk:
1150 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdkSourcemaps:
1151 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html-sound', _hostArtifactToFileName(artifact, _platform));
1152 return _fileSystem.file(path);
1153 case HostArtifact.webPrecompiledDdcSdk:
1154 case HostArtifact.webPrecompiledDdcSdkSourcemaps:
1155 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc', _hostArtifactToFileName(artifact, _platform));
1156 return _fileSystem.file(path);
1157 case HostArtifact.webPrecompiledDdcCanvaskitSdk:
1158 case HostArtifact.webPrecompiledDdcCanvaskitSdkSourcemaps:
1159 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit', _hostArtifactToFileName(artifact, _platform));
1160 return _fileSystem.file(path);
1161 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdk:
1162 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdkSourcemaps:
1163 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
1164 return _fileSystem.file(path);
1165 case HostArtifact.webPrecompiledDdcSoundSdk:
1166 case HostArtifact.webPrecompiledDdcSoundSdkSourcemaps:
1167 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-sound', _hostArtifactToFileName(artifact, _platform));
1168 return _fileSystem.file(path);
1169 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdk:
1170 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdkSourcemaps:
1171 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-sound', _hostArtifactToFileName(artifact, _platform));
1172 return _fileSystem.file(path);
1173 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdk:
1174 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdkSourcemaps:
1175 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-html-sound', _hostArtifactToFileName(artifact, _platform));
1176 return _fileSystem.file(path);
1177 case HostArtifact.idevicesyslog:
1178 case HostArtifact.idevicescreenshot:
1179 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
1180 return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName);
1181 case HostArtifact.skyEnginePath:
1182 final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
1183 final String path = _fileSystem.path.join(dartPackageDirectory.path, _hostArtifactToFileName(artifact, _platform));
1184 return _fileSystem.directory(path);
1185 case HostArtifact.iosDeploy:
1186 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
1187 return _cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName);
1188 case HostArtifact.iproxy:
1189 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
1190 return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName);
1191 case HostArtifact.impellerc:
1192 case HostArtifact.scenec:
1193 case HostArtifact.libtessellator:
1194 final String artifactFileName = _hostArtifactToFileName(artifact, _platform);
1195 final File file = _fileSystem.file(_fileSystem.path.join(_hostEngineOutPath, artifactFileName));
1196 if (!file.existsSync()) {
1197 return _backupCache.getHostArtifact(artifact);
1198 }
1199 return file;
1200 }
1201 }
1202
1203 @override
1204 String getArtifactPath(
1205 Artifact artifact, {
1206 TargetPlatform? platform,
1207 BuildMode? mode,
1208 EnvironmentType? environmentType,
1209 }) {
1210 platform ??= _currentHostPlatform(_platform, _operatingSystemUtils);
1211 platform = _mapTargetPlatform(platform);
1212 final bool isDirectoryArtifact = artifact == Artifact.flutterPatchedSdkPath;
1213 final String? artifactFileName = isDirectoryArtifact ? null : _artifactToFileName(artifact, _platform, mode);
1214 switch (artifact) {
1215 case Artifact.genSnapshot:
1216 return _genSnapshotPath();
1217 case Artifact.flutterTester:
1218 return _flutterTesterPath(platform!);
1219 case Artifact.isolateSnapshotData:
1220 case Artifact.vmSnapshotData:
1221 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName);
1222 case Artifact.icuData:
1223 case Artifact.flutterXcframework:
1224 case Artifact.flutterMacOSXcframework:
1225 return _fileSystem.path.join(localEngineInfo.targetOutPath, artifactFileName);
1226 case Artifact.platformKernelDill:
1227 if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
1228 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'flutter_runner_patched_sdk', artifactFileName);
1229 }
1230 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), artifactFileName);
1231 case Artifact.platformLibrariesJson:
1232 return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName);
1233 case Artifact.flutterFramework:
1234 return _getIosFrameworkPath(
1235 localEngineInfo.targetOutPath, environmentType, _fileSystem, _platform);
1236 case Artifact.flutterFrameworkDsym:
1237 return _getIosFrameworkDsymPath(
1238 localEngineInfo.targetOutPath, environmentType, _fileSystem, _platform);
1239 case Artifact.flutterMacOSFramework:
1240 return _getMacOSFrameworkPath(
1241 localEngineInfo.targetOutPath, _fileSystem, _platform);
1242 case Artifact.flutterMacOSFrameworkDsym:
1243 return _getMacOSFrameworkDsymPath(
1244 localEngineInfo.targetOutPath, _fileSystem, _platform);
1245 case Artifact.flutterPatchedSdkPath:
1246 // When using local engine always use [BuildMode.debug] regardless of
1247 // what was specified in [mode] argument because local engine will
1248 // have only one flutter_patched_sdk in standard location, that
1249 // is happen to be what debug(non-release) mode is using.
1250 if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
1251 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'flutter_runner_patched_sdk');
1252 }
1253 return _getFlutterPatchedSdkPath(BuildMode.debug);
1254 case Artifact.skyEnginePath:
1255 return _fileSystem.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName);
1256 case Artifact.fuchsiaKernelCompiler:
1257 final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
1258 final String modeName = mode!.isRelease ? 'release' : mode.toString();
1259 final String dartBinaries = 'dart_binaries-$modeName-$hostPlatform';
1260 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'host_bundle', dartBinaries, 'kernel_compiler.dart.snapshot');
1261 case Artifact.fuchsiaFlutterRunner:
1262 final String jitOrAot = mode!.isJit ? '_jit' : '_aot';
1263 final String productOrNo = mode.isRelease ? '_product' : '';
1264 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'flutter$jitOrAot${productOrNo}_runner-0.far');
1265 case Artifact.fontSubset:
1266 return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
1267 case Artifact.constFinder:
1268 return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName);
1269 case Artifact.linuxDesktopPath:
1270 case Artifact.linuxHeaders:
1271 case Artifact.windowsDesktopPath:
1272 case Artifact.windowsCppClientWrapper:
1273 return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
1274 case Artifact.engineDartSdkPath:
1275 return _getDartSdkPath();
1276 case Artifact.engineDartBinary:
1277 case Artifact.engineDartAotRuntime:
1278 return _fileSystem.path.join(_getDartSdkPath(), 'bin', artifactFileName);
1279 case Artifact.dart2jsSnapshot:
1280 case Artifact.dart2wasmSnapshot:
1281 case Artifact.frontendServerSnapshotForEngineDartSdk:
1282 return _fileSystem.path.join(_getDartSdkPath(), 'bin', 'snapshots', artifactFileName);
1283 case Artifact.flutterToolsFileGenerators:
1284 return _getFileGeneratorsPath();
1285 case Artifact.flutterPreviewDevice:
1286 return _backupCache.getArtifactPath(
1287 artifact,
1288 platform: platform,
1289 mode: mode,
1290 environmentType: environmentType,
1291 );
1292 }
1293 }
1294
1295 @override
1296 String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) {
1297 return _fileSystem.path.basename(localEngineInfo.targetOutPath);
1298 }
1299
1300 String _getFlutterPatchedSdkPath(BuildMode? buildMode) {
1301 return _fileSystem.path.join(localEngineInfo.targetOutPath,
1302 buildMode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
1303 }
1304
1305 String _getDartSdkPath() {
1306 final String builtPath = _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk');
1307 if (_fileSystem.isDirectorySync(_fileSystem.path.join(builtPath, 'bin'))) {
1308 return builtPath;
1309 }
1310
1311 // If we couldn't find a built dart sdk, let's look for a prebuilt one.
1312 final String prebuiltPath = _fileSystem.path.join(_getFlutterPrebuiltsPath(), _getPrebuiltTarget(), 'dart-sdk');
1313 if (_fileSystem.isDirectorySync(prebuiltPath)) {
1314 return prebuiltPath;
1315 }
1316
1317 throw ToolExit('Unable to find a built dart sdk at: "$builtPath" or a prebuilt dart sdk at: "$prebuiltPath"');
1318 }
1319
1320 String _getFlutterPrebuiltsPath() {
1321 final String engineSrcPath = _fileSystem.path.dirname(_fileSystem.path.dirname(_hostEngineOutPath));
1322 return _fileSystem.path.join(engineSrcPath, 'flutter', 'prebuilts');
1323 }
1324
1325 String _getPrebuiltTarget() {
1326 final TargetPlatform hostPlatform = _currentHostPlatform(_platform, _operatingSystemUtils);
1327 switch (hostPlatform) {
1328 case TargetPlatform.darwin:
1329 return 'macos-x64';
1330 case TargetPlatform.linux_arm64:
1331 return 'linux-arm64';
1332 case TargetPlatform.linux_x64:
1333 return 'linux-x64';
1334 case TargetPlatform.windows_x64:
1335 return 'windows-x64';
1336 case TargetPlatform.windows_arm64:
1337 return 'windows-arm64';
1338 case TargetPlatform.ios:
1339 case TargetPlatform.android:
1340 case TargetPlatform.android_arm:
1341 case TargetPlatform.android_arm64:
1342 case TargetPlatform.android_x64:
1343 case TargetPlatform.android_x86:
1344 case TargetPlatform.fuchsia_arm64:
1345 case TargetPlatform.fuchsia_x64:
1346 case TargetPlatform.web_javascript:
1347 case TargetPlatform.tester:
1348 throwToolExit('Unsupported host platform: $hostPlatform');
1349 }
1350 }
1351
1352 String _getFlutterWebSdkPath() {
1353 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'flutter_web_sdk');
1354 }
1355
1356 String _genSnapshotPath() {
1357 const List<String> clangDirs = <String>['.', 'clang_x64', 'clang_x86', 'clang_i386', 'clang_arm64'];
1358 final String genSnapshotName = _artifactToFileName(Artifact.genSnapshot, _platform)!;
1359 for (final String clangDir in clangDirs) {
1360 final String genSnapshotPath = _fileSystem.path.join(localEngineInfo.targetOutPath, clangDir, genSnapshotName);
1361 if (_processManager.canRun(genSnapshotPath)) {
1362 return genSnapshotPath;
1363 }
1364 }
1365 throw Exception('Unable to find $genSnapshotName');
1366 }
1367
1368 String _flutterTesterPath(TargetPlatform platform) {
1369 if (_platform.isLinux) {
1370 return _fileSystem.path.join(localEngineInfo.targetOutPath, _artifactToFileName(Artifact.flutterTester, _platform));
1371 } else if (_platform.isMacOS) {
1372 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'flutter_tester');
1373 } else if (_platform.isWindows) {
1374 return _fileSystem.path.join(localEngineInfo.targetOutPath, 'flutter_tester.exe');
1375 }
1376 throw Exception('Unsupported platform $platform.');
1377 }
1378
1379 @override
1380 bool get isLocalEngine => true;
1381}
1382
1383class CachedLocalWebSdkArtifacts implements Artifacts {
1384 CachedLocalWebSdkArtifacts({
1385 required Artifacts parent,
1386 required String webSdkPath,
1387 required FileSystem fileSystem,
1388 required Platform platform,
1389 required OperatingSystemUtils operatingSystemUtils
1390 }) : _parent = parent,
1391 _webSdkPath = webSdkPath,
1392 _fileSystem = fileSystem,
1393 _platform = platform,
1394 _operatingSystemUtils = operatingSystemUtils;
1395
1396 final Artifacts _parent;
1397 final String _webSdkPath;
1398 final FileSystem _fileSystem;
1399 final Platform _platform;
1400 final OperatingSystemUtils _operatingSystemUtils;
1401
1402 @override
1403 String getArtifactPath(Artifact artifact, {TargetPlatform? platform, BuildMode? mode, EnvironmentType? environmentType}) {
1404 if (platform == TargetPlatform.web_javascript) {
1405 switch (artifact) {
1406 case Artifact.engineDartSdkPath:
1407 return _getDartSdkPath();
1408 case Artifact.engineDartBinary:
1409 case Artifact.engineDartAotRuntime:
1410 return _fileSystem.path.join(
1411 _getDartSdkPath(), 'bin',
1412 _artifactToFileName(artifact, _platform, mode));
1413 case Artifact.dart2jsSnapshot:
1414 case Artifact.dart2wasmSnapshot:
1415 case Artifact.frontendServerSnapshotForEngineDartSdk:
1416 return _fileSystem.path.join(
1417 _getDartSdkPath(), 'bin', 'snapshots',
1418 _artifactToFileName(artifact, _platform, mode),
1419 );
1420 case Artifact.genSnapshot:
1421 case Artifact.flutterTester:
1422 case Artifact.flutterFramework:
1423 case Artifact.flutterFrameworkDsym:
1424 case Artifact.flutterXcframework:
1425 case Artifact.flutterMacOSFramework:
1426 case Artifact.flutterMacOSFrameworkDsym:
1427 case Artifact.flutterMacOSXcframework:
1428 case Artifact.vmSnapshotData:
1429 case Artifact.isolateSnapshotData:
1430 case Artifact.icuData:
1431 case Artifact.platformKernelDill:
1432 case Artifact.platformLibrariesJson:
1433 case Artifact.flutterPatchedSdkPath:
1434 case Artifact.linuxDesktopPath:
1435 case Artifact.linuxHeaders:
1436 case Artifact.windowsDesktopPath:
1437 case Artifact.windowsCppClientWrapper:
1438 case Artifact.skyEnginePath:
1439 case Artifact.fuchsiaKernelCompiler:
1440 case Artifact.fuchsiaFlutterRunner:
1441 case Artifact.fontSubset:
1442 case Artifact.constFinder:
1443 case Artifact.flutterToolsFileGenerators:
1444 case Artifact.flutterPreviewDevice:
1445 break;
1446 }
1447 }
1448 return _parent.getArtifactPath(artifact, platform: platform, mode: mode, environmentType: environmentType);
1449 }
1450
1451 @override
1452 String getEngineType(TargetPlatform platform, [BuildMode? mode]) => _parent.getEngineType(platform, mode);
1453
1454 @override
1455 FileSystemEntity getHostArtifact(
1456 HostArtifact artifact,
1457 ) {
1458 switch (artifact) {
1459 case HostArtifact.flutterWebSdk:
1460 final String path = _getFlutterWebSdkPath();
1461 return _fileSystem.directory(path);
1462 case HostArtifact.flutterWebLibrariesJson:
1463 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), _hostArtifactToFileName(artifact, _platform));
1464 return _fileSystem.file(path);
1465 case HostArtifact.flutterJsDirectory:
1466 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'flutter_js');
1467 return _fileSystem.directory(path);
1468 case HostArtifact.webPlatformKernelFolder:
1469 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel');
1470 return _fileSystem.file(path);
1471 case HostArtifact.webPlatformDDCKernelDill:
1472 case HostArtifact.webPlatformDDCSoundKernelDill:
1473 case HostArtifact.webPlatformDart2JSKernelDill:
1474 case HostArtifact.webPlatformDart2JSSoundKernelDill:
1475 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _hostArtifactToFileName(artifact, _platform));
1476 return _fileSystem.file(path);
1477 case HostArtifact.webPrecompiledAmdSdk:
1478 case HostArtifact.webPrecompiledAmdSdkSourcemaps:
1479 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd', _hostArtifactToFileName(artifact, _platform));
1480 return _fileSystem.file(path);
1481 case HostArtifact.webPrecompiledAmdCanvaskitSdk:
1482 case HostArtifact.webPrecompiledAmdCanvaskitSdkSourcemaps:
1483 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit', _hostArtifactToFileName(artifact, _platform));
1484 return _fileSystem.file(path);
1485 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdk:
1486 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSdkSourcemaps:
1487 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
1488 return _fileSystem.file(path);
1489 case HostArtifact.webPrecompiledAmdSoundSdk:
1490 case HostArtifact.webPrecompiledAmdSoundSdkSourcemaps:
1491 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-sound', _hostArtifactToFileName(artifact, _platform));
1492 return _fileSystem.file(path);
1493 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdk:
1494 case HostArtifact.webPrecompiledAmdCanvaskitSoundSdkSourcemaps:
1495 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-sound', _hostArtifactToFileName(artifact, _platform));
1496 return _fileSystem.file(path);
1497 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdk:
1498 case HostArtifact.webPrecompiledAmdCanvaskitAndHtmlSoundSdkSourcemaps:
1499 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html-sound', _hostArtifactToFileName(artifact, _platform));
1500 return _fileSystem.file(path);
1501 case HostArtifact.webPrecompiledDdcSdk:
1502 case HostArtifact.webPrecompiledDdcSdkSourcemaps:
1503 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc', _hostArtifactToFileName(artifact, _platform));
1504 return _fileSystem.file(path);
1505 case HostArtifact.webPrecompiledDdcCanvaskitSdk:
1506 case HostArtifact.webPrecompiledDdcCanvaskitSdkSourcemaps:
1507 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit', _hostArtifactToFileName(artifact, _platform));
1508 return _fileSystem.file(path);
1509 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdk:
1510 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSdkSourcemaps:
1511 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-html', _hostArtifactToFileName(artifact, _platform));
1512 return _fileSystem.file(path);
1513 case HostArtifact.webPrecompiledDdcSoundSdk:
1514 case HostArtifact.webPrecompiledDdcSoundSdkSourcemaps:
1515 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-sound', _hostArtifactToFileName(artifact, _platform));
1516 return _fileSystem.file(path);
1517 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdk:
1518 case HostArtifact.webPrecompiledDdcCanvaskitSoundSdkSourcemaps:
1519 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-sound', _hostArtifactToFileName(artifact, _platform));
1520 return _fileSystem.file(path);
1521 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdk:
1522 case HostArtifact.webPrecompiledDdcCanvaskitAndHtmlSoundSdkSourcemaps:
1523 final String path = _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'ddc-canvaskit-html-sound', _hostArtifactToFileName(artifact, _platform));
1524 return _fileSystem.file(path);
1525 case HostArtifact.iosDeploy:
1526 case HostArtifact.idevicesyslog:
1527 case HostArtifact.idevicescreenshot:
1528 case HostArtifact.iproxy:
1529 case HostArtifact.skyEnginePath:
1530 case HostArtifact.impellerc:
1531 case HostArtifact.scenec:
1532 case HostArtifact.libtessellator:
1533 return _parent.getHostArtifact(artifact);
1534 }
1535 }
1536
1537 String _getDartSdkPath() {
1538 // If we couldn't find a built dart sdk, let's look for a prebuilt one.
1539 final String prebuiltPath = _fileSystem.path.join(_getFlutterPrebuiltsPath(), _getPrebuiltTarget(), 'dart-sdk');
1540 if (_fileSystem.isDirectorySync(prebuiltPath)) {
1541 return prebuiltPath;
1542 }
1543
1544 throw ToolExit('Unable to find a prebuilt dart sdk at: "$prebuiltPath"');
1545 }
1546
1547 String _getFlutterPrebuiltsPath() {
1548 final String engineSrcPath = _fileSystem.path.dirname(_fileSystem.path.dirname(_webSdkPath));
1549 return _fileSystem.path.join(engineSrcPath, 'flutter', 'prebuilts');
1550 }
1551
1552 String _getPrebuiltTarget() {
1553 final TargetPlatform hostPlatform = _currentHostPlatform(_platform, _operatingSystemUtils);
1554 switch (hostPlatform) {
1555 case TargetPlatform.darwin:
1556 return 'macos-x64';
1557 case TargetPlatform.linux_arm64:
1558 return 'linux-arm64';
1559 case TargetPlatform.linux_x64:
1560 return 'linux-x64';
1561 case TargetPlatform.windows_x64:
1562 return 'windows-x64';
1563 case TargetPlatform.windows_arm64:
1564 return 'windows-arm64';
1565 case TargetPlatform.ios:
1566 case TargetPlatform.android:
1567 case TargetPlatform.android_arm:
1568 case TargetPlatform.android_arm64:
1569 case TargetPlatform.android_x64:
1570 case TargetPlatform.android_x86:
1571 case TargetPlatform.fuchsia_arm64:
1572 case TargetPlatform.fuchsia_x64:
1573 case TargetPlatform.web_javascript:
1574 case TargetPlatform.tester:
1575 throwToolExit('Unsupported host platform: $hostPlatform');
1576 }
1577 }
1578
1579 String _getFlutterWebSdkPath() {
1580 return _fileSystem.path.join(_webSdkPath, 'flutter_web_sdk');
1581 }
1582
1583 @override
1584 bool get isLocalEngine => _parent.isLocalEngine;
1585
1586 @override
1587 LocalEngineInfo? get localEngineInfo => _parent.localEngineInfo;
1588}
1589
1590/// An implementation of [Artifacts] that provides individual overrides.
1591///
1592/// If an artifact is not provided, the lookup delegates to the parent.
1593class OverrideArtifacts implements Artifacts {
1594 /// Creates a new [OverrideArtifacts].
1595 ///
1596 /// [parent] must be provided.
1597 OverrideArtifacts({
1598 required this.parent,
1599 this.frontendServer,
1600 this.engineDartBinary,
1601 this.platformKernelDill,
1602 this.flutterPatchedSdk,
1603 });
1604
1605 final Artifacts parent;
1606 final File? frontendServer;
1607 final File? engineDartBinary;
1608 final File? platformKernelDill;
1609 final File? flutterPatchedSdk;
1610
1611 @override
1612 LocalEngineInfo? get localEngineInfo => parent.localEngineInfo;
1613
1614 @override
1615 String getArtifactPath(
1616 Artifact artifact, {
1617 TargetPlatform? platform,
1618 BuildMode? mode,
1619 EnvironmentType? environmentType,
1620 }) {
1621 if (artifact == Artifact.engineDartBinary && engineDartBinary != null) {
1622 return engineDartBinary!.path;
1623 }
1624 if (artifact == Artifact.frontendServerSnapshotForEngineDartSdk && frontendServer != null) {
1625 return frontendServer!.path;
1626 }
1627 if (artifact == Artifact.platformKernelDill && platformKernelDill != null) {
1628 return platformKernelDill!.path;
1629 }
1630 if (artifact == Artifact.flutterPatchedSdkPath && flutterPatchedSdk != null) {
1631 return flutterPatchedSdk!.path;
1632 }
1633 return parent.getArtifactPath(
1634 artifact,
1635 platform: platform,
1636 mode: mode,
1637 environmentType: environmentType,
1638 );
1639 }
1640
1641 @override
1642 String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) => parent.getEngineType(platform, mode);
1643
1644 @override
1645 bool get isLocalEngine => parent.isLocalEngine;
1646
1647 @override
1648 FileSystemEntity getHostArtifact(HostArtifact artifact) {
1649 return parent.getHostArtifact(
1650 artifact,
1651 );
1652 }
1653}
1654
1655/// Locate the Dart SDK.
1656String _dartSdkPath(Cache cache) {
1657 return cache.getRoot().childDirectory('dart-sdk').path;
1658}
1659
1660class _TestArtifacts implements Artifacts {
1661 _TestArtifacts(this.fileSystem);
1662
1663 final FileSystem fileSystem;
1664
1665 @override
1666 LocalEngineInfo? get localEngineInfo => null;
1667
1668 @override
1669 String getArtifactPath(
1670 Artifact artifact, {
1671 TargetPlatform? platform,
1672 BuildMode? mode,
1673 EnvironmentType? environmentType,
1674 }) {
1675 // The path to file generators is the same even in the test environment.
1676 if (artifact == Artifact.flutterToolsFileGenerators) {
1677 return _getFileGeneratorsPath();
1678 }
1679
1680 final StringBuffer buffer = StringBuffer();
1681 buffer.write(artifact);
1682 if (platform != null) {
1683 buffer.write('.$platform');
1684 }
1685 if (mode != null) {
1686 buffer.write('.$mode');
1687 }
1688 if (environmentType != null) {
1689 buffer.write('.$environmentType');
1690 }
1691 return buffer.toString();
1692 }
1693
1694 @override
1695 String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) {
1696 return 'test-engine';
1697 }
1698
1699 @override
1700 bool get isLocalEngine => false;
1701
1702 @override
1703 FileSystemEntity getHostArtifact(HostArtifact artifact) {
1704 return fileSystem.file(artifact.toString());
1705 }
1706}
1707
1708class _TestLocalEngine extends _TestArtifacts {
1709 _TestLocalEngine(
1710 String engineOutPath,
1711 String engineHostOutPath,
1712 super.fileSystem,
1713 ) : localEngineInfo = LocalEngineInfo(
1714 targetOutPath: engineOutPath,
1715 hostOutPath: engineHostOutPath,
1716 );
1717
1718 @override
1719 bool get isLocalEngine => true;
1720
1721 @override
1722 final LocalEngineInfo localEngineInfo;
1723}
1724
1725String _getFileGeneratorsPath() {
1726 final String flutterRoot = Cache.defaultFlutterRoot(
1727 fileSystem: globals.localFileSystem,
1728 platform: const LocalPlatform(),
1729 userMessages: UserMessages(),
1730 );
1731 return globals.localFileSystem.path.join(
1732 flutterRoot,
1733 'packages',
1734 'flutter_tools',
1735 'lib',
1736 'src',
1737 'web',
1738 'file_generators',
1739 );
1740}
1741

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com