Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: pkg/dev_compiler/web/web_command.dart

Issue 2598593003: support --options flag and other analysis options flags in DDC (Closed)
Patch Set: merge Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/dev_compiler/test/options/options_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 @JS() 4 @JS()
5 library dev_compiler.web.web_command; 5 library dev_compiler.web.web_command;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:html' show HttpRequest; 9 import 'dart:html' show HttpRequest;
10 10
11 import 'package:analyzer/dart/element/element.dart' 11 import 'package:analyzer/dart/element/element.dart'
12 show 12 show
13 LibraryElement, 13 LibraryElement,
14 ImportElement, 14 ImportElement,
15 ShowElementCombinator, 15 ShowElementCombinator,
16 HideElementCombinator; 16 HideElementCombinator;
17 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver; 17 import 'package:analyzer/file_system/file_system.dart' show ResourceUriResolver;
18 import 'package:analyzer/file_system/memory_file_system.dart' 18 import 'package:analyzer/file_system/memory_file_system.dart'
19 show MemoryResourceProvider; 19 show MemoryResourceProvider;
20 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; 20 import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
21 import 'package:analyzer/src/generated/source.dart' show DartUriResolver;
22 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; 21 import 'package:analyzer/src/summary/idl.dart' show PackageBundle;
23 import 'package:analyzer/src/summary/package_bundle_reader.dart' 22 import 'package:analyzer/src/summary/package_bundle_reader.dart'
24 show 23 show
25 SummaryDataStore, 24 SummaryDataStore,
26 InSummaryUriResolver, 25 InSummaryUriResolver,
27 InputPackagesResultProvider, 26 InputPackagesResultProvider,
28 InSummarySource; 27 InSummarySource;
29 import 'package:analyzer/src/dart/resolver/scope.dart' show Scope; 28 import 'package:analyzer/src/dart/resolver/scope.dart' show Scope;
30 import 'package:analyzer/src/summary/summary_sdk.dart' show SummaryBasedDartSdk;
31 29
32 import 'package:args/command_runner.dart'; 30 import 'package:args/command_runner.dart';
33 31
34 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions; 32 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions;
35 import 'package:dev_compiler/src/compiler/compiler.dart' 33 import 'package:dev_compiler/src/compiler/compiler.dart'
36 show BuildUnit, CompilerOptions, JSModuleFile, ModuleCompiler; 34 show BuildUnit, CompilerOptions, JSModuleFile, ModuleCompiler;
37 35
38 import 'package:dev_compiler/src/compiler/module_builder.dart'; 36 import 'package:dev_compiler/src/compiler/module_builder.dart';
39 import 'package:js/js.dart'; 37 import 'package:js/js.dart';
40 import 'package:path/path.dart' as path; 38 import 'package:path/path.dart' as path;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 86
89 var compileFn = setUpCompile(sdkBytes, summaryBytes, summaryUrls); 87 var compileFn = setUpCompile(sdkBytes, summaryBytes, summaryUrls);
90 onCompileReady(compileFn); 88 onCompileReady(compileFn);
91 }).catchError((error) => onError('Summaries failed to load: $error')); 89 }).catchError((error) => onError('Summaries failed to load: $error'));
92 }).catchError( 90 }).catchError(
93 (error) => onError('Dart sdk summaries failed to load: $error')); 91 (error) => onError('Dart sdk summaries failed to load: $error'));
94 } 92 }
95 93
96 CompileModule setUpCompile(List<int> sdkBytes, List<List<int>> summaryBytes, 94 CompileModule setUpCompile(List<int> sdkBytes, List<List<int>> summaryBytes,
97 List<String> summaryUrls) { 95 List<String> summaryUrls) {
98 var resourceProvider = new MemoryResourceProvider(); 96 var dartSdkSummaryPath = '/dart-sdk/lib/_internal/web_sdk.sum';
97
98 var resourceProvider = new MemoryResourceProvider()
99 ..newFileWithBytes(dartSdkSummaryPath, sdkBytes);
100
99 var resourceUriResolver = new ResourceUriResolver(resourceProvider); 101 var resourceUriResolver = new ResourceUriResolver(resourceProvider);
100 102
101 var packageBundle = new PackageBundle.fromBuffer(sdkBytes);
102 var webDartSdk = new SummaryBasedDartSdk.fromBundle(
103 true, packageBundle, resourceProvider);
104 var sdkResolver = new DartUriResolver(webDartSdk);
105
106 var summaryDataStore = new SummaryDataStore([]); 103 var summaryDataStore = new SummaryDataStore([]);
107 for (var i = 0; i < summaryBytes.length; i++) { 104 for (var i = 0; i < summaryBytes.length; i++) {
108 var bytes = summaryBytes[i]; 105 var bytes = summaryBytes[i];
109 var url = summaryUrls[i]; 106 var url = summaryUrls[i];
110 var summaryBundle = new PackageBundle.fromBuffer(bytes); 107 var summaryBundle = new PackageBundle.fromBuffer(bytes);
111 summaryDataStore.addBundle(url, summaryBundle); 108 summaryDataStore.addBundle(url, summaryBundle);
112 } 109 }
113 var summaryResolver = 110 var summaryResolver =
114 new InSummaryUriResolver(resourceProvider, summaryDataStore); 111 new InSummaryUriResolver(resourceProvider, summaryDataStore);
115 112
116 var fileResolvers = [summaryResolver, resourceUriResolver]; 113 var fileResolvers = [summaryResolver, resourceUriResolver];
117 114
118 var compiler = new ModuleCompiler( 115 var compiler = new ModuleCompiler(
119 new AnalyzerOptions.basic(dartSdkPath: '/dart-sdk'), 116 new AnalyzerOptions.basic(
120 sdkResolver: sdkResolver, 117 dartSdkPath: '/dart-sdk', dartSdkSummaryPath: dartSdkSummaryPath),
118 analysisRoot: '/web-compile-root',
121 fileResolvers: fileResolvers, 119 fileResolvers: fileResolvers,
122 resourceProvider: resourceProvider); 120 resourceProvider: resourceProvider);
123 121
124 var context = compiler.context as AnalysisContextImpl; 122 var context = compiler.context as AnalysisContextImpl;
125 context.resultProvider = 123 context.resultProvider =
126 new InputPackagesResultProvider(compiler.context, summaryDataStore); 124 new InputPackagesResultProvider(compiler.context, summaryDataStore);
127 125
128 var compilerOptions = new CompilerOptions.fromArguments(argResults); 126 var compilerOptions = new CompilerOptions.fromArguments(argResults);
129 127
130 CompileModule compileFn = (String imports, String body, String libraryName, 128 CompileModule compileFn = (String imports, String body, String libraryName,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (source is InSummarySource) { 216 if (source is InSummarySource) {
219 return source.summaryPath.substring(1).replaceAll('.api.ds', ''); 217 return source.summaryPath.substring(1).replaceAll('.api.ds', '');
220 } 218 }
221 return source.toString().substring(1).replaceAll('.dart', ''); 219 return source.toString().substring(1).replaceAll('.dart', '');
222 } 220 }
223 221
224 /// Thrown when the input source code has errors. 222 /// Thrown when the input source code has errors.
225 class CompileErrorException implements Exception { 223 class CompileErrorException implements Exception {
226 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; 224 toString() => '\nPlease fix all errors before compiling (warnings are okay).';
227 } 225 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/test/options/options_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698