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

Unified Diff: lib/src/compiler/command.dart

Issue 1960523002: Support module root (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/command.dart
diff --git a/lib/src/compiler/command.dart b/lib/src/compiler/command.dart
index 29264fbb82bf8baa78130b9b6964f75c20fa68e9..8a033a5251dc840e911932cc1e38b44baf69ab63 100644
--- a/lib/src/compiler/command.dart
+++ b/lib/src/compiler/command.dart
@@ -24,10 +24,12 @@ class CompileCommand extends Command {
CompileCommand({MessageHandler messageHandler})
: this.messageHandler = messageHandler ?? print {
argParser.addOption('out', abbr: 'o', help: 'Output file (required)');
+ argParser.addOption('module-root',
+ help: 'Root module directory. '
+ 'Generated module paths are relative to this root.');
argParser.addOption('build-root',
Jennifer Messerly 2016/05/06 17:15:18 in retrospect, this looks like it should be "libra
- help: '''
-Root of source files. Generated library names are relative to this root.
-''');
+ help: 'Root of source files. '
+ 'Generated library names are relative to this root.');
CompilerOptions.addArguments(argParser);
AnalyzerOptions.addArguments(argParser);
}
@@ -50,8 +52,23 @@ Root of source files. Generated library names are relative to this root.
} else {
buildRoot = Directory.current.path;
}
- var unit = new BuildUnit(path.basenameWithoutExtension(outPath), buildRoot,
- argResults.rest, _moduleForLibrary);
+ var moduleRoot = argResults['module-root'] as String;
+ String modulePath;
+ if (moduleRoot != null) {
+ moduleRoot = path.absolute(moduleRoot);
+ if (!path.isWithin(moduleRoot, outPath)) {
+ usageException('Output file $outPath must be within the module root '
+ 'directory $moduleRoot');
+ }
+ modulePath =
+ path.withoutExtension(path.relative(outPath, from: moduleRoot));
+ } else {
+ moduleRoot = path.dirname(outPath);
+ modulePath = path.basenameWithoutExtension(outPath);
+ }
+
+ var unit = new BuildUnit(modulePath, buildRoot, argResults.rest,
+ (source) => _moduleForLibrary(moduleRoot, source));
JSModuleFile module = compiler.compile(unit, compilerOptions);
module.errors.forEach(messageHandler);
@@ -71,9 +88,17 @@ Root of source files. Generated library names are relative to this root.
}
}
- String _moduleForLibrary(Source source) {
+ String _moduleForLibrary(String moduleRoot, Source source) {
if (source is InSummarySource) {
- return path.basenameWithoutExtension(source.summaryPath);
+ var summaryPath = source.summaryPath;
+ if (path.isWithin(moduleRoot, summaryPath)) {
+ return path
+ .withoutExtension(path.relative(summaryPath, from: moduleRoot));
+ }
+
+ throw usageException(
+ 'Imported file ${source.uri} is not within the module root '
+ 'directory $moduleRoot');
}
throw usageException(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698