| 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 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 for (var name in otherResources) { | 875 for (var name in otherResources) { |
| 876 var namePath = new Path(name); | 876 var namePath = new Path(name); |
| 877 var fromPath = info.filePath.directoryPath.join(namePath); | 877 var fromPath = info.filePath.directoryPath.join(namePath); |
| 878 new File('$tempDir/$name').parent.createSync(recursive: true); | 878 new File('$tempDir/$name').parent.createSync(recursive: true); |
| 879 new File(fromPath.toNativePath()).copySync('$tempDir/$name'); | 879 new File(fromPath.toNativePath()).copySync('$tempDir/$name'); |
| 880 } | 880 } |
| 881 } | 881 } |
| 882 | 882 |
| 883 CommandArtifact compilationArtifact = | 883 CommandArtifact compilationArtifact = |
| 884 compilerConfiguration.computeCompilationArtifact( | 884 compilerConfiguration.computeCompilationArtifact( |
| 885 buildDir, tempDir, compileTimeArguments, environmentOverrides); | 885 tempDir, compileTimeArguments, environmentOverrides); |
| 886 if (!configuration.skipCompilation) { | 886 if (!configuration.skipCompilation) { |
| 887 commands.addAll(compilationArtifact.commands); | 887 commands.addAll(compilationArtifact.commands); |
| 888 } | 888 } |
| 889 | 889 |
| 890 if (expectCompileError(info) && compilerConfiguration.hasCompiler) { | 890 if (expectCompileError(info) && compilerConfiguration.hasCompiler) { |
| 891 // Do not attempt to run the compiled result. A compilation | 891 // Do not attempt to run the compiled result. A compilation |
| 892 // error should be reported by the compilation command. | 892 // error should be reported by the compilation command. |
| 893 return commands; | 893 return commands; |
| 894 } | 894 } |
| 895 | 895 |
| 896 List<String> runtimeArguments = | 896 List<String> runtimeArguments = |
| 897 compilerConfiguration.computeRuntimeArguments( | 897 compilerConfiguration.computeRuntimeArguments( |
| 898 configuration.runtimeConfiguration, | 898 configuration.runtimeConfiguration, |
| 899 buildDir, | |
| 900 info, | 899 info, |
| 901 vmOptions, | 900 vmOptions, |
| 902 sharedOptions, | 901 sharedOptions, |
| 903 args, | 902 args, |
| 904 compilationArtifact); | 903 compilationArtifact); |
| 905 | 904 |
| 906 return commands | 905 return commands |
| 907 ..addAll(configuration.runtimeConfiguration.computeRuntimeCommands( | 906 ..addAll(configuration.runtimeConfiguration.computeRuntimeCommands( |
| 908 this, compilationArtifact, runtimeArguments, environmentOverrides)); | 907 this, compilationArtifact, runtimeArguments, environmentOverrides)); |
| 909 } | 908 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 scriptPath = compiledDartWrapperFilename; | 1082 scriptPath = compiledDartWrapperFilename; |
| 1084 } | 1083 } |
| 1085 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); | 1084 scriptPath = _createUrlPathFromFile(new Path(scriptPath)); |
| 1086 | 1085 |
| 1087 if (configuration.compiler != Compiler.dartdevc) { | 1086 if (configuration.compiler != Compiler.dartdevc) { |
| 1088 content = getHtmlContents(fileName, scriptType, scriptPath); | 1087 content = getHtmlContents(fileName, scriptType, scriptPath); |
| 1089 } else { | 1088 } else { |
| 1090 var jsDir = new Path(compilationTempDir) | 1089 var jsDir = new Path(compilationTempDir) |
| 1091 .relativeTo(TestUtils.dartDir) | 1090 .relativeTo(TestUtils.dartDir) |
| 1092 .toString(); | 1091 .toString(); |
| 1093 content = dartdevcHtml(nameNoExt, jsDir); | 1092 content = dartdevcHtml(nameNoExt, jsDir, buildDir); |
| 1094 } | 1093 } |
| 1095 | 1094 |
| 1096 new File(htmlPath).writeAsStringSync(content); | 1095 new File(htmlPath).writeAsStringSync(content); |
| 1097 } | 1096 } |
| 1098 | 1097 |
| 1099 // Construct the command(s) that compile all the inputs needed by the | 1098 // Construct the command(s) that compile all the inputs needed by the |
| 1100 // browser test. For running Dart in DRT, this will be noop commands. | 1099 // browser test. For running Dart in DRT, this will be noop commands. |
| 1101 var commands = <Command>[]; | 1100 var commands = <Command>[]; |
| 1102 | 1101 |
| 1103 switch (configuration.compiler) { | 1102 switch (configuration.compiler) { |
| 1104 case Compiler.dart2js: | 1103 case Compiler.dart2js: |
| 1105 commands.add(_dart2jsCompileCommand(dartWrapperFilename, | 1104 commands.add(_dart2jsCompileCommand(dartWrapperFilename, |
| 1106 compiledDartWrapperFilename, tempDir, optionsFromFile)); | 1105 compiledDartWrapperFilename, tempDir, optionsFromFile)); |
| 1107 break; | 1106 break; |
| 1108 | 1107 |
| 1109 case Compiler.dartdevc: | 1108 case Compiler.dartdevc: |
| 1110 commands.add(_dartdevcCompileCommand(dartWrapperFilename, | 1109 commands.add(configuration.compilerConfiguration.createCommand( |
| 1111 '$compilationTempDir/$nameNoExt.js', optionsFromFile)); | 1110 dartWrapperFilename, '$compilationTempDir/$nameNoExt.js')); |
| 1112 break; | 1111 break; |
| 1113 | 1112 |
| 1114 case Compiler.none: | 1113 case Compiler.none: |
| 1115 break; | 1114 break; |
| 1116 | 1115 |
| 1117 default: | 1116 default: |
| 1118 assert(false); | 1117 assert(false); |
| 1119 } | 1118 } |
| 1120 | 1119 |
| 1121 // Some tests require compiling multiple input scripts. | 1120 // Some tests require compiling multiple input scripts. |
| 1122 for (var name in optionsFromFile['otherScripts'] as List<String>) { | 1121 for (var name in optionsFromFile['otherScripts'] as List<String>) { |
| 1123 var namePath = new Path(name); | 1122 var namePath = new Path(name); |
| 1124 var fromPath = filePath.directoryPath.join(namePath); | 1123 var fromPath = filePath.directoryPath.join(namePath); |
| 1125 | 1124 |
| 1126 switch (configuration.compiler) { | 1125 switch (configuration.compiler) { |
| 1127 case Compiler.dart2js: | 1126 case Compiler.dart2js: |
| 1128 commands.add(_dart2jsCompileCommand(fromPath.toNativePath(), | 1127 commands.add(_dart2jsCompileCommand(fromPath.toNativePath(), |
| 1129 '$tempDir/${namePath.filename}.js', tempDir, optionsFromFile)); | 1128 '$tempDir/${namePath.filename}.js', tempDir, optionsFromFile)); |
| 1130 break; | 1129 break; |
| 1131 | 1130 |
| 1132 case Compiler.dartdevc: | 1131 case Compiler.dartdevc: |
| 1133 commands.add(_dartdevcCompileCommand(fromPath.toNativePath(), | 1132 commands.add(configuration.compilerConfiguration.createCommand( |
| 1134 '$tempDir/${namePath.filename}.js', optionsFromFile)); | 1133 fromPath.toNativePath(), '$tempDir/${namePath.filename}.js')); |
| 1135 break; | 1134 break; |
| 1136 | 1135 |
| 1137 default: | 1136 default: |
| 1138 assert(configuration.compiler == Compiler.none); | 1137 assert(configuration.compiler == Compiler.none); |
| 1139 } | 1138 } |
| 1140 | 1139 |
| 1141 if (configuration.compiler == Compiler.none) { | 1140 if (configuration.compiler == Compiler.none) { |
| 1142 // For the tests that require multiple input scripts but are not | 1141 // For the tests that require multiple input scripts but are not |
| 1143 // compiled, move the input scripts over with the script so they can | 1142 // compiled, move the input scripts over with the script so they can |
| 1144 // be accessed. | 1143 // be accessed. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 args.add(inputFile); | 1315 args.add(inputFile); |
| 1317 | 1316 |
| 1318 var options = optionsFromFile['sharedOptions'] as List<String>; | 1317 var options = optionsFromFile['sharedOptions'] as List<String>; |
| 1319 if (options != null) args.addAll(options); | 1318 if (options != null) args.addAll(options); |
| 1320 | 1319 |
| 1321 return Command.compilation(Compiler.dart2js.name, outputFile, | 1320 return Command.compilation(Compiler.dart2js.name, outputFile, |
| 1322 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides, | 1321 dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides, |
| 1323 alwaysCompile: !useSdk); | 1322 alwaysCompile: !useSdk); |
| 1324 } | 1323 } |
| 1325 | 1324 |
| 1326 /// Creates a [Command] to compile a single .dart file using dartdevc. | |
| 1327 Command _dartdevcCompileCommand(String inputFile, String outputFile, | |
| 1328 Map<String, dynamic> optionsFromFile) { | |
| 1329 var args = [ | |
| 1330 "--dart-sdk", | |
| 1331 "$buildDir/dart-sdk", | |
| 1332 "--library-root", | |
| 1333 new Path(inputFile).directoryPath.toString(), | |
| 1334 "-o", | |
| 1335 outputFile, | |
| 1336 inputFile | |
| 1337 ]; | |
| 1338 | |
| 1339 // TODO(29923): This compiles everything imported by the test into the | |
| 1340 // same generated JS module, including other packages like expect, | |
| 1341 // stack_trace, etc. Those should be compiled as separate JS modules (by | |
| 1342 // build.py) and loaded dynamically by the test. | |
| 1343 | |
| 1344 return Command.compilation( | |
| 1345 Compiler.dartdevc.name, | |
| 1346 outputFile, | |
| 1347 configuration.compilerConfiguration.bootstrapDependencies(buildDir), | |
| 1348 compilerPath, | |
| 1349 args, | |
| 1350 environmentOverrides); | |
| 1351 } | |
| 1352 | |
| 1353 String get scriptType { | 1325 String get scriptType { |
| 1354 switch (configuration.compiler) { | 1326 switch (configuration.compiler) { |
| 1355 case Compiler.none: | 1327 case Compiler.none: |
| 1356 return 'application/dart'; | 1328 return 'application/dart'; |
| 1357 case Compiler.dart2js: | 1329 case Compiler.dart2js: |
| 1358 case Compiler.dart2analyzer: | 1330 case Compiler.dart2analyzer: |
| 1359 case Compiler.dartdevc: | 1331 case Compiler.dartdevc: |
| 1360 return 'text/javascript'; | 1332 return 'text/javascript'; |
| 1361 default: | 1333 default: |
| 1362 print('Non-web runtime, so no scriptType for: ' | 1334 print('Non-web runtime, so no scriptType for: ' |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 | 1762 |
| 1791 bool isTestFile(String filename) { | 1763 bool isTestFile(String filename) { |
| 1792 // NOTE: We exclude tests and patch files for now. | 1764 // NOTE: We exclude tests and patch files for now. |
| 1793 return filename.endsWith(".dart") && | 1765 return filename.endsWith(".dart") && |
| 1794 !filename.endsWith("_test.dart") && | 1766 !filename.endsWith("_test.dart") && |
| 1795 !filename.contains("_internal/js_runtime/lib"); | 1767 !filename.contains("_internal/js_runtime/lib"); |
| 1796 } | 1768 } |
| 1797 | 1769 |
| 1798 bool get listRecursively => true; | 1770 bool get listRecursively => true; |
| 1799 } | 1771 } |
| OLD | NEW |