Skip to content

Commit

Permalink
Rename build-root to library-root
Browse files Browse the repository at this point in the history
First step on #557.  Will eliminate the deprecated flag once upstream
uses are switched over.

R=jmesserly@google.com

Review URL: https://codereview.chromium.org/2197243002 .
  • Loading branch information
vsmenon committed Aug 1, 2016
1 parent b2353d7 commit 437cca2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
20 changes: 10 additions & 10 deletions pkg/dev_compiler/lib/src/compiler/code_generator.dart
Expand Up @@ -130,7 +130,7 @@ class CodeGenerator extends GeneralizingAstVisitor

BuildUnit _buildUnit;

String _buildRoot;
String _libraryRoot;

bool _superAllowed = true;

Expand Down Expand Up @@ -168,9 +168,9 @@ class CodeGenerator extends GeneralizingAstVisitor
JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits,
List<String> errors) {
_buildUnit = unit;
_buildRoot = _buildUnit.buildRoot;
if (!_buildRoot.endsWith(separator)) {
_buildRoot = '$_buildRoot${separator}';
_libraryRoot = _buildUnit.libraryRoot;
if (!_libraryRoot.endsWith(separator)) {
_libraryRoot = '$_libraryRoot${separator}';
}

var jsTree = _emitModule(compilationUnits);
Expand Down Expand Up @@ -231,7 +231,7 @@ class CodeGenerator extends GeneralizingAstVisitor

var libraryTemp = _isDartRuntime(library)
? _runtimeLibVar
: new JS.TemporaryId(jsLibraryName(_buildRoot, library));
: new JS.TemporaryId(jsLibraryName(_libraryRoot, library));
_libraries[library] = libraryTemp;
items.add(new JS.ExportDeclaration(
js.call('const # = Object.create(null)', [libraryTemp])));
Expand Down Expand Up @@ -5189,7 +5189,7 @@ class CodeGenerator extends GeneralizingAstVisitor
// It's either one of the libraries in this module, or it's an import.
return _libraries[library] ??
_imports.putIfAbsent(library,
() => new JS.TemporaryId(jsLibraryName(_buildRoot, library)));
() => new JS.TemporaryId(jsLibraryName(_libraryRoot, library)));
}

JS.Node/*=T*/ annotate/*<T extends JS.Node>*/(
Expand Down Expand Up @@ -5315,7 +5315,7 @@ class CodeGenerator extends GeneralizingAstVisitor
/// Choose a canonical name from the library element.
/// This never uses the library's name (the identifier in the `library`
/// declaration) as it doesn't have any meaningful rules enforced.
String jsLibraryName(String buildRoot, LibraryElement library) {
String jsLibraryName(String libraryRoot, LibraryElement library) {
var uri = library.source.uri;
if (uri.scheme == 'dart') {
return uri.path;
Expand All @@ -5328,12 +5328,12 @@ String jsLibraryName(String buildRoot, LibraryElement library) {
// TODO(vsm): This is not unique if an escaped '/'appears in a filename.
// E.g., "foo/bar.dart" and "foo$47bar.dart" would collide.
qualifiedPath = uri.pathSegments.skip(1).join(separator);
} else if (uri.toFilePath().startsWith(buildRoot)) {
} else if (uri.toFilePath().startsWith(libraryRoot)) {
qualifiedPath =
uri.path.substring(buildRoot.length).replaceAll('/', separator);
uri.path.substring(libraryRoot.length).replaceAll('/', separator);
} else {
// We don't have a unique name.
throw 'Invalid build root. $buildRoot does not contain ${uri.toFilePath()}';
throw 'Invalid library root. $libraryRoot does not contain ${uri.toFilePath()}';
}
return pathToJSIdentifier(qualifiedPath);
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/dev_compiler/lib/src/compiler/command.dart
Expand Up @@ -26,9 +26,11 @@ class CompileCommand extends Command {
argParser.addOption('module-root',
help: 'Root module directory. '
'Generated module paths are relative to this root.');
argParser.addOption('build-root',
argParser.addOption('library-root',
help: 'Root of source files. '
'Generated library names are relative to this root.');
argParser.addOption('build-root',
help: 'Deprecated in favor of --library-root');
CompilerOptions.addArguments(argParser);
AnalyzerOptions.addArguments(argParser);
}
Expand All @@ -48,11 +50,12 @@ class CompileCommand extends Command {
' -o PATH/TO/OUTPUT_FILE.js');
}

var buildRoot = argResults['build-root'] as String;
if (buildRoot != null) {
buildRoot = path.absolute(buildRoot);
var libraryRoot = argResults['library-root'] as String;
libraryRoot ??= argResults['build-root'] as String;
if (libraryRoot != null) {
libraryRoot = path.absolute(libraryRoot);
} else {
buildRoot = Directory.current.path;
libraryRoot = Directory.current.path;
}
var moduleRoot = argResults['module-root'] as String;
String modulePath;
Expand All @@ -73,7 +76,7 @@ class CompileCommand extends Command {
usageException('Please pass at least one source file as an argument.');
}

var unit = new BuildUnit(modulePath, buildRoot, argResults.rest,
var unit = new BuildUnit(modulePath, libraryRoot, argResults.rest,
(source) => _moduleForLibrary(moduleRoot, source));

JSModuleFile module = compiler.compile(unit, _compilerOptions);
Expand Down
6 changes: 3 additions & 3 deletions pkg/dev_compiler/lib/src/compiler/compiler.dart
Expand Up @@ -292,8 +292,8 @@ class BuildUnit {
/// The name of this module.
final String name;

/// Build root. All library names are relative to this path/prefix.
final String buildRoot;
/// Library root. All library names are relative to this path/prefix.
final String libraryRoot;

/// The list of sources in this module.
///
Expand All @@ -308,7 +308,7 @@ class BuildUnit {
// build units.
final Func1<Source, String> libraryToModule;

BuildUnit(this.name, this.buildRoot, this.sources, this.libraryToModule);
BuildUnit(this.name, this.libraryRoot, this.sources, this.libraryToModule);
}

/// The output of Dart->JS compilation.
Expand Down

0 comments on commit 437cca2

Please sign in to comment.