Skip to content

Commit

Permalink
fixes #276, path manipulation issues on windows. Also fixes server mode
Browse files Browse the repository at this point in the history
R=leafp@google.com

Review URL: https://codereview.chromium.org/1270993002 .
  • Loading branch information
John Messerly committed Aug 4, 2015
1 parent b393e12 commit 2535238
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
14 changes: 11 additions & 3 deletions pkg/dev_compiler/bin/devc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ library dev_compiler.bin.devc;

import 'dart:io';

import 'package:dev_compiler/src/compiler.dart' show validateOptions, compile;
import 'package:dev_compiler/src/compiler.dart'
show validateOptions, compile, setupLogger;
import 'package:dev_compiler/src/options.dart';
import 'package:dev_compiler/src/server/server.dart' show DevServer;

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

bool success = await compile(options);
exit(success ? 0 : 1);
setupLogger(options.logLevel, print);

if (options.serverMode) {
new DevServer(options).start();
} else {
var success = compile(options);
exit(success ? 0 : 1);
}
}
2 changes: 1 addition & 1 deletion pkg/dev_compiler/bin/devrun.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ main(List<String> args) async {
}
var runner = new V8Runner(options);

if (!await compile(options)) exit(1);
if (!compile(options)) exit(1);

var files = await listOutputFiles(options);
var startStatement = 'dart_library.start("${getMainModuleName(options)}");';
Expand Down
19 changes: 6 additions & 13 deletions pkg/dev_compiler/lib/src/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import 'codegen/html_codegen.dart' as html_codegen;
import 'codegen/js_codegen.dart';
import 'info.dart'
show AnalyzerMessage, CheckerResults, LibraryInfo, LibraryUnit;
import 'server/server.dart' show DevServer;
import 'options.dart';
import 'report.dart';

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

Future<bool> compile(CompilerOptions options) async {
setupLogger(options.logLevel, print);

if (options.serverMode) {
return new DevServer(options).start();
} else {
var context = createAnalysisContextWithSources(
options.strongOptions, options.sourceOptions);
var reporter = createErrorReporter(context, options);
// Note: run returns a bool, turned into a future since this function is async.
return new BatchCompiler(context, options, reporter: reporter).run();
}
bool compile(CompilerOptions options) {
assert(!options.serverMode);
var context = createAnalysisContextWithSources(
options.strongOptions, options.sourceOptions);
var reporter = createErrorReporter(context, options);
return new BatchCompiler(context, options, reporter: reporter).run();
}

class BatchCompiler extends AbstractCompiler {
Expand Down
3 changes: 1 addition & 2 deletions pkg/dev_compiler/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser()
/// works when running devc from it's sources or from a snapshot that is
/// activated via `pub global activate`.
String _computeRuntimeDir() {
var scriptUri = Platform.script;
var scriptPath = scriptUri.path;
var scriptPath = path.fromUri(Platform.script);
var file = path.basename(scriptPath);
var dir = path.dirname(scriptPath);
var lastdir = path.basename(dir);
Expand Down
15 changes: 9 additions & 6 deletions pkg/dev_compiler/lib/src/server/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class DevServer {
? SourceResolverOptions.implicitHtmlFile
: entryPath;

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

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

UriResolver _createImplicitEntryResolver(String entryPath) {
var entry = path.absolute(SourceResolverOptions.implicitHtmlFile);
var src = path.absolute(entryPath);
var entry = path.toUri(path.absolute(SourceResolverOptions.implicitHtmlFile));
var src = path.toUri(path.absolute(entryPath));
var provider = new MemoryResourceProvider();
provider.newFile(
entry, '<body><script type="application/dart" src="$src"></script>');
entry.path, '<body><script type="application/dart" src="$src"></script>');
return new _ExistingSourceUriResolver(new ResourceUriResolver(provider));
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/dev_compiler/tool/patch_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import 'package:path/path.dart' as path;

void main(List<String> argv) {
if (argv.length < 2) {
var self = path.relative(Platform.script.path);
var toolDir = path.relative(path.dirname(Platform.script.path));
var self = path.relative(path.fromUri(Platform.script));
var toolDir = path.relative(path.dirname(path.fromUri(Platform.script)));

var inputExample = path.join(toolDir, 'input_sdk');
var outExample = path.relative(
Expand Down

0 comments on commit 2535238

Please sign in to comment.