Skip to content

Commit 1bbbc9f

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/aot] Check in test to ensure in PRODUCT mode we don't retain any code in dart:vmservice_io/dart:_vmservice
The CL also updates a number of pragma annotations to be conditional on non-product mode. Change-Id: Ia00b5089d54bbb8f6f6006ef67d65859ab56c132 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127004 Reviewed-by: Vyacheslav Egorov <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent eec49f3 commit 1bbbc9f

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2019, 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+
// This test ensures that certain core libraries are "empty" in product mode (thereby
6+
// ensuring the right conditional pragma annotations were used).
7+
8+
import "dart:async";
9+
import "dart:io";
10+
11+
import 'package:path/path.dart' as path;
12+
import 'package:kernel/kernel.dart';
13+
import 'package:expect/expect.dart';
14+
15+
import 'use_bare_instructions_flag_test.dart' show run, withTempDir;
16+
17+
const platformFilename = 'vm_platform_strong.dill';
18+
19+
Future main(List<String> args) async {
20+
final buildDir = path.dirname(Platform.resolvedExecutable);
21+
22+
if (!buildDir.contains('Product')) {
23+
print('Skipping test due to running in non-PRODUCT configuration.');
24+
return;
25+
}
26+
27+
if (Platform.isAndroid) {
28+
print('Skipping test due missing "$platformFilename".');
29+
return;
30+
}
31+
32+
final platformDill = path.join(buildDir, platformFilename);
33+
await withTempDir((String tempDir) async {
34+
final helloFile = path.join(tempDir, 'hello.dart');
35+
final helloDillFile = path.join(tempDir, 'hello.dart.dill');
36+
37+
// Compile script to Kernel IR.
38+
await File(helloFile).writeAsString('main() => print("Hello");');
39+
await run('pkg/vm/tool/gen_kernel', <String>[
40+
'--aot',
41+
'--platform=$platformDill',
42+
'-o',
43+
helloDillFile,
44+
helloFile,
45+
]);
46+
47+
// Ensure the AOT dill file will have effectively empty service related
48+
// libraries.
49+
final Component component = loadComponentFromBinary(helloDillFile);
50+
51+
final libVmService = component.libraries
52+
.singleWhere((lib) => lib.importUri.toString() == 'dart:_vmservice');
53+
Expect.isTrue(libVmService.procedures.isEmpty);
54+
Expect.isTrue(libVmService.classes.isEmpty);
55+
Expect.isTrue(libVmService.fields.isEmpty);
56+
57+
final libVmServiceIo = component.libraries
58+
.singleWhere((lib) => lib.importUri.toString() == 'dart:vmservice_io');
59+
Expect.isTrue(libVmServiceIo.procedures.isEmpty);
60+
Expect.isTrue(libVmServiceIo.classes.isEmpty);
61+
62+
// Those fields are currently accessed by by the embedder, even in product
63+
// mode.
64+
Expect.isTrue(libVmServiceIo.fields.length <= 11);
65+
});
66+
}

sdk/lib/vmservice/vmservice.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ class VMService extends MessageRouter {
650650
}
651651
}
652652

653-
@pragma("vm:entry-point", "call")
653+
@pragma("vm:entry-point",
654+
const bool.fromEnvironment("dart.vm.product") ? false : "call")
654655
RawReceivePort boot() {
655656
// Return the port we expect isolate control messages on.
656657
return isolateControlPort;

sdk_nnbd/lib/vmservice/vmservice.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ class VMService extends MessageRouter {
650650
}
651651
}
652652

653-
@pragma("vm:entry-point", "call")
653+
@pragma("vm:entry-point",
654+
const bool.fromEnvironment("dart.vm.product") ? false : "call")
654655
RawReceivePort boot() {
655656
// Return the port we expect isolate control messages on.
656657
return isolateControlPort;

0 commit comments

Comments
 (0)