blob: 1e01c1145b244c13df27bf7327c697a17e883bb3 [file] [log] [blame]
Colin Cross86803cf2018-02-15 14:12:26 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <build/version.h>
18
19#ifdef __ANDROID__
20#include <sys/system_properties.h>
21#endif
22
23namespace android {
24namespace build {
25
Dan Willemsen569edc52018-11-19 09:33:29 -080026#define PLACEHOLDER "SOONG BUILD NUMBER PLACEHOLDER"
27
28extern "C" {
29 char soong_build_number[128] = PLACEHOLDER;
30}
31
Colin Cross86803cf2018-02-15 14:12:26 -080032#ifdef __ANDROID__
33
34std::string GetBuildNumber() {
Dan Willemsen569edc52018-11-19 09:33:29 -080035 if (strcmp(PLACEHOLDER, soong_build_number) != 0) {
36 return soong_build_number;
37 }
38
A. Cody Schuffelen580b93c2021-12-06 16:20:24 -080039#ifdef __ANDROID_VENDOR__
40 const prop_info* pi = __system_property_find("ro.vendor.build.version.incremental");
41#else
Colin Cross86803cf2018-02-15 14:12:26 -080042 const prop_info* pi = __system_property_find("ro.build.version.incremental");
A. Cody Schuffelen580b93c2021-12-06 16:20:24 -080043#endif
Colin Cross86803cf2018-02-15 14:12:26 -080044 if (pi == nullptr) return "";
45
46 std::string property_value;
47 __system_property_read_callback(pi,
48 [](void* cookie, const char*, const char* value, unsigned) {
49 auto property_value = reinterpret_cast<std::string*>(cookie);
50 *property_value = value;
51 },
52 &property_value);
53
54 return property_value;
55}
56
57#else
58
Colin Cross86803cf2018-02-15 14:12:26 -080059std::string GetBuildNumber() {
60 return soong_build_number;
61}
62
63#endif
64} // namespace build
65} // namespace android