| 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 library runtime.tools.kernel_service; | 4 library runtime.tools.kernel_service; |
| 5 | 5 |
| 6 // This is an interface to the Dart Kernel parser and Kernel binary generator. | 6 // This is an interface to the Dart Kernel parser and Kernel binary generator. |
| 7 // | 7 // |
| 8 // It is used by the kernel-isolate to load Dart source code and generate | 8 // It is used by the kernel-isolate to load Dart source code and generate |
| 9 // Kernel binary format. | 9 // Kernel binary format. |
| 10 // | 10 // |
| 11 // This is either invoked as the root script of the Kernel isolate when used | 11 // This is either invoked as the root script of the Kernel isolate when used |
| 12 // as a part of | 12 // as a part of |
| 13 // | 13 // |
| 14 // dart --dfe=runtime/tools/kernel-service.dart ... | 14 // dart --dfe=utils/kernel-service/kernel-service.dart ... |
| 15 // | 15 // |
| 16 // invocation or it is invoked as a standalone script to perform batch mode | 16 // invocation or it is invoked as a standalone script to perform batch mode |
| 17 // compilation requested via an HTTP interface | 17 // compilation requested via an HTTP interface |
| 18 // | 18 // |
| 19 // dart runtime/tools/kernel-service.dart --batch | 19 // dart utils/kernel-service/kernel-service.dart --batch |
| 20 // | 20 // |
| 21 // The port for the batch mode worker is controlled by DFE_WORKER_PORT | 21 // The port for the batch mode worker is controlled by DFE_WORKER_PORT |
| 22 // environment declarations (set by -DDFE_WORKER_PORT=... command line flag). | 22 // environment declarations (set by -DDFE_WORKER_PORT=... command line flag). |
| 23 // When not set (or set to 0) an ephemeral port returned by the OS is used | 23 // When not set (or set to 0) an ephemeral port returned by the OS is used |
| 24 // instead. | 24 // instead. |
| 25 // | 25 // |
| 26 // When this script is used as a Kernel isolate root script and DFE_WORKER_PORT | 26 // When this script is used as a Kernel isolate root script and DFE_WORKER_PORT |
| 27 // is set to non-zero value then Kernel isolate will forward all compilation | 27 // is set to non-zero value then Kernel isolate will forward all compilation |
| 28 // requests it receives to the batch worker on the given port. | 28 // requests it receives to the batch worker on the given port. |
| 29 // | 29 // |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 request.response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; | 305 request.response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; |
| 306 request.response.headers.contentType = ContentType.TEXT; | 306 request.response.headers.contentType = ContentType.TEXT; |
| 307 request.response.write(JSON.encode(result.toJson())); | 307 request.response.write(JSON.encode(result.toJson())); |
| 308 request.response.close(); | 308 request.response.close(); |
| 309 } | 309 } |
| 310 }); | 310 }); |
| 311 ProcessSignal.SIGTERM.watch().first.then((_) => server.close()); | 311 ProcessSignal.SIGTERM.watch().first.then((_) => server.close()); |
| 312 }); | 312 }); |
| 313 } | 313 } |
| 314 | 314 |
| 315 train(String scriptUri) { |
| 316 // TODO(28532): Enable on Windows. |
| 317 if (Platform.isWindows) return; |
| 318 |
| 319 var tag = 1; |
| 320 var responsePort = new RawReceivePort(); |
| 321 responsePort.handler = (response) { |
| 322 if (response[0] == tag) { |
| 323 // Success. |
| 324 responsePort.close(); |
| 325 } else if (response[0] == -tag) { |
| 326 // Compilation error. |
| 327 throw response[4]; |
| 328 } else { |
| 329 throw "Unexpected response: $response"; |
| 330 } |
| 331 }; |
| 332 var request = [tag, responsePort.sendPort, scriptUri]; |
| 333 _processLoadRequest(request); |
| 334 } |
| 335 |
| 315 main([args]) { | 336 main([args]) { |
| 316 if (args?.length == 1 && args[0] == '--batch') { | 337 if (args?.length == 1 && args[0] == '--batch') { |
| 317 startBatchServer(); | 338 startBatchServer(); |
| 339 } else if (args?.length == 2 && args[0] == '--train') { |
| 340 // This entry point is used when creating an app snapshot. The argument |
| 341 // provides a script to compile to warm-up generated code. |
| 342 train(args[1]); |
| 318 } else { | 343 } else { |
| 319 // Entry point for the Kernel isolate. | 344 // Entry point for the Kernel isolate. |
| 320 return new RawReceivePort()..handler = _processLoadRequest; | 345 return new RawReceivePort()..handler = _processLoadRequest; |
| 321 } | 346 } |
| 322 } | 347 } |
| 323 | 348 |
| 324 // This duplicates functionality from the Loader which we can't easily | 349 // This duplicates functionality from the Loader which we can't easily |
| 325 // access from here. | 350 // access from here. |
| 326 Uri _findPackagesFile(Uri base) async { | 351 Uri _findPackagesFile(Uri base) async { |
| 327 var dir = new File.fromUri(base).parent; | 352 var dir = new File.fromUri(base).parent; |
| 328 while (true) { | 353 while (true) { |
| 329 final packagesFile = dir.uri.resolve(".packages"); | 354 final packagesFile = dir.uri.resolve(".packages"); |
| 330 if (await new File.fromUri(packagesFile).exists()) { | 355 if (await new File.fromUri(packagesFile).exists()) { |
| 331 return packagesFile; | 356 return packagesFile; |
| 332 } | 357 } |
| 333 if (dir.parent.path == dir.path) { | 358 if (dir.parent.path == dir.path) { |
| 334 break; | 359 break; |
| 335 } | 360 } |
| 336 dir = dir.parent; | 361 dir = dir.parent; |
| 337 } | 362 } |
| 338 return null; | 363 return null; |
| 339 } | 364 } |
| OLD | NEW |