mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:00:09 +00:00
[dart2js,ddc] Ensure valid d8 breakpoints in testing
D8 breakpoints used in sourcemap testing should only be set for test files and not, accidentally, in sdk source files. This was hit in a dart2js step debugging test where, after unforking, the line number in the test file accidentally matched those of print.dart from the sdk. Change-Id: I6a9c6f5bfd28b8821e9cee9b10cc6c67e4fc689b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146781 Reviewed-by: Joshua Litt <joshualitt@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
097c3aab2c
commit
a2015351c8
|
@ -14,6 +14,7 @@ import 'package:testing/testing.dart';
|
||||||
class Data {
|
class Data {
|
||||||
Uri uri;
|
Uri uri;
|
||||||
Directory outDir;
|
Directory outDir;
|
||||||
|
String testFileName;
|
||||||
AnnotatedCode code;
|
AnnotatedCode code;
|
||||||
List<String> d8Output;
|
List<String> d8Output;
|
||||||
}
|
}
|
||||||
|
@ -75,8 +76,8 @@ class StepWithD8 extends Step<Data, Data, ChainContext> {
|
||||||
@override
|
@override
|
||||||
Future<Result<Data>> run(Data data, ChainContext context) async {
|
Future<Result<Data>> run(Data data, ChainContext context) async {
|
||||||
var outWrapperPath = p.join(data.outDir.path, 'wrapper.js');
|
var outWrapperPath = p.join(data.outDir.path, 'wrapper.js');
|
||||||
var runResult =
|
var runResult = runD8AndStep(data.outDir.path, data.testFileName, data.code,
|
||||||
runD8AndStep(data.outDir.path, data.code, ['--module', outWrapperPath]);
|
['--module', outWrapperPath]);
|
||||||
data.d8Output = (runResult.stdout as String).split('\n');
|
data.d8Output = (runResult.stdout as String).split('\n');
|
||||||
return pass(data);
|
return pass(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,9 @@ class Compile extends Step<Data, Data, ChainContext> {
|
||||||
data.outDir = await Directory.systemTemp.createTemp('ddc_step_test');
|
data.outDir = await Directory.systemTemp.createTemp('ddc_step_test');
|
||||||
data.code = AnnotatedCode.fromText(
|
data.code = AnnotatedCode.fromText(
|
||||||
File(inputFile).readAsStringSync(), commentStart, commentEnd);
|
File(inputFile).readAsStringSync(), commentStart, commentEnd);
|
||||||
|
data.testFileName = 'test.dart';
|
||||||
var outDirUri = data.outDir.uri;
|
var outDirUri = data.outDir.uri;
|
||||||
var testFile = outDirUri.resolve('test.dart');
|
var testFile = outDirUri.resolve(data.testFileName);
|
||||||
File.fromUri(testFile).writeAsStringSync(data.code.sourceCode);
|
File.fromUri(testFile).writeAsStringSync(data.code.sourceCode);
|
||||||
var outputFilename = 'js.js';
|
var outputFilename = 'js.js';
|
||||||
var outputFile = outDirUri.resolve(outputFilename);
|
var outputFile = outDirUri.resolve(outputFilename);
|
||||||
|
|
|
@ -13,8 +13,8 @@ import 'package:source_maps/source_maps.dart';
|
||||||
* It is furthermore expected that the js has been compiled from a file in the
|
* It is furthermore expected that the js has been compiled from a file in the
|
||||||
* same folder called test.dart.
|
* same folder called test.dart.
|
||||||
*/
|
*/
|
||||||
ProcessResult runD8AndStep(
|
ProcessResult runD8AndStep(String outputPath, String testFileName,
|
||||||
String outputPath, AnnotatedCode code, List<String> scriptD8Command) {
|
AnnotatedCode code, List<String> scriptD8Command) {
|
||||||
var outputFile = path.join(outputPath, "js.js");
|
var outputFile = path.join(outputPath, "js.js");
|
||||||
SingleMapping sourceMap =
|
SingleMapping sourceMap =
|
||||||
parse(new File("${outputFile}.map").readAsStringSync());
|
parse(new File("${outputFile}.map").readAsStringSync());
|
||||||
|
@ -37,12 +37,13 @@ ProcessResult runD8AndStep(
|
||||||
// Annotations are 1-based, js breakpoints are 0-based.
|
// Annotations are 1-based, js breakpoints are 0-based.
|
||||||
for (Annotation breakAt
|
for (Annotation breakAt
|
||||||
in code.annotations.where((a) => a.text.trim() == "bl")) {
|
in code.annotations.where((a) => a.text.trim() == "bl")) {
|
||||||
breakpoints.add(_getJsBreakpointLine(sourceMap, breakAt.lineNo - 1));
|
breakpoints
|
||||||
|
.add(_getJsBreakpointLine(testFileName, sourceMap, breakAt.lineNo - 1));
|
||||||
}
|
}
|
||||||
for (Annotation breakAt
|
for (Annotation breakAt
|
||||||
in code.annotations.where((a) => a.text.trim().startsWith("bc:"))) {
|
in code.annotations.where((a) => a.text.trim().startsWith("bc:"))) {
|
||||||
breakpoints.add(_getJsBreakpointLineAndColumn(
|
breakpoints.add(_getJsBreakpointLineAndColumn(
|
||||||
sourceMap, breakAt.lineNo - 1, breakAt.columnNo - 1));
|
testFileName, sourceMap, breakAt.lineNo - 1, breakAt.columnNo - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
File inspectorFile = new File.fromUri(
|
File inspectorFile = new File.fromUri(
|
||||||
|
@ -376,13 +377,16 @@ class _PointMapping {
|
||||||
* frontend/blob/fa18d70a995f06cb73365b2e5b8ae974cf60bd3a/front_end/sources/
|
* frontend/blob/fa18d70a995f06cb73365b2e5b8ae974cf60bd3a/front_end/sources/
|
||||||
* JavaScriptSourceFrame.js#L1520-L1523
|
* JavaScriptSourceFrame.js#L1520-L1523
|
||||||
*/
|
*/
|
||||||
String _getJsBreakpointLine(SingleMapping sourceMap, int breakOnLine) {
|
String _getJsBreakpointLine(
|
||||||
|
String testFileName, SingleMapping sourceMap, int breakOnLine) {
|
||||||
List<_PointMapping> mappingsOnLines = [];
|
List<_PointMapping> mappingsOnLines = [];
|
||||||
for (var line in sourceMap.lines) {
|
for (var line in sourceMap.lines) {
|
||||||
for (var entry in line.entries) {
|
for (var entry in line.entries) {
|
||||||
if (entry.sourceLine == null) continue;
|
if (entry.sourceLine == null) continue;
|
||||||
if (entry.sourceLine >= breakOnLine &&
|
if (entry.sourceLine >= breakOnLine &&
|
||||||
entry.sourceLine < breakOnLine + 4) {
|
entry.sourceLine < breakOnLine + 4 &&
|
||||||
|
entry.sourceUrlId != null &&
|
||||||
|
sourceMap.urls[entry.sourceUrlId] == testFileName) {
|
||||||
mappingsOnLines.add(new _PointMapping(
|
mappingsOnLines.add(new _PointMapping(
|
||||||
entry.sourceLine, entry.sourceColumn, line.line, entry.column));
|
entry.sourceLine, entry.sourceColumn, line.line, entry.column));
|
||||||
}
|
}
|
||||||
|
@ -407,12 +411,14 @@ String _getJsBreakpointLine(SingleMapping sourceMap, int breakOnLine) {
|
||||||
/**
|
/**
|
||||||
* Input and output is expected to be 0-based.
|
* Input and output is expected to be 0-based.
|
||||||
*/
|
*/
|
||||||
String _getJsBreakpointLineAndColumn(
|
String _getJsBreakpointLineAndColumn(String testFileName,
|
||||||
SingleMapping sourceMap, int breakOnLine, int breakOnColumn) {
|
SingleMapping sourceMap, int breakOnLine, int breakOnColumn) {
|
||||||
for (var line in sourceMap.lines) {
|
for (var line in sourceMap.lines) {
|
||||||
for (var entry in line.entries) {
|
for (var entry in line.entries) {
|
||||||
if (entry.sourceLine == breakOnLine &&
|
if (entry.sourceLine == breakOnLine &&
|
||||||
entry.sourceColumn == breakOnColumn)
|
entry.sourceColumn == breakOnColumn &&
|
||||||
|
entry.sourceUrlId != null &&
|
||||||
|
sourceMap.urls[entry.sourceUrlId] == testFileName)
|
||||||
return "${line.line}:${entry.column}";
|
return "${line.line}:${entry.column}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,9 @@ Future runTest(AnnotatedCode annotatedCode, String config,
|
||||||
bool verbose: false,
|
bool verbose: false,
|
||||||
List<String> options: const <String>[]}) async {
|
List<String> options: const <String>[]}) async {
|
||||||
Directory dir = Directory.systemTemp.createTempSync('stepping_test');
|
Directory dir = Directory.systemTemp.createTempSync('stepping_test');
|
||||||
|
String testFileName = 'test.dart';
|
||||||
String path = dir.path;
|
String path = dir.path;
|
||||||
String inputFile = '$path/test.dart';
|
String inputFile = '$path/$testFileName';
|
||||||
new File(inputFile).writeAsStringSync(annotatedCode.sourceCode);
|
new File(inputFile).writeAsStringSync(annotatedCode.sourceCode);
|
||||||
String outputFile = '$path/js.js';
|
String outputFile = '$path/js.js';
|
||||||
List<String> arguments = <String>[
|
List<String> arguments = <String>[
|
||||||
|
@ -82,7 +83,8 @@ Future runTest(AnnotatedCode annotatedCode, String config,
|
||||||
'$sdkPath/_internal/js_runtime/lib/preambles/d8.js',
|
'$sdkPath/_internal/js_runtime/lib/preambles/d8.js',
|
||||||
outputFile
|
outputFile
|
||||||
];
|
];
|
||||||
ProcessResult result = runD8AndStep(dir.path, annotatedCode, scriptD8Command);
|
ProcessResult result =
|
||||||
|
runD8AndStep(dir.path, testFileName, annotatedCode, scriptD8Command);
|
||||||
List<String> d8output = result.stdout.split("\n");
|
List<String> d8output = result.stdout.split("\n");
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
d8output.forEach(print);
|
d8output.forEach(print);
|
||||||
|
|
Loading…
Reference in a new issue