| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, 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 part of fletchc_incremental; | |
| 6 | |
| 7 /// Do not call this method directly. It will be made private. | |
| 8 // TODO(ahe): Make this method private. | |
| 9 Future<CompilerImpl> reuseCompiler( | |
| 10 {CompilerDiagnostics diagnosticHandler, | |
| 11 CompilerInput inputProvider, | |
| 12 CompilerOutput outputProvider, | |
| 13 List<String> options: const [], | |
| 14 CompilerImpl cachedCompiler, | |
| 15 Uri libraryRoot, | |
| 16 Uri nativesJson, | |
| 17 Uri packageConfig, | |
| 18 Uri fletchVm, | |
| 19 bool packagesAreImmutable: false, | |
| 20 Map<String, dynamic> environment, | |
| 21 ReuseLibrariesFunction reuseLibraries, | |
| 22 String platform, | |
| 23 Uri base, | |
| 24 IncrementalCompiler incrementalCompiler}) async { | |
| 25 UserTag oldTag = new UserTag('_reuseCompiler').makeCurrent(); | |
| 26 // if (libraryRoot == null) { | |
| 27 // throw 'Missing libraryRoot'; | |
| 28 // } | |
| 29 if (inputProvider == null) { | |
| 30 throw 'Missing inputProvider'; | |
| 31 } | |
| 32 if (inputProvider is SourceFileProvider && base != null) { | |
| 33 inputProvider.cwd = base; | |
| 34 } | |
| 35 if (diagnosticHandler == null) { | |
| 36 throw 'Missing diagnosticHandler'; | |
| 37 } | |
| 38 if (outputProvider == null) { | |
| 39 outputProvider = new OutputProvider(); | |
| 40 } | |
| 41 if (environment == null) { | |
| 42 environment = {}; | |
| 43 } | |
| 44 CompilerImpl compiler = cachedCompiler; | |
| 45 if (compiler == null || | |
| 46 (libraryRoot != null && compiler.libraryRoot != libraryRoot) || | |
| 47 !compiler.hasIncrementalSupport || | |
| 48 compiler.hasCrashed || | |
| 49 compiler.enqueuer.resolution.hasEnqueuedReflectiveElements || | |
| 50 compiler.deferredLoadTask.isProgramSplit) { | |
| 51 if (compiler != null && compiler.hasIncrementalSupport) { | |
| 52 if (compiler.hasCrashed) { | |
| 53 throw new IncrementalCompilationFailed( | |
| 54 "Unable to reuse compiler due to crash"); | |
| 55 } else if (compiler.enqueuer.resolution.hasEnqueuedReflectiveElements) { | |
| 56 throw new IncrementalCompilationFailed( | |
| 57 "Unable to reuse compiler due to dart:mirrors"); | |
| 58 } else if (compiler.deferredLoadTask.isProgramSplit) { | |
| 59 throw new IncrementalCompilationFailed( | |
| 60 "Unable to reuse compiler due to deferred loading"); | |
| 61 } else { | |
| 62 throw new IncrementalCompilationFailed( | |
| 63 "Unable to reuse compiler"); | |
| 64 } | |
| 65 } | |
| 66 oldTag.makeCurrent(); | |
| 67 FletchCompiler fletchCompiler = new FletchCompiler( | |
| 68 provider: inputProvider, | |
| 69 outputProvider: outputProvider, | |
| 70 handler: diagnosticHandler, | |
| 71 libraryRoot: libraryRoot, | |
| 72 nativesJson: nativesJson, | |
| 73 packageConfig: packageConfig, | |
| 74 fletchVm: fletchVm, | |
| 75 options: options, | |
| 76 environment: environment, | |
| 77 platform: platform, | |
| 78 incrementalCompiler: incrementalCompiler); | |
| 79 compiler = await fletchCompiler.backdoor.compilerImplementation; | |
| 80 return compiler; | |
| 81 } else { | |
| 82 for (final task in compiler.tasks) { | |
| 83 if (task.watch != null) { | |
| 84 task.watch.reset(); | |
| 85 } | |
| 86 } | |
| 87 compiler | |
| 88 ..userOutputProvider = outputProvider | |
| 89 ..provider = inputProvider | |
| 90 ..handler = diagnosticHandler | |
| 91 ..enqueuer.resolution.queueIsClosed = false | |
| 92 ..enqueuer.resolution.hasEnqueuedReflectiveElements = false | |
| 93 ..enqueuer.resolution.hasEnqueuedReflectiveStaticFields = false | |
| 94 ..enqueuer.codegen.queueIsClosed = false | |
| 95 ..enqueuer.codegen.hasEnqueuedReflectiveElements = false | |
| 96 ..enqueuer.codegen.hasEnqueuedReflectiveStaticFields = false | |
| 97 ..compilationFailed = false; | |
| 98 | |
| 99 if (reuseLibraries == null) { | |
| 100 reuseLibraries = (Iterable<LibraryElement> libraries) async { | |
| 101 return libraries.where((LibraryElement library) { | |
| 102 return library.isPlatformLibrary || | |
| 103 (packagesAreImmutable && library.isPackageLibrary); | |
| 104 }); | |
| 105 }; | |
| 106 } | |
| 107 return compiler.libraryLoader.resetLibraries(reuseLibraries).then((_) { | |
| 108 oldTag.makeCurrent(); | |
| 109 return compiler; | |
| 110 }); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 /// Helper class to collect sources. | |
| 115 class StringEventSink implements EventSink<String> { | |
| 116 List<String> data = <String>[]; | |
| 117 | |
| 118 final Function onClose; | |
| 119 | |
| 120 StringEventSink(this.onClose); | |
| 121 | |
| 122 void add(String event) { | |
| 123 if (data == null) throw 'StringEventSink is closed.'; | |
| 124 data.add(event); | |
| 125 } | |
| 126 | |
| 127 void addError(errorEvent, [StackTrace stackTrace]) { | |
| 128 throw 'addError($errorEvent, $stackTrace)'; | |
| 129 } | |
| 130 | |
| 131 void close() { | |
| 132 if (data != null) { | |
| 133 onClose(data.join()); | |
| 134 data = null; | |
| 135 } | |
| 136 } | |
| 137 } | |
| OLD | NEW |