OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file | 5 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file |
6 // when closure_conversion is merged with master. | 6 // when closure_conversion is merged with master. |
7 | 7 |
8 library kernel.testing.kernel_chain; | 8 library kernel.testing.kernel_chain; |
9 | 9 |
10 import 'dart:async' show | 10 import 'dart:async' show |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 StdioProcess, | 70 StdioProcess, |
71 Step, | 71 Step, |
72 TestDescription; | 72 TestDescription; |
73 | 73 |
74 import 'package:kernel/ast.dart' show | 74 import 'package:kernel/ast.dart' show |
75 Program; | 75 Program; |
76 | 76 |
77 import 'package:package_config/discovery.dart' show | 77 import 'package:package_config/discovery.dart' show |
78 loadPackagesFile; | 78 loadPackagesFile; |
79 | 79 |
| 80 import '../environment_variable.dart' show |
| 81 EnvironmentVariable; |
| 82 |
80 typedef Future<TestContext> TestContextConstructor( | 83 typedef Future<TestContext> TestContextConstructor( |
81 Chain suite, Map<String, String> environment, String sdk, Uri vm, | 84 Chain suite, Map<String, String> environment, Uri sdk, Uri vm, |
82 Uri packages, bool strongMode, DartSdk dartSdk, bool updateExpectations); | 85 Uri packages, bool strongMode, DartSdk dartSdk, bool updateExpectations); |
83 | 86 |
84 Future<bool> fileExists(Uri base, String path) async { | 87 Future<bool> fileExists(Uri base, String path) async { |
85 return await new File.fromUri(base.resolve(path)).exists(); | 88 return await new File.fromUri(base.resolve(path)).exists(); |
86 } | 89 } |
87 | 90 |
| 91 final EnvironmentVariable testConfigVariable = new EnvironmentVariable( |
| 92 "DART_CONFIGURATION", |
| 93 "It should be something like 'ReleaseX64', depending on which" |
| 94 " configuration you're testing."); |
| 95 |
| 96 Future<Uri> computePatchedSdk() async { |
| 97 String config = await testConfigVariable.value; |
| 98 String path; |
| 99 switch (Platform.operatingSystem) { |
| 100 case "linux": |
| 101 path = "out/$config/patched_sdk"; |
| 102 break; |
| 103 |
| 104 case "macos": |
| 105 path = "xcodebuild/$config/patched_sdk"; |
| 106 break; |
| 107 |
| 108 case "windows": |
| 109 path = "build/$config/patched_sdk"; |
| 110 break; |
| 111 |
| 112 default: |
| 113 throw "Unsupported operating system: '${Platform.operatingSystem}'."; |
| 114 } |
| 115 Uri sdk = Uri.base.resolve("$path/"); |
| 116 const String asyncDart = "lib/async/async.dart"; |
| 117 if (!await fileExists(sdk, asyncDart)) { |
| 118 throw "Couldn't find '$asyncDart' in '$sdk'."; |
| 119 } |
| 120 const String asyncSources = "lib/async/async_sources.gypi"; |
| 121 if (await fileExists(sdk, asyncSources)) { |
| 122 throw "Found '$asyncSources' in '$sdk', so it isn't a patched SDK."; |
| 123 } |
| 124 return sdk; |
| 125 } |
| 126 |
| 127 Uri computeDartVm(Uri patchedSdk) { |
| 128 return patchedSdk.resolve(Platform.isWindows ? "../dart.exe" : "../dart"); |
| 129 } |
| 130 |
88 abstract class TestContext extends ChainContext { | 131 abstract class TestContext extends ChainContext { |
89 final Uri vm; | 132 final Uri vm; |
90 | 133 |
91 final Uri packages; | 134 final Uri packages; |
92 | 135 |
93 final DartOptions options; | 136 final DartOptions options; |
94 | 137 |
95 final DartSdk dartSdk; | 138 final DartSdk dartSdk; |
96 | 139 |
97 TestContext(String sdk, this.vm, Uri packages, bool strongMode, this.dartSdk) | 140 TestContext(Uri sdk, this.vm, Uri packages, bool strongMode, this.dartSdk) |
98 : packages = packages, | 141 : packages = packages, |
99 options = new DartOptions(strongMode: strongMode, sdk: sdk, | 142 options = new DartOptions(strongMode: strongMode, sdk: sdk.toFilePath(), |
100 packagePath: packages.toFilePath()); | 143 packagePath: packages.toFilePath()); |
101 | 144 |
102 Future<DartLoader> createLoader() async { | 145 Future<DartLoader> createLoader() async { |
103 Repository repository = new Repository(); | 146 Repository repository = new Repository(); |
104 return new DartLoader(repository, options, await loadPackagesFile(packages), | 147 return new DartLoader(repository, options, await loadPackagesFile(packages), |
105 ignoreRedirectingFactories: false, dartSdk: dartSdk); | 148 ignoreRedirectingFactories: false, dartSdk: dartSdk); |
106 } | 149 } |
107 | 150 |
108 static Future<TestContext> create(Chain suite, | 151 static Future<TestContext> create(Chain suite, |
109 Map<String, String> environment, | 152 Map<String, String> environment, |
110 TestContextConstructor constructor) async { | 153 TestContextConstructor constructor) async { |
111 const String suggestion = | 154 Uri sdk = await computePatchedSdk(); |
112 "Try checking the value of environment variable 'DART_AOT_SDK', " | 155 Uri vm = computeDartVm(sdk); |
113 "it should point to a patched SDK."; | |
114 String sdk = await getEnvironmentVariable( | |
115 "DART_AOT_SDK", Environment.directory, | |
116 "Please define environment variable 'DART_AOT_SDK' to point to a " | |
117 "patched SDK.", | |
118 (String n) => "Couldn't locate '$n'. $suggestion"); | |
119 Uri sdkUri = Uri.base.resolve("$sdk/"); | |
120 const String asyncDart = "lib/async/async.dart"; | |
121 if (!await fileExists(sdkUri, asyncDart)) { | |
122 throw "Couldn't find '$asyncDart' in '$sdk'. $suggestion"; | |
123 } | |
124 const String asyncSources = "lib/async/async_sources.gypi"; | |
125 if (await fileExists(sdkUri, asyncSources)) { | |
126 throw "Found '$asyncSources' in '$sdk', so it isn't a patched SDK. " | |
127 "$suggestion"; | |
128 } | |
129 | |
130 String vmPath = await getEnvironmentVariable( | |
131 "DART_AOT_VM", Environment.file, | |
132 "Please define environment variable 'DART_AOT_VM' to point to a " | |
133 "Dart VM that reads .dill files.", | |
134 (String n) => "Couldn't locate '$n'. Please check the value of " | |
135 "environment variable 'DART_AOT_VM', it should point to a " | |
136 "Dart VM that reads .dill files."); | |
137 Uri vm = Uri.base.resolve(vmPath); | |
138 | |
139 Uri packages = Uri.base.resolve(".packages"); | 156 Uri packages = Uri.base.resolve(".packages"); |
140 bool strongMode = false; | 157 bool strongMode = false; |
141 bool updateExpectations = environment["updateExpectations"] != "false"; | 158 bool updateExpectations = environment["updateExpectations"] != "false"; |
142 return constructor(suite, environment, sdk, vm, packages, strongMode, | 159 return constructor(suite, environment, sdk, vm, packages, strongMode, |
143 createDartSdk(sdk, strongMode: strongMode), updateExpectations); | 160 createDartSdk(sdk.toFilePath(), strongMode: strongMode), |
| 161 updateExpectations); |
144 } | 162 } |
145 } | 163 } |
146 | 164 |
147 enum Environment { | |
148 directory, | |
149 file, | |
150 } | |
151 | |
152 Future<String> getEnvironmentVariable( | |
153 String name, Environment kind, String undefined, notFound(String n)) async { | |
154 String result = Platform.environment[name]; | |
155 if (result == null) { | |
156 throw undefined; | |
157 } | |
158 switch (kind) { | |
159 case Environment.directory: | |
160 if (!await new Directory(result).exists()) throw notFound(result); | |
161 break; | |
162 | |
163 case Environment.file: | |
164 if (!await new File(result).exists()) throw notFound(result); | |
165 break; | |
166 } | |
167 return result; | |
168 } | |
169 | |
170 class Kernel extends Step<TestDescription, Program, TestContext> { | 165 class Kernel extends Step<TestDescription, Program, TestContext> { |
171 const Kernel(); | 166 const Kernel(); |
172 | 167 |
173 String get name => "kernel"; | 168 String get name => "kernel"; |
174 | 169 |
175 Future<Result<Program>> run( | 170 Future<Result<Program>> run( |
176 TestDescription description, TestContext testContext) async { | 171 TestDescription description, TestContext testContext) async { |
177 try { | 172 try { |
178 DartLoader loader = await testContext.createLoader(); | 173 DartLoader loader = await testContext.createLoader(); |
179 Target target = getTarget( | 174 Target target = getTarget( |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 381 |
387 Future openWrite(Uri uri, f(IOSink sink)) async { | 382 Future openWrite(Uri uri, f(IOSink sink)) async { |
388 IOSink sink = new File.fromUri(uri).openWrite(); | 383 IOSink sink = new File.fromUri(uri).openWrite(); |
389 try { | 384 try { |
390 await f(sink); | 385 await f(sink); |
391 } finally { | 386 } finally { |
392 await sink.close(); | 387 await sink.close(); |
393 } | 388 } |
394 print("Wrote $uri"); | 389 print("Wrote $uri"); |
395 } | 390 } |
OLD | NEW |