Skip to content

Commit

Permalink
Revert "Support Package Resolution Configuration files."
Browse files Browse the repository at this point in the history
This reverts commit 36c29d0.

BUG=

Review URL: https://codereview.chromium.org//1165943005
  • Loading branch information
harryterkelsen committed Jun 4, 2015
1 parent 36c29d0 commit fcd407b
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 142 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ vars = {
"oauth2_rev": "@1bff41f4d54505c36f2d1a001b83b8b745c452f5",
"observe_rev": "@eee2b8ec34236fa46982575fbccff84f61202ac6",
"observatory_pub_packages_rev": "@45565",
"package_config_tag": "@0.0.3+1",
"package_config_tag": "@0.0.2+4",
"path_rev": "@93b3e2aa1db0ac0c8bab9d341588d77acda60320",
"petitparser_rev" : "@37878",
"ply_rev": "@604b32590ffad5cbb82e4afef1d305512d06ae93",
Expand Down
17 changes: 3 additions & 14 deletions pkg/compiler/lib/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
library compiler;

import 'dart:async';
import 'package:package_config/packages.dart';
import 'src/apiimpl.dart';

// Unless explicitly allowed, passing [:null:] for any argument to the
Expand Down Expand Up @@ -59,19 +58,13 @@ typedef EventSink<String> CompilerOutputProvider(String name,
* [:null:]. If [uri] is not [:null:], neither are [begin] and
* [end]. [uri] indicates the compilation unit from where the
* diagnostic originates. [begin] and [end] are zero-based character
* offsets from the beginning of the compilation unit. [message] is the
* offsets from the beginning of the compilaton unit. [message] is the
* diagnostic message, and [kind] indicates indicates what kind of
* diagnostic it is.
*/
typedef void DiagnosticHandler(Uri uri, int begin, int end,
String message, Diagnostic kind);

/**
* Provides a package lookup mechanism in the case that no package root or
* package resolution configuration file are explicitly specified.
*/
typedef Future<Packages> PackagesDiscoveryProvider(Uri uri);

/// Information resulting from the compilation.
class CompilationResult {
/// `true` if the compilation succeeded, that is, compilation didn't fail due
Expand Down Expand Up @@ -110,9 +103,7 @@ Future<CompilationResult> compile(
DiagnosticHandler handler,
[List<String> options = const [],
CompilerOutputProvider outputProvider,
Map<String, dynamic> environment = const {},
Uri packageConfig,
PackagesDiscoveryProvider packagesDiscoveryProvider]) {
Map<String, dynamic> environment = const {}]) {
if (!libraryRoot.path.endsWith("/")) {
throw new ArgumentError("libraryRoot must end with a /");
}
Expand All @@ -127,9 +118,7 @@ Future<CompilationResult> compile(
libraryRoot,
packageRoot,
options,
environment,
packageConfig,
packagesDiscoveryProvider);
environment);
return compiler.run(script).then((bool success) {
return new CompilationResult(compiler, isSuccess: success);
});
Expand Down
91 changes: 22 additions & 69 deletions pkg/compiler/lib/src/apiimpl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
library leg_apiimpl;

import 'dart:async';
import 'dart:convert';

import '../compiler.dart' as api;
import 'dart2jslib.dart' as leg;
Expand All @@ -14,10 +13,6 @@ import 'elements/elements.dart' as elements;
import 'package:_internal/libraries.dart' hide LIBRARIES;
import 'package:_internal/libraries.dart' as library_info show LIBRARIES;
import 'io/source_file.dart';
import 'package:package_config/packages.dart';
import 'package:package_config/packages_file.dart' as pkgs;
import 'package:package_config/src/packages_impl.dart'
show NonFilePackagesDirectoryPackages, MapPackages;

const bool forceIncrementalSupport =
const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');
Expand All @@ -26,28 +21,22 @@ class Compiler extends leg.Compiler {
api.CompilerInputProvider provider;
api.DiagnosticHandler handler;
final Uri libraryRoot;
final Uri packageConfig;
final Uri packageRoot;
final api.PackagesDiscoveryProvider packagesDiscoveryProvider;
Packages packages;
List<String> options;
Map<String, dynamic> environment;
bool mockableLibraryUsed = false;
final Set<String> allowedLibraryCategories;

leg.GenericTask userHandlerTask;
leg.GenericTask userProviderTask;
leg.GenericTask userPackagesDiscoveryTask;

Compiler(this.provider,
api.CompilerOutputProvider outputProvider,
this.handler,
this.libraryRoot,
this.packageRoot,
List<String> options,
this.environment,
[this.packageConfig,
this.packagesDiscoveryProvider])
this.environment)
: this.options = options,
this.allowedLibraryCategories = getAllowedLibraryCategories(options),
super(
Expand Down Expand Up @@ -106,20 +95,17 @@ class Compiler extends leg.Compiler {
tasks.addAll([
userHandlerTask = new leg.GenericTask('Diagnostic handler', this),
userProviderTask = new leg.GenericTask('Input provider', this),
userPackagesDiscoveryTask =
new leg.GenericTask('Package discovery', this),
]);
if (libraryRoot == null) {
throw new ArgumentError("[libraryRoot] is null.");
}
if (!libraryRoot.path.endsWith("/")) {
throw new ArgumentError("[libraryRoot] must end with a /.");
}
if (packageRoot != null && packageConfig != null) {
throw new ArgumentError("Only one of [packageRoot] or [packageConfig] "
"may be given.");
if (packageRoot == null) {
throw new ArgumentError("[packageRoot] is null.");
}
if (packageRoot != null && !packageRoot.path.endsWith("/")) {
if (!packageRoot.path.endsWith("/")) {
throw new ArgumentError("[packageRoot] must end with a /.");
}
if (!analyzeOnly) {
Expand Down Expand Up @@ -173,7 +159,8 @@ class Compiler extends leg.Compiler {

// TODO(johnniwinther): Merge better with [translateDartUri] when
// [scanBuiltinLibrary] is removed.
String lookupLibraryPath(LibraryInfo info) {
String lookupLibraryPath(String dartLibraryName) {
LibraryInfo info = lookupLibraryInfo(dartLibraryName);
if (info == null) return null;
if (!info.isDart2jsLibrary) return null;
if (!allowedLibraryCategories.contains(info.category)) return null;
Expand Down Expand Up @@ -297,7 +284,7 @@ class Compiler extends leg.Compiler {
Uri translateDartUri(elements.LibraryElement importingLibrary,
Uri resolvedUri, tree.Node node) {
LibraryInfo libraryInfo = lookupLibraryInfo(resolvedUri.path);
String path = lookupLibraryPath(libraryInfo);
String path = lookupLibraryPath(resolvedUri.path);
if (libraryInfo != null &&
libraryInfo.category == "Internal") {
bool allowInternalLibraryAccess = false;
Expand Down Expand Up @@ -345,49 +332,25 @@ class Compiler extends leg.Compiler {
}

Uri translatePackageUri(leg.Spannable node, Uri uri) {
return packages.resolve(uri);
}

Future setupPackages(Uri uri) async {
if (packageRoot != null) {
// Use "non-file" packages because the file version requires a [Directory]
// and we can't depend on 'dart:io' classes.
packages = new NonFilePackagesDirectoryPackages(packageRoot);
} else if (packageConfig != null) {
var packageConfigContents = await provider(packageConfig);
if (packageConfigContents is String) {
packageConfigContents = UTF8.encode(packageConfigContents);
}
packages =
new MapPackages(pkgs.parse(packageConfigContents, packageConfig));
} else {
if (packagesDiscoveryProvider == null) {
packages = Packages.noPackages;
} else {
packages = await callUserPackagesDiscovery(uri);
}
}
return packageRoot.resolve(uri.path);
}

Future<bool> run(Uri uri) async {
Future<bool> run(Uri uri) {
log('Allowed library categories: $allowedLibraryCategories');

await setupPackages(uri);
assert(packages != null);

bool success = await super.run(uri);
int cumulated = 0;
for (final task in tasks) {
int elapsed = task.timing;
if (elapsed != 0) {
cumulated += elapsed;
log('${task.name} took ${elapsed}msec');
return super.run(uri).then((bool success) {
int cumulated = 0;
for (final task in tasks) {
int elapsed = task.timing;
if (elapsed != 0) {
cumulated += elapsed;
log('${task.name} took ${elapsed}msec');
}
}
}
int total = totalCompileTime.elapsedMilliseconds;
log('Total compile-time ${total}msec;'
' unaccounted ${total - cumulated}msec');
return success;
int total = totalCompileTime.elapsedMilliseconds;
log('Total compile-time ${total}msec;'
' unaccounted ${total - cumulated}msec');
return success;
});
}

void reportDiagnostic(leg.Spannable node,
Expand Down Expand Up @@ -436,16 +399,6 @@ class Compiler extends leg.Compiler {
}
}

Future<Packages> callUserPackagesDiscovery(Uri uri) {
try {
return userPackagesDiscoveryTask.measure(
() => packagesDiscoveryProvider(uri));
} catch (ex, s) {
diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s);
rethrow;
}
}

void diagnoseCrashInUserCode(String message, exception, stackTrace) {
hasCrashed = true;
print('$message: ${tryToString(exception)}');
Expand Down
28 changes: 9 additions & 19 deletions pkg/compiler/lib/src/dart2js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'util/uri_extras.dart';
import 'util/util.dart' show stackTraceFilePrefix;
import 'util/command_line.dart';
import 'package:_internal/libraries.dart';
import 'package:package_config/discovery.dart' show findPackages;

const String LIBRARY_ROOT = '../../../../../sdk';
const String OUTPUT_LANGUAGE_DART = 'Dart';
Expand Down Expand Up @@ -106,7 +105,6 @@ Future<api.CompilationResult> compile(List<String> argv) {
Uri libraryRoot = currentDirectory;
Uri out = currentDirectory.resolve('out.js');
Uri sourceMapOut = currentDirectory.resolve('out.js.map');
Uri packageConfig = null;
Uri packageRoot = null;
List<String> options = new List<String>();
bool explicitOut = false;
Expand Down Expand Up @@ -142,10 +140,6 @@ Future<api.CompilationResult> compile(List<String> argv) {
packageRoot = currentDirectory.resolve(extractPath(argument));
}

setPackageConfig(String argument) {
packageConfig = currentDirectory.resolve(extractPath(argument));
}

setOutput(Iterator<String> arguments) {
optionsImplyCompilation.add(arguments.current);
String path;
Expand Down Expand Up @@ -335,7 +329,6 @@ Future<api.CompilationResult> compile(List<String> argv) {
(_) => setTrustPrimitives(
'--trust-primitives')),
new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true),
new OptionHandler('--packages=.+', setPackageConfig),
new OptionHandler('--package-root=.+|-p.+', setPackageRoot),
new OptionHandler('--analyze-all', setAnalyzeAll),
new OptionHandler('--analyze-only', setAnalyzeOnly),
Expand Down Expand Up @@ -410,8 +403,9 @@ Future<api.CompilationResult> compile(List<String> argv) {
"checked mode.");
}

if (packageRoot != null && packageConfig != null) {
helpAndFail("Cannot specify both '--package-root' and '--packages.");
Uri uri = currentDirectory.resolve(arguments[0]);
if (packageRoot == null) {
packageRoot = uri.resolve('./packages/');
}

if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) {
Expand All @@ -437,6 +431,8 @@ Future<api.CompilationResult> compile(List<String> argv) {
"combination with the '--output-type=dart' option.");
}

diagnosticHandler.info('Package root is $packageRoot');

options.add('--out=$out');
options.add('--source-map=$sourceMapOut');

Expand Down Expand Up @@ -471,10 +467,9 @@ Future<api.CompilationResult> compile(List<String> argv) {
return result;
}

Uri uri = currentDirectory.resolve(arguments[0]);
return compileFunc(uri, libraryRoot, packageRoot, inputProvider,
diagnosticHandler, options, outputProvider, environment,
packageConfig, findPackages)
return compileFunc(uri, libraryRoot, packageRoot,
inputProvider, diagnosticHandler,
options, outputProvider, environment)
.then(compilationDone);
}

Expand Down Expand Up @@ -556,12 +551,7 @@ Supported options:
Display version information.
-p<path>, --package-root=<path>
Where to find packages, that is, "package:..." imports. This option cannot
be used with --packages.
--packages=<path>
Path to the package resolution configuration file, which supplies a mapping
of package names to paths. This option cannot be used with --package-root.
Where to find packages, that is, "package:..." imports.
--analyze-all
Analyze all code. Without this option, the compiler only analyzes
Expand Down
11 changes: 3 additions & 8 deletions pkg/compiler/lib/src/mirrors/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ Future<MirrorSystem> analyze(List<Uri> libraries,
Uri packageRoot,
api.CompilerInputProvider inputProvider,
api.DiagnosticHandler diagnosticHandler,
[List<String> options = const <String>[],
Uri packageConfig,
api.PackagesDiscoveryProvider findPackages]) {
[List<String> options = const <String>[]]) {
if (!libraryRoot.path.endsWith("/")) {
throw new ArgumentError("libraryRoot must end with a /");
}
Expand Down Expand Up @@ -56,12 +54,9 @@ Future<MirrorSystem> analyze(List<Uri> libraries,
Compiler compiler = new apiimpl.Compiler(inputProvider,
null,
internalDiagnosticHandler,
libraryRoot,
packageRoot,
libraryRoot, packageRoot,
options,
const {},
packageConfig,
findPackages);
const {});
compiler.librariesToAnalyzeWhenRun = libraries;
return compiler.run(null).then((bool success) {
if (success && !compilationFailed) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/dart2js_incremental/lib/caching_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ Future<Compiler> reuseCompiler(
libraryRoot,
packageRoot,
options,
environment,
null,
null);
environment);
JavaScriptBackend backend = compiler.backend;

// Much like a scout, an incremental compiler is always prepared. For
Expand Down
3 changes: 1 addition & 2 deletions tests/compiler/dart2js/bad_output_io_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class CollectingFormattingDiagnosticHandler
}

testOutputProvider(script, libraryRoot, packageRoot, inputProvider, handler,
[options, outputProvider, environment, packageConfig,
findPackages]) {
[options, outputProvider, environment]) {
diagnosticHandler = new CollectingFormattingDiagnosticHandler();
outputProvider("/non/existing/directory/should/fail/file", "js");
}
Expand Down
10 changes: 2 additions & 8 deletions tests/compiler/dart2js/exit_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ class TestCompiler extends apiimpl.Compiler {
Uri packageRoot,
List<String> options,
Map<String, dynamic> environment,
Uri packageConfig,
api.PackagesDiscoveryProvider findPackages,
String this.testMarker,
String this.testType,
Function this.onTest)
: super(inputProvider, outputProvider, handler, libraryRoot,
packageRoot, options, environment, packageConfig, findPackages) {
packageRoot, options, environment) {
scanner = new TestScanner(this);
resolver = new TestResolver(this, backend.constantCompilerTask);
test('Compiler');
Expand Down Expand Up @@ -158,9 +156,7 @@ Future testExitCode(
api.DiagnosticHandler handler,
[List<String> options = const [],
api.CompilerOutputProvider outputProvider,
Map<String, dynamic> environment = const {},
Uri packageConfig,
api.PackagesDiscoveryProvider findPackages]) {
Map<String, dynamic> environment = const {}]) {
libraryRoot = Platform.script.resolve('../../../sdk/');
outputProvider = NullSink.outputProvider;
// Use this to silence the test when debugging:
Expand All @@ -172,8 +168,6 @@ Future testExitCode(
packageRoot,
options,
environment,
packageConfig,
findPackages,
marker,
type,
onTest);
Expand Down
Loading

0 comments on commit fcd407b

Please sign in to comment.