From 76387a9c5b3d89035be13a84b5303e2780e94e6e Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Mon, 25 Apr 2022 19:46:13 +0000 Subject: [PATCH] Support for google3 locations in 'packageRoot' and KernelCompilationService. Change-Id: I90910bc3c966f648ade107d10d4c7f593c67c7a4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242162 Reviewed-by: Samuel Rawlins Commit-Queue: Konstantin Shcheglov --- .../summary2/kernel_compilation_service.dart | 45 +++++++++++++++---- pkg/analyzer_utilities/lib/package_root.dart | 8 ++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/pkg/analyzer/lib/src/summary2/kernel_compilation_service.dart b/pkg/analyzer/lib/src/summary2/kernel_compilation_service.dart index e7ed68cfdd7..36caada4605 100644 --- a/pkg/analyzer/lib/src/summary2/kernel_compilation_service.dart +++ b/pkg/analyzer/lib/src/summary2/kernel_compilation_service.dart @@ -36,11 +36,7 @@ class KernelCompilationService { } final executablePath = io.Platform.resolvedExecutable; - final binPath = package_path.dirname(executablePath); - final sdkPath = package_path.dirname(binPath); - - final frontEndSnapshotPath = package_path.join( - binPath, 'snapshots', 'frontend_server.dart.snapshot'); + final sdkPaths = _computeSdkPaths(); final socketCompleter = Completer(); final serverSocket = await _loopbackServerSocket(); @@ -52,7 +48,7 @@ class KernelCompilationService { final addressStr = '$host:${serverSocket.port}'; final process = await io.Process.start(executablePath, [ - frontEndSnapshotPath, + sdkPaths.frontEndSnapshot, '--binary-protocol-address=$addressStr', ]); @@ -66,8 +62,7 @@ class KernelCompilationService { final requestChannel = RequestChannel(socket); // Put the platform dill. - final platformDillPath = package_path.join( - sdkPath, 'lib', '_internal', 'vm_platform_strong.dill'); + final platformDillPath = sdkPaths.platformDill; final platformDillBytes = io.File(platformDillPath).readAsBytesSync(); await requestChannel.sendRequest('dill.put', { 'uri': 'dill:vm', @@ -149,6 +144,30 @@ class KernelCompilationService { }); } + static _SdkPaths _computeSdkPaths() { + // Check for google3. + final runFiles = io.Platform.environment['RUNFILES']; + if (runFiles != null) { + final frontServerPath = io.Platform.environment['FRONTEND_SERVER_PATH']!; + final platformDillPath = io.Platform.environment['PLATFORM_DILL_PATH']!; + return _SdkPaths( + frontEndSnapshot: package_path.join(runFiles, frontServerPath), + platformDill: package_path.join(runFiles, platformDillPath), + ); + } + + final executablePath = io.Platform.resolvedExecutable; + final binPath = package_path.dirname(executablePath); + final sdkPath = package_path.dirname(binPath); + + return _SdkPaths( + frontEndSnapshot: package_path.join( + binPath, 'snapshots', 'frontend_server.dart.snapshot'), + platformDill: package_path.join( + sdkPath, 'lib', '_internal', 'vm_platform_strong.dill'), + ); + } + static Future _loopbackServerSocket() async { try { return await io.ServerSocket.bind(io.InternetAddress.loopbackIPv6, 0); @@ -199,3 +218,13 @@ class _Lock { } } } + +class _SdkPaths { + final String frontEndSnapshot; + final String platformDill; + + _SdkPaths({ + required this.frontEndSnapshot, + required this.platformDill, + }); +} diff --git a/pkg/analyzer_utilities/lib/package_root.dart b/pkg/analyzer_utilities/lib/package_root.dart index aa3d27c1398..61a3c96793a 100644 --- a/pkg/analyzer_utilities/lib/package_root.dart +++ b/pkg/analyzer_utilities/lib/package_root.dart @@ -25,5 +25,13 @@ String get packageRoot { if (pkgIndex != -1) { return pathos.joinAll(parts.sublist(0, pkgIndex + 1)) + pathos.separator; } + // Try google3 environment. We expect that all packages that will be + // accessed via this root are configured in the BUILD file, and located + // inside this single root. + final runFiles = Platform.environment['RUNFILES']; + final analyzerPackagesRoot = Platform.environment['ANALYZER_PACKAGES_ROOT']; + if (runFiles != null && analyzerPackagesRoot != null) { + return pathos.join(runFiles, analyzerPackagesRoot); + } throw StateError('Unable to find sdk/pkg/ in $scriptPath'); }