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