aboutsummaryrefslogtreecommitdiffstats
path: root/cc/linker.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-02-15 14:12:26 -0800
committerColin Cross <ccross@android.com>2018-03-02 16:55:51 -0800
commit86803cfe6e814d3699e842cfc41244cd9a6e0c30 (patch)
treeddb07422dff2e413f4761eaa6dbc22be5ea966e9 /cc/linker.go
parent8673b5b959def87c0f3f5922b1eea430b1215b62 (diff)
downloadbuild_soong-86803cfe6e814d3699e842cfc41244cd9a6e0c30.tar.gz
build_soong-86803cfe6e814d3699e842cfc41244cd9a6e0c30.tar.bz2
build_soong-86803cfe6e814d3699e842cfc41244cd9a6e0c30.zip
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
Diffstat (limited to 'cc/linker.go')
-rw-r--r--cc/linker.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/cc/linker.go b/cc/linker.go
index fae55425..bcedc8da 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -18,6 +18,7 @@ import (
"android/soong/android"
"fmt"
+ "github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -95,6 +96,9 @@ type BaseLinkerProperties struct {
Exclude_static_libs []string
}
}
+
+ // make android::build:GetBuildNumber() available containing the build ID.
+ Use_version_lib *bool `android:"arch_variant"`
}
func NewBaseLinker() *baseLinker {
@@ -136,6 +140,10 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...)
+ if Bool(linker.Properties.Use_version_lib) {
+ deps.WholeStaticLibs = append(deps.WholeStaticLibs, "libbuildversion")
+ }
+
if ctx.useVndk() {
deps.SharedLibs = removeListFromList(deps.SharedLibs, linker.Properties.Target.Vendor.Exclude_shared_libs)
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, linker.Properties.Target.Vendor.Exclude_shared_libs)
@@ -278,3 +286,31 @@ func (linker *baseLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
panic(fmt.Errorf("baseLinker doesn't know how to link"))
}
+
+// Injecting version symbols
+// Some host modules want a version number, but we don't want to rebuild it every time. Optionally add a step
+// after linking that injects a constant placeholder with the current version number.
+
+func init() {
+ pctx.HostBinToolVariable("symbolInjectCmd", "symbol_inject")
+}
+
+var injectVersionSymbol = pctx.AndroidStaticRule("injectVersionSymbol",
+ blueprint.RuleParams{
+ Command: "$symbolInjectCmd -i $in -o $out -s soong_build_number " +
+ "-from 'SOONG BUILD NUMBER PLACEHOLDER' -v $buildNumberFromFile",
+ CommandDeps: []string{"$symbolInjectCmd"},
+ },
+ "buildNumberFromFile")
+
+func (linker *baseLinker) injectVersionSymbol(ctx ModuleContext, in android.Path, out android.WritablePath) {
+ ctx.Build(pctx, android.BuildParams{
+ Rule: injectVersionSymbol,
+ Description: "inject version symbol",
+ Input: in,
+ Output: out,
+ Args: map[string]string{
+ "buildNumberFromFile": ctx.Config().BuildNumberFromFile(),
+ },
+ })
+}