From c3ee6dc5ee35c2dfa6d622bbe3ae645e15987e22 Mon Sep 17 00:00:00 2001 From: John Messerly Date: Fri, 22 Jul 2016 11:39:35 -0700 Subject: [PATCH] fix #606, allow specifying the summary file extension R=paulberry@google.com Review URL: https://codereview.chromium.org/2176763002 . --- .../lib/src/compiler/command.dart | 21 ++++++++++++------- .../lib/src/compiler/compiler.dart | 7 +++++++ pkg/dev_compiler/test/worker/worker_test.dart | 4 +++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pkg/dev_compiler/lib/src/compiler/command.dart b/pkg/dev_compiler/lib/src/compiler/command.dart index d9c96a329eaf..cd498b7f3176 100644 --- a/pkg/dev_compiler/lib/src/compiler/command.dart +++ b/pkg/dev_compiler/lib/src/compiler/command.dart @@ -17,9 +17,8 @@ typedef void MessageHandler(Object message); /// The command for invoking the modular compiler. class CompileCommand extends Command { - get name => 'compile'; - get description => 'Compile a set of Dart files into a JavaScript module.'; final MessageHandler messageHandler; + CompilerOptions _compilerOptions; CompileCommand({MessageHandler messageHandler}) : this.messageHandler = messageHandler ?? print { @@ -34,11 +33,14 @@ class CompileCommand extends Command { AnalyzerOptions.addArguments(argParser); } + get name => 'compile'; + get description => 'Compile a set of Dart files into a JavaScript module.'; + @override void run() { var compiler = new ModuleCompiler(new AnalyzerOptions.fromArguments(argResults)); - var compilerOptions = new CompilerOptions.fromArguments(argResults); + _compilerOptions = new CompilerOptions.fromArguments(argResults); var outPath = argResults['out']; if (outPath == null) { @@ -74,7 +76,7 @@ class CompileCommand extends Command { var unit = new BuildUnit(modulePath, buildRoot, argResults.rest, (source) => _moduleForLibrary(moduleRoot, source)); - JSModuleFile module = compiler.compile(unit, compilerOptions); + JSModuleFile module = compiler.compile(unit, _compilerOptions); module.errors.forEach(messageHandler); if (!module.isValid) throw new CompileErrorException(); @@ -87,7 +89,8 @@ class CompileCommand extends Command { .writeAsStringSync(JSON.encode(module.placeSourceMap(mapPath))); } if (module.summaryBytes != null) { - var summaryPath = path.withoutExtension(outPath) + '.sum'; + var summaryPath = path.withoutExtension(outPath) + + '.${_compilerOptions.summaryExtension}'; new File(summaryPath).writeAsBytesSync(module.summaryBytes); } } @@ -95,9 +98,11 @@ class CompileCommand extends Command { String _moduleForLibrary(String moduleRoot, Source source) { if (source is InSummarySource) { var summaryPath = source.summaryPath; - if (path.isWithin(moduleRoot, summaryPath)) { - return path - .withoutExtension(path.relative(summaryPath, from: moduleRoot)); + var ext = '.${_compilerOptions.summaryExtension}'; + if (path.isWithin(moduleRoot, summaryPath) && summaryPath.endsWith(ext)) { + var buildUnitPath = + summaryPath.substring(0, summaryPath.length - ext.length); + return path.relative(buildUnitPath, from: moduleRoot); } throw usageException( diff --git a/pkg/dev_compiler/lib/src/compiler/compiler.dart b/pkg/dev_compiler/lib/src/compiler/compiler.dart index 8bc3b307cd6a..cac85b1b1f94 100644 --- a/pkg/dev_compiler/lib/src/compiler/compiler.dart +++ b/pkg/dev_compiler/lib/src/compiler/compiler.dart @@ -158,6 +158,9 @@ class CompilerOptions { /// This is required for a modular build process. final bool summarizeApi; + /// The file extension for summaries. + final String summaryExtension; + /// Whether to preserve metdata only accessible via mirrors final bool emitMetadata; @@ -205,6 +208,7 @@ class CompilerOptions { {this.sourceMap: true, this.sourceMapComment: true, this.summarizeApi: true, + this.summaryExtension: 'sum', this.unsafeForceCompile: false, this.emitMetadata: false, this.closure: false, @@ -220,6 +224,7 @@ class CompilerOptions { : sourceMap = args['source-map'], sourceMapComment = args['source-map-comment'], summarizeApi = args['summarize'], + summaryExtension = args['summary-extension'], unsafeForceCompile = args['unsafe-force-compile'], emitMetadata = args['emit-metadata'], closure = args['closure-experimental'], @@ -233,6 +238,8 @@ class CompilerOptions { static ArgParser addArguments(ArgParser parser) => parser ..addFlag('summarize', help: 'emit an API summary file', defaultsTo: true) + ..addOption('summary-extension', + help: 'file extension for Dart summary files', defaultsTo: 'sum') ..addFlag('source-map', help: 'emit source mapping', defaultsTo: true) ..addFlag('source-map-comment', help: 'adds a sourceMappingURL comment to the end of the JS,\n' diff --git a/pkg/dev_compiler/test/worker/worker_test.dart b/pkg/dev_compiler/test/worker/worker_test.dart index 04c5057a7731..6685acfda349 100644 --- a/pkg/dev_compiler/test/worker/worker_test.dart +++ b/pkg/dev_compiler/test/worker/worker_test.dart @@ -101,7 +101,7 @@ main() { final helloDart = new File('test/worker/hello.dart').absolute; final greetingJS = new File('test/worker/greeting.js').absolute; - final greetingSummary = new File('test/worker/greeting.sum').absolute; + final greetingSummary = new File('test/worker/greeting.api.ds').absolute; final helloJS = new File('test/worker/hello_world.js').absolute; setUp(() { @@ -122,6 +122,7 @@ main() { var result = Process.runSync('dart', [ 'bin/dartdevc.dart', 'compile', + '--summary-extension=api.ds', '--no-source-map', '-o', greetingJS.path, @@ -138,6 +139,7 @@ main() { 'compile', '--no-source-map', '--no-summarize', + '--summary-extension=api.ds', '-s', greetingSummary.path, '-o',