mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:14:36 +00:00
[test/ffi] Make the test generator async
The `dart format` step takes 8 seconds currently on the large files. This cuts down the total time from 21 seconds to 9 on my machine. TEST=This only changes the test generator, nothing should change. Bug: https://github.com/dart-lang/sdk/issues/45007 Change-Id: Ie4940fdd3a43a923ca28cb39b0673cc19f81a10a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216664 Auto-Submit: Daco Harkes <dacoharkes@google.com> Reviewed-by: Clement Skau <cskau@google.com>
This commit is contained in:
parent
3403e31094
commit
e512402b05
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
|
|
@ -870,6 +870,7 @@ headerDartCallTest(bool nnbd) {
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
@ -890,8 +891,8 @@ final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
|||
""";
|
||||
}
|
||||
|
||||
void writeDartCallTest() {
|
||||
for (bool nnbd in [true, false]) {
|
||||
Future<void> writeDartCallTest() async {
|
||||
await Future.wait([true, false].map((nnbd) async {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write(headerDartCallTest(nnbd));
|
||||
|
||||
|
@ -908,9 +909,9 @@ void writeDartCallTest() {
|
|||
buffer.writeAll(functions.map((e) => e.dartCallCode(isLeaf: true)));
|
||||
|
||||
final path = callTestPath(nnbd);
|
||||
File(path).writeAsStringSync(buffer.toString());
|
||||
Process.runSync("dart", ["format", path]);
|
||||
}
|
||||
await File(path).writeAsString(buffer.toString());
|
||||
await runProcess("dart", ["format", path]);
|
||||
}));
|
||||
}
|
||||
|
||||
String callTestPath(bool nnbd) {
|
||||
|
@ -929,6 +930,7 @@ headerDartCallbackTest(bool nnbd) {
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
@ -960,8 +962,8 @@ void main() {
|
|||
""";
|
||||
}
|
||||
|
||||
void writeDartCallbackTest() {
|
||||
for (bool nnbd in [true, false]) {
|
||||
Future<void> writeDartCallbackTest() async {
|
||||
await Future.wait([true, false].map((nnbd) async {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write(headerDartCallbackTest(nnbd));
|
||||
|
||||
|
@ -974,9 +976,9 @@ void writeDartCallbackTest() {
|
|||
buffer.writeAll(functions.map((e) => e.dartCallbackCode(nnbd)));
|
||||
|
||||
final path = callbackTestPath(nnbd);
|
||||
File(path).writeAsStringSync(buffer.toString());
|
||||
Process.runSync("dart", ["format", path]);
|
||||
}
|
||||
await File(path).writeAsString(buffer.toString());
|
||||
await runProcess("dart", ["format", path]);
|
||||
}));
|
||||
}
|
||||
|
||||
String callbackTestPath(bool nnbd) {
|
||||
|
@ -993,6 +995,7 @@ const headerC = """
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -1031,7 +1034,7 @@ const footerC = """
|
|||
} // namespace dart
|
||||
""";
|
||||
|
||||
void writeC() {
|
||||
Future<void> writeC() async {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.write(headerC);
|
||||
|
||||
|
@ -1041,8 +1044,8 @@ void writeC() {
|
|||
|
||||
buffer.write(footerC);
|
||||
|
||||
File(ccPath).writeAsStringSync(buffer.toString());
|
||||
Process.runSync("clang-format", ["-i", ccPath]);
|
||||
await File(ccPath).writeAsString(buffer.toString());
|
||||
await runProcess("clang-format", ["-i", ccPath]);
|
||||
}
|
||||
|
||||
final ccPath = Platform.script
|
||||
|
@ -1062,13 +1065,37 @@ Generates:
|
|||
""");
|
||||
}
|
||||
|
||||
void main(List<String> arguments) {
|
||||
void main(List<String> arguments) async {
|
||||
if (arguments.length != 0) {
|
||||
printUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
writeDartCallTest();
|
||||
writeDartCallbackTest();
|
||||
writeC();
|
||||
await Future.wait([
|
||||
writeDartCallTest(),
|
||||
writeDartCallbackTest(),
|
||||
writeC(),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> runProcess(String executable, List<String> arguments) async {
|
||||
final commandString = [executable, ...arguments].join(' ');
|
||||
stdout.writeln('Running `$commandString`.');
|
||||
final process = await Process.start(
|
||||
executable,
|
||||
arguments,
|
||||
runInShell: true,
|
||||
includeParentEnvironment: true,
|
||||
).then((process) {
|
||||
process.stdout.forEach((data) => stdout.add(data));
|
||||
process.stderr.forEach((data) => stderr.add(data));
|
||||
return process;
|
||||
});
|
||||
final exitCode = await process.exitCode;
|
||||
if (exitCode != 0) {
|
||||
final message = 'Command `$commandString` failed with exit code $exitCode.';
|
||||
stderr.writeln(message);
|
||||
throw Exception(message);
|
||||
}
|
||||
stdout.writeln('Command `$commandString` done.');
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
//
|
||||
// This file has been automatically generated. Please do not edit it manually.
|
||||
// Generated by tests/ffi/generator/structs_by_value_tests_generator.dart.
|
||||
//
|
||||
// SharedObjects=ffi_test_functions
|
||||
// VMOptions=
|
||||
|
|
Loading…
Reference in a new issue