Skip to content

Commit 97a09b9

Browse files
sstricklCommit Queue
authored and
Commit Queue
committed
[sdk] Add NativeRuntime.buildId to dart:developer.
TEST=vm/dart/build_id Issue: #51941 CoreLibraryReviewExempt: Native runtime only API Change-Id: Ib3757480f0eab6d147385a87adf657f4f709ec4e Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-win-release-x64-try,vm-aot-win-product-x64-try,vm-aot-win-debug-x64c-try,vm-aot-android-release-arm_x64-try,vm-fuchsia-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307122 Reviewed-by: Slava Egorov <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Tess Strickland <[email protected]> Reviewed-by: Lasse Nielsen <[email protected]>
1 parent 1c3011c commit 97a09b9

File tree

8 files changed

+66
-0
lines changed

8 files changed

+66
-0
lines changed

runtime/lib/developer.cc

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "vm/object_store.h"
1919
#include "vm/service.h"
2020
#include "vm/service_isolate.h"
21+
#include "vm/zone_text_buffer.h"
2122

2223
namespace dart {
2324

@@ -179,6 +180,25 @@ DEFINE_NATIVE_ENTRY(Developer_reachability_barrier, 0, 0) {
179180
#endif
180181
}
181182

183+
DEFINE_NATIVE_ENTRY(Developer_NativeRuntime_buildId, 0, 0) {
184+
#if defined(DART_PRECOMPILED_RUNTIME)
185+
IsolateGroup* isolate_group = thread->isolate_group();
186+
ASSERT(isolate_group != nullptr);
187+
if (const uint8_t* instructions =
188+
isolate_group->source()->snapshot_instructions) {
189+
const auto& build_id = OS::GetAppBuildId(instructions);
190+
if (build_id.data != nullptr) {
191+
ZoneTextBuffer buffer(zone);
192+
for (intptr_t i = 0; i < build_id.len; i++) {
193+
buffer.Printf("%2.2x", build_id.data[i]);
194+
}
195+
return String::New(buffer.buffer());
196+
}
197+
}
198+
#endif
199+
return String::null();
200+
}
201+
182202
DEFINE_NATIVE_ENTRY(Developer_NativeRuntime_writeHeapSnapshotToFile, 0, 1) {
183203
#if defined(DART_ENABLE_HEAP_SNAPSHOT_WRITER)
184204
const String& filename =
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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:developer';
6+
7+
import 'package:expect/expect.dart';
8+
9+
import 'use_flag_test_helper.dart';
10+
11+
void main() {
12+
final buildId = NativeRuntime.buildId;
13+
if (isAOTRuntime) {
14+
Expect.isNotNull(buildId);
15+
Expect.isTrue(buildId!.isNotEmpty, 'Build ID is an empty string');
16+
} else {
17+
Expect.isNull(buildId); // Should be null in JIT mode.
18+
}
19+
print(buildId);
20+
}

runtime/vm/bootstrap_natives.h

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ namespace dart {
7878
V(Developer_log, 8) \
7979
V(Developer_postEvent, 2) \
8080
V(Developer_webServerControl, 3) \
81+
V(Developer_NativeRuntime_buildId, 0) \
8182
V(Developer_NativeRuntime_writeHeapSnapshotToFile, 1) \
8283
V(Developer_reachability_barrier, 0) \
8384
V(Double_getIsNegative, 1) \

sdk/lib/_internal/js_dev_runtime/patch/developer_patch.dart

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ UserTag getCurrentTag() => _currentTag;
233233

234234
@patch
235235
abstract final class NativeRuntime {
236+
@patch
237+
static String? get buildId => null;
238+
236239
@patch
237240
static void writeHeapSnapshotToFile(String filepath) =>
238241
throw UnsupportedError(

sdk/lib/_internal/js_runtime/lib/developer_patch.dart

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ UserTag getCurrentTag() => _currentTag;
153153

154154
@patch
155155
abstract final class NativeRuntime {
156+
@patch
157+
static String? get buildId => null;
158+
156159
@patch
157160
static void writeHeapSnapshotToFile(String filepath) =>
158161
throw UnsupportedError(

sdk/lib/_internal/vm/lib/developer.dart

+4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ external String _getIsolateIDFromSendPort(SendPort sendPort);
181181

182182
@patch
183183
abstract final class NativeRuntime {
184+
@patch
185+
@pragma("vm:external-name", "Developer_NativeRuntime_buildId")
186+
external static String? get buildId;
187+
184188
@patch
185189
@pragma("vm:external-name", "Developer_NativeRuntime_writeHeapSnapshotToFile")
186190
external static void writeHeapSnapshotToFile(String filepath);

sdk/lib/_internal/wasm/lib/developer.dart

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ void _reportTaskEvent(
6060

6161
@patch
6262
abstract final class NativeRuntime {
63+
@patch
64+
static String? get buildId => null;
65+
6366
@patch
6467
static void writeHeapSnapshotToFile(String filepath) =>
6568
throw UnsupportedError(

sdk/lib/developer/developer.dart

+12
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ external int get reachabilityBarrier;
143143

144144
/// Functionality available on the native runtime.
145145
abstract final class NativeRuntime {
146+
/// The build ID for the running application.
147+
///
148+
/// The build ID of an application is a string containing a hexadecimal
149+
/// representation of an arbitrarily sized sequence of bytes. This string
150+
/// can be used to match a specific ahead-of-time compiled version of an
151+
/// application, for example, to determine which debugging artifacts emitted
152+
/// during compilation should be used to translate crash and error reports.
153+
///
154+
/// The build ID is only available for ahead-of-time compiled programs. If a
155+
/// build ID is not available, the value is `null`.
156+
external static String? get buildId;
157+
146158
/// Writes a snapshot of the heap to [filepath].
147159
///
148160
/// The [filepath] should be a native file path that can be opened for writing.

0 commit comments

Comments
 (0)