2015-07-10 04:57:48 +08:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
package android
|
2015-07-10 04:57:48 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2015-11-25 09:53:15 +08:00
|
|
|
"runtime"
|
2015-07-10 04:57:48 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-10-13 05:38:15 +08:00
|
|
|
PreDepsMutators(func(ctx RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("variable", variableMutator).Parallel()
|
|
|
|
})
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type variableProperties struct {
|
|
|
|
Product_variables struct {
|
2015-09-17 07:48:54 +08:00
|
|
|
Platform_sdk_version struct {
|
|
|
|
Asflags []string
|
2017-05-09 04:43:00 +08:00
|
|
|
Cflags []string
|
2015-09-17 07:48:54 +08:00
|
|
|
}
|
2015-12-02 08:31:16 +08:00
|
|
|
|
|
|
|
// unbundled_build is a catch-all property to annotate modules that don't build in one or
|
|
|
|
// more unbundled branches, usually due to dependencies missing from the manifest.
|
|
|
|
Unbundled_build struct {
|
|
|
|
Enabled *bool `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2016-01-06 06:27:55 +08:00
|
|
|
|
|
|
|
Brillo struct {
|
2016-10-04 14:36:47 +08:00
|
|
|
Cflags []string
|
2016-01-06 06:27:55 +08:00
|
|
|
Version_script *string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2016-03-02 06:08:42 +08:00
|
|
|
|
|
|
|
Malloc_not_svelte struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
2016-05-13 09:04:18 +08:00
|
|
|
|
|
|
|
Safestack struct {
|
|
|
|
Cflags []string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2016-07-13 05:57:40 +08:00
|
|
|
|
2016-07-26 08:42:18 +08:00
|
|
|
Binder32bit struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
2016-09-23 05:49:10 +08:00
|
|
|
|
2017-05-03 01:58:50 +08:00
|
|
|
Device_uses_hwc2 struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
|
|
|
|
2017-05-05 04:57:05 +08:00
|
|
|
Override_rs_driver struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
|
|
|
|
2017-05-19 06:44:02 +08:00
|
|
|
// treble is true when a build is a Treble compliant device. This is automatically set when
|
|
|
|
// a build is shipped with Android O, but can be overriden. This controls such things as
|
|
|
|
// the sepolicy split and enabling the Treble linker namespaces.
|
|
|
|
Treble struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
|
|
|
|
2016-12-09 01:46:35 +08:00
|
|
|
// debuggable is true for eng and userdebug builds, and can be used to turn on additional
|
|
|
|
// debugging features that don't significantly impact runtime behavior. userdebug builds
|
|
|
|
// are used for dogfooding and performance testing, and should be as similar to user builds
|
|
|
|
// as possible.
|
2016-09-23 05:49:10 +08:00
|
|
|
Debuggable struct {
|
2016-10-04 14:36:47 +08:00
|
|
|
Cflags []string
|
|
|
|
Cppflags []string
|
2017-04-15 05:38:47 +08:00
|
|
|
Init_rc []string
|
2016-09-23 05:49:10 +08:00
|
|
|
}
|
2016-12-09 01:46:35 +08:00
|
|
|
|
|
|
|
// eng is true for -eng builds, and can be used to turn on additionaly heavyweight debugging
|
|
|
|
// features.
|
|
|
|
Eng struct {
|
|
|
|
Cflags []string
|
|
|
|
Cppflags []string
|
|
|
|
}
|
2017-05-06 04:37:11 +08:00
|
|
|
|
|
|
|
Pdk struct {
|
|
|
|
Enabled *bool
|
|
|
|
}
|
2017-08-24 05:58:37 +08:00
|
|
|
|
|
|
|
Uml struct {
|
|
|
|
Cppflags []string
|
|
|
|
}
|
2015-12-02 08:31:16 +08:00
|
|
|
} `android:"arch_variant"`
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var zeroProductVariables variableProperties
|
|
|
|
|
2015-08-28 04:28:01 +08:00
|
|
|
type productVariables struct {
|
2016-05-11 15:27:49 +08:00
|
|
|
// Suffix to add to generated Makefiles
|
|
|
|
Make_suffix *string `json:",omitempty"`
|
|
|
|
|
2017-07-29 03:39:46 +08:00
|
|
|
Platform_sdk_version *int `json:",omitempty"`
|
|
|
|
Platform_version_active_codenames []string `json:",omitempty"`
|
|
|
|
Platform_version_future_codenames []string `json:",omitempty"`
|
2015-09-18 05:33:42 +08:00
|
|
|
|
2015-09-23 07:56:09 +08:00
|
|
|
DeviceName *string `json:",omitempty"`
|
2015-09-18 05:33:42 +08:00
|
|
|
DeviceArch *string `json:",omitempty"`
|
|
|
|
DeviceArchVariant *string `json:",omitempty"`
|
|
|
|
DeviceCpuVariant *string `json:",omitempty"`
|
|
|
|
DeviceAbi *[]string `json:",omitempty"`
|
2015-10-21 05:29:35 +08:00
|
|
|
DeviceUsesClang *bool `json:",omitempty"`
|
2016-11-19 06:54:24 +08:00
|
|
|
DeviceVndkVersion *string `json:",omitempty"`
|
2015-09-18 05:33:42 +08:00
|
|
|
|
|
|
|
DeviceSecondaryArch *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryArchVariant *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryCpuVariant *string `json:",omitempty"`
|
|
|
|
DeviceSecondaryAbi *[]string `json:",omitempty"`
|
|
|
|
|
|
|
|
HostArch *string `json:",omitempty"`
|
|
|
|
HostSecondaryArch *string `json:",omitempty"`
|
2015-11-25 09:53:15 +08:00
|
|
|
|
|
|
|
CrossHost *string `json:",omitempty"`
|
|
|
|
CrossHostArch *string `json:",omitempty"`
|
|
|
|
CrossHostSecondaryArch *string `json:",omitempty"`
|
2015-12-02 08:31:16 +08:00
|
|
|
|
2016-03-17 03:35:33 +08:00
|
|
|
Allow_missing_dependencies *bool `json:",omitempty"`
|
|
|
|
Unbundled_build *bool `json:",omitempty"`
|
|
|
|
Brillo *bool `json:",omitempty"`
|
|
|
|
Malloc_not_svelte *bool `json:",omitempty"`
|
2016-05-13 09:04:18 +08:00
|
|
|
Safestack *bool `json:",omitempty"`
|
2016-05-18 07:35:02 +08:00
|
|
|
HostStaticBinaries *bool `json:",omitempty"`
|
2016-07-26 08:42:18 +08:00
|
|
|
Binder32bit *bool `json:",omitempty"`
|
2016-08-30 07:14:13 +08:00
|
|
|
UseGoma *bool `json:",omitempty"`
|
2016-09-23 05:49:10 +08:00
|
|
|
Debuggable *bool `json:",omitempty"`
|
2016-12-09 01:46:35 +08:00
|
|
|
Eng *bool `json:",omitempty"`
|
2017-01-20 05:54:55 +08:00
|
|
|
EnableCFI *bool `json:",omitempty"`
|
2017-05-03 01:58:50 +08:00
|
|
|
Device_uses_hwc2 *bool `json:",omitempty"`
|
2017-05-19 06:44:02 +08:00
|
|
|
Treble *bool `json:",omitempty"`
|
2017-05-26 01:18:24 +08:00
|
|
|
Pdk *bool `json:",omitempty"`
|
2017-08-24 05:58:37 +08:00
|
|
|
Uml *bool `json:",omitempty"`
|
2016-01-07 06:41:07 +08:00
|
|
|
|
2017-07-14 05:46:05 +08:00
|
|
|
IntegerOverflowExcludePaths *[]string `json:",omitempty"`
|
|
|
|
|
2016-12-06 09:16:02 +08:00
|
|
|
VendorPath *string `json:",omitempty"`
|
|
|
|
|
2016-09-27 06:45:04 +08:00
|
|
|
ClangTidy *bool `json:",omitempty"`
|
|
|
|
TidyChecks *string `json:",omitempty"`
|
|
|
|
|
2017-02-28 01:01:54 +08:00
|
|
|
NativeCoverage *bool `json:",omitempty"`
|
|
|
|
CoveragePaths *[]string `json:",omitempty"`
|
|
|
|
CoverageExcludePaths *[]string `json:",omitempty"`
|
2017-02-10 08:16:31 +08:00
|
|
|
|
2016-08-25 06:25:47 +08:00
|
|
|
DevicePrefer32BitExecutables *bool `json:",omitempty"`
|
|
|
|
HostPrefer32BitExecutables *bool `json:",omitempty"`
|
|
|
|
|
2016-11-03 05:34:39 +08:00
|
|
|
SanitizeHost []string `json:",omitempty"`
|
|
|
|
SanitizeDevice []string `json:",omitempty"`
|
2017-06-29 00:10:48 +08:00
|
|
|
SanitizeDeviceDiag []string `json:",omitempty"`
|
2016-11-03 05:34:39 +08:00
|
|
|
SanitizeDeviceArch []string `json:",omitempty"`
|
2016-12-20 05:44:41 +08:00
|
|
|
|
|
|
|
ArtUseReadBarrier *bool `json:",omitempty"`
|
2016-12-09 07:45:07 +08:00
|
|
|
|
|
|
|
BtConfigIncludeDir *string `json:",omitempty"`
|
2017-05-05 04:57:05 +08:00
|
|
|
|
|
|
|
Override_rs_driver *string `json:",omitempty"`
|
2017-07-03 12:18:12 +08:00
|
|
|
|
|
|
|
DeviceKernelHeaders []string `json:",omitempty"`
|
2015-09-17 04:53:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func boolPtr(v bool) *bool {
|
|
|
|
return &v
|
2015-08-28 04:28:01 +08:00
|
|
|
}
|
|
|
|
|
2015-09-17 07:48:54 +08:00
|
|
|
func intPtr(v int) *int {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2015-09-18 05:33:42 +08:00
|
|
|
func stringPtr(v string) *string {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2015-09-19 01:57:10 +08:00
|
|
|
func (v *productVariables) SetDefaultConfig() {
|
|
|
|
*v = productVariables{
|
2016-11-11 03:08:00 +08:00
|
|
|
Platform_sdk_version: intPtr(24),
|
2015-09-18 05:33:42 +08:00
|
|
|
HostArch: stringPtr("x86_64"),
|
|
|
|
HostSecondaryArch: stringPtr("x86"),
|
2015-09-23 07:56:09 +08:00
|
|
|
DeviceName: stringPtr("flounder"),
|
2015-09-18 05:33:42 +08:00
|
|
|
DeviceArch: stringPtr("arm64"),
|
2016-03-30 13:06:05 +08:00
|
|
|
DeviceArchVariant: stringPtr("armv8-a"),
|
2015-09-18 05:33:42 +08:00
|
|
|
DeviceCpuVariant: stringPtr("denver64"),
|
|
|
|
DeviceAbi: &[]string{"arm64-v8a"},
|
2015-10-21 05:29:35 +08:00
|
|
|
DeviceUsesClang: boolPtr(true),
|
2015-09-18 05:33:42 +08:00
|
|
|
DeviceSecondaryArch: stringPtr("arm"),
|
|
|
|
DeviceSecondaryArchVariant: stringPtr("armv7-a-neon"),
|
2015-09-23 07:56:09 +08:00
|
|
|
DeviceSecondaryCpuVariant: stringPtr("denver"),
|
2015-09-18 05:33:42 +08:00
|
|
|
DeviceSecondaryAbi: &[]string{"armeabi-v7a"},
|
2016-03-02 06:08:42 +08:00
|
|
|
Malloc_not_svelte: boolPtr(false),
|
2016-05-13 09:04:18 +08:00
|
|
|
Safestack: boolPtr(false),
|
2015-08-28 04:28:01 +08:00
|
|
|
}
|
2015-11-25 09:53:15 +08:00
|
|
|
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
v.CrossHost = stringPtr("windows")
|
|
|
|
v.CrossHostArch = stringPtr("x86")
|
2016-02-04 15:16:33 +08:00
|
|
|
v.CrossHostSecondaryArch = stringPtr("x86_64")
|
2015-11-25 09:53:15 +08:00
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func variableMutator(mctx BottomUpMutatorContext) {
|
|
|
|
var module Module
|
2015-07-10 04:57:48 +08:00
|
|
|
var ok bool
|
2016-05-19 06:37:25 +08:00
|
|
|
if module, ok = mctx.Module().(Module); !ok {
|
2015-07-10 04:57:48 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: depend on config variable, create variants, propagate variants up tree
|
|
|
|
a := module.base()
|
2015-10-29 08:23:31 +08:00
|
|
|
variableValues := reflect.ValueOf(&a.variableProperties.Product_variables).Elem()
|
2015-07-10 04:57:48 +08:00
|
|
|
zeroValues := reflect.ValueOf(zeroProductVariables.Product_variables)
|
|
|
|
|
|
|
|
for i := 0; i < variableValues.NumField(); i++ {
|
|
|
|
variableValue := variableValues.Field(i)
|
|
|
|
zeroValue := zeroValues.Field(i)
|
2015-08-28 04:28:01 +08:00
|
|
|
name := variableValues.Type().Field(i).Name
|
|
|
|
property := "product_variables." + proptools.PropertyNameForField(name)
|
|
|
|
|
2015-09-17 04:53:42 +08:00
|
|
|
// Check that the variable was set for the product
|
2015-08-28 04:28:01 +08:00
|
|
|
val := reflect.ValueOf(mctx.Config().(Config).ProductVariables).FieldByName(name)
|
2015-09-17 04:53:42 +08:00
|
|
|
if !val.IsValid() || val.Kind() != reflect.Ptr || val.IsNil() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
val = val.Elem()
|
|
|
|
|
|
|
|
// For bools, check that the value is true
|
|
|
|
if val.Kind() == reflect.Bool && val.Bool() == false {
|
|
|
|
continue
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
|
2015-09-17 04:53:42 +08:00
|
|
|
// Check if any properties were set for the module
|
|
|
|
if reflect.DeepEqual(variableValue.Interface(), zeroValue.Interface()) {
|
|
|
|
continue
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2015-09-17 04:53:42 +08:00
|
|
|
|
|
|
|
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 06:37:25 +08:00
|
|
|
func (a *ModuleBase) setVariableProperties(ctx BottomUpMutatorContext,
|
2015-07-10 04:57:48 +08:00
|
|
|
prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
|
2017-05-06 07:16:24 +08:00
|
|
|
printfIntoProperties(ctx, prefix, productVariablePropertyValue, variableValue)
|
2015-07-10 04:57:48 +08:00
|
|
|
|
2015-10-29 08:23:31 +08:00
|
|
|
err := proptools.AppendMatchingProperties(a.generalProperties,
|
|
|
|
productVariablePropertyValue.Addr().Interface(), nil)
|
|
|
|
if err != nil {
|
|
|
|
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
|
|
|
ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
|
2017-05-06 07:16:24 +08:00
|
|
|
func printfIntoPropertiesError(ctx BottomUpMutatorContext, prefix string,
|
|
|
|
productVariablePropertyValue reflect.Value, i int, err error) {
|
|
|
|
|
|
|
|
field := productVariablePropertyValue.Type().Field(i).Name
|
|
|
|
property := prefix + "." + proptools.PropertyNameForField(field)
|
|
|
|
ctx.PropertyErrorf(property, "%s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printfIntoProperties(ctx BottomUpMutatorContext, prefix string,
|
|
|
|
productVariablePropertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
|
2015-07-10 04:57:48 +08:00
|
|
|
for i := 0; i < productVariablePropertyValue.NumField(); i++ {
|
|
|
|
propertyValue := productVariablePropertyValue.Field(i)
|
2015-12-03 07:24:38 +08:00
|
|
|
kind := propertyValue.Kind()
|
|
|
|
if kind == reflect.Ptr {
|
|
|
|
if propertyValue.IsNil() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
propertyValue = propertyValue.Elem()
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
switch propertyValue.Kind() {
|
|
|
|
case reflect.String:
|
2017-05-06 07:16:24 +08:00
|
|
|
err := printfIntoProperty(propertyValue, variableValue)
|
|
|
|
if err != nil {
|
|
|
|
printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
case reflect.Slice:
|
|
|
|
for j := 0; j < propertyValue.Len(); j++ {
|
2017-05-06 07:16:24 +08:00
|
|
|
err := printfIntoProperty(propertyValue.Index(j), variableValue)
|
|
|
|
if err != nil {
|
|
|
|
printfIntoPropertiesError(ctx, prefix, productVariablePropertyValue, i, err)
|
|
|
|
}
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2015-12-03 07:24:38 +08:00
|
|
|
case reflect.Bool:
|
|
|
|
// Nothing
|
2015-07-10 04:57:48 +08:00
|
|
|
case reflect.Struct:
|
2017-05-06 07:16:24 +08:00
|
|
|
printfIntoProperties(ctx, prefix, propertyValue, variableValue)
|
2015-07-10 04:57:48 +08:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-06 07:16:24 +08:00
|
|
|
func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) error {
|
2015-07-10 04:57:48 +08:00
|
|
|
s := propertyValue.String()
|
2017-05-06 07:16:24 +08:00
|
|
|
|
|
|
|
count := strings.Count(s, "%")
|
|
|
|
if count == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > 1 {
|
|
|
|
return fmt.Errorf("product variable properties only support a single '%%'")
|
|
|
|
}
|
|
|
|
|
2015-07-10 04:57:48 +08:00
|
|
|
if strings.Contains(s, "%d") {
|
|
|
|
switch v := variableValue.(type) {
|
|
|
|
case int:
|
2017-05-06 07:16:24 +08:00
|
|
|
// Nothing
|
2015-07-10 04:57:48 +08:00
|
|
|
case bool:
|
|
|
|
if v {
|
2017-05-06 07:16:24 +08:00
|
|
|
variableValue = 1
|
|
|
|
} else {
|
|
|
|
variableValue = 0
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
|
|
|
default:
|
2017-05-06 07:16:24 +08:00
|
|
|
return fmt.Errorf("unsupported type %T for %%d", variableValue)
|
|
|
|
}
|
|
|
|
} else if strings.Contains(s, "%s") {
|
|
|
|
switch variableValue.(type) {
|
|
|
|
case string:
|
|
|
|
// Nothing
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unsupported type %T for %%s", variableValue)
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2017-05-06 07:16:24 +08:00
|
|
|
} else {
|
|
|
|
return fmt.Errorf("unsupported %% in product variable property")
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|
2017-05-06 07:16:24 +08:00
|
|
|
|
|
|
|
propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, variableValue)))
|
|
|
|
|
|
|
|
return nil
|
2015-07-10 04:57:48 +08:00
|
|
|
}
|