blob: 5242025eb4210f890c3ea57119849c56c6bdf664 [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
Colin Cross86803cf2018-02-15 14:12:26 -080039 const prop_info* pi = __system_property_find("ro.build.version.incremental");
40 if (pi == nullptr) return "";
41
42 std::string property_value;
43 __system_property_read_callback(pi,
44 [](void* cookie, const char*, const char* value, unsigned) {
45 auto property_value = reinterpret_cast<std::string*>(cookie);
46 *property_value = value;
47 },
48 &property_value);
49
50 return property_value;
51}
52
53#else
54
Colin Cross86803cf2018-02-15 14:12:26 -080055std::string GetBuildNumber() {
56 return soong_build_number;
57}
58
59#endif
60} // namespace build
61} // namespace android