[ddc,frontend_server] Remove macro tests
Change-Id: I1227eaed501e0175859e3c7759d88a8b19e8f4d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406964 Reviewed-by: Nicholas Shahan <nshahan@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com>
This commit is contained in:
committed by
Commit Queue
parent
f05ae1c3af
commit
7b9c5d938b
@@ -25,11 +25,9 @@ dependencies:
|
||||
dev_dependencies:
|
||||
browser_launcher: any
|
||||
expect: any
|
||||
frontend_server: any
|
||||
http_multi_server: any
|
||||
js: any
|
||||
lints: any
|
||||
macros: any
|
||||
modular_test: any
|
||||
reload_test: any
|
||||
shelf: any
|
||||
|
||||
@@ -1,247 +0,0 @@
|
||||
// Copyright (c) 2023, 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:bazel_worker/bazel_worker.dart';
|
||||
import 'package:dev_compiler/ddc.dart' as ddc;
|
||||
import 'package:frontend_server/compute_kernel.dart';
|
||||
import 'package:macros/src/bootstrap.dart';
|
||||
import 'package:macros/src/executor/serialization.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
Directory tmp = Directory.systemTemp.createTempSync('ddc_worker_test');
|
||||
File file(String path) => File.fromUri(tmp.uri.resolve(path));
|
||||
String _resolvePath(String executableRelativePath) {
|
||||
return Uri.file(Platform.resolvedExecutable)
|
||||
.resolve(executableRelativePath)
|
||||
.toFilePath();
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('DDC: Macros', timeout: Timeout(Duration(minutes: 2)), () {
|
||||
late File testMacroDart;
|
||||
late String bootstrapDillPathVm;
|
||||
late String bootstrapAotPathVm;
|
||||
late File bootstrapDillFileDdc;
|
||||
late Uri testMacroUri;
|
||||
late File packageConfig;
|
||||
late List<String> ddcArgs;
|
||||
late List<String> executableArgs;
|
||||
late String dartAot;
|
||||
|
||||
final applyTestMacroDart = file('apply_test_macro.dart');
|
||||
final testMacroJS = file('test_macro.js');
|
||||
final testMacroSummary = file('test_macro.dill');
|
||||
final applyTestMacroJS = file('apply_test_macro.js');
|
||||
|
||||
setUp(() async {
|
||||
// Write a simple test macro and supporting package config.
|
||||
testMacroDart = file('lib/test_macro.dart')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
import 'package:macros/macros.dart';
|
||||
|
||||
macro class TestMacro implements ClassDeclarationsMacro {
|
||||
const TestMacro();
|
||||
|
||||
@override
|
||||
Future<void> buildDeclarationsForClass(
|
||||
ClassDeclaration clazz, MemberDeclarationBuilder builder) async {
|
||||
builder.declareInType(DeclarationCode.fromString('int get x => 0;'));
|
||||
}
|
||||
}
|
||||
''');
|
||||
packageConfig = file('.dart_tool/package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "test_macro",
|
||||
"rootUri": "../",
|
||||
"packageUri": "lib/"
|
||||
},
|
||||
{
|
||||
"name": "_macros",
|
||||
"rootUri": "${Platform.script.resolve('../../../_macros')}",
|
||||
"packageUri": "lib/"
|
||||
},
|
||||
{
|
||||
"name": "macros",
|
||||
"rootUri": "${Platform.script.resolve('../../../macros')}",
|
||||
"packageUri": "lib/"
|
||||
},
|
||||
{
|
||||
"name": "meta",
|
||||
"rootUri": "${Platform.script.resolve('../../../meta')}",
|
||||
"packageUri": "lib/"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
|
||||
// Write the macro entrypoint, the "bootstrap" file.
|
||||
testMacroUri = Uri.parse('package:test_macro/test_macro.dart');
|
||||
var bootstrapContent = bootstrapMacroIsolate(
|
||||
{
|
||||
testMacroUri.toString(): {
|
||||
'TestMacro': [''],
|
||||
},
|
||||
},
|
||||
SerializationMode.byteData,
|
||||
);
|
||||
var bootstrapFile = file('bootstrap.dart')
|
||||
..writeAsStringSync(bootstrapContent);
|
||||
|
||||
// Compile the macro to vm dill to be run by the CFE.
|
||||
var productPlatformDill = File(_resolvePath('../'
|
||||
'lib/_internal/vm_platform_strong_product.dill'));
|
||||
var ddcPlatformDill = File(_resolvePath('../'
|
||||
'lib/_internal/ddc_outline.dill'));
|
||||
bootstrapDillPathVm = 'bootstrap.dart.dill';
|
||||
var bootstrapResult = await computeKernel([
|
||||
'--enable-experiment=macros',
|
||||
'--no-summary',
|
||||
'--no-summary-only',
|
||||
'--target=vm',
|
||||
'--dart-sdk-summary=${productPlatformDill.uri}',
|
||||
'--output=$bootstrapDillPathVm',
|
||||
'--source=${bootstrapFile.uri}',
|
||||
'--source=${testMacroDart.uri}',
|
||||
'--packages-file=${packageConfig.uri}',
|
||||
]);
|
||||
expect(bootstrapResult.succeeded, true);
|
||||
|
||||
// Compile the macro to vm AOT executable to be run by the CFE.
|
||||
bootstrapAotPathVm = 'bootstrap.dart.exe';
|
||||
var bootstrapAotResult = Process.runSync(Platform.resolvedExecutable, [
|
||||
'compile',
|
||||
'exe',
|
||||
'--enable-experiment=macros',
|
||||
'-o',
|
||||
bootstrapAotPathVm,
|
||||
bootstrapFile.path,
|
||||
]);
|
||||
expect(bootstrapAotResult.exitCode, EXIT_CODE_OK);
|
||||
|
||||
// Compile the macro to ddc dill for the ddc build.
|
||||
bootstrapDillFileDdc = file('bootstrap_ddc.dart.dill');
|
||||
var bootstrapResultDdc = await computeKernel([
|
||||
'--enable-experiment=macros',
|
||||
'--target=ddc',
|
||||
'--dart-sdk-summary=${ddcPlatformDill.uri}',
|
||||
'--output=${bootstrapDillFileDdc.path}',
|
||||
'--source=${bootstrapFile.uri}',
|
||||
'--source=${testMacroDart.uri}',
|
||||
'--packages-file=${packageConfig.uri}',
|
||||
]);
|
||||
expect(bootstrapResultDdc.succeeded, true);
|
||||
|
||||
// Write source that applies the macro.
|
||||
applyTestMacroDart.writeAsStringSync('''
|
||||
import 'package:test_macro/test_macro.dart';
|
||||
|
||||
@TestMacro()
|
||||
class TestClass{}
|
||||
|
||||
void main() {
|
||||
// Use the declaration created by the macro, so the compile will fail if the
|
||||
// macro application fails.
|
||||
print(TestClass().x);
|
||||
}
|
||||
''');
|
||||
ddcArgs = [
|
||||
'--enable-experiment=macros',
|
||||
'--dart-sdk-summary',
|
||||
_resolvePath('../../ddc_outline.dill'),
|
||||
'--packages=${packageConfig.uri}',
|
||||
];
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
if (tmp.existsSync()) tmp.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
test('compile using dartdevc source code', () async {
|
||||
await ddc.internalMain([
|
||||
...ddcArgs,
|
||||
'--no-source-map',
|
||||
'-o',
|
||||
testMacroJS.path,
|
||||
testMacroDart.path,
|
||||
]);
|
||||
// TODO(johnniwinther): Is there a way to verify that no errors/warnings
|
||||
// were reported?
|
||||
expect(exitCode, EXIT_CODE_OK);
|
||||
|
||||
expect(testMacroJS.existsSync(), isTrue);
|
||||
expect(testMacroSummary.existsSync(), isTrue);
|
||||
|
||||
await ddc.internalMain([
|
||||
...ddcArgs,
|
||||
'--precompiled-macro',
|
||||
'$bootstrapDillPathVm;$testMacroUri',
|
||||
'--no-source-map',
|
||||
'--no-summarize',
|
||||
'-s',
|
||||
testMacroSummary.path,
|
||||
'-s',
|
||||
bootstrapDillFileDdc.path,
|
||||
'-o',
|
||||
applyTestMacroJS.path,
|
||||
applyTestMacroDart.path,
|
||||
]);
|
||||
// TODO(johnniwinther): Is there a way to verify that no errors/warnings
|
||||
// were reported?
|
||||
expect(exitCode, EXIT_CODE_OK);
|
||||
expect(applyTestMacroJS.existsSync(), isTrue);
|
||||
});
|
||||
|
||||
test('compile using dartdevc snapshot', () {
|
||||
executableArgs = [
|
||||
_resolvePath('snapshots/dartdevc_aot.dart.snapshot'),
|
||||
...ddcArgs
|
||||
];
|
||||
|
||||
dartAot = p.absolute(p.dirname(Platform.resolvedExecutable),
|
||||
Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime');
|
||||
|
||||
var result = Process.runSync(dartAot, [
|
||||
...executableArgs,
|
||||
'--no-source-map',
|
||||
'-o',
|
||||
testMacroJS.path,
|
||||
testMacroDart.path,
|
||||
]);
|
||||
expect(result.stdout, isEmpty);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, EXIT_CODE_OK);
|
||||
|
||||
expect(testMacroJS.existsSync(), isTrue);
|
||||
expect(testMacroSummary.existsSync(), isTrue);
|
||||
|
||||
result = Process.runSync(dartAot, [
|
||||
...executableArgs,
|
||||
'--precompiled-macro',
|
||||
'$bootstrapAotPathVm;$testMacroUri',
|
||||
'--no-source-map',
|
||||
'--no-summarize',
|
||||
'-s',
|
||||
testMacroSummary.path,
|
||||
'-s',
|
||||
bootstrapDillFileDdc.path,
|
||||
'-o',
|
||||
applyTestMacroJS.path,
|
||||
applyTestMacroDart.path,
|
||||
]);
|
||||
expect(result.stdout, isEmpty);
|
||||
expect(result.stderr, isEmpty);
|
||||
expect(result.exitCode, EXIT_CODE_OK);
|
||||
expect(applyTestMacroJS.existsSync(), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
// Copyright (c) 2023, 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:frontend_server/compute_kernel.dart';
|
||||
import 'package:macros/src/bootstrap.dart';
|
||||
import 'package:macros/src/executor/serialization.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() async {
|
||||
group('basic macro', timeout: new Timeout(new Duration(minutes: 2)), () {
|
||||
late File productPlatformDill;
|
||||
late Directory tempDir;
|
||||
late Uri testMacroUri;
|
||||
late File packageConfig;
|
||||
late File bootstrapDillFile;
|
||||
|
||||
setUp(() async {
|
||||
productPlatformDill = new File('${Platform.resolvedExecutable}/../../'
|
||||
'lib/_internal/vm_platform_strong_product.dill');
|
||||
Directory systemTempDir = Directory.systemTemp;
|
||||
tempDir = systemTempDir.createTempSync('frontendServerTest');
|
||||
testMacroUri = Uri.parse('package:test_macro/test_macro.dart');
|
||||
String bootstrapContent = bootstrapMacroIsolate(
|
||||
{
|
||||
testMacroUri.toString(): {
|
||||
'TestMacro': [''],
|
||||
},
|
||||
},
|
||||
SerializationMode.byteData,
|
||||
);
|
||||
File bootstrapFile = new File('${tempDir.path}/bootstrap.dart')
|
||||
..writeAsStringSync(bootstrapContent);
|
||||
packageConfig = new File('${tempDir.path}/.dart_tool/package_config.json')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
{
|
||||
"configVersion": 2,
|
||||
"packages": [
|
||||
{
|
||||
"name": "test_macro",
|
||||
"rootUri": "../",
|
||||
"packageUri": "lib/"
|
||||
},
|
||||
{
|
||||
"name": "macros",
|
||||
"rootUri": "${Platform.script.resolve('../../macros')}",
|
||||
"packageUri": "lib/"
|
||||
},
|
||||
{
|
||||
"name": "_macros",
|
||||
"rootUri": "${Platform.script.resolve('../../_macros')}",
|
||||
"packageUri": "lib/"
|
||||
},
|
||||
{
|
||||
"name": "meta",
|
||||
"rootUri": "${Platform.script.resolve('../../meta')}",
|
||||
"packageUri": "lib/"
|
||||
}
|
||||
]
|
||||
}
|
||||
''');
|
||||
File testMacroFile = new File('${tempDir.path}/lib/test_macro.dart')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
import 'package:macros/macros.dart';
|
||||
|
||||
macro class TestMacro implements ClassDeclarationsMacro {
|
||||
const TestMacro();
|
||||
|
||||
@override
|
||||
Future<void> buildDeclarationsForClass(
|
||||
ClassDeclaration clazz, MemberDeclarationBuilder builder) async {
|
||||
builder.declareInType(DeclarationCode.fromString('int get x => 0;'));
|
||||
}
|
||||
}
|
||||
''');
|
||||
|
||||
bootstrapDillFile = new File('${tempDir.path}/bootstrap.dart.dill');
|
||||
ComputeKernelResult bootstrapResult = await computeKernel([
|
||||
'--enable-experiment=macros',
|
||||
'--no-summary',
|
||||
'--no-summary-only',
|
||||
'--target=vm',
|
||||
'--dart-sdk-summary=${productPlatformDill.uri}',
|
||||
'--output=${bootstrapDillFile.path}',
|
||||
'--source=${bootstrapFile.uri}',
|
||||
'--source=${testMacroFile.uri}',
|
||||
'--packages-file=${packageConfig.uri}',
|
||||
]);
|
||||
expect(bootstrapResult.succeeded, true);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
for (bool useIncrementalCompiler in [true, false]) {
|
||||
test(
|
||||
'can be compiled and applied'
|
||||
'${useIncrementalCompiler ? ' with incremental compiler' : ''}',
|
||||
() async {
|
||||
File applyTestMacroFile =
|
||||
new File('${tempDir.path}/lib/apply_test_macro.dart')
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('''
|
||||
import 'package:test_macro/test_macro.dart';
|
||||
|
||||
@TestMacro()
|
||||
class TestClass{}
|
||||
|
||||
void main() {
|
||||
// Use the declaration created by the macro, so the compile will fail if the
|
||||
// macro application fails.
|
||||
print(TestClass().x);
|
||||
}
|
||||
''');
|
||||
File applyTestMacroDill =
|
||||
new File('${tempDir.path}/apply_test_macro.dart.dill');
|
||||
ComputeKernelResult applyTestMacroResult = await computeKernel([
|
||||
if (useIncrementalCompiler) '--use-incremental-compiler',
|
||||
'--enable-experiment=macros',
|
||||
'--no-summary',
|
||||
'--no-summary-only',
|
||||
'--target=vm',
|
||||
'--dart-sdk-summary=${productPlatformDill.uri}',
|
||||
'--output=${applyTestMacroDill.path}',
|
||||
'--source=${applyTestMacroFile.uri}',
|
||||
'--packages-file=${packageConfig.uri}',
|
||||
'--enable-experiment=macros',
|
||||
'--precompiled-macro',
|
||||
'${bootstrapDillFile.uri};$testMacroUri',
|
||||
'--macro-serialization-mode=bytedata',
|
||||
]);
|
||||
expect(applyTestMacroResult.succeeded, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright (c) 2024, 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 'package:macros/macros.dart';
|
||||
|
||||
/// Adds a function with a specified name to a class, with no body and a void
|
||||
/// return type.
|
||||
macro class AddFunction implements ClassDeclarationsMacro {
|
||||
/// The name of the function to add.
|
||||
final String name;
|
||||
|
||||
const AddFunction(this.name);
|
||||
|
||||
@override
|
||||
void buildDeclarationsForClass(
|
||||
ClassDeclaration clazz, MemberDeclarationBuilder builder) {
|
||||
builder.declareInType(DeclarationCode.fromString('void $name() {}'));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
analyzer:
|
||||
enable-experiment:
|
||||
- macros
|
||||
@@ -1,12 +0,0 @@
|
||||
// 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 'add_function.dart';
|
||||
|
||||
void main() {
|
||||
A().myFunc();
|
||||
}
|
||||
|
||||
@AddFunction('myFunc')
|
||||
class A {}
|
||||
@@ -1,19 +0,0 @@
|
||||
# Copyright (c) 2024, 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.
|
||||
#
|
||||
# Tests running precompiled macros from dependent modules.
|
||||
dependencies:
|
||||
main: [add_function]
|
||||
add_function: [macros]
|
||||
macros: [_macros]
|
||||
macros:
|
||||
add_function:
|
||||
dev-dart-app:/add_function.dart:
|
||||
AddFunction:
|
||||
- ""
|
||||
flags:
|
||||
- macros
|
||||
packages:
|
||||
macros: ../../../pkg/macros/lib
|
||||
_macros: ../../../pkg/_macros/lib
|
||||
Reference in New Issue
Block a user