Dynamically load packages for dartdevc tests in test.dart.

This involves a few pieces:

- Add support to DDC for specifying the module name associated with a
  given summary. This lets test.dart invoke DDC using summaries in the
  build directory outside of the directory containing the test itself.

- Add support to the build scripts for building the packages. This adds
  a new GN target that builds everything needed to run test.dart with
  dartdevc. In particular, it invokes build_pkgs.dart to compile the
  relevant packages to JS+summary so that the tests can use them.

  This requires some changes to build_pkgs.dart so it can output to a
  given directory.

- In test.dart, when tests are compiled with dartdevc, pass in the
  summaries for the packages so they don't get compiled in. Then, when
  the test is run, configure require.js with the right paths to their
  JS files so they can be loaded.

  I also removed a bunch of unneeded buildDir parameters being passed
  around the various CompilerConfiguration class methods now that they
  have direct access to the configuration.

Fix #29923.

R=vsm@google.com, whesse@google.com, zra@google.com

Review-Url: https://codereview.chromium.org/2955513002 .
This commit is contained in:
Bob Nystrom 2017-06-29 13:45:55 -07:00
parent f6b7fd307a
commit 0b2c9b048d
14 changed files with 317 additions and 186 deletions

View file

@ -73,7 +73,7 @@ script:
- if [[ -z "$TEST" ]]; then ./tool/presubmit.sh ; fi
- if [[ "$TEST" == coverage ]]; then ./tool/build_sdk.sh && ./tool/coverage.sh ; fi
- if [[ "$TEST" == node ]]; then ./tool/node_test.sh ; fi
- if [[ "$TEST" == package ]]; then ./tool/build_sdk.sh && ./tool/build_pkgs.dart ; fi
- if [[ "$TEST" == package ]]; then ./tool/build_sdk.sh && ./tool/build_pkgs.dart gen/codegen_output/pkg travis; fi
env:
- ANALYZER=master
- ANALYZER=master DDC_BROWSERS=Firefox

View file

@ -32,6 +32,8 @@ class AnalyzerOptions {
/// List of summary file paths.
final List<String> summaryPaths;
final Map<String, String> customSummaryModules = {};
/// Path to the dart-sdk, or `null` if the path couldn't be determined.
final String dartSdkPath;
@ -51,6 +53,7 @@ class AnalyzerOptions {
: dartSdkPath = dartSdkPath ?? getSdkDir().path,
summaryPaths = summaryPaths ?? const [] {
contextBuilderOptions.declaredVariables ??= const {};
_parseCustomSummaryModules();
}
factory AnalyzerOptions.basic(
@ -109,6 +112,24 @@ class AnalyzerOptions {
}
return mappings;
}
/// A summary path can contain ":" followed by an explicit module name to
/// allow working with summaries whose physical location is outside of the
/// module root directory.
///
/// Removes any explicit module names from [summaryPaths] and populates with
/// [customSummaryModules] with them.
void _parseCustomSummaryModules() {
for (var i = 0; i < summaryPaths.length; i++) {
var summaryPath = summaryPaths[i];
var comma = summaryPath.indexOf(":");
if (comma != -1) {
summaryPaths[i] = summaryPath.substring(0, comma);
customSummaryModules[summaryPaths[i]] =
summaryPath.substring(comma + 1);
}
}
}
}
/// Creates a SourceFactory configured by the [options].

View file

@ -180,8 +180,12 @@ void _compile(ArgResults argResults, AnalyzerOptions analyzerOptions,
modulePath = path.basenameWithoutExtension(firstOutPath);
}
var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest,
(source) => _moduleForLibrary(moduleRoot, source, compilerOpts));
var unit = new BuildUnit(
modulePath,
libraryRoot,
argResults.rest,
(source) =>
_moduleForLibrary(moduleRoot, source, analyzerOptions, compilerOpts));
var module = compiler.compile(unit, compilerOpts);
module.errors.forEach(printFn);
@ -217,10 +221,15 @@ void _compile(ArgResults argResults, AnalyzerOptions analyzerOptions,
}
}
String _moduleForLibrary(
String moduleRoot, Source source, CompilerOptions compilerOpts) {
String _moduleForLibrary(String moduleRoot, Source source,
AnalyzerOptions analyzerOptions, CompilerOptions compilerOpts) {
if (source is InSummarySource) {
var summaryPath = source.summaryPath;
if (analyzerOptions.customSummaryModules.containsKey(summaryPath)) {
return analyzerOptions.customSummaryModules[summaryPath];
}
var ext = '.${compilerOpts.summaryExtension}';
if (path.isWithin(moduleRoot, summaryPath) && summaryPath.endsWith(ext)) {
var buildUnitPath =

View file

@ -254,7 +254,7 @@ class CompilerOptions {
/// The file extension for summaries.
final String summaryExtension;
/// Whether to preserve metdata only accessible via mirrors
/// Whether to preserve metdata only accessible via mirrors.
final bool emitMetadata;
/// Whether to force compilation of code with static errors.
@ -267,16 +267,16 @@ class CompilerOptions {
/// Whether to emit Closure Compiler-friendly code.
final bool closure;
/// Hoist the types at instance creation sites
/// Hoist the types at instance creation sites.
final bool hoistInstanceCreation;
/// Hoist types from class signatures
/// Hoist types from class signatures.
final bool hoistSignatureTypes;
/// Name types in type tests
/// Name types in type tests.
final bool nameTypeTests;
/// Hoist types in type tests
/// Hoist types in type tests.
final bool hoistTypeTests;
/// Enable ES6 destructuring of named parameters. Off by default.

View file

@ -79,4 +79,21 @@ main() {
var analysisOptions = compiler.context.analysisOptions;
expect(analysisOptions.enableStrictCallChecks, isTrue);
});
test('custom module name for summary', () {
var args = <String>[
'-snormal',
'-scustom/path:module',
'-sanother',
'-scustom/path2:module2'
];
var argResults = ddcArgParser().parse(args);
var options = new AnalyzerOptions.fromArguments(argResults);
expect(options.summaryPaths,
orderedEquals(['normal', 'custom/path', 'another', 'custom/path2']));
expect(options.customSummaryModules['custom/path'], equals('module'));
expect(options.customSummaryModules['custom/path2'], equals('module2'));
expect(options.customSummaryModules.containsKey('normal'), isFalse);
});
}

View file

@ -1,20 +1,31 @@
#!/usr/bin/env dart
import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:dev_compiler/src/compiler/command.dart';
/// Compiles the packages that the DDC tests use to JS into:
///
/// gen/codegen_output/pkg/...
///
/// Assumes the working directory is pkg/dev_compiler.
///
/// If no arguments are passed, builds the all of the modules tested on Travis.
/// If "test" is passed, only builds the modules needed by the tests.
void main(List<String> arguments) {
var test = arguments.length == 1 && arguments[0] == 'test';
final String scriptDirectory = p.dirname(p.fromUri(Platform.script));
String outputDirectory;
new Directory("gen/codegen_output/pkg").createSync(recursive: true);
/// Compiles the packages that the DDC tests use to JS into the given output
/// directory. Usage:
///
/// dart build_pkgs.dart <output_dir> [travis]
///
/// If "travis" is passed, builds the all of the modules tested on Travis.
/// Otherwise, only builds the modules needed by the tests.
void main(List<String> arguments) {
var isTravis = arguments.isNotEmpty && arguments.last == "travis";
if (isTravis) arguments.removeLast();
if (arguments.length != 1) {
print("Usage: dart build_pkgs.dart <output_dir> [travis]");
exit(1);
}
outputDirectory = arguments[0];
new Directory(outputDirectory).createSync(recursive: true);
// Build leaf packages. These have no other package dependencies.
@ -23,7 +34,7 @@ void main(List<String> arguments) {
compileModule('expect', libs: ['minitest']);
compileModule('js', libs: ['js_util']);
compileModule('meta');
if (!test) {
if (isTravis) {
compileModule('lookup_map');
compileModule('microlytics', libs: ['html_channels']);
compileModule('typed_mock');
@ -33,7 +44,7 @@ void main(List<String> arguments) {
compileModule('collection');
compileModule('matcher');
compileModule('path');
if (!test) {
if (isTravis) {
compileModule('args', libs: ['command_runner']);
compileModule('charcode');
compileModule('fixnum');
@ -49,11 +60,11 @@ void main(List<String> arguments) {
// Composite packages with dependencies.
compileModule('stack_trace', deps: ['path']);
if (!test) {
if (isTravis) {
compileModule('async', deps: ['collection']);
}
if (test) {
if (!isTravis) {
compileModule('unittest',
deps: ['matcher', 'path', 'stack_trace'],
libs: ['html_config', 'html_individual_config', 'html_enhanced_config'],
@ -65,9 +76,10 @@ void main(List<String> arguments) {
/// [libs] and [deps] on other modules.
void compileModule(String module,
{List<String> libs, List<String> deps, bool unsafeForceCompile: false}) {
var sdkSummary = p.join(scriptDirectory, "../lib/sdk/ddc_sdk.sum");
var args = [
'--dart-sdk-summary=lib/sdk/ddc_sdk.sum',
'-ogen/codegen_output/pkg/$module.js'
'--dart-sdk-summary=$sdkSummary',
'-o${outputDirectory}/$module.js'
];
// There is always a library that matches the module.
@ -83,7 +95,7 @@ void compileModule(String module,
// Add summaries for any modules this depends on.
if (deps != null) {
for (var dep in deps) {
args.add('-sgen/codegen_output/pkg/$dep.sum');
args.add('-s${outputDirectory}/$dep.sum');
}
}
@ -96,9 +108,10 @@ void compileModule(String module,
// but I'm not sure how they'll affect the other non-DDC tests. For now, just
// use ours.
if (module == 'async_helper') {
args.add('--url-mapping=package:async_helper/async_helper.dart,'
'test/codegen/async_helper.dart');
args.add('--url-mapping=package:async_helper/async_helper.dart,' +
p.join(scriptDirectory, "../test/codegen/async_helper.dart"));
}
compile(args);
var exitCode = compile(args);
if (exitCode != 0) exit(exitCode);
}

View file

@ -2,4 +2,4 @@
# TODO: This script is deprecated in favor of the Dart version. For now, forward
# to it so existing scripts don't break. Eventually, delete this one.
./tool/build_pkgs.dart
./tool/build_pkgs.dart gen/codegen_output/pkg travis

View file

@ -1,5 +0,0 @@
#!/bin/bash
# TODO: This script is deprecated in favor of the Dart version. For now, forward
# to it so existing scripts don't break. Eventually, delete this one.
./tool/build_pkgs.dart test

View file

@ -27,7 +27,7 @@ if [ -d gen/codegen_output ]; then
rm -r gen/codegen_output || fail
fi
./tool/build_pkgs.dart test
./tool/build_test_pkgs.sh
# Make sure we don't run tests in code coverage mode.
# this will cause us to generate files that are not part of the baseline

View file

@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'utils.dart';
String getHtmlContents(String title, String scriptType, String scriptPath) {
return """
<!DOCTYPE html>
@ -38,7 +40,13 @@ String getHtmlContents(String title, String scriptType, String scriptPath) {
/// The [testName] is the short name of the test without any subdirectory path
/// or extension, like "math_test". The [testJSDir] is the relative path to the
/// build directory where the dartdevc-generated JS file is stored.
String dartdevcHtml(String testName, String testJSDir) => """
String dartdevcHtml(String testName, String testJSDir, String buildDir) {
var packagePaths = testPackages
.map((package) => ' "$package": "/root_dart/$buildDir/gen/utils/'
'dartdevc/pkg/$package",')
.join("\n");
return """
<!DOCTYPE html>
<html>
<head>
@ -60,10 +68,9 @@ String dartdevcHtml(String testName, String testJSDir) => """
<script>
var require = {
baseUrl: "/root_dart/$testJSDir",
// TODO(29923): Add paths to the packages that are used in tests once they
// are being built. Right now, they are compiled into the test module itself.
paths: {
"dart_sdk": "/root_dart/pkg/dev_compiler/lib/js/amd/dart_sdk",
$packagePaths
}
};
@ -75,8 +82,17 @@ window.ddcSettings = {
<script type="text/javascript"
src="/root_dart/third_party/requirejs/require.js"></script>
<script type="text/javascript">
requirejs(["$testName", "dart_sdk"],
function($testName, dart_sdk) {
requirejs(["$testName", "dart_sdk", "async_helper"],
function($testName, dart_sdk, async_helper) {
function finish() {
// dev_compiler's test runner (language_test.js) uses this to notify the
// test results, but it isn't needed for test.dart.
}
// TODO(rnystrom): This uses DDC's forked version of async_helper. Unfork
// these packages when possible.
async_helper.async_helper.asyncTestInitialize(finish);
dart_sdk._isolate_helper.startRootIsolate(function() {}, []);
dartMainRunner($testName.$testName.main);
});
@ -84,6 +100,7 @@ requirejs(["$testName", "dart_sdk"],
</body>
</html>
""";
}
String dartTestWrapper(String libraryPathComponent) {
return """

View file

@ -83,7 +83,7 @@ abstract class CompilerConfiguration {
// TODO(ahe): It shouldn't be necessary to pass [buildDir] to any of these
// functions. It is fixed for a given configuration.
String computeCompilerPath(String buildDir) {
String computeCompilerPath() {
throw "Unknown compiler for: $runtimeType";
}
@ -91,9 +91,17 @@ abstract class CompilerConfiguration {
String get executableScriptSuffix => Platform.isWindows ? '.bat' : '';
List<Uri> bootstrapDependencies(String buildDir) => const <Uri>[];
List<Uri> bootstrapDependencies() => const <Uri>[];
CommandArtifact computeCompilationArtifact(String buildDir, String tempDir,
/// Creates a [Command] to compile [inputFile] to [outputFile].
Command createCommand(String inputFile, String outputFile) {
// TODO(rnystrom): See if this method can be unified with
// computeCompilationArtifact() and/or computeCompilerArguments() for the
// other compilers.
throw new UnsupportedError("$this does not support createCommand().");
}
CommandArtifact computeCompilationArtifact(String tempDir,
List<String> arguments, Map<String, String> environmentOverrides) {
return new CommandArtifact([], null, null);
}
@ -105,7 +113,6 @@ abstract class CompilerConfiguration {
List<String> computeRuntimeArguments(
RuntimeConfiguration runtimeConfiguration,
String buildDir,
TestInformation info,
List<String> vmOptions,
List<String> sharedOptions,
@ -126,12 +133,12 @@ class NoneCompilerConfiguration extends CompilerConfiguration {
List<String> computeRuntimeArguments(
RuntimeConfiguration runtimeConfiguration,
String buildDir,
TestInformation info,
List<String> vmOptions,
List<String> sharedOptions,
List<String> originalArguments,
CommandArtifact artifact) {
var buildDir = _configuration.buildDirectory;
var args = <String>[];
if (useDfe) {
args.add('--dfe=${buildDir}/gen/kernel-service.dart.snapshot');
@ -205,7 +212,7 @@ class ComposedCompilerConfiguration extends CompilerConfiguration {
Configuration configuration, this.pipelineCommands)
: super._subclass(configuration);
CommandArtifact computeCompilationArtifact(String buildDir, String tempDir,
CommandArtifact computeCompilationArtifact(String tempDir,
List<String> globalArguments, Map<String, String> environmentOverrides) {
var allCommands = <Command>[];
@ -213,8 +220,7 @@ class ComposedCompilerConfiguration extends CompilerConfiguration {
var arguments = pipelineCommands[0].extractArguments(globalArguments, null);
CommandArtifact artifact = pipelineCommands[0]
.compilerConfiguration
.computeCompilationArtifact(
buildDir, tempDir, arguments, environmentOverrides);
.computeCompilationArtifact(tempDir, arguments, environmentOverrides);
allCommands.addAll(artifact.commands);
// The following compilation commands are based on the output of the
@ -223,8 +229,8 @@ class ComposedCompilerConfiguration extends CompilerConfiguration {
PipelineCommand command = pipelineCommands[i];
arguments = command.extractArguments(globalArguments, artifact.filename);
artifact = command.compilerConfiguration.computeCompilationArtifact(
buildDir, tempDir, arguments, environmentOverrides);
artifact = command.compilerConfiguration
.computeCompilationArtifact(tempDir, arguments, environmentOverrides);
allCommands.addAll(artifact.commands);
}
@ -241,7 +247,6 @@ class ComposedCompilerConfiguration extends CompilerConfiguration {
List<String> computeRuntimeArguments(
RuntimeConfiguration runtimeConfiguration,
String buildDir,
TestInformation info,
List<String> vmOptions,
List<String> sharedOptions,
@ -251,7 +256,6 @@ class ComposedCompilerConfiguration extends CompilerConfiguration {
pipelineCommands.last.compilerConfiguration;
return lastCompilerConfiguration.computeRuntimeArguments(
runtimeConfiguration,
buildDir,
info,
vmOptions,
sharedOptions,
@ -268,7 +272,7 @@ class Dart2xCompilerConfiguration extends CompilerConfiguration {
Dart2xCompilerConfiguration(this.moniker, Configuration configuration)
: super._subclass(configuration);
String computeCompilerPath(String buildDir) {
String computeCompilerPath() {
var prefix = 'sdk/bin';
var suffix = executableScriptSuffix;
@ -280,33 +284,28 @@ class Dart2xCompilerConfiguration extends CompilerConfiguration {
}
if (_useSdk) {
prefix = '$buildDir/dart-sdk/bin';
prefix = '${_configuration.buildDirectory}/dart-sdk/bin';
}
return '$prefix/dart2js$suffix';
}
Command computeCompilationCommand(String outputFileName, String buildDir,
Command computeCompilationCommand(String outputFileName,
List<String> arguments, Map<String, String> environmentOverrides) {
arguments = arguments.toList();
arguments.add('--out=$outputFileName');
return Command.compilation(
moniker,
outputFileName,
bootstrapDependencies(buildDir),
computeCompilerPath(buildDir),
arguments,
environmentOverrides,
return Command.compilation(moniker, outputFileName, bootstrapDependencies(),
computeCompilerPath(), arguments, environmentOverrides,
alwaysCompile: !_useSdk);
}
List<Uri> bootstrapDependencies(String buildDir) {
List<Uri> bootstrapDependencies() {
if (!_useSdk) return const <Uri>[];
return _bootstrapDependenciesCache.putIfAbsent(
buildDir,
_configuration.buildDirectory,
() => [
Uri.base
.resolveUri(new Uri.directory(buildDir))
.resolveUri(new Uri.directory(_configuration.buildDirectory))
.resolve('dart-sdk/bin/snapshots/dart2js.dart.snapshot')
]);
}
@ -325,26 +324,25 @@ class Dart2jsCompilerConfiguration extends Dart2xCompilerConfiguration {
return multiplier;
}
CommandArtifact computeCompilationArtifact(String buildDir, String tempDir,
CommandArtifact computeCompilationArtifact(String tempDir,
List<String> arguments, Map<String, String> environmentOverrides) {
var compilerArguments = arguments.toList()
..addAll(_configuration.dart2jsOptions);
return new CommandArtifact([
computeCompilationCommand(
'$tempDir/out.js', buildDir, compilerArguments, environmentOverrides)
'$tempDir/out.js', compilerArguments, environmentOverrides)
], '$tempDir/out.js', 'application/javascript');
}
List<String> computeRuntimeArguments(
RuntimeConfiguration runtimeConfiguration,
String buildDir,
TestInformation info,
List<String> vmOptions,
List<String> sharedOptions,
List<String> originalArguments,
CommandArtifact artifact) {
Uri sdk = _useSdk
? new Uri.directory(buildDir).resolve('dart-sdk/')
? new Uri.directory(_configuration.buildDirectory).resolve('dart-sdk/')
: new Uri.directory(TestUtils.dartDir.toNativePath()).resolve('sdk/');
Uri preambleDir = sdk.resolve('lib/_internal/js_runtime/lib/preambles/');
return runtimeConfiguration.dart2jsPreambles(preambleDir)
@ -357,42 +355,55 @@ class DartdevcCompilerConfiguration extends CompilerConfiguration {
DartdevcCompilerConfiguration(Configuration configuration)
: super._subclass(configuration);
String computeCompilerPath(String buildDir) {
var dir = _useSdk ? "$buildDir/dart-sdk" : "sdk";
String computeCompilerPath() {
var dir = _useSdk ? "${_configuration.buildDirectory}/dart-sdk" : "sdk";
return "$dir/bin/dartdevc$executableScriptSuffix";
}
CommandArtifact computeCompilationArtifact(String buildDir, String tempDir,
List<String> arguments, Map<String, String> environmentOverrides) {
// TODO(rnystrom): There is a lot of overlap between this code and
// _dartdevcCompileCommand() in test_suite.dart. This code path is only hit
// when the test is expected to have a compile error. Consider refactoring
// to unify the two (and likewise for dart2js).
Command createCommand(String inputFile, String outputFile) {
var moduleRoot =
new Path(outputFile).directoryPath.directoryPath.toString();
var args = [
"--dart-sdk",
"${_configuration.buildDirectory}/dart-sdk",
"--library-root",
new Path(inputFile).directoryPath.toString(),
"--module-root",
moduleRoot,
"--no-summarize",
"--no-source-map",
"-o",
outputFile,
inputFile,
];
// Link to the summaries for the available packages, so that they don't
// get recompiled into the test's own module.
for (var package in testPackages) {
args.add("-s");
// Since the summaries for the packages are not near the tests, we give
// dartdevc explicit module paths for each one. When the test is run, we
// will tell require.js where to find each package's compiled JS.
var summary = _configuration.buildDirectory +
"/gen/utils/dartdevc/pkg/$package.sum";
args.add("$summary:$package");
}
return Command.compilation(Compiler.dartdevc.name, outputFile,
bootstrapDependencies(), computeCompilerPath(), args, const {});
}
CommandArtifact computeCompilationArtifact(String tempDir,
List<String> arguments, Map<String, String> environmentOverrides) {
// TODO(rnystrom): Are there other arguments here that we need to keep?
// What about arguments specified in the test itself?
var inputFile = arguments.last;
var outputFile = "$tempDir/${inputFile.replaceAll('.dart', '.js')}";
var compilerArguments = [
"--dart-sdk",
"$buildDir/dart-sdk",
"--library-root",
new Path(inputFile).directoryPath.toString(),
"-o",
"$tempDir/out.js",
inputFile
];
var command = Command.compilation(
Compiler.dartdevc.name,
"$tempDir/out.js",
bootstrapDependencies(buildDir),
computeCompilerPath(buildDir),
compilerArguments,
environmentOverrides);
return new CommandArtifact(
[command], "$tempDir/out.js", "application/javascript");
return new CommandArtifact([createCommand(inputFile, outputFile)],
outputFile, "application/javascript");
}
}
@ -414,26 +425,26 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration {
return multiplier;
}
CommandArtifact computeCompilationArtifact(String buildDir, String tempDir,
CommandArtifact computeCompilationArtifact(String tempDir,
List<String> arguments, Map<String, String> environmentOverrides) {
var commands = [
computeCompilationCommand(
tempDir, buildDir, arguments, environmentOverrides)
computeCompilationCommand(tempDir, arguments, environmentOverrides)
];
if (!_configuration.useBlobs) {
commands.add(computeAssembleCommand(
tempDir, buildDir, arguments, environmentOverrides));
commands.add(
computeAssembleCommand(tempDir, arguments, environmentOverrides));
commands.add(computeRemoveAssemblyCommand(
tempDir, buildDir, arguments, environmentOverrides));
tempDir, arguments, environmentOverrides));
}
return new CommandArtifact(
commands, '$tempDir', 'application/dart-precompiled');
}
Command computeCompilationCommand(String tempDir, String buildDir,
List<String> arguments, Map<String, String> environmentOverrides) {
Command computeCompilationCommand(String tempDir, List<String> arguments,
Map<String, String> environmentOverrides) {
var buildDir = _configuration.buildDirectory;
String exec;
if (_isAndroid) {
if (_isArm) {
@ -465,13 +476,13 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration {
args.addAll(arguments);
return Command.compilation('precompiler', tempDir,
bootstrapDependencies(buildDir), exec, args, environmentOverrides,
return Command.compilation('precompiler', tempDir, bootstrapDependencies(),
exec, args, environmentOverrides,
alwaysCompile: !_useSdk);
}
Command computeAssembleCommand(String tempDir, String buildDir,
List arguments, Map<String, String> environmentOverrides) {
Command computeAssembleCommand(String tempDir, List arguments,
Map<String, String> environmentOverrides) {
String cc, shared, ldFlags;
if (_isAndroid) {
var ndk = "third_party/android_tools/ndk";
@ -527,20 +538,20 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration {
args.add('$tempDir/out.aotsnapshot');
args.add('$tempDir/out.S');
return Command.compilation('assemble', tempDir,
bootstrapDependencies(buildDir), exec, args, environmentOverrides,
return Command.compilation('assemble', tempDir, bootstrapDependencies(),
exec, args, environmentOverrides,
alwaysCompile: !_useSdk);
}
// This step reduces the amount of space needed to run the precompilation
// tests by 60%.
Command computeRemoveAssemblyCommand(String tempDir, String buildDir,
List arguments, Map<String, String> environmentOverrides) {
Command computeRemoveAssemblyCommand(String tempDir, List arguments,
Map<String, String> environmentOverrides) {
var exec = 'rm';
var args = ['$tempDir/out.S'];
return Command.compilation('remove_assembly', tempDir,
bootstrapDependencies(buildDir), exec, args, environmentOverrides,
bootstrapDependencies(), exec, args, environmentOverrides,
alwaysCompile: !_useSdk);
}
@ -568,7 +579,6 @@ class PrecompilerCompilerConfiguration extends CompilerConfiguration {
List<String> computeRuntimeArguments(
RuntimeConfiguration runtimeConfiguration,
String buildDir,
TestInformation info,
List<String> vmOptions,
List<String> sharedOptions,
@ -607,24 +617,24 @@ class AppJitCompilerConfiguration extends CompilerConfiguration {
return multiplier;
}
CommandArtifact computeCompilationArtifact(String buildDir, String tempDir,
CommandArtifact computeCompilationArtifact(String tempDir,
List<String> arguments, Map<String, String> environmentOverrides) {
var snapshot = "$tempDir/out.jitsnapshot";
return new CommandArtifact([
computeCompilationCommand(
tempDir, buildDir, arguments, environmentOverrides)
], snapshot, 'application/dart-snapshot');
return new CommandArtifact(
[computeCompilationCommand(tempDir, arguments, environmentOverrides)],
snapshot,
'application/dart-snapshot');
}
Command computeCompilationCommand(String tempDir, String buildDir,
List<String> arguments, Map<String, String> environmentOverrides) {
var exec = "$buildDir/dart";
Command computeCompilationCommand(String tempDir, List<String> arguments,
Map<String, String> environmentOverrides) {
var exec = "${_configuration.buildDirectory}/dart";
var snapshot = "$tempDir/out.jitsnapshot";
var args = ["--snapshot=$snapshot", "--snapshot-kind=app-jit"];
args.addAll(arguments);
return Command.compilation('app_jit', tempDir,
bootstrapDependencies(buildDir), exec, args, environmentOverrides,
return Command.compilation('app_jit', tempDir, bootstrapDependencies(),
exec, args, environmentOverrides,
alwaysCompile: !_useSdk);
}
@ -643,7 +653,6 @@ class AppJitCompilerConfiguration extends CompilerConfiguration {
List<String> computeRuntimeArguments(
RuntimeConfiguration runtimeConfiguration,
String buildDir,
TestInformation info,
List<String> vmOptions,
List<String> sharedOptions,
@ -670,7 +679,7 @@ class AnalyzerCompilerConfiguration extends CompilerConfiguration {
int get timeoutMultiplier => 4;
String computeCompilerPath(String buildDir) {
String computeCompilerPath() {
var prefix = 'sdk/bin';
String suffix = executableScriptSuffix;
if (_isHostChecked) {
@ -683,12 +692,12 @@ class AnalyzerCompilerConfiguration extends CompilerConfiguration {
return '$prefix/dartanalyzer_developer$suffix';
}
if (_useSdk) {
prefix = '$buildDir/dart-sdk/bin';
prefix = '${_configuration.buildDirectory}/dart-sdk/bin';
}
return '$prefix/dartanalyzer$suffix';
}
CommandArtifact computeCompilationArtifact(String buildDir, String tempDir,
CommandArtifact computeCompilationArtifact(String tempDir,
List<String> arguments, Map<String, String> environmentOverrides) {
arguments = arguments.toList();
if (_isChecked || _isStrong) {
@ -700,14 +709,12 @@ class AnalyzerCompilerConfiguration extends CompilerConfiguration {
// Since this is not a real compilation, no artifacts are produced.
return new CommandArtifact([
Command.analysis(
computeCompilerPath(buildDir), arguments, environmentOverrides)
Command.analysis(computeCompilerPath(), arguments, environmentOverrides)
], null, null);
}
List<String> computeRuntimeArguments(
RuntimeConfiguration runtimeConfiguration,
String buildDir,
TestInformation info,
List<String> vmOptions,
List<String> sharedOptions,

View file

@ -167,7 +167,7 @@ abstract class TestSuite {
String get compilerPath {
var compilerConfiguration = configuration.compilerConfiguration;
if (!compilerConfiguration.hasCompiler) return null;
var name = compilerConfiguration.computeCompilerPath(buildDir);
var name = compilerConfiguration.computeCompilerPath();
// TODO(ahe): Only validate this once, in test_options.dart.
TestUtils.ensureExists(name, configuration);
@ -882,7 +882,7 @@ class StandardTestSuite extends TestSuite {
CommandArtifact compilationArtifact =
compilerConfiguration.computeCompilationArtifact(
buildDir, tempDir, compileTimeArguments, environmentOverrides);
tempDir, compileTimeArguments, environmentOverrides);
if (!configuration.skipCompilation) {
commands.addAll(compilationArtifact.commands);
}
@ -896,7 +896,6 @@ class StandardTestSuite extends TestSuite {
List<String> runtimeArguments =
compilerConfiguration.computeRuntimeArguments(
configuration.runtimeConfiguration,
buildDir,
info,
vmOptions,
sharedOptions,
@ -1090,7 +1089,7 @@ class StandardTestSuite extends TestSuite {
var jsDir = new Path(compilationTempDir)
.relativeTo(TestUtils.dartDir)
.toString();
content = dartdevcHtml(nameNoExt, jsDir);
content = dartdevcHtml(nameNoExt, jsDir, buildDir);
}
new File(htmlPath).writeAsStringSync(content);
@ -1107,8 +1106,8 @@ class StandardTestSuite extends TestSuite {
break;
case Compiler.dartdevc:
commands.add(_dartdevcCompileCommand(dartWrapperFilename,
'$compilationTempDir/$nameNoExt.js', optionsFromFile));
commands.add(configuration.compilerConfiguration.createCommand(
dartWrapperFilename, '$compilationTempDir/$nameNoExt.js'));
break;
case Compiler.none:
@ -1130,8 +1129,8 @@ class StandardTestSuite extends TestSuite {
break;
case Compiler.dartdevc:
commands.add(_dartdevcCompileCommand(fromPath.toNativePath(),
'$tempDir/${namePath.filename}.js', optionsFromFile));
commands.add(configuration.compilerConfiguration.createCommand(
fromPath.toNativePath(), '$tempDir/${namePath.filename}.js'));
break;
default:
@ -1323,33 +1322,6 @@ class StandardTestSuite extends TestSuite {
alwaysCompile: !useSdk);
}
/// Creates a [Command] to compile a single .dart file using dartdevc.
Command _dartdevcCompileCommand(String inputFile, String outputFile,
Map<String, dynamic> optionsFromFile) {
var args = [
"--dart-sdk",
"$buildDir/dart-sdk",
"--library-root",
new Path(inputFile).directoryPath.toString(),
"-o",
outputFile,
inputFile
];
// TODO(29923): This compiles everything imported by the test into the
// same generated JS module, including other packages like expect,
// stack_trace, etc. Those should be compiled as separate JS modules (by
// build.py) and loaded dynamically by the test.
return Command.compilation(
Compiler.dartdevc.name,
outputFile,
configuration.compilerConfiguration.bootstrapDependencies(buildDir),
compilerPath,
args,
environmentOverrides);
}
String get scriptType {
switch (configuration.compiler) {
case Compiler.none:

View file

@ -19,6 +19,19 @@ String MAX_STDIO_DELAY_PASSED_MESSAGE =
($MAX_STDIO_DELAY passed). Please note that this could be an indicator
that there is a hanging process which we were unable to kill.""";
/// The names of the packages that are available for use in tests.
const testPackages = const [
"async_helper",
"collection",
"expect",
"js",
"matcher",
"meta",
"path",
"stack_trace",
"unittest"
];
class DebugLogger {
static IOSink _sink;

View file

@ -3,6 +3,7 @@
# BSD-style license that can be found in the LICENSE file.
import("../application_snapshot.gni")
import("../create_timestamp.gni")
application_snapshot("dartdevc") {
main_dart = "../../pkg/dev_compiler/bin/dartdevc.dart"
@ -19,25 +20,33 @@ application_snapshot("dartdevc") {
rebase_path("../../pkg/dev_compiler/bin/dartdevc.dart"),
]
inputs = exec_script("../../tools/list_dart_files.py",
[ "absolute",
rebase_path("../../pkg/dev_compiler/bin") ],
[
"absolute",
rebase_path("../../pkg/dev_compiler/bin"),
],
"list lines")
}
sdk_lib_files = exec_script(
"../../tools/list_dart_files.py",
[ "absolute", rebase_path("../../sdk/lib") ],
"list lines")
sdk_lib_files = exec_script("../../tools/list_dart_files.py",
[
"absolute",
rebase_path("../../sdk/lib"),
],
"list lines")
compiler_files = exec_script(
"../../tools/list_dart_files.py",
[ "absolute", rebase_path("../../pkg/compiler") ],
"list lines")
compiler_files = exec_script("../../tools/list_dart_files.py",
[
"absolute",
rebase_path("../../pkg/compiler"),
],
"list lines")
dev_compiler_files = exec_script(
"../../tools/list_dart_files.py",
[ "absolute", rebase_path("../../pkg/dev_compiler") ],
"list lines")
dev_compiler_files = exec_script("../../tools/list_dart_files.py",
[
"absolute",
rebase_path("../../pkg/dev_compiler"),
],
"list lines")
template("dart2js_compile") {
assert(defined(invoker.main), "Must specify the main file")
@ -55,8 +64,7 @@ template("dart2js_compile") {
]
dot_packages = rebase_path("../../.packages")
compiler =
rebase_path("../../pkg/compiler/lib/src/dart2js.dart")
compiler = rebase_path("../../pkg/compiler/lib/src/dart2js.dart")
args = [
"--packages=$dot_packages",
@ -78,3 +86,62 @@ dart2js_compile("stack_trace_mapper") {
main = rebase_path("../../pkg/dev_compiler/web/stack_trace_mapper.dart")
out = "$root_out_dir/dev_compiler/build/web/dart_stack_trace_mapper.js"
}
# Builds everything needed to run dartdevc tests using test.dart.
group("dartdevc_test") {
deps = [
":dartdevc",
":dartdevc_test_pkg",
"../../sdk:create_sdk",
]
}
create_timestamp_file("dartdevc_files_stamp") {
path = rebase_path("../../pkg/dev_compiler/lib")
output = "$target_gen_dir/dartdevc_files.stamp"
}
# Compiles the packages used by the tests to JS with dartdevc so that they are
# available for loading by the tests.
compiled_action("dartdevc_test_pkg") {
tool = "../../runtime/bin:dart"
deps = [
":dartdevc_files_stamp",
"../../pkg:pkg_files_stamp",
]
inputs = [
"$target_gen_dir/dartdevc_files.stamp",
"$root_gen_dir/pkg_files.stamp",
]
outputs = [
"$target_gen_dir/pkg/async_helper.js",
"$target_gen_dir/pkg/async_helper.sum",
"$target_gen_dir/pkg/collection.js",
"$target_gen_dir/pkg/collection.sum",
"$target_gen_dir/pkg/expect.js",
"$target_gen_dir/pkg/expect.sum",
"$target_gen_dir/pkg/js.js",
"$target_gen_dir/pkg/js.sum",
"$target_gen_dir/pkg/matcher.js",
"$target_gen_dir/pkg/matcher.sum",
"$target_gen_dir/pkg/meta.js",
"$target_gen_dir/pkg/meta.sum",
"$target_gen_dir/pkg/path.js",
"$target_gen_dir/pkg/path.sum",
"$target_gen_dir/pkg/stack_trace.js",
"$target_gen_dir/pkg/stack_trace.sum",
# TODO(rnystrom): Remove this when unittest is no longer used. Also remove
# any of the above packages that are only here because unittest uses them.
"$target_gen_dir/pkg/unittest.js",
"$target_gen_dir/pkg/unittest.sum",
]
args = [
rebase_path("../../pkg/dev_compiler/tool/build_pkgs.dart"),
rebase_path("$target_gen_dir/pkg"),
]
}