Files
sdk/pkg/vm/test/unlinked_ast_to_text_test.dart
T
Ryan Macnak ab4f9351b1 Rename vm_platform_strong.dill to vm_platform.dill.
The name has always been annoying because it did not add strong typing. And now there aren't variants of the VM platform to distinguish.

Leave a copy at the old name to not immediately break illegal uses.

TEST=ci
Cq-Include-Trybots: luci.dart.try:flutter-analyze-try,flutter-frontend-try,flutter-linux-try
Change-Id: Ie76fa7f16940aa1ba8d582eb5197f0ae55dc8938
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429828
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-16 18:33:38 -07:00

83 lines
2.6 KiB
Dart

// Copyright (c) 2019, 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:args/args.dart';
import 'package:expect/expect.dart';
import 'package:kernel/kernel.dart';
import 'package:kernel/binary/ast_to_binary.dart';
import 'package:vm/kernel_front_end.dart';
main() async {
final outDir = Directory.systemTemp.createTempSync(
"incremental_load_from_dill_test",
);
final dillFile = outDir.uri.resolve("dart2js.dart.dill").toFilePath();
final unlinkedDillFile =
outDir.uri.resolve("dart2js.dart.unlinked.dill").toFilePath();
final unlinkedDillTxtFile =
outDir.uri.resolve("dart2js.dart.unlinked dill.txt").toFilePath();
final executable = Platform.executable;
late final String platformDill;
if (executable.endsWith('ReleaseX64/dart')) {
platformDill =
Uri.parse(executable).resolve('vm_platform.dill').toFilePath();
} else if (executable.endsWith('dart-sdk/bin/dart')) {
platformDill =
Uri.parse(
executable,
).resolve('../lib/_internal/vm_platform.dill').toFilePath();
} else {
print(
'Skipping test due to not being run .../ReleaseX64/dart or .../dart-sdk/bin/dart.',
);
return;
}
try {
final arguments = <String>[
'--platform=$platformDill',
'--output=$dillFile',
'pkg/compiler/lib/src/dart2js.dart',
];
// Compile dart2js.dart.
final ArgParser argParser = createCompilerArgParser();
final int exitCode = await runCompiler(
argParser.parse(arguments),
'<usage>',
);
Expect.equals(0, exitCode);
// Load the dart2js.dart.dill and write the unlinked version.
final component = loadComponentFromBinary(dillFile);
final sink = File(unlinkedDillFile).openWrite();
final printer = BinaryPrinter(
sink,
libraryFilter: (lib) => !lib.importUri.isScheme('dart'),
);
printer.writeComponentFile(component);
await sink.close();
// Ensure we can load the unlinked dill file and ensure it doesn't include
// core libraries.
final unlinkedComponent = loadComponentFromBinary(unlinkedDillFile);
final coreLibraryCount =
unlinkedComponent.libraries
.where(
(lib) => lib.importUri.isScheme('dart') && lib.members.isNotEmpty,
)
.length;
Expect.equals(0, coreLibraryCount);
// Ensure we can print the unlinked kernel to text.
writeComponentToText(unlinkedComponent, path: unlinkedDillTxtFile);
} finally {
outDir.deleteSync(recursive: true);
}
}