Skip to content

Commit 2535238

Browse files
author
John Messerly
committed
fixes #276, path manipulation issues on windows. Also fixes server mode
[email protected] Review URL: https://codereview.chromium.org/1270993002 .
1 parent b393e12 commit 2535238

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

pkg/dev_compiler/bin/devc.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ library dev_compiler.bin.devc;
99

1010
import 'dart:io';
1111

12-
import 'package:dev_compiler/src/compiler.dart' show validateOptions, compile;
12+
import 'package:dev_compiler/src/compiler.dart'
13+
show validateOptions, compile, setupLogger;
1314
import 'package:dev_compiler/src/options.dart';
15+
import 'package:dev_compiler/src/server/server.dart' show DevServer;
1416

1517
void _showUsageAndExit() {
1618
print('usage: dartdevc [<options>] <file.dart>...\n');
@@ -24,6 +26,12 @@ main(List<String> args) async {
2426
var options = validateOptions(args);
2527
if (options == null || options.help) _showUsageAndExit();
2628

27-
bool success = await compile(options);
28-
exit(success ? 0 : 1);
29+
setupLogger(options.logLevel, print);
30+
31+
if (options.serverMode) {
32+
new DevServer(options).start();
33+
} else {
34+
var success = compile(options);
35+
exit(success ? 0 : 1);
36+
}
2937
}

pkg/dev_compiler/bin/devrun.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ main(List<String> args) async {
3939
}
4040
var runner = new V8Runner(options);
4141

42-
if (!await compile(options)) exit(1);
42+
if (!compile(options)) exit(1);
4343

4444
var files = await listOutputFiles(options);
4545
var startStatement = 'dart_library.start("${getMainModuleName(options)}");';

pkg/dev_compiler/lib/src/compiler.dart

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import 'codegen/html_codegen.dart' as html_codegen;
3434
import 'codegen/js_codegen.dart';
3535
import 'info.dart'
3636
show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit;
37-
import 'server/server.dart' show DevServer;
3837
import 'options.dart';
3938
import 'report.dart';
4039

@@ -64,18 +63,12 @@ CompilerOptions validateOptions(List<String> args, {bool forceOutDir: false}) {
6463
return options;
6564
}
6665

67-
Future<bool> compile(CompilerOptions options) async {
68-
setupLogger(options.logLevel, print);
69-
70-
if (options.serverMode) {
71-
return new DevServer(options).start();
72-
} else {
73-
var context = createAnalysisContextWithSources(
74-
options.strongOptions, options.sourceOptions);
75-
var reporter = createErrorReporter(context, options);
76-
// Note: run returns a bool, turned into a future since this function is async.
77-
return new BatchCompiler(context, options, reporter: reporter).run();
78-
}
66+
bool compile(CompilerOptions options) {
67+
assert(!options.serverMode);
68+
var context = createAnalysisContextWithSources(
69+
options.strongOptions, options.sourceOptions);
70+
var reporter = createErrorReporter(context, options);
71+
return new BatchCompiler(context, options, reporter: reporter).run();
7972
}
8073

8174
class BatchCompiler extends AbstractCompiler {

pkg/dev_compiler/lib/src/options.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser()
311311
/// works when running devc from it's sources or from a snapshot that is
312312
/// activated via `pub global activate`.
313313
String _computeRuntimeDir() {
314-
var scriptUri = Platform.script;
315-
var scriptPath = scriptUri.path;
314+
var scriptPath = path.fromUri(Platform.script);
316315
var file = path.basename(scriptPath);
317316
var dir = path.dirname(scriptPath);
318317
var lastdir = path.basename(dir);

pkg/dev_compiler/lib/src/server/server.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class DevServer {
246246
? SourceResolverOptions.implicitHtmlFile
247247
: entryPath;
248248

249-
Future<bool> start() async {
249+
Future start() async {
250250
// Create output directory if needed. shelf_static will fail otherwise.
251251
var out = new Directory(outDir);
252252
if (!await out.exists()) await out.create(recursive: true);
@@ -257,8 +257,11 @@ class DevServer {
257257
defaultDocument: _entryPath));
258258
await shelf.serve(handler, host, port);
259259
print('Serving $_entryPath at http://$host:$port/');
260-
CheckerResults results = compiler.run();
261-
return !results.failure;
260+
// Give the compiler a head start. This is not needed for correctness,
261+
// but will likely speed up the first load. Regardless of whether compile
262+
// succeeds we should still start the server.
263+
compiler.run();
264+
// Server has started so this future will complete.
262265
}
263266

264267
shelf.Handler rebuildAndCache(shelf.Handler handler) => (request) {
@@ -285,11 +288,11 @@ class DevServer {
285288
}
286289

287290
UriResolver _createImplicitEntryResolver(String entryPath) {
288-
var entry = path.absolute(SourceResolverOptions.implicitHtmlFile);
289-
var src = path.absolute(entryPath);
291+
var entry = path.toUri(path.absolute(SourceResolverOptions.implicitHtmlFile));
292+
var src = path.toUri(path.absolute(entryPath));
290293
var provider = new MemoryResourceProvider();
291294
provider.newFile(
292-
entry, '<body><script type="application/dart" src="$src"></script>');
295+
entry.path, '<body><script type="application/dart" src="$src"></script>');
293296
return new _ExistingSourceUriResolver(new ResourceUriResolver(provider));
294297
}
295298

pkg/dev_compiler/tool/patch_sdk.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import 'package:path/path.dart' as path;
1515

1616
void main(List<String> argv) {
1717
if (argv.length < 2) {
18-
var self = path.relative(Platform.script.path);
19-
var toolDir = path.relative(path.dirname(Platform.script.path));
18+
var self = path.relative(path.fromUri(Platform.script));
19+
var toolDir = path.relative(path.dirname(path.fromUri(Platform.script)));
2020

2121
var inputExample = path.join(toolDir, 'input_sdk');
2222
var outExample = path.relative(

0 commit comments

Comments
 (0)