Skip to content

Commit a32d37e

Browse files
Dan ChevalierCommit Queue
Dan Chevalier
authored and
Commit Queue
committed
Initial implementation of Dart Tooling Daemon server
This will contain the code for running the DTD server. When this is fully funcitonal VSCode will be responsible for running the, and letting our other tools(i.e. DevTools) know which address it is running at. Change-Id: Ia4cc9553f000a5e765f604541f4846b107d4d00c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338501 Commit-Queue: Dan Chevalier <[email protected]> Reviewed-by: Devon Carew <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
1 parent d0b6ce5 commit a32d37e

File tree

8 files changed

+162
-0
lines changed

8 files changed

+162
-0
lines changed

pkg/dtd_impl/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
4+
bin/dtd_server

pkg/dtd_impl/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
- Initial version.

pkg/dtd_impl/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2023, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkg/dtd_impl/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The server implementation for the Dart Tooling Daemon. This is meant to be run
2+
by our internal tooling and facilitates communication between our internal
3+
tools.
4+
5+
# Running the sample
6+
7+
## Running with the Dart SDK
8+
9+
You can run the example with the [Dart SDK](https://dart.dev/get-dart)
10+
like this:
11+
12+
```
13+
$ dart run bin/dtd_server.dart
14+
The Dart Tooling Daemon is listening on 0.0.0.0:8080
15+
```
16+
17+
## Compiling the binary
18+
19+
`dart compile exe bin/dtd_server.dart -o bin/dtd_server`

pkg/dtd_impl/analysis_options.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include: package:lints/recommended.yaml
2+
3+
linter:
4+
rules:
5+
- avoid_void_async
6+
- unawaited_futures

pkg/dtd_impl/bin/dtd_server.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2023, 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+
import 'dart:io';
6+
7+
import 'package:shelf/shelf.dart';
8+
import 'package:shelf/shelf_io.dart';
9+
import 'package:shelf_router/shelf_router.dart';
10+
11+
// Configure routes.
12+
final _router = Router()
13+
..get('/', _rootHandler)
14+
..get('/echo/<message>', _echoHandler);
15+
16+
Response _rootHandler(Request req) {
17+
return Response.ok('Hello, World!\n');
18+
}
19+
20+
Response _echoHandler(Request request) {
21+
final message = request.params['message'];
22+
return Response.ok('$message\n');
23+
}
24+
25+
void main(List<String> args) async {
26+
// Use any available host or container IP (usually `0.0.0.0`).
27+
final ip = InternetAddress.anyIPv4;
28+
29+
// Configure a pipeline that logs requests.
30+
final handler =
31+
Pipeline().addMiddleware(logRequests()).addHandler(_router.call);
32+
33+
// For running in containers, we respect the PORT environment variable.
34+
final port = int.parse(Platform.environment['PORT'] ?? '8080');
35+
final server = await serve(handler, ip, port);
36+
print(
37+
'The Dart Tooling Daemon is listening on ${server.address.host}:${server.port}',
38+
);
39+
}

pkg/dtd_impl/pubspec.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: dtd_impl
2+
description: A server app using the shelf package and Docker.
3+
repository: https://github.com/dart-lang/sdk/tree/main/pkg/dtd_impl
4+
publish_to: none
5+
6+
environment:
7+
sdk: ^3.3.0-152.0.dev
8+
9+
# Use 'any' constraints here; we get our versions from the DEPS file.
10+
dependencies:
11+
shelf: any
12+
shelf_router: any
13+
# We use 'any' version constraints here as we get our package versions from
14+
# the dart-lang/sdk repo's DEPS file. Note that this is a special case; the
15+
# best practice for packages is to specify their compatible version ranges.
16+
# See also https://dart.dev/tools/pub/dependencies.
17+
# dev_dependencies:
18+
# http: any
19+
# lints: any
20+
# test: any

pkg/dtd_impl/test/server_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2023, 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+
// TODO(danchevalier) make these tests relevant.
6+
// import 'dart:io';
7+
8+
// import 'package:http/http.dart';
9+
// import 'package:test/test.dart';
10+
11+
void main() {
12+
// final port = '8080';
13+
// final host = 'http://0.0.0.0:$port';
14+
// late Process p;
15+
16+
// setUp(() async {
17+
// p = await Process.start(
18+
// 'dart',
19+
// ['run', 'bin/dtd_server.dart'],
20+
// environment: {'PORT': port},
21+
// );
22+
// // Wait for server to start and print to stdout.
23+
// await p.stdout.first;
24+
// });
25+
26+
// tearDown(() => p.kill());
27+
28+
// test('Root', () async {
29+
// final response = await get(Uri.parse('$host/'));
30+
// expect(response.statusCode, 200);
31+
// expect(response.body, 'Hello, World!\n');
32+
// });
33+
34+
// test('Echo', () async {
35+
// final response = await get(Uri.parse('$host/echo/hello'));
36+
// expect(response.statusCode, 200);
37+
// expect(response.body, 'hello\n');
38+
// });
39+
40+
// test('404', () async {
41+
// final response = await get(Uri.parse('$host/foobar'));
42+
// expect(response.statusCode, 404);
43+
// });
44+
}

0 commit comments

Comments
 (0)