Files
sdk/pkg/dev_compiler/tool/build_pkgs.dart
T
Jenny Messerly be815e1a86 [dartdevc] fix #35013, move DDC off Analyzer task model
The new file pkg/dev_compiler/lib/src/analyzer/driver.dart handles
building the linked summary for a build unit, and then is capable of
doing analysis using LibraryAnalyzer.

The algorithm is very similar to analyzer_cli's build mode. The
biggest difference is that `dartdevc` has existing support for
discovering source files from the explicit source list (rather than
requiring every source to be listed on the command line). We don't want
to break that support, so there's a bit of logic to follow imports,
exports, and parts.

After the linked summary is produced, DDC gets the analysis results
(errors and resolved AST) for each library, and compiles it into a JS
module.

Change-Id: I7bf1ce1eca73fd036002e498de5924c488b534dc
Reviewed-on: https://dart-review.googlesource.com/c/82469
Commit-Queue: Jenny Messerly <jmesserly@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Vijay Menon <vsm@google.com>
2018-11-06 00:52:24 +00:00

158 lines
4.9 KiB
Dart
Executable File

#!/usr/bin/env dart
import 'dart:async';
import 'dart:io';
import 'package:args/args.dart';
import 'package:path/path.dart' as p;
import 'package:dev_compiler/src/compiler/shared_command.dart';
final String scriptDirectory = p.dirname(p.fromUri(Platform.script));
final String repoDirectory = p.normalize(p.join(scriptDirectory, "../../../"));
/// Path to the SDK analyzer summary file, "ddc_sdk.sum".
String analyzerSummary;
/// Path to the SDK kernel summary file, "ddc_sdk.dill".
String kernelSummary;
/// The directory that output is written to.
///
/// The DDC kernel SDK should be directly in this directory. The resulting
/// packages will be placed in a "pkg" subdirectory of this.
String outputDirectory;
/// Compiles the packages that the DDC tests use to JS into the given output
/// directory.
///
/// If "--travis" is passed, builds the all of the modules tested on Travis.
/// Otherwise, only builds the modules needed by the tests.
///
/// If "--analyzer-sdk" is provided, uses that summary file and compiles the
/// packages to JS and analyzer summaries against that SDK summary. Otherwise,
/// it skips generating analyzer summaries and compiling to JS.
///
/// If "--kernel-sdk" is provided, uses that summary file and generates kernel
/// summaries for the test packages against that SDK summary. Otherwise, skips
/// generating kernel summaries.
Future main(List<String> arguments) async {
var argParser = ArgParser();
argParser.addOption("analyzer-sdk",
help: "Path to SDK analyzer summary '.sum' file");
argParser.addOption("kernel-sdk",
help: "Path to SDK Kernel summary '.dill' file");
argParser.addOption("output",
abbr: "o", help: "Directory to write output to.");
argParser.addFlag("travis",
help: "Build the additional packages tested on Travis.");
ArgResults argResults;
try {
argResults = argParser.parse(arguments);
} on ArgParserException catch (ex) {
_usageError(argParser, ex.message);
}
if (argResults.rest.isNotEmpty) {
_usageError(
argParser, 'Unexpected arguments "${argResults.rest.join(' ')}".');
}
var isTravis = argResults["travis"] as bool;
analyzerSummary = argResults["analyzer-sdk"] as String;
kernelSummary = argResults["kernel-sdk"] as String;
outputDirectory = argResults["output"] as String;
// Build leaf packages. These have no other package dependencies.
// Under pkg.
await compileModule('async_helper');
await compileModule('expect', libs: ['minitest']);
await compileModule('js', libs: ['js_util']);
await compileModule('meta');
if (isTravis) {
await compileModule('microlytics', libs: ['html_channels']);
}
// Under third_party/pkg.
await compileModule('collection');
await compileModule('path');
if (isTravis) {
await compileModule('args', libs: ['command_runner']);
await compileModule('charcode');
await compileModule('fixnum');
await compileModule('logging');
await compileModule('markdown');
await compileModule('mime');
await compileModule('plugin', libs: ['manager']);
await compileModule('typed_data');
await compileModule('usage');
await compileModule('utf');
}
// Composite packages with dependencies.
await compileModule('stack_trace', deps: ['path']);
await compileModule('matcher', deps: ['stack_trace']);
if (isTravis) {
await compileModule('async', deps: ['collection']);
}
if (!isTravis) {
await compileModule('unittest', deps: [
'path',
'stack_trace'
], libs: [
'html_config',
'html_individual_config',
'html_enhanced_config'
]);
}
}
void _usageError(ArgParser parser, [String message]) {
if (message != null) {
stderr.writeln(message);
stderr.writeln();
}
stderr.writeln("Usage: dart build_pkgs.dart ...");
stderr.writeln();
stderr.writeln(parser.usage);
exit(1);
}
/// Compiles a [module] with a single matching ".dart" library and additional
/// [libs] and [deps] on other modules.
Future compileModule(String module,
{List<String> libs = const [], List<String> deps = const []}) async {
makeArgs({bool kernel = false}) {
var pkgDirectory = p.join(outputDirectory, kernel ? 'pkg_kernel' : 'pkg');
Directory(pkgDirectory).createSync(recursive: true);
var args = <String>[];
if (kernel) args.add('-k');
args.addAll([
'--dart-sdk-summary=${kernel ? kernelSummary : analyzerSummary}',
'-o${pkgDirectory}/$module.js',
'package:$module/$module.dart'
]);
for (var lib in libs) {
args.add('package:$module/$lib.dart');
}
for (var dep in deps) {
args.add('-s${pkgDirectory}/$dep.${kernel ? "dill" : "sum"}');
}
return args;
}
if (analyzerSummary != null) {
var result = await compile(ParsedArguments.from(makeArgs()));
if (!result.success) exit(result.exitCode);
}
if (kernelSummary != null) {
var result = await compile(ParsedArguments.from(makeArgs(kernel: true)));
if (!result.success) exit(result.exitCode);
}
}