| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // Test generating and running a simple precompiled snapshot of this script. | |
| 6 | |
| 7 import 'dart:io'; | |
| 8 | |
| 9 main(List args) { | |
| 10 if (args.length > 0 && args[0] == "--hello") { | |
| 11 print("Hello"); | |
| 12 return; | |
| 13 } | |
| 14 | |
| 15 var cc, cc_flags, shared, libname; | |
| 16 if (Platform.isLinux) { | |
| 17 cc = 'gcc'; | |
| 18 shared = '-shared'; | |
| 19 libname = 'libprecompiled.so'; | |
| 20 } else if (Platform.isMacOS) { | |
| 21 cc = 'clang'; | |
| 22 shared = '-dynamiclib'; | |
| 23 libname = 'libprecompiled.dylib'; | |
| 24 } else { | |
| 25 print("Test only supports Linux and Mac"); | |
| 26 return; | |
| 27 } | |
| 28 | |
| 29 if (Platform.version.contains("x64")) { | |
| 30 cc_flags = "-m64"; | |
| 31 } else if (Platform.version.contains("simarm64")) { | |
| 32 cc_flags = "-m64"; | |
| 33 } else if (Platform.version.contains("simarm")) { | |
| 34 cc_flags = "-m32"; | |
| 35 } else if (Platform.version.contains("simmips")) { | |
| 36 cc_flags = "-m32"; | |
| 37 } else if (Platform.version.contains("arm")) { | |
| 38 cc_flags = ""; | |
| 39 } else if (Platform.version.contains("mips")) { | |
| 40 cc_flags = "-EL"; | |
| 41 } else { | |
| 42 print("Architecture not supported: ${Platform.version}"); | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 print("Creating precompiled snapshot..."); | |
| 47 var abs_package_root = Uri.parse(Platform.packageRoot).toFilePath(); | |
| 48 var dart_executable = | |
| 49 Directory.current.path + Platform.pathSeparator + Platform.executable; | |
| 50 Directory tmp; | |
| 51 try { | |
| 52 tmp = Directory.current.createTempSync("temp_precompilation_test"); | |
| 53 var exec = "${dart_executable}_bootstrap"; | |
| 54 var args = ["--package-root=$abs_package_root", | |
| 55 "--gen-precompiled-snapshot", | |
| 56 "${abs_package_root}compiler/src/dart2js.dart"]; | |
| 57 print("$exec ${args.join(' ')}"); | |
| 58 var result = Process.runSync(exec, args, workingDirectory: tmp.path); | |
| 59 if (result.exitCode != 0) { | |
| 60 print(result.stdout); | |
| 61 print(result.stderr); | |
| 62 throw "Snapshot generation failed."; | |
| 63 } | |
| 64 | |
| 65 // Check if gcc is present, and skip test if it is not. | |
| 66 print("Creating shared library..."); | |
| 67 try { | |
| 68 result = Process.runSync( | |
| 69 cc, | |
| 70 ["--version"], | |
| 71 workingDirectory: tmp.path); | |
| 72 if (result.exitCode != 0) { | |
| 73 throw "$cc --version failed."; | |
| 74 } | |
| 75 } catch(e) { | |
| 76 print("Skipping test because $cc is not present: $e"); | |
| 77 return; | |
| 78 } | |
| 79 | |
| 80 result = Process.runSync( | |
| 81 cc, | |
| 82 [shared, cc_flags, "-nostartfiles", "-o", libname, "precompiled.S"], | |
| 83 workingDirectory: tmp.path); | |
| 84 if (result.exitCode != 0) { | |
| 85 print(result.stdout); | |
| 86 print(result.stderr); | |
| 87 throw "Shared library creation failed!"; | |
| 88 } | |
| 89 | |
| 90 print("Running test program..."); | |
| 91 var ld_library_path = new String.fromEnvironment("LD_LIBRARY_PATH"); | |
| 92 ld_library_path = "${ld_library_path}:${tmp.path}"; | |
| 93 exec = "${dart_executable}_precompiled_runtime"; | |
| 94 args = ["--run-precompiled-snapshot", "ignored_script", "--version"]; | |
| 95 print("LD_LIBRARY_PATH=$ld_library_path $exec ${args.join(' ')}"); | |
| 96 result = Process.runSync(exec, args, | |
| 97 workingDirectory: tmp.path, | |
| 98 environment: {"LD_LIBRARY_PATH": ld_library_path}); | |
| 99 if (result.exitCode != 0) { | |
| 100 print(result.stdout); | |
| 101 print(result.stderr); | |
| 102 throw "Precompiled binary failed."; | |
| 103 } | |
| 104 print(result.stdout); | |
| 105 if (!result.stdout.contains("Dart-to-JavaScript compiler")) { | |
| 106 throw "Precompiled binary output mismatch."; | |
| 107 } | |
| 108 } finally { | |
| 109 tmp?.deleteSync(recursive: true); | |
| 110 } | |
| 111 } | |
| OLD | NEW |