2021-08-23 19:05:17 +02:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
2020-11-26 01:06:39 +01:00
|
|
|
package bp2build
|
|
|
|
|
2021-08-23 19:04:20 +02:00
|
|
|
/*
|
|
|
|
For shareable/common bp2build testing functionality and dumping ground for
|
|
|
|
specific-but-shared functionality among tests in package
|
|
|
|
*/
|
|
|
|
|
2020-11-26 01:06:39 +01:00
|
|
|
import (
|
2021-09-22 21:52:58 +02:00
|
|
|
"fmt"
|
2021-08-23 18:10:00 +02:00
|
|
|
"strings"
|
2021-05-19 15:14:26 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-11-26 01:06:39 +01:00
|
|
|
"android/soong/android"
|
2020-12-14 14:25:34 +01:00
|
|
|
"android/soong/bazel"
|
2020-11-26 01:06:39 +01:00
|
|
|
)
|
|
|
|
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
var (
|
|
|
|
// A default configuration for tests to not have to specify bp2build_available on top level targets.
|
|
|
|
bp2buildConfig = android.Bp2BuildConfig{
|
|
|
|
android.BP2BUILD_TOPLEVEL: android.Bp2BuildDefaultTrueRecursively,
|
|
|
|
}
|
2021-05-19 15:14:26 +02:00
|
|
|
|
|
|
|
buildDir string
|
Add os/target configurable selects for label list attributes.
This CL is pretty large, so I recommend starting with reading the newly
added tests for the expected behavior.
This change works in conjunction with the linked CLs in the Gerrit topic.
Those CLs add support for new platform() definitions for OS targets
specified in Soong's arch.go, which are configurable through
Android.bp's `target {}` property. It works similary to previous CLs
adding support for the `arch {}` property.
These configurable props are keyed by the OS: android, linux_bionic,
windows, and so on. They map to `select` statements in label list
attributes, which this CL enables for cc_library_headers' header_libs
and export_header_lib_headers props.
This enables //bionic/libc:libc_headers to be generated correctly, from:
cc_library_headers {
name: "libc_headers",
target: {
android: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
linux_bionic: {
header_libs: ["libc_headers_arch"],
export_header_lib_headers: ["libc_headers_arch"],
},
},
// omitted props
}
to:
cc_library_headers(
name = "libc_headers",
deps = [] + select({
"//build/bazel/platforms/os:android": [
":libc_headers_arch",
],
"//build/bazel/platforms/os:linux_bionic": [
":libc_headers_arch",
],
"//conditions:default": [],
}),
)
Test: TH
Test: Verify generated //bionic/libc:libc_headers
Fixes: 183597786
Change-Id: I01016cc2cc9a71449f02300d747f01decebf3f6e
2021-03-24 07:18:33 +01:00
|
|
|
)
|
|
|
|
|
2021-09-02 13:44:42 +02:00
|
|
|
func checkError(t *testing.T, errs []error, expectedErr error) bool {
|
2021-08-23 18:10:00 +02:00
|
|
|
t.Helper()
|
2021-09-02 13:44:42 +02:00
|
|
|
|
|
|
|
if len(errs) != 1 {
|
2021-08-26 14:37:59 +02:00
|
|
|
return false
|
2021-09-02 13:44:42 +02:00
|
|
|
}
|
|
|
|
if errs[0].Error() == expectedErr.Error() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func errored(t *testing.T, tc bp2buildTestCase, errs []error) bool {
|
|
|
|
t.Helper()
|
|
|
|
if tc.expectedErr != nil {
|
|
|
|
// Rely on checkErrors, as this test case is expected to have an error.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-08-23 18:10:00 +02:00
|
|
|
if len(errs) > 0 {
|
|
|
|
for _, err := range errs {
|
2021-09-02 13:44:42 +02:00
|
|
|
t.Errorf("%s: %s", tc.description, err)
|
2021-08-23 18:10:00 +02:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2021-09-02 13:44:42 +02:00
|
|
|
|
|
|
|
// All good, continue execution.
|
2021-08-23 18:10:00 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-08-23 18:17:32 +02:00
|
|
|
func runBp2BuildTestCaseSimple(t *testing.T, tc bp2buildTestCase) {
|
2021-08-23 18:10:00 +02:00
|
|
|
t.Helper()
|
|
|
|
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, tc)
|
|
|
|
}
|
|
|
|
|
|
|
|
type bp2buildTestCase struct {
|
|
|
|
description string
|
|
|
|
moduleTypeUnderTest string
|
|
|
|
moduleTypeUnderTestFactory android.ModuleFactory
|
|
|
|
moduleTypeUnderTestBp2BuildMutator func(android.TopDownMutatorContext)
|
|
|
|
blueprint string
|
|
|
|
expectedBazelTargets []string
|
|
|
|
filesystem map[string]string
|
|
|
|
dir string
|
2021-09-02 13:44:42 +02:00
|
|
|
expectedErr error
|
2021-08-26 14:37:59 +02:00
|
|
|
unconvertedDepsMode unconvertedDepsMode
|
2021-08-23 18:10:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.RegistrationContext), tc bp2buildTestCase) {
|
|
|
|
t.Helper()
|
|
|
|
dir := "."
|
|
|
|
filesystem := make(map[string][]byte)
|
|
|
|
toParse := []string{
|
|
|
|
"Android.bp",
|
|
|
|
}
|
|
|
|
for f, content := range tc.filesystem {
|
|
|
|
if strings.HasSuffix(f, "Android.bp") {
|
|
|
|
toParse = append(toParse, f)
|
|
|
|
}
|
|
|
|
filesystem[f] = []byte(content)
|
|
|
|
}
|
|
|
|
config := android.TestConfig(buildDir, nil, tc.blueprint, filesystem)
|
|
|
|
ctx := android.NewTestContext(config)
|
|
|
|
|
|
|
|
registerModuleTypes(ctx)
|
|
|
|
ctx.RegisterModuleType(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestFactory)
|
|
|
|
ctx.RegisterBp2BuildConfig(bp2buildConfig)
|
|
|
|
ctx.RegisterBp2BuildMutator(tc.moduleTypeUnderTest, tc.moduleTypeUnderTestBp2BuildMutator)
|
|
|
|
ctx.RegisterForBazelConversion()
|
|
|
|
|
2021-09-02 13:44:42 +02:00
|
|
|
_, parseErrs := ctx.ParseFileList(dir, toParse)
|
|
|
|
if errored(t, tc, parseErrs) {
|
2021-08-23 18:10:00 +02:00
|
|
|
return
|
|
|
|
}
|
2021-09-02 13:44:42 +02:00
|
|
|
_, resolveDepsErrs := ctx.ResolveDependencies(config)
|
|
|
|
if errored(t, tc, resolveDepsErrs) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
errs := append(parseErrs, resolveDepsErrs...)
|
|
|
|
if tc.expectedErr != nil && checkError(t, errs, tc.expectedErr) {
|
2021-08-23 18:10:00 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
checkDir := dir
|
|
|
|
if tc.dir != "" {
|
|
|
|
checkDir = tc.dir
|
|
|
|
}
|
|
|
|
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
|
2021-08-26 14:37:59 +02:00
|
|
|
codegenCtx.unconvertedDepMode = tc.unconvertedDepsMode
|
|
|
|
bazelTargets, errs := generateBazelTargetsForDir(codegenCtx, checkDir)
|
|
|
|
if tc.expectedErr != nil && checkError(t, errs, tc.expectedErr) {
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
android.FailIfErrored(t, errs)
|
|
|
|
}
|
2021-08-23 18:10:00 +02:00
|
|
|
if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount {
|
2021-08-31 22:30:36 +02:00
|
|
|
t.Errorf("%s: Expected %d bazel target, got `%d``",
|
|
|
|
tc.description, expectedCount, actualCount)
|
2021-08-23 18:10:00 +02:00
|
|
|
} else {
|
|
|
|
for i, target := range bazelTargets {
|
|
|
|
if w, g := tc.expectedBazelTargets[i], target.content; w != g {
|
|
|
|
t.Errorf(
|
2021-08-31 22:30:36 +02:00
|
|
|
"%s: Expected generated Bazel target to be `%s`, got `%s`",
|
|
|
|
tc.description, w, g)
|
2021-08-23 18:10:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 01:06:39 +01:00
|
|
|
type nestedProps struct {
|
|
|
|
Nested_prop string
|
|
|
|
}
|
|
|
|
|
2021-09-14 17:17:21 +02:00
|
|
|
type EmbeddedProps struct {
|
|
|
|
Embedded_prop string
|
|
|
|
}
|
|
|
|
|
|
|
|
type OtherEmbeddedProps struct {
|
|
|
|
Other_embedded_prop string
|
|
|
|
}
|
|
|
|
|
2020-11-26 01:06:39 +01:00
|
|
|
type customProps struct {
|
2021-09-14 17:17:21 +02:00
|
|
|
EmbeddedProps
|
|
|
|
*OtherEmbeddedProps
|
|
|
|
|
2020-11-26 01:06:39 +01:00
|
|
|
Bool_prop bool
|
|
|
|
Bool_ptr_prop *bool
|
|
|
|
// Ensure that properties tagged `blueprint:mutated` are omitted
|
|
|
|
Int_prop int `blueprint:"mutated"`
|
|
|
|
Int64_ptr_prop *int64
|
|
|
|
String_prop string
|
|
|
|
String_ptr_prop *string
|
|
|
|
String_list_prop []string
|
|
|
|
|
|
|
|
Nested_props nestedProps
|
|
|
|
Nested_props_ptr *nestedProps
|
2021-04-22 00:15:34 +02:00
|
|
|
|
2021-08-04 21:17:02 +02:00
|
|
|
Arch_paths []string `android:"path,arch_variant"`
|
|
|
|
Arch_paths_exclude []string `android:"path,arch_variant"`
|
2020-11-26 01:06:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type customModule struct {
|
|
|
|
android.ModuleBase
|
2021-02-17 16:17:28 +01:00
|
|
|
android.BazelModuleBase
|
2020-11-26 01:06:39 +01:00
|
|
|
|
|
|
|
props customProps
|
|
|
|
}
|
|
|
|
|
|
|
|
// OutputFiles is needed because some instances of this module use dist with a
|
|
|
|
// tag property which requires the module implements OutputFileProducer.
|
|
|
|
func (m *customModule) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
return android.PathsForTesting("path" + tag), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *customModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
// nothing for now.
|
|
|
|
}
|
|
|
|
|
|
|
|
func customModuleFactoryBase() android.Module {
|
|
|
|
module := &customModule{}
|
|
|
|
module.AddProperties(&module.props)
|
2021-02-17 16:17:28 +01:00
|
|
|
android.InitBazelModule(module)
|
2020-11-26 01:06:39 +01:00
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func customModuleFactory() android.Module {
|
|
|
|
m := customModuleFactoryBase()
|
2021-04-22 00:15:34 +02:00
|
|
|
android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibBoth)
|
2020-11-26 01:06:39 +01:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
type testProps struct {
|
|
|
|
Test_prop struct {
|
|
|
|
Test_string_prop string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type customTestModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
props customProps
|
|
|
|
test_props testProps
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *customTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
// nothing for now.
|
|
|
|
}
|
|
|
|
|
|
|
|
func customTestModuleFactoryBase() android.Module {
|
|
|
|
m := &customTestModule{}
|
|
|
|
m.AddProperties(&m.props)
|
|
|
|
m.AddProperties(&m.test_props)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func customTestModuleFactory() android.Module {
|
|
|
|
m := customTestModuleFactoryBase()
|
|
|
|
android.InitAndroidModule(m)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
type customDefaultsModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func customDefaultsModuleFactoryBase() android.DefaultsModule {
|
|
|
|
module := &customDefaultsModule{}
|
|
|
|
module.AddProperties(&customProps{})
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
func customDefaultsModuleFactoryBasic() android.Module {
|
|
|
|
return customDefaultsModuleFactoryBase()
|
|
|
|
}
|
|
|
|
|
|
|
|
func customDefaultsModuleFactory() android.Module {
|
|
|
|
m := customDefaultsModuleFactoryBase()
|
|
|
|
android.InitDefaultsModule(m)
|
|
|
|
return m
|
|
|
|
}
|
2020-12-14 14:25:34 +01:00
|
|
|
|
2021-09-14 17:17:21 +02:00
|
|
|
type EmbeddedAttr struct {
|
|
|
|
Embedded_attr string
|
|
|
|
}
|
|
|
|
|
|
|
|
type OtherEmbeddedAttr struct {
|
|
|
|
Other_embedded_attr string
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:25:34 +01:00
|
|
|
type customBazelModuleAttributes struct {
|
2021-09-14 17:17:21 +02:00
|
|
|
EmbeddedAttr
|
|
|
|
*OtherEmbeddedAttr
|
2020-12-14 14:25:34 +01:00
|
|
|
String_prop string
|
|
|
|
String_list_prop []string
|
2021-04-22 00:15:34 +02:00
|
|
|
Arch_paths bazel.LabelListAttribute
|
2020-12-14 14:25:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func customBp2BuildMutator(ctx android.TopDownMutatorContext) {
|
|
|
|
if m, ok := ctx.Module().(*customModule); ok {
|
2021-03-10 08:05:59 +01:00
|
|
|
if !m.ConvertWithBp2build(ctx) {
|
2021-02-05 09:03:24 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-11 21:41:03 +02:00
|
|
|
paths := bazel.LabelListAttribute{}
|
2021-04-22 00:15:34 +02:00
|
|
|
|
2021-05-21 14:37:59 +02:00
|
|
|
for axis, configToProps := range m.GetArchVariantProperties(ctx, &customProps{}) {
|
|
|
|
for config, props := range configToProps {
|
|
|
|
if archProps, ok := props.(*customProps); ok && archProps.Arch_paths != nil {
|
2021-08-04 21:17:02 +02:00
|
|
|
paths.SetSelectValue(axis, config, android.BazelLabelForModuleSrcExcludes(ctx, archProps.Arch_paths, archProps.Arch_paths_exclude))
|
2021-05-21 14:37:59 +02:00
|
|
|
}
|
2021-04-22 00:15:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 21:17:02 +02:00
|
|
|
paths.ResolveExcludes()
|
|
|
|
|
2021-02-05 09:01:50 +01:00
|
|
|
attrs := &customBazelModuleAttributes{
|
2020-12-14 14:25:34 +01:00
|
|
|
String_prop: m.props.String_prop,
|
|
|
|
String_list_prop: m.props.String_list_prop,
|
2021-04-22 00:15:34 +02:00
|
|
|
Arch_paths: paths,
|
2021-02-05 09:01:50 +01:00
|
|
|
}
|
2021-09-14 17:17:21 +02:00
|
|
|
attrs.Embedded_attr = m.props.Embedded_prop
|
|
|
|
if m.props.OtherEmbeddedProps != nil {
|
|
|
|
attrs.OtherEmbeddedAttr = &OtherEmbeddedAttr{Other_embedded_attr: m.props.OtherEmbeddedProps.Other_embedded_prop}
|
|
|
|
}
|
2021-02-05 09:01:50 +01:00
|
|
|
|
2021-02-19 17:06:17 +01:00
|
|
|
props := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "custom",
|
|
|
|
}
|
2021-02-05 09:01:50 +01:00
|
|
|
|
2021-08-31 22:30:36 +02:00
|
|
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs)
|
2020-12-14 14:25:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-27 03:58:43 +01:00
|
|
|
|
|
|
|
// A bp2build mutator that uses load statements and creates a 1:M mapping from
|
|
|
|
// module to target.
|
|
|
|
func customBp2BuildMutatorFromStarlark(ctx android.TopDownMutatorContext) {
|
|
|
|
if m, ok := ctx.Module().(*customModule); ok {
|
2021-03-10 08:05:59 +01:00
|
|
|
if !m.ConvertWithBp2build(ctx) {
|
2021-02-05 09:03:24 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-05 09:01:50 +01:00
|
|
|
baseName := m.Name()
|
|
|
|
attrs := &customBazelModuleAttributes{}
|
|
|
|
|
2021-02-19 17:06:17 +01:00
|
|
|
myLibraryProps := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "my_library",
|
|
|
|
Bzl_load_location: "//build/bazel/rules:rules.bzl",
|
|
|
|
}
|
2021-08-31 22:30:36 +02:00
|
|
|
ctx.CreateBazelTargetModule(myLibraryProps, android.CommonAttributes{Name: baseName}, attrs)
|
2021-02-19 17:06:17 +01:00
|
|
|
|
|
|
|
protoLibraryProps := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "proto_library",
|
|
|
|
Bzl_load_location: "//build/bazel/rules:proto.bzl",
|
|
|
|
}
|
2021-08-31 22:30:36 +02:00
|
|
|
ctx.CreateBazelTargetModule(protoLibraryProps, android.CommonAttributes{Name: baseName + "_proto_library_deps"}, attrs)
|
2021-02-19 17:06:17 +01:00
|
|
|
|
|
|
|
myProtoLibraryProps := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "my_proto_library",
|
|
|
|
Bzl_load_location: "//build/bazel/rules:proto.bzl",
|
|
|
|
}
|
2021-08-31 22:30:36 +02:00
|
|
|
ctx.CreateBazelTargetModule(myProtoLibraryProps, android.CommonAttributes{Name: baseName + "_my_proto_library_deps"}, attrs)
|
2021-01-27 03:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-22 16:19:34 +01:00
|
|
|
|
|
|
|
// Helper method for tests to easily access the targets in a dir.
|
2021-08-26 14:37:59 +02:00
|
|
|
func generateBazelTargetsForDir(codegenCtx *CodegenContext, dir string) (BazelTargets, []error) {
|
2021-04-21 13:10:09 +02:00
|
|
|
// TODO: Set generateFilegroups to true and/or remove the generateFilegroups argument completely
|
2021-08-26 14:37:59 +02:00
|
|
|
res, err := GenerateBazelTargets(codegenCtx, false)
|
|
|
|
return res.buildFileToTargets[dir], err
|
2021-02-22 16:19:34 +01:00
|
|
|
}
|
2021-08-04 21:17:02 +02:00
|
|
|
|
|
|
|
func registerCustomModuleForBp2buildConversion(ctx *android.TestContext) {
|
|
|
|
ctx.RegisterModuleType("custom", customModuleFactory)
|
|
|
|
ctx.RegisterBp2BuildMutator("custom", customBp2BuildMutator)
|
|
|
|
ctx.RegisterForBazelConversion()
|
|
|
|
}
|
2021-09-22 21:52:58 +02:00
|
|
|
|
|
|
|
func simpleModuleDoNotConvertBp2build(typ, name string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
%s {
|
|
|
|
name: "%s",
|
|
|
|
bazel_module: { bp2build_available: false },
|
|
|
|
}`, typ, name)
|
|
|
|
}
|
2021-11-08 18:56:31 +01:00
|
|
|
|
|
|
|
type attrNameToString map[string]string
|
|
|
|
|
|
|
|
func makeBazelTarget(typ, name string, attrs attrNameToString) string {
|
|
|
|
attrStrings := make([]string, 0, len(attrs)+1)
|
|
|
|
attrStrings = append(attrStrings, fmt.Sprintf(` name = "%s",`, name))
|
|
|
|
for _, k := range android.SortedStringKeys(attrs) {
|
|
|
|
attrStrings = append(attrStrings, fmt.Sprintf(" %s = %s,", k, attrs[k]))
|
|
|
|
}
|
|
|
|
return fmt.Sprintf(`%s(
|
|
|
|
%s
|
|
|
|
)`, typ, strings.Join(attrStrings, "\n"))
|
|
|
|
}
|