Home | History | Annotate | Download | only in libbuildversion
      1 /*
      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 
     23 namespace android {
     24 namespace build {
     25 
     26 #ifdef __ANDROID__
     27 
     28 std::string GetBuildNumber() {
     29   const prop_info* pi = __system_property_find("ro.build.version.incremental");
     30   if (pi == nullptr) return "";
     31 
     32   std::string property_value;
     33   __system_property_read_callback(pi,
     34                                   [](void* cookie, const char*, const char* value, unsigned) {
     35                                     auto property_value = reinterpret_cast<std::string*>(cookie);
     36                                     *property_value = value;
     37                                   },
     38                                   &property_value);
     39 
     40   return property_value;
     41 }
     42 
     43 #else
     44 
     45 extern "C" {
     46   char soong_build_number[128] = "SOONG BUILD NUMBER PLACEHOLDER";
     47 }
     48 
     49 std::string GetBuildNumber() {
     50   return soong_build_number;
     51 }
     52 
     53 #endif
     54 }  // namespace build
     55 }  // namespace android
     56