2015-07-09 22:57:48 +02: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.
|
|
|
|
|
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2015-11-25 02:53:15 +01:00
|
|
|
"runtime"
|
2015-07-09 22:57:48 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-10-29 23:25:03 +01:00
|
|
|
RegisterBottomUpMutator("variable", variableMutator)
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type variableProperties struct {
|
|
|
|
Product_variables struct {
|
2015-09-17 01:48:54 +02:00
|
|
|
Platform_sdk_version struct {
|
|
|
|
Asflags []string
|
|
|
|
}
|
2015-12-02 01:31:16 +01: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-05 23:27:55 +01:00
|
|
|
|
|
|
|
Brillo struct {
|
|
|
|
Version_script *string `android:"arch_variant"`
|
|
|
|
} `android:"arch_variant"`
|
2016-03-01 23:08:42 +01:00
|
|
|
|
|
|
|
Malloc_not_svelte struct {
|
|
|
|
Cflags []string
|
|
|
|
}
|
2015-12-02 01:31:16 +01:00
|
|
|
} `android:"arch_variant"`
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var zeroProductVariables variableProperties
|
|
|
|
|
2015-08-27 22:28:01 +02:00
|
|
|
type productVariables struct {
|
2016-03-01 23:08:42 +01:00
|
|
|
Platform_sdk_version *int `json:",omitempty"`
|
2015-09-17 23:33:42 +02:00
|
|
|
|
2015-09-23 01:56:09 +02:00
|
|
|
DeviceName *string `json:",omitempty"`
|
2015-09-17 23:33:42 +02:00
|
|
|
DeviceArch *string `json:",omitempty"`
|
|
|
|
DeviceArchVariant *string `json:",omitempty"`
|
|
|
|
DeviceCpuVariant *string `json:",omitempty"`
|
|
|
|
DeviceAbi *[]string `json:",omitempty"`
|
2015-10-20 23:29:35 +02:00
|
|
|
DeviceUsesClang *bool `json:",omitempty"`
|
2015-09-17 23:33:42 +02: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 02:53:15 +01:00
|
|
|
|
|
|
|
CrossHost *string `json:",omitempty"`
|
|
|
|
CrossHostArch *string `json:",omitempty"`
|
|
|
|
CrossHostSecondaryArch *string `json:",omitempty"`
|
2015-12-02 01:31:16 +01:00
|
|
|
|
2016-03-16 20:35:33 +01:00
|
|
|
Allow_missing_dependencies *bool `json:",omitempty"`
|
|
|
|
Unbundled_build *bool `json:",omitempty"`
|
|
|
|
Brillo *bool `json:",omitempty"`
|
|
|
|
Malloc_not_svelte *bool `json:",omitempty"`
|
2015-09-16 22:53:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func boolPtr(v bool) *bool {
|
|
|
|
return &v
|
2015-08-27 22:28:01 +02:00
|
|
|
}
|
|
|
|
|
2015-09-17 01:48:54 +02:00
|
|
|
func intPtr(v int) *int {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2015-09-17 23:33:42 +02:00
|
|
|
func stringPtr(v string) *string {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
2015-09-18 19:57:10 +02:00
|
|
|
func (v *productVariables) SetDefaultConfig() {
|
|
|
|
*v = productVariables{
|
2015-09-17 23:33:42 +02:00
|
|
|
Platform_sdk_version: intPtr(22),
|
|
|
|
HostArch: stringPtr("x86_64"),
|
|
|
|
HostSecondaryArch: stringPtr("x86"),
|
2015-09-23 01:56:09 +02:00
|
|
|
DeviceName: stringPtr("flounder"),
|
2015-09-17 23:33:42 +02:00
|
|
|
DeviceArch: stringPtr("arm64"),
|
2016-03-30 07:06:05 +02:00
|
|
|
DeviceArchVariant: stringPtr("armv8-a"),
|
2015-09-17 23:33:42 +02:00
|
|
|
DeviceCpuVariant: stringPtr("denver64"),
|
|
|
|
DeviceAbi: &[]string{"arm64-v8a"},
|
2015-10-20 23:29:35 +02:00
|
|
|
DeviceUsesClang: boolPtr(true),
|
2015-09-17 23:33:42 +02:00
|
|
|
DeviceSecondaryArch: stringPtr("arm"),
|
|
|
|
DeviceSecondaryArchVariant: stringPtr("armv7-a-neon"),
|
2015-09-23 01:56:09 +02:00
|
|
|
DeviceSecondaryCpuVariant: stringPtr("denver"),
|
2015-09-17 23:33:42 +02:00
|
|
|
DeviceSecondaryAbi: &[]string{"armeabi-v7a"},
|
2016-03-01 23:08:42 +01:00
|
|
|
Malloc_not_svelte: boolPtr(false),
|
2015-08-27 22:28:01 +02:00
|
|
|
}
|
2015-11-25 02:53:15 +01:00
|
|
|
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
v.CrossHost = stringPtr("windows")
|
|
|
|
v.CrossHostArch = stringPtr("x86")
|
2016-02-04 08:16:33 +01:00
|
|
|
v.CrossHostSecondaryArch = stringPtr("x86_64")
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func variableMutator(mctx AndroidBottomUpMutatorContext) {
|
2015-07-09 22:57:48 +02:00
|
|
|
var module AndroidModule
|
|
|
|
var ok bool
|
|
|
|
if module, ok = mctx.Module().(AndroidModule); !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: depend on config variable, create variants, propagate variants up tree
|
|
|
|
a := module.base()
|
2015-10-29 01:23:31 +01:00
|
|
|
variableValues := reflect.ValueOf(&a.variableProperties.Product_variables).Elem()
|
2015-07-09 22:57:48 +02:00
|
|
|
zeroValues := reflect.ValueOf(zeroProductVariables.Product_variables)
|
|
|
|
|
|
|
|
for i := 0; i < variableValues.NumField(); i++ {
|
|
|
|
variableValue := variableValues.Field(i)
|
|
|
|
zeroValue := zeroValues.Field(i)
|
2015-08-27 22:28:01 +02:00
|
|
|
name := variableValues.Type().Field(i).Name
|
|
|
|
property := "product_variables." + proptools.PropertyNameForField(name)
|
|
|
|
|
2015-09-16 22:53:42 +02:00
|
|
|
// Check that the variable was set for the product
|
2015-08-27 22:28:01 +02:00
|
|
|
val := reflect.ValueOf(mctx.Config().(Config).ProductVariables).FieldByName(name)
|
2015-09-16 22:53:42 +02: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-09 22:57:48 +02:00
|
|
|
|
2015-09-16 22:53:42 +02:00
|
|
|
// Check if any properties were set for the module
|
|
|
|
if reflect.DeepEqual(variableValue.Interface(), zeroValue.Interface()) {
|
|
|
|
continue
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
2015-09-16 22:53:42 +02:00
|
|
|
|
|
|
|
a.setVariableProperties(mctx, property, variableValue, val.Interface())
|
2015-07-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func (a *AndroidModuleBase) setVariableProperties(ctx AndroidBottomUpMutatorContext,
|
2015-07-09 22:57:48 +02:00
|
|
|
prefix string, productVariablePropertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
|
2015-12-03 00:24:38 +01:00
|
|
|
printfIntoProperties(productVariablePropertyValue, variableValue)
|
2015-07-09 22:57:48 +02:00
|
|
|
|
2015-10-29 01:23:31 +01: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-09 22:57:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func printfIntoProperties(productVariablePropertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
for i := 0; i < productVariablePropertyValue.NumField(); i++ {
|
|
|
|
propertyValue := productVariablePropertyValue.Field(i)
|
2015-12-03 00:24:38 +01:00
|
|
|
kind := propertyValue.Kind()
|
|
|
|
if kind == reflect.Ptr {
|
|
|
|
if propertyValue.IsNil() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
propertyValue = propertyValue.Elem()
|
|
|
|
}
|
2015-07-09 22:57:48 +02:00
|
|
|
switch propertyValue.Kind() {
|
|
|
|
case reflect.String:
|
|
|
|
printfIntoProperty(propertyValue, variableValue)
|
|
|
|
case reflect.Slice:
|
|
|
|
for j := 0; j < propertyValue.Len(); j++ {
|
|
|
|
printfIntoProperty(propertyValue.Index(j), variableValue)
|
|
|
|
}
|
2015-12-03 00:24:38 +01:00
|
|
|
case reflect.Bool:
|
|
|
|
// Nothing
|
2015-07-09 22:57:48 +02:00
|
|
|
case reflect.Struct:
|
|
|
|
printfIntoProperties(propertyValue, variableValue)
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported field kind %q", propertyValue.Kind()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func printfIntoProperty(propertyValue reflect.Value, variableValue interface{}) {
|
|
|
|
s := propertyValue.String()
|
|
|
|
// For now, we only support int formats
|
|
|
|
var i int
|
|
|
|
if strings.Contains(s, "%d") {
|
|
|
|
switch v := variableValue.(type) {
|
|
|
|
case int:
|
|
|
|
i = v
|
|
|
|
case bool:
|
|
|
|
if v {
|
|
|
|
i = 1
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported type %T", variableValue))
|
|
|
|
}
|
|
|
|
propertyValue.Set(reflect.ValueOf(fmt.Sprintf(s, i)))
|
|
|
|
}
|
|
|
|
}
|