From d2ad13d0397565d603b287aa76d9c16616f1a6f4 Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Thu, 20 May 2021 14:00:01 +0200 Subject: [PATCH] Revert "Use the frontend server to compile pub executables (#2968)" (#3006) This reverts commit e01e3a41a88e1cfeb0c1c61a61effb02979c3ebc. --- .github/workflows/test.yaml | 2 +- lib/src/dart.dart | 86 +++++++++++++++--------------------- lib/src/entrypoint.dart | 27 +++-------- lib/src/executable.dart | 4 +- lib/src/global_packages.dart | 5 ++- pubspec.yaml | 1 - 6 files changed, 47 insertions(+), 78 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 847cb96bd..6782f9d22 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -70,5 +70,5 @@ jobs: cat "$_TESTS_FILE.${{ matrix.shard }}" shell: bash - name: Run tests - run: dart test --use-data-isolate-strategy --preset travis $(cat $_TESTS_FILE.${{ matrix.shard }}) + run: dart test --preset travis $(cat $_TESTS_FILE.${{ matrix.shard }}) shell: bash diff --git a/lib/src/dart.dart b/lib/src/dart.dart index 7b1f55a2d..f3a9a80f4 100644 --- a/lib/src/dart.dart +++ b/lib/src/dart.dart @@ -18,8 +18,6 @@ import 'package:analyzer/dart/analysis/session.dart'; import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/error/error.dart'; import 'package:cli_util/cli_util.dart'; -import 'package:frontend_server_client/frontend_server_client.dart'; -import 'package:meta/meta.dart'; import 'package:path/path.dart' as p; import 'exceptions.dart'; @@ -40,6 +38,41 @@ bool isEntrypoint(CompilationUnit dart) { }); } +/// Snapshots the Dart executable at [executablePath] to a snapshot at +/// [snapshotPath]. +/// +/// If [packageConfigFile] is passed, it's used to resolve `package:` URIs in +/// the executable. Otherwise, a `packages/` directory or a package spec is +/// inferred from the executable's location. +/// +/// If [name] is passed, it is used to describe the executable in logs and error +/// messages. +Future snapshot( + String executablePath, + String snapshotPath, { + String packageConfigFile, + String name, +}) async { + final args = [ + if (packageConfigFile != null) '--packages=$packageConfigFile', + '--snapshot=$snapshotPath', + p.toUri(executablePath).toString() + ]; + + final result = await runProcess(Platform.executable, args); + final highlightedName = name = log.bold(name ?? executablePath.toString()); + if (result.success) { + log.message('Precompiled $highlightedName.'); + } else { + // Don't leave partial results. + deleteEntry(snapshotPath); + + throw ApplicationException( + log.yellow('Failed to precompile $highlightedName:\n') + + result.stderr.join('\n')); + } +} + class AnalysisContextManager { /// The map from a context root directory to to the context. final Map _contexts = {}; @@ -148,52 +181,3 @@ class AnalyzerErrorGroup implements Exception { @override String toString() => errors.join('\n'); } - -/// Precompiles the Dart executable at [executablePath] to a kernel file at -/// [outputPath]. -/// -/// This file is also cached at [incrementalDillOutputPath] which is used to -/// initialize the compiler on future runs. -/// -/// The [packageConfigPath] should point at the package config file to be used -/// for `package:` uri resolution. -/// -/// The [name] is used to describe the executable in logs and error messages. -Future precompile({ - @required String executablePath, - @required String incrementalDillOutputPath, - @required String name, - @required String outputPath, - @required String packageConfigPath, -}) async { - ensureDir(p.dirname(outputPath)); - ensureDir(p.dirname(incrementalDillOutputPath)); - const platformDill = 'lib/_internal/vm_platform_strong.dill'; - final sdkRoot = p.relative(p.dirname(p.dirname(Platform.resolvedExecutable))); - var client = await FrontendServerClient.start( - executablePath, - incrementalDillOutputPath, - platformDill, - sdkRoot: sdkRoot, - packagesJson: packageConfigPath, - printIncrementalDependencies: false, - ); - try { - var result = await client.compile(); - - final highlightedName = log.bold(name); - if (result?.errorCount == 0) { - log.message('Precompiled $highlightedName.'); - await File(incrementalDillOutputPath).copy(outputPath); - } else { - // Don't leave partial results. - deleteEntry(outputPath); - - throw ApplicationException( - log.yellow('Failed to precompile $highlightedName:\n') + - (result?.compilerOutputLines?.join('\n') ?? '')); - } - } finally { - client.kill(); - } -} diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart index c1d34e69a..ec6645782 100644 --- a/lib/src/entrypoint.dart +++ b/lib/src/entrypoint.dart @@ -171,10 +171,6 @@ class Entrypoint { /// The path to the directory containing dependency executable snapshots. String get _snapshotPath => p.join(cachePath, 'bin'); - /// The path to the directory containing previous dill files for incremental - /// builds. - String get _incrementalDillsPath => p.join(cachePath, 'incremental'); - /// Loads the entrypoint from a package at [rootDir]. Entrypoint(String rootDir, this.cache) : root = Package.load(null, rootDir, cache.sources), @@ -338,7 +334,7 @@ class Entrypoint { ensureDir(_snapshotPath); } return waitAndPrintErrors(executables.map((executable) { - var dir = p.dirname(pathOfExecutable(executable)); + var dir = p.dirname(snapshotPathOfExecutable(executable)); cleanDir(dir); return _precompileExecutable(executable); })); @@ -348,18 +344,16 @@ class Entrypoint { /// Precompiles executable .dart file at [path] to a snapshot. Future precompileExecutable(Executable executable) async { return await log.progress('Precompiling executable', () async { - ensureDir(p.dirname(pathOfExecutable(executable))); + ensureDir(p.dirname(snapshotPathOfExecutable(executable))); return waitAndPrintErrors([_precompileExecutable(executable)]); }); } Future _precompileExecutable(Executable executable) async { final package = executable.package; - await dart.precompile( - executablePath: resolveExecutable(executable), - outputPath: pathOfExecutable(executable), - incrementalDillOutputPath: incrementalDillPathOfExecutable(executable), - packageConfigPath: packageConfigFile, + await dart.snapshot( + resolveExecutable(executable), snapshotPathOfExecutable(executable), + packageConfigFile: packageConfigFile, name: '$package:${p.basenameWithoutExtension(executable.relativePath)}'); } @@ -371,7 +365,7 @@ class Entrypoint { /// different sdk. /// /// [path] must be relative. - String pathOfExecutable(Executable executable) { + String snapshotPathOfExecutable(Executable executable) { assert(p.isRelative(executable.relativePath)); final versionSuffix = sdk.version; return isGlobal @@ -381,15 +375,6 @@ class Entrypoint { '${p.basename(executable.relativePath)}-$versionSuffix.snapshot'); } - String incrementalDillPathOfExecutable(Executable executable) { - assert(p.isRelative(executable.relativePath)); - return isGlobal - ? p.join(_incrementalDillsPath, - '${p.basename(executable.relativePath)}.incremental.dill') - : p.join(_incrementalDillsPath, executable.package, - '${p.basename(executable.relativePath)}.incremental.dill'); - } - /// The absolute path of [executable] resolved relative to [this]. String resolveExecutable(Executable executable) { return p.join( diff --git a/lib/src/executable.dart b/lib/src/executable.dart index 5bd12b6ff..1883d2353 100644 --- a/lib/src/executable.dart +++ b/lib/src/executable.dart @@ -72,7 +72,7 @@ Future runExecutable( entrypoint.migrateCache(); - var snapshotPath = entrypoint.pathOfExecutable(executable); + var snapshotPath = entrypoint.snapshotPathOfExecutable(executable); // Don't compile snapshots for mutable packages, since their code may // change later on. @@ -327,7 +327,7 @@ Future getExecutableForCommand( if (!allowSnapshot || entrypoint.packageGraph.isPackageMutable(package)) { return p.relative(path, from: root); } else { - final snapshotPath = entrypoint.pathOfExecutable(executable); + final snapshotPath = entrypoint.snapshotPathOfExecutable(executable); if (!fileExists(snapshotPath)) { await warningsOnlyUnlessTerminal( () => entrypoint.precompileExecutable(executable), diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index a5a5e5b51..8c6f78c5e 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -590,7 +590,8 @@ To recompile executables, first run `global deactivate ${dep.name}`. deleteEntry(file); _createBinStub( entrypoint.root, p.basenameWithoutExtension(file), binStubScript, - overwrite: true, snapshot: entrypoint.pathOfExecutable(executable)); + overwrite: true, + snapshot: entrypoint.snapshotPathOfExecutable(executable)); } } } @@ -640,7 +641,7 @@ To recompile executables, first run `global deactivate ${dep.name}`. executable, script, overwrite: overwriteBinStubs, - snapshot: entrypoint.pathOfExecutable( + snapshot: entrypoint.snapshotPathOfExecutable( exec.Executable.adaptProgramName(package.name, script), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 5902f9d31..222a5a5fe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,6 @@ dependencies: cli_util: ^0.3.0 collection: ^1.15.0 crypto: ^3.0.1 - frontend_server_client: ^2.0.0 http: ^0.13.3 http_multi_server: ^3.0.1 meta: ^1.3.0