Skip to content

Commit b34704d

Browse files
authored
build_daemon: drop pkg:uuid dev_dep (#3722)
Just inline a simple version from somewhere else
1 parent b3d3ef1 commit b34704d

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

build_daemon/pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ dev_dependencies:
2929
mockito: ^5.0.0
3030
test: ^1.25.5
3131
test_descriptor: ^2.0.0
32-
uuid: ^3.0.0
3332

3433
topics:
3534
- build-runner

build_daemon/test/daemon_test.dart

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import 'package:build_daemon/src/fakes/fake_builder.dart';
1717
import 'package:build_daemon/src/fakes/fake_change_provider.dart';
1818
import 'package:test/test.dart';
1919
import 'package:test_descriptor/test_descriptor.dart' as d;
20-
import 'package:uuid/uuid.dart';
20+
21+
import 'uuid.dart';
2122

2223
final defaultIdleTimeoutSec = defaultIdleTimeout.inSeconds;
2324
void main() {
2425
var testDaemons = <Process>[];
2526
var testWorkspaces = <String>[];
26-
var uuid = const Uuid();
2727
group('Daemon', () {
2828
setUp(() {
2929
testDaemons.clear();
@@ -41,7 +41,7 @@ void main() {
4141
}
4242
});
4343
test('can be stopped', () async {
44-
var workspace = uuid.v1();
44+
var workspace = generateV4UUID();
4545
testWorkspaces.add(workspace);
4646
var daemon = Daemon(workspace);
4747
await daemon.start(
@@ -53,20 +53,20 @@ void main() {
5353
await daemon.stop();
5454
});
5555
test('can run if no other daemon is running', () async {
56-
var workspace = uuid.v1();
56+
var workspace = generateV4UUID();
5757
var daemon = await _runDaemon(workspace);
5858
testDaemons.add(daemon);
5959
expect(await _statusOf(daemon), 'RUNNING');
6060
});
6161
test('shuts down if no client connects', () async {
62-
var workspace = uuid.v1();
62+
var workspace = generateV4UUID();
6363
var daemon = await _runDaemon(workspace, timeout: 1);
6464
testDaemons.add(daemon);
6565
expect(await daemon.exitCode, isNotNull);
6666
});
6767
test('can not run if another daemon is running in the same workspace',
6868
() async {
69-
var workspace = uuid.v1();
69+
var workspace = generateV4UUID();
7070
testWorkspaces.add(workspace);
7171
var daemonOne =
7272
await _runDaemon(workspace, timeout: defaultIdleTimeoutSec * 2);
@@ -77,8 +77,8 @@ void main() {
7777
}, timeout: const Timeout.factor(2));
7878
test('can run if another daemon is running in a different workspace',
7979
() async {
80-
var workspace1 = uuid.v1();
81-
var workspace2 = uuid.v1();
80+
var workspace1 = generateV4UUID();
81+
var workspace2 = generateV4UUID();
8282
testWorkspaces.addAll([workspace1, workspace2]);
8383
var daemonOne = await _runDaemon(workspace1);
8484
expect(await _statusOf(daemonOne), 'RUNNING');
@@ -87,7 +87,7 @@ void main() {
8787
expect(await _statusOf(daemonTwo), 'RUNNING');
8888
}, timeout: const Timeout.factor(2));
8989
test('can start two daemons at the same time', () async {
90-
var workspace = uuid.v1();
90+
var workspace = generateV4UUID();
9191
testWorkspaces.add(workspace);
9292
var daemonOne = await _runDaemon(workspace);
9393
expect(await _statusOf(daemonOne), 'RUNNING');
@@ -96,20 +96,20 @@ void main() {
9696
testDaemons.addAll([daemonOne, daemonTwo]);
9797
}, timeout: const Timeout.factor(2));
9898
test('logs the version when running', () async {
99-
var workspace = uuid.v1();
99+
var workspace = generateV4UUID();
100100
testWorkspaces.add(workspace);
101101
var daemon = await _runDaemon(workspace);
102102
testDaemons.add(daemon);
103103
expect(await _statusOf(daemon), 'RUNNING');
104104
expect(await Daemon(workspace).runningVersion(), currentVersion);
105105
});
106106
test('does not set the current version if not running', () async {
107-
var workspace = uuid.v1();
107+
var workspace = generateV4UUID();
108108
testWorkspaces.add(workspace);
109109
expect(await Daemon(workspace).runningVersion(), null);
110110
});
111111
test('logs the options when running', () async {
112-
var workspace = uuid.v1();
112+
var workspace = generateV4UUID();
113113
testWorkspaces.add(workspace);
114114
var daemon = await _runDaemon(workspace);
115115
testDaemons.add(daemon);
@@ -118,12 +118,12 @@ void main() {
118118
(await Daemon(workspace).currentOptions()).contains('foo'), isTrue);
119119
});
120120
test('does not log the options if not running', () async {
121-
var workspace = uuid.v1();
121+
var workspace = generateV4UUID();
122122
testWorkspaces.add(workspace);
123123
expect((await Daemon(workspace).currentOptions()).isEmpty, isTrue);
124124
});
125125
test('cleans up after itself', () async {
126-
var workspace = uuid.v1();
126+
var workspace = generateV4UUID();
127127
testWorkspaces.add(workspace);
128128
var daemon = await _runDaemon(workspace);
129129
// Wait for the daemon to be running before checking the workspace exits.
@@ -135,7 +135,7 @@ void main() {
135135
expect(Directory(daemonWorkspace(workspace)).existsSync(), isFalse);
136136
});
137137
test('daemon stops after file changes stream has error', () async {
138-
var workspace = uuid.v1();
138+
var workspace = generateV4UUID();
139139
testWorkspaces.add(workspace);
140140
var daemon =
141141
await _runDaemon(workspace, errorChangeProviderAfterNSeconds: 1);
@@ -144,7 +144,7 @@ void main() {
144144
expect(Directory(daemonWorkspace(workspace)).existsSync(), isFalse);
145145
});
146146
test('daemon stops after file changes stream is closed', () async {
147-
var workspace = uuid.v1();
147+
var workspace = generateV4UUID();
148148
testWorkspaces.add(workspace);
149149
var daemon =
150150
await _runDaemon(workspace, closeChangeProviderAfterNSeconds: 1);

build_daemon/test/uuid.dart

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2024, 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+
5+
// Copied from https://github.com/dart-lang/sdk/blob/9d28b1eb9f9cfb7331fef25238be5cba593e37ac/pkg/frontend_server/lib/src/uuid.dart
6+
7+
import 'dart:math' show Random;
8+
9+
/// A UUID generator.
10+
///
11+
/// The generated values are 128 bit numbers encoded in a specific string
12+
/// format.
13+
///
14+
/// Generate a version 4 (random) uuid. This is a uuid scheme that only uses
15+
/// random numbers as the source of the generated uuid.
16+
// TODO: replace with a MUCH more simple, random string that matches
17+
// the use case.
18+
String generateV4UUID() {
19+
var special = 8 + _random.nextInt(4);
20+
21+
return '${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}-'
22+
'${_bitsDigits(16, 4)}-'
23+
'4${_bitsDigits(12, 3)}-'
24+
'${_printDigits(special, 1)}${_bitsDigits(12, 3)}-'
25+
'${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}${_bitsDigits(16, 4)}';
26+
}
27+
28+
final Random _random = Random();
29+
30+
String _bitsDigits(int bitCount, int digitCount) =>
31+
_printDigits(_generateBits(bitCount), digitCount);
32+
33+
int _generateBits(int bitCount) => _random.nextInt(1 << bitCount);
34+
35+
String _printDigits(int value, int count) =>
36+
value.toRadixString(16).padLeft(count, '0');

build_runner/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ $ dart run test
234234

235235
[Bazel]: https://bazel.build/
236236
[`package:build`]: https://pub.dev/packages/build
237-
[analysis_options]: https://github.com/dart-lang/build/blob/master/analysis/analysis_options.yaml
237+
[analysis_options]: https://github.com/dart-lang/build/blob/master/analysis_options.yaml
238238

239239
[builder]: https://pub.dev/documentation/build/latest/build/Builder-class.html
240240
[run_fn]: https://pub.dev/documentation/build_runner/latest/build_runner/run.html

0 commit comments

Comments
 (0)