Skip to content

Commit

Permalink
fix #606, allow specifying the summary file extension
Browse files Browse the repository at this point in the history
R=paulberry@google.com

Review URL: https://codereview.chromium.org/2176763002 .
  • Loading branch information
John Messerly committed Jul 22, 2016
1 parent c1e97b4 commit c3ee6dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
21 changes: 13 additions & 8 deletions pkg/dev_compiler/lib/src/compiler/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand All @@ -87,17 +89,20 @@ 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);
}
}

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(
Expand Down
7 changes: 7 additions & 0 deletions pkg/dev_compiler/lib/src/compiler/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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'],
Expand All @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion pkg/dev_compiler/test/worker/worker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(() {
Expand All @@ -122,6 +122,7 @@ main() {
var result = Process.runSync('dart', [
'bin/dartdevc.dart',
'compile',
'--summary-extension=api.ds',
'--no-source-map',
'-o',
greetingJS.path,
Expand All @@ -138,6 +139,7 @@ main() {
'compile',
'--no-source-map',
'--no-summarize',
'--summary-extension=api.ds',
'-s',
greetingSummary.path,
'-o',
Expand Down

0 comments on commit c3ee6dc

Please # to comment.