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

Side by Side Diff: lib/src/options.dart

Issue 1235503010: fixes #219, able to compile multiple entry points (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 4
5 /// Set of flags and options passed to the compiler 5 /// Set of flags and options passed to the compiler
6 library dev_compiler.src.options; 6 library dev_compiler.src.options;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
(...skipping 14 matching lines...) Expand all
25 25
26 /// Package root when resolving 'package:' urls the standard way. 26 /// Package root when resolving 'package:' urls the standard way.
27 final String packageRoot; 27 final String packageRoot;
28 28
29 /// List of paths used for the multi-package resolver. 29 /// List of paths used for the multi-package resolver.
30 final List<String> packagePaths; 30 final List<String> packagePaths;
31 31
32 /// List of additional non-Dart resources to resolve and serve. 32 /// List of additional non-Dart resources to resolve and serve.
33 final List<String> resources; 33 final List<String> resources;
34 34
35 /// File where to start compilation from.
36 // TODO(jmesserly): this is used to configure SourceFactory resolvers only
37 // when [useImplicitHtml] is set. Probably useImplicitHtml should be factored
38 // out into ServerOptions or something along those lines.
39 final String entryPointFile;
40
41 // True if the resolver should implicitly provide an html entry point. 35 // True if the resolver should implicitly provide an html entry point.
42 final bool useImplicitHtml; 36 final bool useImplicitHtml;
43 static const String implicitHtmlFile = 'index.html'; 37 static const String implicitHtmlFile = 'index.html';
44 38
45 /// Whether to use a mock-sdk during compilation. 39 /// Whether to use a mock-sdk during compilation.
46 final bool useMockSdk; 40 final bool useMockSdk;
47 41
48 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't 42 /// Path to the dart-sdk. Null if `useMockSdk` is true or if the path couldn't
49 /// be determined 43 /// be determined
50 final String dartSdkPath; 44 final String dartSdkPath;
51 45
52 const SourceResolverOptions({this.useMockSdk: false, this.dartSdkPath, 46 const SourceResolverOptions({this.useMockSdk: false, this.dartSdkPath,
53 this.useMultiPackage: false, this.customUrlMappings: const {}, 47 this.useMultiPackage: false, this.customUrlMappings: const {},
54 this.packageRoot: 'packages/', this.packagePaths: const <String>[], 48 this.packageRoot: 'packages/', this.packagePaths: const <String>[],
55 this.resources: const <String>[], this.entryPointFile: null, 49 this.resources: const <String>[], this.useImplicitHtml: false});
56 this.useImplicitHtml: false});
57 } 50 }
58 51
59 // TODO(jmesserly): refactor all codegen options here. 52 // TODO(jmesserly): refactor all codegen options here.
60 class CodegenOptions { 53 class CodegenOptions {
61 /// Whether to emit the source map files. 54 /// Whether to emit the source map files.
62 final bool emitSourceMaps; 55 final bool emitSourceMaps;
63 56
64 /// Whether to force compilation of code with static errors. 57 /// Whether to force compilation of code with static errors.
65 final bool forceCompile; 58 final bool forceCompile;
66 59
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 final int port; 102 final int port;
110 103
111 /// Host name or address for HTTP server when [serverMode] is on. 104 /// Host name or address for HTTP server when [serverMode] is on.
112 final String host; 105 final String host;
113 106
114 /// Location for runtime files, such as `dart_runtime.js`. By default this is 107 /// Location for runtime files, such as `dart_runtime.js`. By default this is
115 /// inferred to be under `lib/runtime/` in the location of the `dev_compiler` 108 /// inferred to be under `lib/runtime/` in the location of the `dev_compiler`
116 /// package (if we can infer where that is located). 109 /// package (if we can infer where that is located).
117 final String runtimeDir; 110 final String runtimeDir;
118 111
112 final List<String> inputs;
113
119 CompilerOptions({this.strongOptions: const StrongModeOptions(), 114 CompilerOptions({this.strongOptions: const StrongModeOptions(),
120 this.sourceOptions: const SourceResolverOptions(), 115 this.sourceOptions: const SourceResolverOptions(),
121 this.codegenOptions: const CodegenOptions(), this.checkSdk: false, 116 this.codegenOptions: const CodegenOptions(), this.checkSdk: false,
122 this.dumpInfo: false, this.dumpInfoFile, this.useColors: true, 117 this.dumpInfo: false, this.dumpInfoFile, this.useColors: true,
123 this.help: false, this.logLevel: Level.SEVERE, this.serverMode: false, 118 this.help: false, this.logLevel: Level.SEVERE, this.serverMode: false,
124 this.enableHashing: false, this.widget: true, this.host: 'localhost', 119 this.enableHashing: false, this.widget: true, this.host: 'localhost',
125 this.port: 8080, this.runtimeDir}); 120 this.port: 8080, this.runtimeDir, this.inputs});
126 } 121 }
127 122
128 /// Parses options from the command-line 123 /// Parses options from the command-line
129 CompilerOptions parseOptions(List<String> argv) { 124 CompilerOptions parseOptions(List<String> argv) {
130 ArgResults args = argParser.parse(argv); 125 ArgResults args = argParser.parse(argv);
131 bool showUsage = args['help']; 126 bool showUsage = args['help'];
132 127
133 var serverMode = args['server']; 128 var serverMode = args['server'];
134 var enableHashing = args['hashing']; 129 var enableHashing = args['hashing'];
135 if (enableHashing == null) { 130 if (enableHashing == null) {
(...skipping 26 matching lines...) Expand all
162 var customUrlMappings = <String, String>{}; 157 var customUrlMappings = <String, String>{};
163 for (var mapping in args['url-mapping']) { 158 for (var mapping in args['url-mapping']) {
164 var splitMapping = mapping.split(','); 159 var splitMapping = mapping.split(',');
165 if (splitMapping.length != 2) { 160 if (splitMapping.length != 2) {
166 showUsage = true; 161 showUsage = true;
167 continue; 162 continue;
168 } 163 }
169 customUrlMappings[splitMapping[0]] = splitMapping[1]; 164 customUrlMappings[splitMapping[0]] = splitMapping[1];
170 } 165 }
171 166
172 var entryPointFile = args.rest.length == 0 ? null : args.rest.first; 167 if (serverMode && args.rest.length != 1) showUsage = true;
173 168
174 return new CompilerOptions( 169 return new CompilerOptions(
175 codegenOptions: new CodegenOptions( 170 codegenOptions: new CodegenOptions(
176 emitSourceMaps: args['source-maps'], 171 emitSourceMaps: args['source-maps'],
177 forceCompile: args['force-compile'] || serverMode, 172 forceCompile: args['force-compile'] || serverMode,
178 outputDir: outputDir), 173 outputDir: outputDir),
179 sourceOptions: new SourceResolverOptions( 174 sourceOptions: new SourceResolverOptions(
180 useMockSdk: args['mock-sdk'], 175 useMockSdk: args['mock-sdk'],
181 dartSdkPath: sdkPath, 176 dartSdkPath: sdkPath,
182 entryPointFile: entryPointFile, 177 useImplicitHtml: serverMode &&
183 useImplicitHtml: serverMode && entryPointFile.endsWith('.dart'), 178 args.rest.length == 1 &&
179 args.rest[0].endsWith('.dart'),
184 customUrlMappings: customUrlMappings, 180 customUrlMappings: customUrlMappings,
185 useMultiPackage: args['use-multi-package'], 181 useMultiPackage: args['use-multi-package'],
186 packageRoot: args['package-root'], 182 packageRoot: args['package-root'],
187 packagePaths: args['package-paths'].split(','), 183 packagePaths: args['package-paths'].split(','),
188 resources: args['resources'] 184 resources: args['resources']
189 .split(',') 185 .split(',')
190 .where((s) => s.isNotEmpty) 186 .where((s) => s.isNotEmpty)
191 .toList()), 187 .toList()),
192 strongOptions: new StrongModeOptions.fromArguments(args), 188 strongOptions: new StrongModeOptions.fromArguments(args),
193 checkSdk: args['sdk-check'], 189 checkSdk: args['sdk-check'],
194 dumpInfo: dumpInfo, 190 dumpInfo: dumpInfo,
195 dumpInfoFile: args['dump-info-file'], 191 dumpInfoFile: args['dump-info-file'],
196 useColors: useColors, 192 useColors: useColors,
197 help: showUsage, 193 help: showUsage,
198 logLevel: logLevel, 194 logLevel: logLevel,
199 serverMode: serverMode, 195 serverMode: serverMode,
200 enableHashing: enableHashing, 196 enableHashing: enableHashing,
201 widget: args['widget'], 197 widget: args['widget'],
202 host: args['host'], 198 host: args['host'],
203 port: int.parse(args['port']), 199 port: int.parse(args['port']),
204 runtimeDir: runtimeDir); 200 runtimeDir: runtimeDir,
201 inputs: args.rest);
205 } 202 }
206 203
207 final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser() 204 final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser()
208 ..addFlag('sdk-check', 205 ..addFlag('sdk-check',
209 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) 206 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false)
210 ..addFlag('mock-sdk', 207 ..addFlag('mock-sdk',
211 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false) 208 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false)
212 209
213 // input/output options 210 // input/output options
214 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null) 211 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // The pub-cache directory is two levels up, but we verify that the layout 301 // The pub-cache directory is two levels up, but we verify that the layout
305 // looks correct. 302 // looks correct.
306 if (path.basename(dir) != 'dev_compiler') return null; 303 if (path.basename(dir) != 'dev_compiler') return null;
307 dir = path.dirname(dir); 304 dir = path.dirname(dir);
308 if (path.basename(dir) != 'global_packages') return null; 305 if (path.basename(dir) != 'global_packages') return null;
309 dir = path.dirname(dir); 306 dir = path.dirname(dir);
310 return path.join(dir, cacheDir, 'lib', 'runtime'); 307 return path.join(dir, cacheDir, 'lib', 'runtime');
311 } 308 }
312 return null; 309 return null;
313 } 310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698