Skip to content

Commit d67ab97

Browse files
authored
[bazel_worker] Upgrade protobuf + cleanups (#2195)
1 parent 6866f9b commit d67ab97

17 files changed

+99
-98
lines changed

.github/workflows/bazel_worker.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,24 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
sdk: [3.4, dev]
30+
sdk: [stable, dev]
3131
steps:
3232
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
3333
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
3434
with:
3535
sdk: ${{ matrix.sdk }}
3636
- run: dart pub get
37-
- run: "dart format --output=none --set-exit-if-changed ."
37+
38+
- run: dart format --output=none --set-exit-if-changed .
3839
if: ${{ matrix.sdk == 'dev' }}
39-
- name: Test
40-
run: ./tool/travis.sh
40+
41+
- run: dart analyze --fatal-infos
42+
43+
- run: dart run benchmark/benchmark.dart
44+
45+
- run: dart test
46+
47+
- name: dart test e2e_test
48+
run: |
49+
cd e2e_test
50+
dart test

pkgs/bazel_worker/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.1.4
2+
3+
* Require Dart SDK `^3.9.0`.
4+
* Widen `package:protobuf` constraint to allow 5.0.0 and requiring minimum 4.0.0.
5+
16
## 1.1.3
27

38
* Require Dart SDK `^3.4.0`.

pkgs/bazel_worker/e2e_test/lib/async_worker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:bazel_worker/bazel_worker.dart';
1212
class ExampleAsyncWorker extends AsyncWorkerLoop {
1313
/// Set [sendPort] to run in an isolate.
1414
ExampleAsyncWorker([SendPort? sendPort])
15-
: super(connection: AsyncWorkerConnection(sendPort: sendPort));
15+
: super(connection: AsyncWorkerConnection(sendPort: sendPort));
1616

1717
@override
1818
Future<WorkResponse> performRequest(WorkRequest request) async {

pkgs/bazel_worker/e2e_test/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
name: e2e_test
22
publish_to: none
33

4+
resolution: workspace
5+
46
environment:
5-
sdk: ^3.4.0
7+
sdk: ^3.9.0
68

79
dependencies:
8-
bazel_worker:
9-
path: ../
10+
bazel_worker: any
1011

1112
dev_dependencies:
1213
cli_util: ^0.4.2

pkgs/bazel_worker/example/client.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
15
import 'dart:io';
26

37
import 'package:bazel_worker/driver.dart';
48

59
void main() async {
610
var scratchSpace = await Directory.systemTemp.createTemp();
711
var driver = BazelWorkerDriver(
8-
() => Process.start(
9-
Platform.resolvedExecutable,
10-
[
11-
Platform.script.resolve('worker.dart').toFilePath(),
12-
],
13-
workingDirectory: scratchSpace.path),
12+
() => Process.start(Platform.resolvedExecutable, [
13+
Platform.script.resolve('worker.dart').toFilePath(),
14+
], workingDirectory: scratchSpace.path),
1415
maxWorkers: 4,
1516
);
1617
var response = await driver.doWork(WorkRequest(arguments: ['foo']));

pkgs/bazel_worker/example/worker.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
15
import 'dart:io';
26
import 'package:bazel_worker/bazel_worker.dart';
37

pkgs/bazel_worker/lib/src/async_message_grouper.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ class AsyncMessageGrouper implements MessageGrouper {
4141
int _messagePos = 0;
4242

4343
AsyncMessageGrouper(Stream<List<int>> inputStream)
44-
: _inputQueue = StreamQueue(inputStream);
44+
: _inputQueue = StreamQueue(inputStream);
4545

4646
/// Returns the next full message that is received, or null if none are left.
4747
@override
4848
Future<List<int>?> get next async {
4949
try {
5050
// Loop while there is data in the input buffer or the input stream.
51-
while (
52-
_inputBufferPos != _inputBuffer.length || await _inputQueue.hasNext) {
51+
while (_inputBufferPos != _inputBuffer.length ||
52+
await _inputQueue.hasNext) {
5353
// If the input buffer is empty fill it from the input stream.
5454
if (_inputBufferPos == _inputBuffer.length) {
5555
_inputBuffer = await _inputQueue.next;

pkgs/bazel_worker/lib/src/driver/driver.dart

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class BazelWorkerDriver {
4949
int? maxIdleWorkers,
5050
int? maxWorkers,
5151
int? maxRetries,
52-
}) : _maxIdleWorkers = maxIdleWorkers ?? 4,
53-
_maxWorkers = maxWorkers ?? 4,
54-
_maxRetries = maxRetries ?? 4;
52+
}) : _maxIdleWorkers = maxIdleWorkers ?? 4,
53+
_maxWorkers = maxWorkers ?? 4,
54+
_maxRetries = maxRetries ?? 4;
5555

5656
/// Waits for an available worker, and then sends [WorkRequest] to it.
5757
///
@@ -111,29 +111,31 @@ class BazelWorkerDriver {
111111
// work queue.
112112
var futureWorker = _spawnWorker();
113113
_spawningWorkers.add(futureWorker);
114-
futureWorker.then((worker) {
115-
_spawningWorkers.remove(futureWorker);
116-
_readyWorkers.add(worker);
117-
var connection = StdDriverConnection.forWorker(worker);
118-
_workerConnections[worker] = connection;
119-
_runWorker(worker, attempt);
120-
121-
// When the worker exits we should retry running the work queue in case
122-
// there is more work to be done. This is primarily just a defensive
123-
// thing but is cheap to do.
124-
//
125-
// We don't use `exitCode` because it is null for detached processes (
126-
// which is common for workers).
127-
connection.done.then((_) {
128-
_idleWorkers.remove(worker);
129-
_readyWorkers.remove(worker);
130-
_runWorkQueue();
131-
});
132-
}).onError<Object>((e, s) {
133-
_spawningWorkers.remove(futureWorker);
134-
if (attempt.responseCompleter.isCompleted) return;
135-
attempt.responseCompleter.completeError(e, s);
136-
});
114+
futureWorker
115+
.then((worker) {
116+
_spawningWorkers.remove(futureWorker);
117+
_readyWorkers.add(worker);
118+
var connection = StdDriverConnection.forWorker(worker);
119+
_workerConnections[worker] = connection;
120+
_runWorker(worker, attempt);
121+
122+
// When the worker exits we should retry running the work queue in case
123+
// there is more work to be done. This is primarily just a defensive
124+
// thing but is cheap to do.
125+
//
126+
// We don't use `exitCode` because it is null for detached processes (
127+
// which is common for workers).
128+
connection.done.then((_) {
129+
_idleWorkers.remove(worker);
130+
_readyWorkers.remove(worker);
131+
_runWorkQueue();
132+
});
133+
})
134+
.onError<Object>((e, s) {
135+
_spawningWorkers.remove(futureWorker);
136+
if (attempt.responseCompleter.isCompleted) return;
137+
attempt.responseCompleter.completeError(e, s);
138+
});
137139
}
138140
// Recursively calls itself until one of the bail out conditions are met.
139141
_runWorkQueue();

pkgs/bazel_worker/lib/src/driver/driver_connection.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class StdDriverConnection implements DriverConnection {
3737
StdDriverConnection({
3838
Stream<List<int>>? inputStream,
3939
StreamSink<List<int>>? outputStream,
40-
}) : _messageGrouper = AsyncMessageGrouper(inputStream ?? stdin),
41-
_outputStream = outputStream ?? stdout;
40+
}) : _messageGrouper = AsyncMessageGrouper(inputStream ?? stdin),
41+
_outputStream = outputStream ?? stdout;
4242

4343
factory StdDriverConnection.forWorker(Process worker) => StdDriverConnection(
44-
inputStream: worker.stdout,
45-
outputStream: worker.stdin,
46-
);
44+
inputStream: worker.stdout,
45+
outputStream: worker.stdin,
46+
);
4747

4848
/// Note: This will attempts to recover from invalid proto messages by parsing
4949
/// them as strings. This is a common error case for workers (they print a

pkgs/bazel_worker/lib/src/message_grouper_state.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ class _MessageReader {
109109
int _numMessageBytesReceived = 0;
110110

111111
_MessageReader(int length)
112-
: _message = Uint8List(length),
113-
_length = length,
114-
_done = length == 0;
112+
: _message = Uint8List(length),
113+
_length = length,
114+
_done = length == 0;
115115

116116
/// Reads [byte] into [_message].
117117
void readByte(int byte) {

0 commit comments

Comments
 (0)