Parse engine src path from an absolute --local-engine (#78496)
This commit is contained in:
@@ -54,45 +54,8 @@ class LocalEngineLocator {
|
||||
|
||||
if (engineSourcePath == null && localEngine != null) {
|
||||
try {
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
_fileSystem.file(
|
||||
// TODO(jonahwilliams): update to package_config
|
||||
packagePath ?? _fileSystem.path.join('.packages'),
|
||||
),
|
||||
logger: _logger,
|
||||
throwOnError: false,
|
||||
);
|
||||
// Skip if sky_engine is the version in bin/cache.
|
||||
Uri engineUri = packageConfig[kFlutterEnginePackageName]?.packageUriRoot;
|
||||
final String cachedPath = _fileSystem.path.join(_flutterRoot, 'bin', 'cache', 'pkg', kFlutterEnginePackageName, 'lib');
|
||||
if (engineUri != null && _fileSystem.identicalSync(cachedPath, engineUri.path)) {
|
||||
_logger.printTrace('Local engine auto-detection sky_engine in $packagePath is the same version in bin/cache.');
|
||||
engineUri = null;
|
||||
}
|
||||
// If sky_engine is specified and the engineSourcePath not set, try to
|
||||
// determine the engineSourcePath by sky_engine setting. A typical engine Uri
|
||||
// looks like:
|
||||
// file://flutter-engine-local-path/src/out/host_debug_unopt/gen/dart-pkg/sky_engine/lib/
|
||||
if (engineUri?.path != null) {
|
||||
engineSourcePath = _fileSystem.directory(engineUri.path)
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.path;
|
||||
if (engineSourcePath != null && (engineSourcePath == _fileSystem.path.dirname(engineSourcePath) || engineSourcePath.isEmpty)) {
|
||||
engineSourcePath = null;
|
||||
throwToolExit(
|
||||
_userMessages.runnerNoEngineSrcDir(
|
||||
kFlutterEnginePackageName,
|
||||
kFlutterEngineEnvironmentVariableName,
|
||||
),
|
||||
exitCode: 2,
|
||||
);
|
||||
}
|
||||
}
|
||||
engineSourcePath = _findEngineSourceByLocalEngine(localEngine);
|
||||
engineSourcePath ??= await _findEngineSourceByPackageConfig(packagePath);
|
||||
} on FileSystemException catch (e) {
|
||||
_logger.printTrace('Local engine auto-detection file exception: $e');
|
||||
engineSourcePath = null;
|
||||
@@ -113,12 +76,79 @@ class LocalEngineLocator {
|
||||
if (engineSourcePath != null) {
|
||||
_logger.printTrace('Local engine source at $engineSourcePath');
|
||||
return _findEngineBuildPath(localEngine, engineSourcePath);
|
||||
} else if (localEngine != null) {
|
||||
_logger.printTrace('Could not find engine source for $localEngine, skipping');
|
||||
}
|
||||
if (localEngine != null) {
|
||||
throwToolExit(
|
||||
_userMessages.runnerNoEngineSrcDir(
|
||||
kFlutterEnginePackageName,
|
||||
kFlutterEngineEnvironmentVariableName,
|
||||
),
|
||||
exitCode: 2,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String _findEngineSourceByLocalEngine(String localEngine) {
|
||||
// When the local engine is an absolute path to a variant inside the
|
||||
// out directory, parse the engine source.
|
||||
// --local-engine /path/to/cache/builder/src/out/host_debug_unopt
|
||||
if (_fileSystem.path.isAbsolute(localEngine)) {
|
||||
final Directory localEngineDirectory = _fileSystem.directory(localEngine);
|
||||
final Directory outDirectory = localEngineDirectory?.parent;
|
||||
final Directory srcDirectory = outDirectory?.parent;
|
||||
if (localEngineDirectory.existsSync() && outDirectory?.basename == 'out' && srcDirectory?.basename == 'src') {
|
||||
_logger.printTrace('Parsed engine source from local engine as ${srcDirectory.path}.');
|
||||
return srcDirectory.path;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<String> _findEngineSourceByPackageConfig(String packagePath) async {
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
_fileSystem.file(
|
||||
// TODO(jonahwilliams): update to package_config
|
||||
packagePath ?? _fileSystem.path.join('.packages'),
|
||||
),
|
||||
logger: _logger,
|
||||
throwOnError: false,
|
||||
);
|
||||
// Skip if sky_engine is the version in bin/cache.
|
||||
Uri engineUri = packageConfig[kFlutterEnginePackageName]?.packageUriRoot;
|
||||
final String cachedPath = _fileSystem.path.join(_flutterRoot, 'bin', 'cache', 'pkg', kFlutterEnginePackageName, 'lib');
|
||||
if (engineUri != null && _fileSystem.identicalSync(cachedPath, engineUri.path)) {
|
||||
_logger.printTrace('Local engine auto-detection sky_engine in $packagePath is the same version in bin/cache.');
|
||||
engineUri = null;
|
||||
}
|
||||
// If sky_engine is specified and the engineSourcePath not set, try to
|
||||
// determine the engineSourcePath by sky_engine setting. A typical engine Uri
|
||||
// looks like:
|
||||
// file://flutter-engine-local-path/src/out/host_debug_unopt/gen/dart-pkg/sky_engine/lib/
|
||||
String engineSourcePath;
|
||||
if (engineUri?.path != null) {
|
||||
engineSourcePath = _fileSystem.directory(engineUri.path)
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.parent
|
||||
?.path;
|
||||
if (engineSourcePath != null && (engineSourcePath == _fileSystem.path.dirname(engineSourcePath) || engineSourcePath.isEmpty)) {
|
||||
engineSourcePath = null;
|
||||
throwToolExit(
|
||||
_userMessages.runnerNoEngineSrcDir(
|
||||
kFlutterEnginePackageName,
|
||||
kFlutterEngineEnvironmentVariableName,
|
||||
),
|
||||
exitCode: 2,
|
||||
);
|
||||
}
|
||||
}
|
||||
return engineSourcePath;
|
||||
}
|
||||
|
||||
// Determine the host engine directory associated with the local engine:
|
||||
// Strip '_sim_' since there are no host simulator builds.
|
||||
String _getHostEngineBasename(String localEngineBasename) {
|
||||
|
||||
Reference in New Issue
Block a user