Merge "Add x86_host vars to config.bzl"
This commit is contained in:
@@ -15,11 +15,12 @@
|
|||||||
package bp2build
|
package bp2build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
|
||||||
"android/soong/bazel"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/bazel"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Codegen is the backend of bp2build. The code generator is responsible for
|
// Codegen is the backend of bp2build. The code generator is responsible for
|
||||||
@@ -43,7 +44,7 @@ func Codegen(ctx *CodegenContext) CodegenMetrics {
|
|||||||
writeFiles(ctx, bp2buildDir, bp2buildFiles)
|
writeFiles(ctx, bp2buildDir, bp2buildFiles)
|
||||||
|
|
||||||
soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName)
|
soongInjectionDir := android.PathForOutput(ctx, bazel.SoongInjectionDirName)
|
||||||
writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(res.metrics))
|
writeFiles(ctx, soongInjectionDir, CreateSoongInjectionFiles(ctx.Config(), res.metrics))
|
||||||
|
|
||||||
return res.metrics
|
return res.metrics
|
||||||
}
|
}
|
||||||
|
@@ -17,11 +17,11 @@ type BazelFile struct {
|
|||||||
Contents string
|
Contents string
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateSoongInjectionFiles(metrics CodegenMetrics) []BazelFile {
|
func CreateSoongInjectionFiles(cfg android.Config, metrics CodegenMetrics) []BazelFile {
|
||||||
var files []BazelFile
|
var files []BazelFile
|
||||||
|
|
||||||
files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
|
files = append(files, newFile("cc_toolchain", GeneratedBuildFileName, "")) // Creates a //cc_toolchain package.
|
||||||
files = append(files, newFile("cc_toolchain", "constants.bzl", config.BazelCcToolchainVars()))
|
files = append(files, newFile("cc_toolchain", "constants.bzl", config.BazelCcToolchainVars(cfg)))
|
||||||
|
|
||||||
files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.convertedModules, "\n")))
|
files = append(files, newFile("metrics", "converted_modules.txt", strings.Join(metrics.convertedModules, "\n")))
|
||||||
|
|
||||||
|
@@ -17,6 +17,8 @@ package bp2build
|
|||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
type bazelFilepath struct {
|
type bazelFilepath struct {
|
||||||
@@ -80,7 +82,7 @@ func TestCreateBazelFiles_QueryView_AddsTopLevelFiles(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
|
func TestCreateBazelFiles_Bp2Build_CreatesDefaultFiles(t *testing.T) {
|
||||||
files := CreateSoongInjectionFiles(CodegenMetrics{})
|
files := CreateSoongInjectionFiles(android.Config{}, CodegenMetrics{})
|
||||||
|
|
||||||
expectedFilePaths := []bazelFilepath{
|
expectedFilePaths := []bazelFilepath{
|
||||||
{
|
{
|
||||||
|
@@ -16,9 +16,13 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
|
"github.com/google/blueprint"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -26,18 +30,27 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type bazelVarExporter interface {
|
type bazelVarExporter interface {
|
||||||
asBazel(exportedStringVariables, exportedStringListVariables) []bazelConstant
|
asBazel(android.Config, exportedStringVariables, exportedStringListVariables, exportedConfigDependingVariables) []bazelConstant
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helpers for exporting cc configuration information to Bazel.
|
// Helpers for exporting cc configuration information to Bazel.
|
||||||
var (
|
var (
|
||||||
// Map containing toolchain variables that are independent of the
|
// Maps containing toolchain variables that are independent of the
|
||||||
// environment variables of the build.
|
// environment variables of the build.
|
||||||
exportedStringListVars = exportedStringListVariables{}
|
exportedStringListVars = exportedStringListVariables{}
|
||||||
exportedStringVars = exportedStringVariables{}
|
exportedStringVars = exportedStringVariables{}
|
||||||
exportedStringListDictVars = exportedStringListDictVariables{}
|
exportedStringListDictVars = exportedStringListDictVariables{}
|
||||||
|
|
||||||
|
/// Maps containing variables that are dependent on the build config.
|
||||||
|
exportedConfigDependingVars = exportedConfigDependingVariables{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type exportedConfigDependingVariables map[string]interface{}
|
||||||
|
|
||||||
|
func (m exportedConfigDependingVariables) Set(k string, v interface{}) {
|
||||||
|
m[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that string s has no invalid characters to be generated into the bzl file.
|
// Ensure that string s has no invalid characters to be generated into the bzl file.
|
||||||
func validateCharacters(s string) string {
|
func validateCharacters(s string) string {
|
||||||
for _, c := range []string{`\n`, `"`, `\`} {
|
for _, c := range []string{`\n`, `"`, `\`} {
|
||||||
@@ -74,10 +87,14 @@ func printBazelList(items []string, indentLevel int) string {
|
|||||||
return strings.Join(list, "\n")
|
return strings.Join(list, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m exportedStringVariables) asBazel(stringScope exportedStringVariables, stringListScope exportedStringListVariables) []bazelConstant {
|
func (m exportedStringVariables) asBazel(config android.Config,
|
||||||
|
stringVars exportedStringVariables, stringListVars exportedStringListVariables, cfgDepVars exportedConfigDependingVariables) []bazelConstant {
|
||||||
ret := make([]bazelConstant, 0, len(m))
|
ret := make([]bazelConstant, 0, len(m))
|
||||||
for k, variableValue := range m {
|
for k, variableValue := range m {
|
||||||
expandedVar := expandVar(variableValue, exportedStringVars, exportedStringListVars)
|
expandedVar, err := expandVar(config, variableValue, stringVars, stringListVars, cfgDepVars)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("error expanding config variable %s: %s", k, err))
|
||||||
|
}
|
||||||
if len(expandedVar) > 1 {
|
if len(expandedVar) > 1 {
|
||||||
panic(fmt.Errorf("%s expands to more than one string value: %s", variableValue, expandedVar))
|
panic(fmt.Errorf("%s expands to more than one string value: %s", variableValue, expandedVar))
|
||||||
}
|
}
|
||||||
@@ -101,7 +118,9 @@ func (m exportedStringListVariables) Set(k string, v []string) {
|
|||||||
m[k] = v
|
m[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m exportedStringListVariables) asBazel(stringScope exportedStringVariables, stringListScope exportedStringListVariables) []bazelConstant {
|
func (m exportedStringListVariables) asBazel(config android.Config,
|
||||||
|
stringScope exportedStringVariables, stringListScope exportedStringListVariables,
|
||||||
|
exportedVars exportedConfigDependingVariables) []bazelConstant {
|
||||||
ret := make([]bazelConstant, 0, len(m))
|
ret := make([]bazelConstant, 0, len(m))
|
||||||
// For each exported variable, recursively expand elements in the variableValue
|
// For each exported variable, recursively expand elements in the variableValue
|
||||||
// list to ensure that interpolated variables are expanded according to their values
|
// list to ensure that interpolated variables are expanded according to their values
|
||||||
@@ -109,7 +128,11 @@ func (m exportedStringListVariables) asBazel(stringScope exportedStringVariables
|
|||||||
for k, variableValue := range m {
|
for k, variableValue := range m {
|
||||||
var expandedVars []string
|
var expandedVars []string
|
||||||
for _, v := range variableValue {
|
for _, v := range variableValue {
|
||||||
expandedVars = append(expandedVars, expandVar(v, stringScope, stringListScope)...)
|
expandedVar, err := expandVar(config, v, stringScope, stringListScope, exportedVars)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("Error expanding config variable %s=%s: %s", k, v, err))
|
||||||
|
}
|
||||||
|
expandedVars = append(expandedVars, expandedVar...)
|
||||||
}
|
}
|
||||||
// Assign the list as a bzl-private variable; this variable will be exported
|
// Assign the list as a bzl-private variable; this variable will be exported
|
||||||
// out through a constants struct later.
|
// out through a constants struct later.
|
||||||
@@ -121,6 +144,18 @@ func (m exportedStringListVariables) asBazel(stringScope exportedStringVariables
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convenience function to declare a static "source path" variable and export it to Bazel's cc_toolchain.
|
||||||
|
func exportVariableConfigMethod(name string, method interface{}) blueprint.Variable {
|
||||||
|
exportedConfigDependingVars.Set(name, method)
|
||||||
|
return pctx.VariableConfigMethod(name, method)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convenience function to declare a static "source path" variable and export it to Bazel's cc_toolchain.
|
||||||
|
func exportSourcePathVariable(name string, value string) {
|
||||||
|
pctx.SourcePathVariable(name, value)
|
||||||
|
exportedStringVars.Set(name, value)
|
||||||
|
}
|
||||||
|
|
||||||
// Convenience function to declare a static variable and export it to Bazel's cc_toolchain.
|
// Convenience function to declare a static variable and export it to Bazel's cc_toolchain.
|
||||||
func exportStringListStaticVariable(name string, value []string) {
|
func exportStringListStaticVariable(name string, value []string) {
|
||||||
pctx.StaticVariable(name, strings.Join(value, " "))
|
pctx.StaticVariable(name, strings.Join(value, " "))
|
||||||
@@ -145,7 +180,8 @@ func printBazelStringListDict(dict map[string][]string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Since dictionaries are not supported in Ninja, we do not expand variables for dictionaries
|
// Since dictionaries are not supported in Ninja, we do not expand variables for dictionaries
|
||||||
func (m exportedStringListDictVariables) asBazel(_ exportedStringVariables, _ exportedStringListVariables) []bazelConstant {
|
func (m exportedStringListDictVariables) asBazel(_ android.Config, _ exportedStringVariables,
|
||||||
|
_ exportedStringListVariables, _ exportedConfigDependingVariables) []bazelConstant {
|
||||||
ret := make([]bazelConstant, 0, len(m))
|
ret := make([]bazelConstant, 0, len(m))
|
||||||
for k, dict := range m {
|
for k, dict := range m {
|
||||||
ret = append(ret, bazelConstant{
|
ret = append(ret, bazelConstant{
|
||||||
@@ -158,19 +194,20 @@ func (m exportedStringListDictVariables) asBazel(_ exportedStringVariables, _ ex
|
|||||||
|
|
||||||
// BazelCcToolchainVars generates bzl file content containing variables for
|
// BazelCcToolchainVars generates bzl file content containing variables for
|
||||||
// Bazel's cc_toolchain configuration.
|
// Bazel's cc_toolchain configuration.
|
||||||
func BazelCcToolchainVars() string {
|
func BazelCcToolchainVars(config android.Config) string {
|
||||||
return bazelToolchainVars(
|
return bazelToolchainVars(
|
||||||
|
config,
|
||||||
exportedStringListDictVars,
|
exportedStringListDictVars,
|
||||||
exportedStringListVars,
|
exportedStringListVars,
|
||||||
exportedStringVars)
|
exportedStringVars)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bazelToolchainVars(vars ...bazelVarExporter) string {
|
func bazelToolchainVars(config android.Config, vars ...bazelVarExporter) string {
|
||||||
ret := "# GENERATED FOR BAZEL FROM SOONG. DO NOT EDIT.\n\n"
|
ret := "# GENERATED FOR BAZEL FROM SOONG. DO NOT EDIT.\n\n"
|
||||||
|
|
||||||
results := []bazelConstant{}
|
results := []bazelConstant{}
|
||||||
for _, v := range vars {
|
for _, v := range vars {
|
||||||
results = append(results, v.asBazel(exportedStringVars, exportedStringListVars)...)
|
results = append(results, v.asBazel(config, exportedStringVars, exportedStringListVars, exportedConfigDependingVars)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(results, func(i, j int) bool { return results[i].variableName < results[j].variableName })
|
sort.Slice(results, func(i, j int) bool { return results[i].variableName < results[j].variableName })
|
||||||
@@ -201,34 +238,35 @@ func bazelToolchainVars(vars ...bazelVarExporter) string {
|
|||||||
// string slice than to handle a pass-by-referenced map, which would make it
|
// string slice than to handle a pass-by-referenced map, which would make it
|
||||||
// quite complex to track depth-first interpolations. It's also unlikely the
|
// quite complex to track depth-first interpolations. It's also unlikely the
|
||||||
// interpolation stacks are deep (n > 1).
|
// interpolation stacks are deep (n > 1).
|
||||||
func expandVar(toExpand string, stringScope exportedStringVariables, stringListScope exportedStringListVariables) []string {
|
func expandVar(config android.Config, toExpand string, stringScope exportedStringVariables,
|
||||||
|
stringListScope exportedStringListVariables, exportedVars exportedConfigDependingVariables) ([]string, error) {
|
||||||
// e.g. "${ExternalCflags}"
|
// e.g. "${ExternalCflags}"
|
||||||
r := regexp.MustCompile(`\${([a-zA-Z0-9_]+)}`)
|
r := regexp.MustCompile(`\${([a-zA-Z0-9_]+)}`)
|
||||||
|
|
||||||
// Internal recursive function.
|
// Internal recursive function.
|
||||||
var expandVarInternal func(string, map[string]bool) []string
|
var expandVarInternal func(string, map[string]bool) (string, error)
|
||||||
expandVarInternal = func(toExpand string, seenVars map[string]bool) []string {
|
expandVarInternal = func(toExpand string, seenVars map[string]bool) (string, error) {
|
||||||
var ret []string
|
var ret string
|
||||||
for _, v := range strings.Split(toExpand, " ") {
|
remainingString := toExpand
|
||||||
matches := r.FindStringSubmatch(v)
|
for len(remainingString) > 0 {
|
||||||
|
matches := r.FindStringSubmatch(remainingString)
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
return []string{v}
|
return ret + remainingString, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(matches) != 2 {
|
if len(matches) != 2 {
|
||||||
panic(fmt.Errorf(
|
panic(fmt.Errorf("Expected to only match 1 subexpression in %s, got %d", remainingString, len(matches)-1))
|
||||||
"Expected to only match 1 subexpression in %s, got %d",
|
|
||||||
v,
|
|
||||||
len(matches)-1))
|
|
||||||
}
|
}
|
||||||
|
matchIndex := strings.Index(remainingString, matches[0])
|
||||||
|
ret += remainingString[:matchIndex]
|
||||||
|
remainingString = remainingString[matchIndex+len(matches[0]):]
|
||||||
|
|
||||||
// Index 1 of FindStringSubmatch contains the subexpression match
|
// Index 1 of FindStringSubmatch contains the subexpression match
|
||||||
// (variable name) of the capture group.
|
// (variable name) of the capture group.
|
||||||
variable := matches[1]
|
variable := matches[1]
|
||||||
// toExpand contains a variable.
|
// toExpand contains a variable.
|
||||||
if _, ok := seenVars[variable]; ok {
|
if _, ok := seenVars[variable]; ok {
|
||||||
panic(fmt.Errorf(
|
return ret, fmt.Errorf(
|
||||||
"Unbounded recursive interpolation of variable: %s", variable))
|
"Unbounded recursive interpolation of variable: %s", variable)
|
||||||
}
|
}
|
||||||
// A map is passed-by-reference. Create a new map for
|
// A map is passed-by-reference. Create a new map for
|
||||||
// this scope to prevent variables seen in one depth-first expansion
|
// this scope to prevent variables seen in one depth-first expansion
|
||||||
@@ -239,15 +277,65 @@ func expandVar(toExpand string, stringScope exportedStringVariables, stringListS
|
|||||||
}
|
}
|
||||||
newSeenVars[variable] = true
|
newSeenVars[variable] = true
|
||||||
if unexpandedVars, ok := stringListScope[variable]; ok {
|
if unexpandedVars, ok := stringListScope[variable]; ok {
|
||||||
|
expandedVars := []string{}
|
||||||
for _, unexpandedVar := range unexpandedVars {
|
for _, unexpandedVar := range unexpandedVars {
|
||||||
ret = append(ret, expandVarInternal(unexpandedVar, newSeenVars)...)
|
expandedVar, err := expandVarInternal(unexpandedVar, newSeenVars)
|
||||||
|
if err != nil {
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
expandedVars = append(expandedVars, expandedVar)
|
||||||
}
|
}
|
||||||
|
ret += strings.Join(expandedVars, " ")
|
||||||
} else if unexpandedVar, ok := stringScope[variable]; ok {
|
} else if unexpandedVar, ok := stringScope[variable]; ok {
|
||||||
ret = append(ret, expandVarInternal(unexpandedVar, newSeenVars)...)
|
expandedVar, err := expandVarInternal(unexpandedVar, newSeenVars)
|
||||||
|
if err != nil {
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
ret += expandedVar
|
||||||
|
} else if unevaluatedVar, ok := exportedVars[variable]; ok {
|
||||||
|
evalFunc := reflect.ValueOf(unevaluatedVar)
|
||||||
|
validateVariableMethod(variable, evalFunc)
|
||||||
|
evaluatedResult := evalFunc.Call([]reflect.Value{reflect.ValueOf(config)})
|
||||||
|
evaluatedValue := evaluatedResult[0].Interface().(string)
|
||||||
|
expandedVar, err := expandVarInternal(evaluatedValue, newSeenVars)
|
||||||
|
if err != nil {
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
ret += expandedVar
|
||||||
|
} else {
|
||||||
|
return "", fmt.Errorf("Unbound config variable %s", variable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret, nil
|
||||||
|
}
|
||||||
|
var ret []string
|
||||||
|
for _, v := range strings.Split(toExpand, " ") {
|
||||||
|
val, err := expandVarInternal(v, map[string]bool{})
|
||||||
|
if err != nil {
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
ret = append(ret, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
return expandVarInternal(toExpand, map[string]bool{})
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateVariableMethod(name string, methodValue reflect.Value) {
|
||||||
|
methodType := methodValue.Type()
|
||||||
|
if methodType.Kind() != reflect.Func {
|
||||||
|
panic(fmt.Errorf("method given for variable %s is not a function",
|
||||||
|
name))
|
||||||
|
}
|
||||||
|
if n := methodType.NumIn(); n != 1 {
|
||||||
|
panic(fmt.Errorf("method for variable %s has %d inputs (should be 1)",
|
||||||
|
name, n))
|
||||||
|
}
|
||||||
|
if n := methodType.NumOut(); n != 1 {
|
||||||
|
panic(fmt.Errorf("method for variable %s has %d outputs (should be 1)",
|
||||||
|
name, n))
|
||||||
|
}
|
||||||
|
if kind := methodType.Out(0).Kind(); kind != reflect.String {
|
||||||
|
panic(fmt.Errorf("method for variable %s does not return a string",
|
||||||
|
name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,13 +16,21 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExpandVars(t *testing.T) {
|
func TestExpandVars(t *testing.T) {
|
||||||
|
android_arm64_config := android.TestConfig("out", nil, "", nil)
|
||||||
|
android_arm64_config.BuildOS = android.Android
|
||||||
|
android_arm64_config.BuildArch = android.Arm64
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
|
config android.Config
|
||||||
stringScope exportedStringVariables
|
stringScope exportedStringVariables
|
||||||
stringListScope exportedStringListVariables
|
stringListScope exportedStringListVariables
|
||||||
|
configVars exportedConfigDependingVariables
|
||||||
toExpand string
|
toExpand string
|
||||||
expectedValues []string
|
expectedValues []string
|
||||||
}{
|
}{
|
||||||
@@ -57,7 +65,7 @@ func TestExpandVars(t *testing.T) {
|
|||||||
"bar": []string{"baz", "${qux}"},
|
"bar": []string{"baz", "${qux}"},
|
||||||
},
|
},
|
||||||
toExpand: "${foo}",
|
toExpand: "${foo}",
|
||||||
expectedValues: []string{"baz", "hello"},
|
expectedValues: []string{"baz hello"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "double level expansion",
|
description: "double level expansion",
|
||||||
@@ -75,7 +83,7 @@ func TestExpandVars(t *testing.T) {
|
|||||||
"b": []string{"d"},
|
"b": []string{"d"},
|
||||||
},
|
},
|
||||||
toExpand: "${a}",
|
toExpand: "${a}",
|
||||||
expectedValues: []string{"d", "c"},
|
expectedValues: []string{"d c"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "double level expansion, with two variables in a string",
|
description: "double level expansion, with two variables in a string",
|
||||||
@@ -85,7 +93,7 @@ func TestExpandVars(t *testing.T) {
|
|||||||
"c": []string{"e"},
|
"c": []string{"e"},
|
||||||
},
|
},
|
||||||
toExpand: "${a}",
|
toExpand: "${a}",
|
||||||
expectedValues: []string{"d", "e"},
|
expectedValues: []string{"d e"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "triple level expansion with two variables in a string",
|
description: "triple level expansion with two variables in a string",
|
||||||
@@ -96,13 +104,38 @@ func TestExpandVars(t *testing.T) {
|
|||||||
"d": []string{"foo"},
|
"d": []string{"foo"},
|
||||||
},
|
},
|
||||||
toExpand: "${a}",
|
toExpand: "${a}",
|
||||||
expectedValues: []string{"foo", "foo", "foo"},
|
expectedValues: []string{"foo foo foo"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "expansion with config depending vars",
|
||||||
|
configVars: exportedConfigDependingVariables{
|
||||||
|
"a": func(c android.Config) string { return c.BuildOS.String() },
|
||||||
|
"b": func(c android.Config) string { return c.BuildArch.String() },
|
||||||
|
},
|
||||||
|
config: android_arm64_config,
|
||||||
|
toExpand: "${a}-${b}",
|
||||||
|
expectedValues: []string{"android-arm64"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "double level multi type expansion",
|
||||||
|
stringListScope: exportedStringListVariables{
|
||||||
|
"platform": []string{"${os}-${arch}"},
|
||||||
|
"const": []string{"const"},
|
||||||
|
},
|
||||||
|
configVars: exportedConfigDependingVariables{
|
||||||
|
"os": func(c android.Config) string { return c.BuildOS.String() },
|
||||||
|
"arch": func(c android.Config) string { return c.BuildArch.String() },
|
||||||
|
"foo": func(c android.Config) string { return "foo" },
|
||||||
|
},
|
||||||
|
config: android_arm64_config,
|
||||||
|
toExpand: "${const}/${platform}/${foo}",
|
||||||
|
expectedValues: []string{"const/android-arm64/foo"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
t.Run(testCase.description, func(t *testing.T) {
|
t.Run(testCase.description, func(t *testing.T) {
|
||||||
output := expandVar(testCase.toExpand, testCase.stringScope, testCase.stringListScope)
|
output, _ := expandVar(testCase.config, testCase.toExpand, testCase.stringScope, testCase.stringListScope, testCase.configVars)
|
||||||
if len(output) != len(testCase.expectedValues) {
|
if len(output) != len(testCase.expectedValues) {
|
||||||
t.Errorf("Expected %d values, got %d", len(testCase.expectedValues), len(output))
|
t.Errorf("Expected %d values, got %d", len(testCase.expectedValues), len(output))
|
||||||
}
|
}
|
||||||
@@ -119,6 +152,7 @@ func TestExpandVars(t *testing.T) {
|
|||||||
func TestBazelToolchainVars(t *testing.T) {
|
func TestBazelToolchainVars(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
config android.Config
|
||||||
vars []bazelVarExporter
|
vars []bazelVarExporter
|
||||||
expectedOut string
|
expectedOut string
|
||||||
}{
|
}{
|
||||||
@@ -248,7 +282,7 @@ constants = struct(
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
out := bazelToolchainVars(tc.vars...)
|
out := bazelToolchainVars(tc.config, tc.vars...)
|
||||||
if out != tc.expectedOut {
|
if out != tc.expectedOut {
|
||||||
t.Errorf("Expected \n%s, got \n%s", tc.expectedOut, out)
|
t.Errorf("Expected \n%s, got \n%s", tc.expectedOut, out)
|
||||||
}
|
}
|
||||||
|
@@ -404,7 +404,7 @@ func init() {
|
|||||||
pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
|
pctx.StaticVariableWithEnvOverride("REAbiLinkerExecStrategy", "RBE_ABI_LINKER_EXEC_STRATEGY", remoteexec.LocalExecStrategy)
|
||||||
}
|
}
|
||||||
|
|
||||||
var HostPrebuiltTag = pctx.VariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
|
var HostPrebuiltTag = exportVariableConfigMethod("HostPrebuiltTag", android.Config.PrebuiltOS)
|
||||||
|
|
||||||
func ClangPath(ctx android.PathContext, file string) android.SourcePath {
|
func ClangPath(ctx android.PathContext, file string) android.SourcePath {
|
||||||
type clangToolKey string
|
type clangToolKey string
|
||||||
|
@@ -120,40 +120,40 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pctx.StaticVariable("LinuxGccVersion", linuxGccVersion)
|
exportStringStaticVariable("LinuxGccVersion", linuxGccVersion)
|
||||||
pctx.StaticVariable("LinuxGlibcVersion", linuxGlibcVersion)
|
exportStringStaticVariable("LinuxGlibcVersion", linuxGlibcVersion)
|
||||||
|
|
||||||
// Most places use the full GCC version. A few only use up to the first two numbers.
|
// Most places use the full GCC version. A few only use up to the first two numbers.
|
||||||
if p := strings.Split(linuxGccVersion, "."); len(p) > 2 {
|
if p := strings.Split(linuxGccVersion, "."); len(p) > 2 {
|
||||||
pctx.StaticVariable("ShortLinuxGccVersion", strings.Join(p[:2], "."))
|
exportStringStaticVariable("ShortLinuxGccVersion", strings.Join(p[:2], "."))
|
||||||
} else {
|
} else {
|
||||||
pctx.StaticVariable("ShortLinuxGccVersion", linuxGccVersion)
|
exportStringStaticVariable("ShortLinuxGccVersion", linuxGccVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
pctx.SourcePathVariable("LinuxGccRoot",
|
exportSourcePathVariable("LinuxGccRoot",
|
||||||
"prebuilts/gcc/${HostPrebuiltTag}/host/x86_64-linux-glibc${LinuxGlibcVersion}-${ShortLinuxGccVersion}")
|
"prebuilts/gcc/linux-x86/host/x86_64-linux-glibc${LinuxGlibcVersion}-${ShortLinuxGccVersion}")
|
||||||
|
|
||||||
pctx.StaticVariable("LinuxGccTriple", "x86_64-linux")
|
exportStringListStaticVariable("LinuxGccTriple", []string{"x86_64-linux"})
|
||||||
|
|
||||||
pctx.StaticVariable("LinuxCflags", strings.Join(linuxCflags, " "))
|
exportStringListStaticVariable("LinuxCflags", linuxCflags)
|
||||||
pctx.StaticVariable("LinuxLdflags", strings.Join(linuxLdflags, " "))
|
exportStringListStaticVariable("LinuxLdflags", linuxLdflags)
|
||||||
pctx.StaticVariable("LinuxLldflags", strings.Join(linuxLdflags, " "))
|
exportStringListStaticVariable("LinuxLldflags", linuxLdflags)
|
||||||
|
exportStringListStaticVariable("LinuxGlibcCflags", linuxGlibcCflags)
|
||||||
|
exportStringListStaticVariable("LinuxGlibcLdflags", linuxGlibcLdflags)
|
||||||
|
exportStringListStaticVariable("LinuxGlibcLldflags", linuxGlibcLdflags)
|
||||||
|
exportStringListStaticVariable("LinuxMuslCflags", linuxMuslCflags)
|
||||||
|
exportStringListStaticVariable("LinuxMuslLdflags", linuxMuslLdflags)
|
||||||
|
exportStringListStaticVariable("LinuxMuslLldflags", linuxMuslLdflags)
|
||||||
|
|
||||||
pctx.StaticVariable("LinuxX86Cflags", strings.Join(linuxX86Cflags, " "))
|
exportStringListStaticVariable("LinuxX86Cflags", linuxX86Cflags)
|
||||||
pctx.StaticVariable("LinuxX8664Cflags", strings.Join(linuxX8664Cflags, " "))
|
exportStringListStaticVariable("LinuxX8664Cflags", linuxX8664Cflags)
|
||||||
pctx.StaticVariable("LinuxX86Ldflags", strings.Join(linuxX86Ldflags, " "))
|
exportStringListStaticVariable("LinuxX86Ldflags", linuxX86Ldflags)
|
||||||
pctx.StaticVariable("LinuxX86Lldflags", strings.Join(linuxX86Ldflags, " "))
|
exportStringListStaticVariable("LinuxX86Lldflags", linuxX86Ldflags)
|
||||||
pctx.StaticVariable("LinuxX8664Ldflags", strings.Join(linuxX8664Ldflags, " "))
|
exportStringListStaticVariable("LinuxX8664Ldflags", linuxX8664Ldflags)
|
||||||
pctx.StaticVariable("LinuxX8664Lldflags", strings.Join(linuxX8664Ldflags, " "))
|
exportStringListStaticVariable("LinuxX8664Lldflags", linuxX8664Ldflags)
|
||||||
// Yasm flags
|
// Yasm flags
|
||||||
pctx.StaticVariable("LinuxX86YasmFlags", "-f elf32 -m x86")
|
exportStringListStaticVariable("LinuxX86YasmFlags", []string{"-f elf32 -m x86"})
|
||||||
pctx.StaticVariable("LinuxX8664YasmFlags", "-f elf64 -m amd64")
|
exportStringListStaticVariable("LinuxX8664YasmFlags", []string{"-f elf64 -m amd64"})
|
||||||
|
|
||||||
pctx.StaticVariable("LinuxGlibcCflags", strings.Join(linuxGlibcCflags, " "))
|
|
||||||
pctx.StaticVariable("LinuxGlibcLdflags", strings.Join(linuxGlibcLdflags, " "))
|
|
||||||
pctx.StaticVariable("LinuxGlibcLldflags", strings.Join(linuxGlibcLdflags, " "))
|
|
||||||
pctx.StaticVariable("LinuxMuslCflags", strings.Join(linuxMuslCflags, " "))
|
|
||||||
pctx.StaticVariable("LinuxMuslLdflags", strings.Join(linuxMuslLdflags, " "))
|
|
||||||
pctx.StaticVariable("LinuxMuslLldflags", strings.Join(linuxMuslLdflags, " "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type toolchainLinux struct {
|
type toolchainLinux struct {
|
||||||
|
Reference in New Issue
Block a user