What Is Art.go? And Why Is It Considered A Way To Write Conditionals In Bp Files?
I am trying to find a way to write a conditional inside a .bp file. I found a documentation here: https://android.googlesource.com/platform/build/soong/+/HEAD/README.md It has a 'H
Solution 1:
In your project folder, create a "my_defaults.go" file, where you can define the logic that adds custom build flags based on environment variables or other conditions (which is basically what happens in the art.go that was given as an example).
package my_defaults
import (
"android/soong/android""android/soong/cc"
)
funcglobalFlags(ctx android.BaseContext) []string {
var cflags []stringif ctx.AConfig().Getenv("SOME_ENV_VAR") == "some_value" {
cflags = append(cflags, "-DCONDITIONAL")
}
return cflags
}
funcdeviceFlags(ctx android.BaseContext) []string {
var cflags []stringreturn cflags
}
funchostFlags(ctx android.BaseContext) []string {
var cflags []stringreturn cflags
}
funcmyDefaults(ctx android.LoadHookContext) {
type props struct {
Target struct {
Android struct {
Cflags []string
Enabled *bool
}
Host struct {
Enabled *bool
}
Linux struct {
Cflags []string
}
Darwin struct {
Cflags []string
}
}
Cflags []string
}
p := &props{}
p.Cflags = globalFlags(ctx)
p.Target.Android.Cflags = deviceFlags(ctx)
h := hostFlags(ctx)
p.Target.Linux.Cflags = h
p.Target.Darwin.Cflags = h
ctx.AppendProperties(p)
}
funcinit() {
android.RegisterModuleType("my_defaults", myDefaultsFactory)
}
funcmyDefaultsFactory() android.Module {
module := cc.DefaultsFactory()
android.AddLoadHook(module, myDefaults)
return module
}
In your Android.bp, declare the following module:
bootstrap_go_package {
name: "soong-my_defaults",
pkgPath: "android/soong/my/defaults",
deps: [
"soong",
"soong-android",
"soong-cc"
],
srcs: [
"my_defaults.go"
],
pluginFor: ["soong_build"]
}
You can then use "my_defaults" instead of the usual "cc_defaults" in your Android.bp, e.g.
my_defaults {
name: "my-defaults-instance"// Set some additional non-conditional cflags ...
}
cc_binary {
name: "my_binary",
defaults: ["my-defaults-instance"]
}
Post a Comment for "What Is Art.go? And Why Is It Considered A Way To Write Conditionals In Bp Files?"