Index: dart/tools/testing/dart/compiler_configuration.dart |
diff --git a/dart/tools/testing/dart/compiler_configuration.dart b/dart/tools/testing/dart/compiler_configuration.dart |
index a7e6a9fa6987982ea54b6156d70e2453b844caca..abe30edf891a2f69a6b255c832b1807be4fff949 100644 |
--- a/dart/tools/testing/dart/compiler_configuration.dart |
+++ b/dart/tools/testing/dart/compiler_configuration.dart |
@@ -4,78 +4,373 @@ |
library compiler_configuration; |
+import 'dart:io' show |
+ Platform; |
+ |
+import 'runtime_configuration.dart' show |
+ RuntimeConfiguration; |
+ |
+import 'test_runner.dart' show |
+ Command, |
+ CommandBuilder, |
+ CompilationCommand; |
+ |
+import 'test_suite.dart' show |
+ TestInformation; |
+ |
+/// Grouping of a command with its expected result. |
+class CommandArtifact { |
+ final List<Command> commands; |
+ |
+ /// Expected result of running [command]. |
+ final String filename; |
ricow1
2014/03/03 07:47:08
I am not sure expected result is a good comment he
|
+ |
+ /// MIME type of [filename]. |
+ final String mimeType; |
+ |
+ CommandArtifact(this.commands, this.filename, this.mimeType); |
+} |
+ |
+Uri nativeDirectoryToUri(String nativePath) { |
+ Uri uri = new Uri.file(nativePath); |
+ String path = uri.path; |
+ return (path == '' || path.endsWith('/')) |
+ ? uri |
+ : Uri.parse('$uri/'); |
+} |
+ |
abstract class CompilerConfiguration { |
+ final bool isDebug; |
+ final bool isChecked; |
+ final bool isHostChecked; |
+ final bool useSdk; |
+ |
// TODO(ahe): Remove this constructor and move the switch to |
// test_options.dart. We probably want to store an instance of |
// [CompilerConfiguration] in [configuration] there. |
factory CompilerConfiguration(Map configuration) { |
String compiler = configuration['compiler']; |
+ |
+ // TODO(ahe): Move these booleans into a struction configuration object |
ricow1
2014/03/03 07:47:08
+1 on that
|
+ // which can eventually completely replace the Map-based configuration |
+ // object. |
+ bool isDebug = configuration['mode'] == 'debug'; |
+ bool isChecked = configuration['checked']; |
+ bool isHostChecked = configuration['host_checked']; |
+ bool useSdk = configuration['use_sdk']; |
+ bool isCsp = configuration['csp']; |
+ |
switch (compiler) { |
case 'dartanalyzer': |
+ return new AnalyzerCompilerConfiguration( |
+ 'dartanalyzer', isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
case 'dart2analyzer': |
- return new AnalyzerCompilerConfiguration(); |
+ return new DartBasedAnalyzerCompilerConfiguration( |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
case 'dart2js': |
- return new Dart2jsCompilerConfiguration(); |
+ return new Dart2jsCompilerConfiguration( |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk, isCsp: isCsp); |
case 'dart2dart': |
- return new Dart2dartCompilerConfiguration(); |
+ return new Dart2dartCompilerConfiguration( |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
case 'none': |
- return new NoneCompilerConfiguration(); |
+ return new NoneCompilerConfiguration( |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
default: |
throw "Unknown compiler '$compiler'"; |
} |
} |
- CompilerConfiguration._subclass(); |
+ CompilerConfiguration._subclass({ |
+ this.isDebug: false, |
+ this.isChecked: false, |
+ this.isHostChecked: false, |
+ this.useSdk: false}); |
/// Return a multiplier used to give tests longer time to run. |
- int computeTimeoutMultiplier({ |
- bool isDebug: false, |
- bool isChecked: false, |
- bool isHostChecked: false}) { |
+ // TODO(ahe): Convert to getter! |
+ int computeTimeoutMultiplier() { |
return 1; |
} |
+ |
+ // 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) { |
+ throw "Unknown compiler for: $runtimeType"; |
+ } |
+ |
+ bool get hasCompiler => true; |
+ |
+ String get executableScriptSuffix => Platform.isWindows ? '.bat' : ''; |
+ |
+ // TODO(ahe): Remove this. |
+ bool get isCsp => false; |
+ |
+ List<Uri> bootstrapDependencies(String buildDir) => const <Uri>[]; |
+ |
+ CommandArtifact computeCompilationArtifact( |
+ String buildDir, |
+ String tempDir, |
+ CommandBuilder commandBuilder, |
+ List arguments, |
+ Map<String, String> environmentOverrides) { |
+ return new CommandArtifact([], null, null); |
+ } |
+ |
+ List<String> computeRuntimeArguments( |
+ RuntimeConfiguration runtimeConfiguration, |
+ TestInformation info, |
+ List<String> vmOptions, |
+ List<String> sharedOptions, |
+ List<String> originalArguments, |
+ CommandArtifact artifact) { |
+ return <String>[artifact.filename]; |
+ } |
} |
/// The "none" compiler. |
class NoneCompilerConfiguration extends CompilerConfiguration { |
- NoneCompilerConfiguration() |
- : super._subclass(); |
+ NoneCompilerConfiguration({ |
+ bool isDebug, |
+ bool isChecked, |
+ bool isHostChecked, |
+ bool useSdk}) |
+ : super._subclass( |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
+ |
+ bool get hasCompiler => false; |
+ |
+ List<String> computeRuntimeArguments( |
+ RuntimeConfiguration runtimeConfiguration, |
+ TestInformation info, |
+ List<String> vmOptions, |
+ List<String> sharedOptions, |
+ List<String> originalArguments, |
+ CommandArtifact artifact) { |
+ return <String>[] |
+ ..addAll(vmOptions) |
+ ..addAll(sharedOptions) |
+ ..addAll(originalArguments); |
+ } |
} |
/// Common configuration for dart2js-based tools, such as, dart2js and |
/// dart2dart. |
class Dart2xCompilerConfiguration extends CompilerConfiguration { |
- Dart2xCompilerConfiguration() |
- : super._subclass(); |
+ final String moniker; |
ricow1
2014/03/03 07:47:08
could this just be toolName - I had to look up mon
|
+ |
+ Dart2xCompilerConfiguration( |
+ this.moniker, |
+ {bool isDebug, |
+ bool isChecked, |
+ bool isHostChecked, |
+ bool useSdk}) |
+ : super._subclass( |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
+ |
+ String computeCompilerPath(String buildDir) { |
+ var prefix = 'sdk/bin/'; |
+ String suffix = executableScriptSuffix; |
+ if (isHostChecked) { |
+ // The script dart2js_developer is not included in the |
+ // shipped SDK, that is the script is not installed in |
+ // "$buildDir/dart-sdk/bin/" |
+ return '$prefix/dart2js_developer$suffix'; |
+ } else { |
+ if (useSdk) { |
+ prefix = '$buildDir/dart-sdk/bin'; |
+ } |
+ return '$prefix/dart2js$suffix'; |
+ } |
+ } |
+ |
+ CompilationCommand computeCompilationCommand( |
+ String outputFileName, |
+ String buildDir, |
+ CommandBuilder commandBuilder, |
+ List arguments, |
+ Map<String, String> environmentOverrides) { |
+ arguments = new List.from(arguments); |
+ arguments.add('--out=$outputFileName'); |
+ |
+ return commandBuilder.getCompilationCommand( |
+ moniker, outputFileName, !useSdk, |
+ bootstrapDependencies(buildDir), |
+ computeCompilerPath(buildDir), |
+ arguments, environmentOverrides); |
+ } |
+ |
+ List<Uri> bootstrapDependencies(String buildDir) { |
+ if (!useSdk) return const <Uri>[]; |
+ |
+ Uri absoluteBuildDir = Uri.base.resolveUri(nativeDirectoryToUri(buildDir)); |
+ return [absoluteBuildDir.resolve( |
+ 'dart-sdk/bin/snapshots/dart2js.dart.snapshot')]; |
+ } |
} |
/// Configuration for dart2js compiler. |
class Dart2jsCompilerConfiguration extends Dart2xCompilerConfiguration { |
- int computeTimeoutMultiplier({ |
- bool isDebug: false, |
- bool isChecked: false, |
- bool isHostChecked: false}) { |
+ final bool isCsp; |
+ |
+ Dart2jsCompilerConfiguration({ |
+ bool isDebug, |
+ bool isChecked, |
+ bool isHostChecked, |
+ bool useSdk, |
+ bool this.isCsp}) |
+ : super( |
+ 'dart2js', |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
+ |
+ int computeTimeoutMultiplier() { |
int multiplier = 1; |
if (isDebug) multiplier *= 4; |
if (isChecked) multiplier *= 2; |
if (isHostChecked) multiplier *= 16; |
return multiplier; |
} |
+ |
+ CommandArtifact computeCompilationArtifact( |
+ String buildDir, |
+ String tempDir, |
+ CommandBuilder commandBuilder, |
+ List arguments, |
+ Map<String, String> environmentOverrides) { |
+ String normalOutput = '$tempDir/out.js'; |
+ String cspOutput = '$tempDir/out.precompiled.js'; |
+ return new CommandArtifact( |
+ <Command>[ |
+ this.computeCompilationCommand( |
+ normalOutput, |
+ buildDir, |
+ CommandBuilder.instance, |
+ arguments, |
+ environmentOverrides)], |
+ // dart2js always produce both out.js and out.precompiled.js. To avoid |
+ // recompiling the CSP version, we always tell the CompilationCommand |
+ // to track the timestamp of out.js, but select which one to run based |
+ // on CSP mode. |
+ isCsp ? cspOutput : normalOutput, |
+ 'application/javascript'); |
+ } |
} |
/// Configuration for dart2dart compiler. |
class Dart2dartCompilerConfiguration extends Dart2xCompilerConfiguration { |
+ Dart2dartCompilerConfiguration({ |
+ bool isDebug, |
+ bool isChecked, |
+ bool isHostChecked, |
+ bool useSdk}) |
+ : super( |
+ 'dart2dart', |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
+ |
+ CommandArtifact computeCompilationArtifact( |
+ String buildDir, |
+ String tempDir, |
+ CommandBuilder commandBuilder, |
+ List arguments, |
+ Map<String, String> environmentOverrides) { |
+ String outputFileName = '$tempDir/out.dart'; |
+ arguments = new List.from(arguments)..add('--output-type=dart'); |
+ return new CommandArtifact( |
+ <Command>[ |
+ this.computeCompilationCommand( |
+ outputFileName, |
+ buildDir, |
+ CommandBuilder.instance, |
+ arguments, |
+ environmentOverrides)], |
+ outputFileName, |
+ 'application/dart'); |
+ } |
+ |
+ List<String> computeRuntimeArguments( |
+ RuntimeConfiguration runtimeConfiguration, |
+ TestInformation info, |
+ List<String> vmOptions, |
+ List<String> sharedOptions, |
+ List<String> originalArguments, |
+ CommandArtifact artifact) { |
+ // TODO(antonm): support checked. |
+ return <String>[] |
+ ..addAll(vmOptions) |
+ ..add('--ignore-unrecognized-flags') |
+ ..add(artifact.filename); |
+ } |
} |
/// Common configuration for analyzer-based tools, such as, dartanalyzer. |
class AnalyzerCompilerConfiguration extends CompilerConfiguration { |
- AnalyzerCompilerConfiguration() |
- : super._subclass(); |
+ final String moniker; |
+ |
+ AnalyzerCompilerConfiguration( |
+ this.moniker, |
+ {bool isDebug, |
+ bool isChecked, |
+ bool isHostChecked, |
+ bool useSdk}) |
+ : super._subclass( |
+ isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
- int computeTimeoutMultiplier({ |
- bool isDebug: false, |
- bool isChecked: false, |
- bool isHostChecked: false}) { |
+ int computeTimeoutMultiplier() { |
return 4; |
} |
+ |
+ String computeCompilerPath(String buildDir) { |
+ String suffix = executableScriptSuffix; |
+ return 'sdk/bin/dartanalyzer_developer$suffix'; |
+ } |
+ |
+ CommandArtifact computeCompilationArtifact( |
+ String buildDir, |
+ String tempDir, |
+ CommandBuilder commandBuilder, |
+ List arguments, |
+ Map<String, String> environmentOverrides) { |
+ return new CommandArtifact( |
+ <Command>[ |
+ commandBuilder.getAnalysisCommand( |
+ moniker, computeCompilerPath(buildDir), arguments, |
+ environmentOverrides, |
+ flavor: moniker)], |
+ null, null); // Since this is not a real compilation, no artifacts are |
+ // produced. |
+ } |
+ |
+ List<String> computeRuntimeArguments( |
+ RuntimeConfiguration runtimeConfiguration, |
+ TestInformation info, |
+ List<String> vmOptions, |
+ List<String> sharedOptions, |
+ List<String> originalArguments, |
+ CommandArtifact artifact) { |
+ return <String>[]; |
+ } |
+} |
+ |
+class DartBasedAnalyzerCompilerConfiguration |
+ extends AnalyzerCompilerConfiguration { |
+ DartBasedAnalyzerCompilerConfiguration({ |
+ bool isDebug, |
+ bool isChecked, |
+ bool isHostChecked, |
+ bool useSdk}) |
+ : super( |
+ 'dart2analyzer', isDebug: isDebug, isChecked: isChecked, |
+ isHostChecked: isHostChecked, useSdk: useSdk); |
+ |
+ String computeCompilerPath(String buildDir) => 'editor/tools/analyzer'; |
} |