Skip to content

Commit

Permalink
[vm/aot] Check in test to ensure in PRODUCT mode we don't retain any …
Browse files Browse the repository at this point in the history
…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 <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
  • Loading branch information
mkustermann authored and commit-bot@chromium.org committed Dec 4, 2019
1 parent eec49f3 commit 1bbbc9f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
66 changes: 66 additions & 0 deletions runtime/tests/vm/dart/product_aot_kernel_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// This test ensures that certain core libraries are "empty" in product mode (thereby
// ensuring the right conditional pragma annotations were used).

import "dart:async";
import "dart:io";

import 'package:path/path.dart' as path;
import 'package:kernel/kernel.dart';
import 'package:expect/expect.dart';

import 'use_bare_instructions_flag_test.dart' show run, withTempDir;

const platformFilename = 'vm_platform_strong.dill';

Future main(List<String> args) async {
final buildDir = path.dirname(Platform.resolvedExecutable);

if (!buildDir.contains('Product')) {
print('Skipping test due to running in non-PRODUCT configuration.');
return;
}

if (Platform.isAndroid) {
print('Skipping test due missing "$platformFilename".');
return;
}

final platformDill = path.join(buildDir, platformFilename);
await withTempDir((String tempDir) async {
final helloFile = path.join(tempDir, 'hello.dart');
final helloDillFile = path.join(tempDir, 'hello.dart.dill');

// Compile script to Kernel IR.
await File(helloFile).writeAsString('main() => print("Hello");');
await run('pkg/vm/tool/gen_kernel', <String>[
'--aot',
'--platform=$platformDill',
'-o',
helloDillFile,
helloFile,
]);

// Ensure the AOT dill file will have effectively empty service related
// libraries.
final Component component = loadComponentFromBinary(helloDillFile);

final libVmService = component.libraries
.singleWhere((lib) => lib.importUri.toString() == 'dart:_vmservice');
Expect.isTrue(libVmService.procedures.isEmpty);
Expect.isTrue(libVmService.classes.isEmpty);
Expect.isTrue(libVmService.fields.isEmpty);

final libVmServiceIo = component.libraries
.singleWhere((lib) => lib.importUri.toString() == 'dart:vmservice_io');
Expect.isTrue(libVmServiceIo.procedures.isEmpty);
Expect.isTrue(libVmServiceIo.classes.isEmpty);

// Those fields are currently accessed by by the embedder, even in product
// mode.
Expect.isTrue(libVmServiceIo.fields.length <= 11);
});
}
3 changes: 2 additions & 1 deletion sdk/lib/vmservice/vmservice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ class VMService extends MessageRouter {
}
}

@pragma("vm:entry-point", "call")
@pragma("vm:entry-point",
const bool.fromEnvironment("dart.vm.product") ? false : "call")
RawReceivePort boot() {
// Return the port we expect isolate control messages on.
return isolateControlPort;
Expand Down
3 changes: 2 additions & 1 deletion sdk_nnbd/lib/vmservice/vmservice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ class VMService extends MessageRouter {
}
}

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

0 comments on commit 1bbbc9f

Please sign in to comment.