-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build macros, run them, serve a (test) service, host, connect to it (#20
- Loading branch information
1 parent
00a097a
commit b3f4c73
Showing
31 changed files
with
1,210 additions
and
103 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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:dart_model/dart_model.dart'; | ||
|
||
/// Creates the entrypoint script for [macros]. | ||
String createBootstrap(List<QualifiedName> macros) { | ||
final script = StringBuffer(); | ||
for (var i = 0; i != macros.length; ++i) { | ||
final macro = macros[i]; | ||
// TODO(davidmorgan): pick non-clashing prefixes. | ||
script.writeln("import '${macro.uri}' as m$i;"); | ||
} | ||
script.write(''' | ||
import 'dart:convert' as convert; | ||
import 'package:_macro_client/macro_client.dart' as macro_client; | ||
import 'package:macro_service/macro_service.dart' as macro_service; | ||
void main(List<String> arguments) { | ||
macro_client.MacroClient.run( | ||
endpoint: macro_service.HostEndpoint.fromJson( | ||
convert.json.decode(arguments[0])), | ||
macros: ['''); | ||
for (var i = 0; i != macros.length; ++i) { | ||
final macro = macros[i]; | ||
script.write('m$i.${macro.name}()'); | ||
if (i != macros.length - 1) script.write(', '); | ||
} | ||
script.writeln(']);'); | ||
script.writeln('}'); | ||
return script.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,8 @@ stages: | |
- format: | ||
sdk: | ||
- dev | ||
- unit_test: | ||
- test: --test-randomize-ordering-seed=random | ||
os: | ||
- linux | ||
- windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ dependencies: | |
|
||
dev_dependencies: | ||
dart_flutter_team_lints: ^3.0.0 | ||
test: ^1.25.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 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 'dart:io'; | ||
import 'dart:isolate'; | ||
|
||
import 'package:_macro_builder/macro_builder.dart'; | ||
import 'package:_macro_builder/src/bootstrap.dart'; | ||
import 'package:dart_model/dart_model.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(MacroBuilder, () { | ||
test('bootstrap matches golden', () async { | ||
final script = createBootstrap([ | ||
QualifiedName('package:_test_macros/declare_x_macro.dart#DeclareX'), | ||
QualifiedName('package:_test_macros/declare_y_macro.dart#DeclareY'), | ||
QualifiedName( | ||
'package:_more_macros/other_macro.dart#OtherMacroImplementation') | ||
]); | ||
|
||
expect(script, ''' | ||
import 'package:_test_macros/declare_x_macro.dart' as m0; | ||
import 'package:_test_macros/declare_y_macro.dart' as m1; | ||
import 'package:_more_macros/other_macro.dart' as m2; | ||
import 'dart:convert' as convert; | ||
import 'package:_macro_client/macro_client.dart' as macro_client; | ||
import 'package:macro_service/macro_service.dart' as macro_service; | ||
void main(List<String> arguments) { | ||
macro_client.MacroClient.run( | ||
endpoint: macro_service.HostEndpoint.fromJson( | ||
convert.json.decode(arguments[0])), | ||
macros: [m0.DeclareX(), m1.DeclareY(), m2.OtherMacroImplementation()]); | ||
} | ||
'''); | ||
}); | ||
|
||
test('builds macros', () async { | ||
final builder = MacroBuilder(); | ||
|
||
final bundle = await builder.build(Isolate.packageConfigSync!, [ | ||
QualifiedName( | ||
'package:_test_macros/declare_x_macro.dart#DeclareXImplementation') | ||
]); | ||
|
||
expect(File(bundle.executablePath).existsSync(), true); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,8 @@ stages: | |
- format: | ||
sdk: | ||
- dev | ||
- unit_test: | ||
- test: --test-randomize-ordering-seed=random | ||
os: | ||
- linux | ||
- windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:_macro_client/macro_client.dart'; | ||
import 'package:_test_macros/declare_x_macro.dart'; | ||
import 'package:macro_service/macro_service.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(MacroClient, () { | ||
test('connects to service', () async { | ||
final serverSocket = await ServerSocket.bind('localhost', 0); | ||
addTearDown(serverSocket.close); | ||
|
||
unawaited(MacroClient.run( | ||
endpoint: HostEndpoint(port: serverSocket.port), | ||
macros: [DeclareXImplementation()])); | ||
|
||
expect( | ||
serverSocket.first.timeout(const Duration(seconds: 10)), completes); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.