-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build macros, run them, serve a (test) service, host, connect to it #20
Merged
+1,210
−103
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, done. |
||||||||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we separate out an interface here, and then have an implementation which imports
dart:io
? It might anyways make sense to have an abstraction here, for kernel versions or a version which uses the front end as a library (this might live in the SDK, under pkg/front_end).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure this will end up with multiple implementations; added a TODO.
Some of them may come from code already in the analyzer and/or CFE.