Skip to content

Commit ec8320c

Browse files
committed
update macro benchmark to use a multiMacroExecutor and support configuring the communication channel
1 parent 59bde59 commit ec8320c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

working/macros/example/benchmark/simple.dart

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import 'package:_fe_analyzer_shared/src/macros/executor/isolated_executor.dart'
3232
as isolatedExecutor;
3333
import 'package:_fe_analyzer_shared/src/macros/executor/process_executor.dart'
3434
as processExecutor;
35+
import 'package:_fe_analyzer_shared/src/macros/executor/multi_executor.dart'
36+
as multiExecutor;
3537

3638
final _watch = Stopwatch()..start();
3739
void _log(String message) {
@@ -47,6 +49,11 @@ final argParser = ArgParser()
4749
allowed: ['aot', 'isolate'],
4850
defaultsTo: 'aot',
4951
help: 'The execution strategy for precompiled macros.')
52+
..addOption('communication-channel',
53+
allowed: ['socket', 'stdio'],
54+
defaultsTo: 'stdio',
55+
help: 'The communication channel to use when running as a separate'
56+
' process.')
5057
..addFlag('help', negatable: false, hide: true);
5158

5259
// Run this script to print out the generated augmentation library for an example class.
@@ -82,6 +89,10 @@ void main(List<String> args) async {
8289
Platform.script.path.endsWith('.dill')
8390
? 'jit'
8491
: 'aot';
92+
93+
var communicationChannel = parsedArgs['communication-channel'] == 'stdio'
94+
? processExecutor.CommunicationChannel.stdio
95+
: processExecutor.CommunicationChannel.socket;
8596
_log('''
8697
Running with the following options:
8798
@@ -130,13 +141,13 @@ Host app mode: $hostMode
130141
}
131142

132143
_log('Loading the macro executor');
133-
var executor = macroExecutionStrategy == 'aot'
134-
? await processExecutor.start(
135-
serverSerializationMode,
136-
processExecutor.CommunicationChannel.socket,
137-
kernelOutputFile.uri.toFilePath())
144+
var executorImpl = macroExecutionStrategy == 'aot'
145+
? await processExecutor.start(serverSerializationMode,
146+
communicationChannel, kernelOutputFile.uri.toFilePath())
138147
: await isolatedExecutor.start(
139148
serverSerializationMode, kernelOutputFile.uri);
149+
var executor = multiExecutor.MultiMacroExecutor()
150+
..registerExecutorFactory(() => executorImpl, {macroUri});
140151

141152
_log('Instantiating macro');
142153
var instanceId = await executor.instantiateMacro(

0 commit comments

Comments
 (0)