| Index: sdk/lib/_internal/pub/lib/src/dart.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/dart.dart b/sdk/lib/_internal/pub/lib/src/dart.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a4a3914535f2c817adb0aa590aecb7fbb0b075b0
|
| --- /dev/null
|
| +++ b/sdk/lib/_internal/pub/lib/src/dart.dart
|
| @@ -0,0 +1,70 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library dart;
|
| +
|
| +import 'dart:async';
|
| +import 'dart:io';
|
| +import 'dart:math' as math;
|
| +
|
| +import 'package:analyzer_experimental/analyzer.dart';
|
| +import 'package:pathos/path.dart' as path;
|
| +import '../../../compiler/compiler.dart' as api;
|
| +import '../../../compiler/implementation/mirrors/dart2js_mirror.dart' as dart2js
|
| + show analyze, Dart2JsMirrorSystem;
|
| +import '../../../compiler/implementation/mirrors/mirrors.dart'
|
| + show MirrorSystem;
|
| +import '../../../compiler/implementation/source_file_provider.dart'
|
| + show FormattingDiagnosticHandler, SourceFileProvider;
|
| +import '../../../compiler/implementation/filenames.dart'
|
| + show appendSlash;
|
| +
|
| +import 'io.dart';
|
| +import 'sdk.dart' as sdk;
|
| +import 'utils.dart';
|
| +
|
| +/// Returns [entrypoint] compiled to JavaScript (or to Dart if [toDart] is
|
| +/// true).
|
| +///
|
| +/// By default, the package root is assumed to be adjacent to [entrypoint], but
|
| +/// if [packageRoot] is passed that will be used instead.
|
| +Future<String> compile(String entrypoint, {String packageRoot,
|
| + bool toDart: false}) {
|
| + return new Future.sync(() {
|
| + var provider = new SourceFileProvider();
|
| + var options = <String>['--categories=Client,Server', '--minify'];
|
| + if (toDart) options.add('--output-type=dart');
|
| + if (packageRoot == null) {
|
| + packageRoot = path.join(path.dirname(entrypoint), 'packages');
|
| + }
|
| +
|
| + return api.compile(
|
| + pathToFileUri(entrypoint),
|
| + pathToFileUri(appendSlash(_libPath)),
|
| + pathToFileUri(appendSlash(packageRoot)),
|
| + provider.readStringFromUri,
|
| + new FormattingDiagnosticHandler(provider).diagnosticHandler,
|
| + options);
|
| + }).then((result) {
|
| + if (result != null) return result;
|
| + throw new ApplicationException('Failed to compile "$entrypoint".');
|
| + });
|
| +}
|
| +
|
| +/// Returns the path to the library directory. This corresponds to the "sdk"
|
| +/// directory in the repo and to the root of the compiled SDK.
|
| +String get _libPath {
|
| + if (runningFromSdk) return sdk.rootDirectory;
|
| + return path.join(repoRoot, 'sdk');
|
| +}
|
| +
|
| +/// Returns whether [dart] looks like an entrypoint file.
|
| +bool isEntrypoint(CompilationUnit dart) {
|
| + // TODO(nweiz): this misses the case where a Dart file doesn't contain main(),
|
| + // but it parts in another file that does.
|
| + return dart.declarations.any((node) {
|
| + return node is FunctionDeclaration && node.name.name == "main" &&
|
| + node.functionExpression.parameters.elements.isEmpty;
|
| + });
|
| +}
|
|
|