OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Classes and methods for enumerating and preparing tests. | 6 * Classes and methods for enumerating and preparing tests. |
7 * | 7 * |
8 * This library includes: | 8 * This library includes: |
9 * | 9 * |
10 * - Creating tests by listing all the Dart files in certain directories, | 10 * - Creating tests by listing all the Dart files in certain directories, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 */ | 160 */ |
161 String get buildDir => configuration.buildDirectory; | 161 String get buildDir => configuration.buildDirectory; |
162 | 162 |
163 /** | 163 /** |
164 * The path to the compiler for this suite's configuration. Returns `null` if | 164 * The path to the compiler for this suite's configuration. Returns `null` if |
165 * no compiler should be used. | 165 * no compiler should be used. |
166 */ | 166 */ |
167 String get compilerPath { | 167 String get compilerPath { |
168 var compilerConfiguration = configuration.compilerConfiguration; | 168 var compilerConfiguration = configuration.compilerConfiguration; |
169 if (!compilerConfiguration.hasCompiler) return null; | 169 if (!compilerConfiguration.hasCompiler) return null; |
170 var name = compilerConfiguration.computeCompilerPath(buildDir); | 170 var name = compilerConfiguration.computeCompilerPath(); |
171 | 171 |
172 // TODO(ahe): Only validate this once, in test_options.dart. | 172 // TODO(ahe): Only validate this once, in test_options.dart. |
173 TestUtils.ensureExists(name, configuration); | 173 TestUtils.ensureExists(name, configuration); |
174 return name; | 174 return name; |
175 } | 175 } |
176 | 176 |
177 String get pubPath { | 177 String get pubPath { |
178 var prefix = 'sdk/bin/'; | 178 var prefix = 'sdk/bin/'; |
179 if (configuration.useSdk) { | 179 if (configuration.useSdk) { |
180 prefix = '$buildDir/dart-sdk/bin/'; | 180 prefix = '$buildDir/dart-sdk/bin/'; |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 for (var name in otherResources) { | 874 for (var name in otherResources) { |
875 var namePath = new Path(name); | 875 var namePath = new Path(name); |
876 var fromPath = info.filePath.directoryPath.join(namePath); | 876 var fromPath = info.filePath.directoryPath.join(namePath); |
877 new File('$tempDir/$name').parent.createSync(recursive: true); | 877 new File('$tempDir/$name').parent.createSync(recursive: true); |
878 new File(fromPath.toNativePath()).copySync('$tempDir/$name'); | 878 new File(fromPath.toNativePath()).copySync('$tempDir/$name'); |
879 } | 879 } |
880 } | 880 } |
881 | 881 |
882 CommandArtifact compilationArtifact = | 882 CommandArtifact compilationArtifact = |
883 compilerConfiguration.computeCompilationArtifact( | 883 compilerConfiguration.computeCompilationArtifact( |
884 buildDir, tempDir, compileTimeArguments, environmentOverrides); | 884 tempDir, compileTimeArguments, environmentOverrides); |
885 if (!configuration.skipCompilation) { | 885 if (!configuration.skipCompilation) { |
886 commands.addAll(compilationArtifact.commands); | 886 commands.addAll(compilationArtifact.commands); |
887 } | 887 } |
888 | 888 |
889 if (expectCompileError(info) && compilerConfiguration.hasCompiler) { | 889 if (expectCompileError(info) && compilerConfiguration.hasCompiler) { |
890 // Do not attempt to run the compiled result. A compilation | 890 // Do not attempt to run the compiled result. A compilation |
891 // error should be reported by the compilation command. | 891 // error should be reported by the compilation command. |
892 return commands; | 892 return commands; |
893 } | 893 } |
894 | 894 |
895 List<String> runtimeArguments = | 895 List<String> runtimeArguments = |
896 compilerConfiguration.computeRuntimeArguments( | 896 compilerConfiguration.computeRuntimeArguments( |
897 configuration.runtimeConfiguration, | 897 configuration.runtimeConfiguration, |
898 buildDir, | |
899 info, | 898 info, |
900 vmOptions, | 899 vmOptions, |
901 sharedOptions, | 900 sharedOptions, |
902 args, | 901 args, |
903 compilationArtifact); | 902 compilationArtifact); |
904 | 903 |
905 return commands | 904 return commands |
906 ..addAll(configuration.runtimeConfiguration.computeRuntimeCommands( | 905 ..addAll(configuration.runtimeConfiguration.computeRuntimeCommands( |
907 this, compilationArtifact, runtimeArguments, environmentOverrides)); | 906 this, compilationArtifact, runtimeArguments, environmentOverrides)); |
908 } | 907 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 scriptPath = compiledDartWrapperFilename; | 1081 scriptPath = compiledDartWrapperFilename; |
1083 } | 1082 } |
1084 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); | 1083 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); |
1085 | 1084 |
1086 if (configuration.compiler == Compiler.dart2js) { | 1085 if (configuration.compiler == Compiler.dart2js) { |
1087 content = getHtmlContents(fileName, scriptType, scriptPath); | 1086 content = getHtmlContents(fileName, scriptType, scriptPath); |
1088 } else { | 1087 } else { |
1089 var jsDir = new Path(compilationTempDir) | 1088 var jsDir = new Path(compilationTempDir) |
1090 .relativeTo(TestUtils.dartDir) | 1089 .relativeTo(TestUtils.dartDir) |
1091 .toString(); | 1090 .toString(); |
1092 content = dartdevcHtml(nameNoExt, jsDir); | 1091 content = dartdevcHtml(nameNoExt, jsDir, buildDir); |
1093 } | 1092 } |
1094 | 1093 |
1095 new File(htmlPath).writeAsStringSync(content); | 1094 new File(htmlPath).writeAsStringSync(content); |
1096 } | 1095 } |
1097 | 1096 |
1098 // Construct the command(s) that compile all the inputs needed by the | 1097 // Construct the command(s) that compile all the inputs needed by the |
1099 // browser test. For running Dart in DRT, this will be noop commands. | 1098 // browser test. For running Dart in DRT, this will be noop commands. |
1100 var commands = <Command>[]; | 1099 var commands = <Command>[]; |
1101 | 1100 |
1102 switch (configuration.compiler) { | 1101 switch (configuration.compiler) { |
1103 case Compiler.dart2js: | 1102 case Compiler.dart2js: |
1104 commands.add(_dart2jsCompileCommand(dartWrapperFilename, | 1103 commands.add(_dart2jsCompileCommand(dartWrapperFilename, |
1105 compiledDartWrapperFilename, tempDir, optionsFromFile)); | 1104 compiledDartWrapperFilename, tempDir, optionsFromFile)); |
1106 break; | 1105 break; |
1107 | 1106 |
1108 case Compiler.dartdevc: | 1107 case Compiler.dartdevc: |
1109 commands.add(_dartdevcCompileCommand(dartWrapperFilename, | 1108 commands.add(configuration.compilerConfiguration.createCommand( |
1110 '$compilationTempDir/$nameNoExt.js', optionsFromFile)); | 1109 dartWrapperFilename, '$compilationTempDir/$nameNoExt.js')); |
1111 break; | 1110 break; |
1112 | 1111 |
1113 default: | 1112 default: |
1114 assert(false); | 1113 assert(false); |
1115 } | 1114 } |
1116 | 1115 |
1117 // Some tests require compiling multiple input scripts. | 1116 // Some tests require compiling multiple input scripts. |
1118 for (var name in optionsFromFile['otherScripts'] as List<String>) { | 1117 for (var name in optionsFromFile['otherScripts'] as List<String>) { |
1119 var namePath = new Path(name); | 1118 var namePath = new Path(name); |
1120 var fromPath = filePath.directoryPath.join(namePath); | 1119 var fromPath = filePath.directoryPath.join(namePath); |
1121 | 1120 |
1122 switch (configuration.compiler) { | 1121 switch (configuration.compiler) { |
1123 case Compiler.dart2js: | 1122 case Compiler.dart2js: |
1124 commands.add(_dart2jsCompileCommand(fromPath.toNativePath(), | 1123 commands.add(_dart2jsCompileCommand(fromPath.toNativePath(), |
1125 '$tempDir/${namePath.filename}.js', tempDir, optionsFromFile)); | 1124 '$tempDir/${namePath.filename}.js', tempDir, optionsFromFile)); |
1126 break; | 1125 break; |
1127 | 1126 |
1128 case Compiler.dartdevc: | 1127 case Compiler.dartdevc: |
1129 commands.add(_dartdevcCompileCommand(fromPath.toNativePath(), | 1128 commands.add(configuration.compilerConfiguration.createCommand( |
1130 '$tempDir/${namePath.filename}.js', optionsFromFile)); | 1129 fromPath.toNativePath(), '$tempDir/${namePath.filename}.js')); |
1131 break; | 1130 break; |
1132 | 1131 |
1133 default: | 1132 default: |
1134 assert(configuration.compiler == Compiler.none); | 1133 assert(configuration.compiler == Compiler.none); |
1135 } | 1134 } |
1136 | 1135 |
1137 if (configuration.compiler == Compiler.none) { | 1136 if (configuration.compiler == Compiler.none) { |
1138 // For the tests that require multiple input scripts but are not | 1137 // For the tests that require multiple input scripts but are not |
1139 // compiled, move the input scripts over with the script so they can | 1138 // compiled, move the input scripts over with the script so they can |
1140 // be accessed. | 1139 // be accessed. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 args.add(inputFile); | 1311 args.add(inputFile); |
1313 | 1312 |
1314 var options = optionsFromFile['sharedOptions'] as List<String>; | 1313 var options = optionsFromFile['sharedOptions'] as List<String>; |
1315 if (options != null) args.addAll(options); | 1314 if (options != null) args.addAll(options); |
1316 | 1315 |
1317 return Command.compilation(Compiler.dart2js.name, outputFile, | 1316 return Command.compilation(Compiler.dart2js.name, outputFile, |
1318 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides, | 1317 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides, |
1319 alwaysCompile: !useSdk); | 1318 alwaysCompile: !useSdk); |
1320 } | 1319 } |
1321 | 1320 |
1322 /// Creates a [Command] to compile a single .dart file using dartdevc. | |
1323 Command _dartdevcCompileCommand(String inputFile, String outputFile, | |
1324 Map<String, dynamic> optionsFromFile) { | |
1325 var args = [ | |
1326 "--dart-sdk", | |
1327 "$buildDir/dart-sdk", | |
1328 "--library-root", | |
1329 new Path(inputFile).directoryPath.toString(), | |
1330 "-o", | |
1331 outputFile, | |
1332 inputFile | |
1333 ]; | |
1334 | |
1335 // TODO(29923): This compiles everything imported by the test into the | |
1336 // same generated JS module, including other packages like expect, | |
1337 // stack_trace, etc. Those should be compiled as separate JS modules (by | |
1338 // build.py) and loaded dynamically by the test. | |
1339 | |
1340 return Command.compilation( | |
1341 Compiler.dartdevc.name, | |
1342 outputFile, | |
1343 configuration.compilerConfiguration.bootstrapDependencies(buildDir), | |
1344 compilerPath, | |
1345 args, | |
1346 environmentOverrides); | |
1347 } | |
1348 | |
1349 String get scriptType { | 1321 String get scriptType { |
1350 switch (configuration.compiler) { | 1322 switch (configuration.compiler) { |
1351 case Compiler.none: | 1323 case Compiler.none: |
1352 return 'application/dart'; | 1324 return 'application/dart'; |
1353 case Compiler.dart2js: | 1325 case Compiler.dart2js: |
1354 case Compiler.dart2analyzer: | 1326 case Compiler.dart2analyzer: |
1355 case Compiler.dartdevc: | 1327 case Compiler.dartdevc: |
1356 return 'text/javascript'; | 1328 return 'text/javascript'; |
1357 default: | 1329 default: |
1358 print('Non-web runtime, so no scriptType for: ' | 1330 print('Non-web runtime, so no scriptType for: ' |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 | 1758 |
1787 bool isTestFile(String filename) { | 1759 bool isTestFile(String filename) { |
1788 // NOTE: We exclude tests and patch files for now. | 1760 // NOTE: We exclude tests and patch files for now. |
1789 return filename.endsWith(".dart") && | 1761 return filename.endsWith(".dart") && |
1790 !filename.endsWith("_test.dart") && | 1762 !filename.endsWith("_test.dart") && |
1791 !filename.contains("_internal/js_runtime/lib"); | 1763 !filename.contains("_internal/js_runtime/lib"); |
1792 } | 1764 } |
1793 | 1765 |
1794 bool get listRecursively => true; | 1766 bool get listRecursively => true; |
1795 } | 1767 } |
OLD | NEW |