From 1bbbc9f599ad9c1c95be4e696011eb1253933609 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Wed, 4 Dec 2019 15:30:58 +0000 Subject: [PATCH] [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 Commit-Queue: Martin Kustermann --- .../vm/dart/product_aot_kernel_test.dart | 66 +++++++++++++++++++ sdk/lib/vmservice/vmservice.dart | 3 +- sdk_nnbd/lib/vmservice/vmservice.dart | 3 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 runtime/tests/vm/dart/product_aot_kernel_test.dart diff --git a/runtime/tests/vm/dart/product_aot_kernel_test.dart b/runtime/tests/vm/dart/product_aot_kernel_test.dart new file mode 100644 index 000000000000..82198a186d14 --- /dev/null +++ b/runtime/tests/vm/dart/product_aot_kernel_test.dart @@ -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 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', [ + '--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); + }); +} diff --git a/sdk/lib/vmservice/vmservice.dart b/sdk/lib/vmservice/vmservice.dart index 3c5bcbe8a648..410406ca0941 100644 --- a/sdk/lib/vmservice/vmservice.dart +++ b/sdk/lib/vmservice/vmservice.dart @@ -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; diff --git a/sdk_nnbd/lib/vmservice/vmservice.dart b/sdk_nnbd/lib/vmservice/vmservice.dart index c1540ab9835c..aa7878fb1164 100644 --- a/sdk_nnbd/lib/vmservice/vmservice.dart +++ b/sdk_nnbd/lib/vmservice/vmservice.dart @@ -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;