Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86803cfe authored by Colin Cross's avatar Colin Cross
Browse files

add a library to report build numbers without causing rebuilds

Allow native modules to specify use_version_lib, which will make
an android::build::GetBuildNumber() function available.  For host
builds, the function will return the build number at the time that
the module was linked.  For device modules it will return the
value of the ro.build.version.incremental property.

Bug: 71719137
Test: build_version_test
Test: m build_version_test && touch build/make/core/Makefile build/soong/cc/libbuildversion/tests/build_version_test.cpp && m build_version_test shows different build numbers for binary and library tests.
Change-Id: I6f7d40b7574bb8206866c4e39bad9c710c796e32
parent 8673b5b9
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -323,6 +323,12 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
			flagsToBuilderFlags(flags), afterPrefixSymbols)
	}

	if Bool(binary.baseLinker.Properties.Use_version_lib) && ctx.Host() {
		versionedOutputFile := outputFile
		outputFile = android.PathForModuleOut(ctx, "unversioned", fileName)
		binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
	}

	linkerDeps = append(linkerDeps, deps.SharedLibsDeps...)
	linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
	linkerDeps = append(linkerDeps, objs.tidyFiles...)
+12 −0
Original line number Diff line number Diff line
cc_library_static {
    name: "libbuildversion",
    host_supported: true,
    srcs: ["libbuildversion.cpp"],
    export_include_dirs: ["include"],
    cflags: ["-fvisibility=hidden"],
    target: {
        windows: {
            enabled: true,
        },
    },
}
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef BUILD_VERSION_H
#define BUILD_VERSION_H

#include <string>

namespace android {
namespace build {

std::string GetBuildNumber();

} // namespace build
} // namespace android

#endif  // BUILD_VERSION_H
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <build/version.h>

#ifdef __ANDROID__
#include <sys/system_properties.h>
#endif

namespace android {
namespace build {

#ifdef __ANDROID__

std::string GetBuildNumber() {
  const prop_info* pi = __system_property_find("ro.build.version.incremental");
  if (pi == nullptr) return "";

  std::string property_value;
  __system_property_read_callback(pi,
                                  [](void* cookie, const char*, const char* value, unsigned) {
                                    auto property_value = reinterpret_cast<std::string*>(cookie);
                                    *property_value = value;
                                  },
                                  &property_value);

  return property_value;
}

#else

extern "C" {
  char soong_build_number[128] = "SOONG BUILD NUMBER PLACEHOLDER";
}

std::string GetBuildNumber() {
  return soong_build_number;
}

#endif
}  // namespace build
}  // namespace android
+35 −0
Original line number Diff line number Diff line
cc_defaults {
    name: "build_version_test_defaults",
    use_version_lib: true,
    host_supported: true,
    target: {
        windows: {
            enabled: true,
        },
    },
}

cc_test {
    name: "build_version_test",
    defaults: ["build_version_test_defaults"],
    srcs: ["build_version_test.cpp"],
    target: {
        android: {
            shared_libs: ["libbuild_version_test"],
        },
        not_windows: {
            shared_libs: ["libbuild_version_test"],
        },
    },
}

cc_library_shared {
    name: "libbuild_version_test",
    defaults: ["build_version_test_defaults"],
    srcs: ["build_version_test_lib.cpp"],
    target: {
        windows: {
            enabled: false,
        },
    },
}
Loading