Files
sdk/pkg/dev_compiler/test/sourcemap/sourcemaps_ddc_suite.dart
T
Paul Berry 5dc2156ba4 Cherry-pick be815e1a86 to analyzer branch
Original commit message:

    [dartdevc] fix #35013, move DDC off Analyzer task model

    The new file pkg/dev_compiler/lib/src/analyzer/driver.dart handles
    building the linked summary for a build unit, and then is capable of
    doing analysis using LibraryAnalyzer.

    The algorithm is very similar to analyzer_cli's build mode. The
    biggest difference is that `dartdevc` has existing support for
    discovering source files from the explicit source list (rather than
    requiring every source to be listed on the command line). We don't want
    to break that support, so there's a bit of logic to follow imports,
    exports, and parts.

    After the linked summary is produced, DDC gets the analysis results
    (errors and resolved AST) for each library, and compiles it into a JS
    module.

Change-Id: I8d1855c27f9976cad6fd9ccb567b75a613e6048c
Reviewed-on: https://dart-review.googlesource.com/c/83060
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2018-11-06 21:43:42 +00:00

86 lines
2.7 KiB
Dart

// Copyright (c) 2017, 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.
import 'dart:io';
import 'package:dev_compiler/src/analyzer/command.dart';
import 'package:testing/testing.dart';
import 'common.dart';
import 'ddc_common.dart';
Future<ChainContext> createContext(
Chain suite, Map<String, String> environment) async {
return SourceMapContext(environment);
}
class SourceMapContext extends ChainContextWithCleanupHelper {
final Map<String, String> environment;
SourceMapContext(this.environment);
List<Step> _steps;
List<Step> get steps => _steps ??= <Step>[
const Setup(),
Compile(DevCompilerRunner(environment.containsKey("debug"))),
const StepWithD8(),
CheckSteps(environment.containsKey("debug")),
];
bool debugging() => environment.containsKey("debug");
}
class DevCompilerRunner implements CompilerRunner {
final bool debugging;
const DevCompilerRunner([this.debugging = false]);
Future<Null> run(Uri inputFile, Uri outputFile, Uri outWrapperFile) async {
Uri outDir = outputFile.resolve(".");
String outputFilename = outputFile.pathSegments.last;
File sdkJsFile = findInOutDir("gen/utils/dartdevc/js/es6/dart_sdk.js");
var jsSdkPath = sdkJsFile.uri;
File ddcSdkSummary = findInOutDir("gen/utils/dartdevc/ddc_sdk.sum");
var ddc = getDdcDir().uri.resolve("bin/dartdevc.dart");
List<String> args = <String>[
"--modules=es6",
"--dart-sdk-summary=${ddcSdkSummary.path}",
"--library-root",
outDir.toFilePath(),
"-o",
outputFile.toFilePath(),
inputFile.toFilePath()
];
var result = compile(args);
var exitCode = result?.exitCode;
if (exitCode != 0) {
throw "Exit code: $exitCode from ddc when running something like "
"$dartExecutable ${ddc.toFilePath()} "
"${args.reduce((value, element) => '$value "$element"')}";
}
var jsContent = File.fromUri(outputFile).readAsStringSync();
File.fromUri(outputFile).writeAsStringSync(jsContent.replaceFirst(
"from 'dart_sdk'", "from '${uriPathForwardSlashed(jsSdkPath)}'"));
if (debugging) {
createHtmlWrapper(
sdkJsFile, outputFile, jsContent, outputFilename, outDir);
}
var inputFileName = inputFile.pathSegments.last;
var inputFileNameNoExt =
inputFileName.substring(0, inputFileName.lastIndexOf("."));
File.fromUri(outWrapperFile).writeAsStringSync(
getWrapperContent(jsSdkPath, inputFileNameNoExt, outputFilename));
}
}
main(List<String> arguments) => runMe(arguments, createContext, "testing.json");