2023-09-06 02:19:45 +02:00
|
|
|
// Copyright 2023 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 bp2build
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"android/soong/aconfig"
|
|
|
|
"android/soong/android"
|
2023-09-15 00:10:03 +02:00
|
|
|
"android/soong/cc"
|
2023-09-20 00:09:10 +02:00
|
|
|
"android/soong/java"
|
2023-09-06 02:19:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func registerAconfigModuleTypes(ctx android.RegistrationContext) {
|
|
|
|
aconfig.RegisterBuildComponents(ctx)
|
2023-09-15 00:10:03 +02:00
|
|
|
ctx.RegisterModuleType("cc_library", cc.LibraryFactory)
|
2023-09-20 00:09:10 +02:00
|
|
|
ctx.RegisterModuleType("java_library", java.LibraryFactory)
|
2023-09-06 02:19:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAconfigDeclarations(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_declarations {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"foo1.aconfig",
|
|
|
|
"test/foo2.aconfig",
|
|
|
|
],
|
|
|
|
package: "com.android.foo",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
expectedBazelTarget := MakeBazelTargetNoRestrictions(
|
|
|
|
"aconfig_declarations",
|
|
|
|
"foo",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `[
|
|
|
|
"foo1.aconfig",
|
|
|
|
"test/foo2.aconfig",
|
|
|
|
]`,
|
|
|
|
"package": `"com.android.foo"`,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
|
|
|
Blueprint: bp,
|
|
|
|
ExpectedBazelTargets: []string{expectedBazelTarget},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAconfigValues(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_values {
|
|
|
|
name: "foo",
|
|
|
|
srcs: [
|
|
|
|
"foo1.textproto",
|
|
|
|
],
|
|
|
|
package: "com.android.foo",
|
|
|
|
}
|
|
|
|
aconfig_value_set {
|
|
|
|
name: "bar",
|
|
|
|
values: [
|
|
|
|
"foo"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
`
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"aconfig_values",
|
|
|
|
"foo",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["foo1.textproto"]`,
|
|
|
|
"package": `"com.android.foo"`,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"aconfig_value_set",
|
|
|
|
"bar",
|
|
|
|
AttrNameToString{
|
|
|
|
"values": `[":foo"]`,
|
|
|
|
},
|
|
|
|
)}
|
|
|
|
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
|
|
|
Blueprint: bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
}
|
2023-09-15 00:10:03 +02:00
|
|
|
|
|
|
|
func TestCcAconfigLibrary(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_declarations {
|
|
|
|
name: "foo_aconfig_declarations",
|
|
|
|
srcs: [
|
|
|
|
"foo1.aconfig",
|
|
|
|
],
|
|
|
|
package: "com.android.foo",
|
|
|
|
}
|
|
|
|
cc_library {
|
|
|
|
name: "server_configurable_flags",
|
|
|
|
srcs: ["bar.cc"],
|
|
|
|
}
|
|
|
|
cc_aconfig_library {
|
|
|
|
name: "foo",
|
|
|
|
aconfig_declarations: "foo_aconfig_declarations",
|
|
|
|
}
|
|
|
|
`
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"aconfig_declarations",
|
|
|
|
"foo_aconfig_declarations",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["foo1.aconfig"]`,
|
|
|
|
"package": `"com.android.foo"`,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"cc_aconfig_library",
|
|
|
|
"foo",
|
|
|
|
AttrNameToString{
|
|
|
|
"aconfig_declarations": `":foo_aconfig_declarations"`,
|
|
|
|
"dynamic_deps": `[":server_configurable_flags"]`,
|
2023-10-11 12:51:28 +02:00
|
|
|
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
2023-09-15 00:10:03 +02:00
|
|
|
},
|
|
|
|
)}
|
|
|
|
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
2023-09-28 01:11:26 +02:00
|
|
|
Blueprint: bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
StubbedBuildDefinitions: []string{"server_configurable_flags"},
|
2023-09-15 00:10:03 +02:00
|
|
|
})
|
|
|
|
}
|
2023-09-20 00:09:10 +02:00
|
|
|
|
|
|
|
func TestJavaAconfigLibrary(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_declarations {
|
|
|
|
name: "foo_aconfig_declarations",
|
|
|
|
srcs: [
|
|
|
|
"foo1.aconfig",
|
|
|
|
],
|
|
|
|
package: "com.android.foo",
|
|
|
|
}
|
2023-10-13 20:19:48 +02:00
|
|
|
java_library {
|
|
|
|
name: "foo_java_library",
|
|
|
|
srcs: ["foo.java"],
|
|
|
|
sdk_version: "current",
|
|
|
|
}
|
2023-09-20 00:09:10 +02:00
|
|
|
java_aconfig_library {
|
|
|
|
name: "foo",
|
|
|
|
aconfig_declarations: "foo_aconfig_declarations",
|
2023-10-13 20:19:48 +02:00
|
|
|
libs: ["foo_java_library"],
|
2023-09-20 00:09:10 +02:00
|
|
|
test: true,
|
|
|
|
}
|
|
|
|
`
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"aconfig_declarations",
|
|
|
|
"foo_aconfig_declarations",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["foo1.aconfig"]`,
|
|
|
|
"package": `"com.android.foo"`,
|
|
|
|
},
|
|
|
|
),
|
2023-10-13 20:19:48 +02:00
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"java_library",
|
|
|
|
"foo_java_library",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["foo.java"]`,
|
|
|
|
"sdk_version": `"current"`,
|
|
|
|
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "foo_java_library"),
|
2023-09-20 00:09:10 +02:00
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"java_aconfig_library",
|
|
|
|
"foo",
|
|
|
|
AttrNameToString{
|
|
|
|
"aconfig_declarations": `":foo_aconfig_declarations"`,
|
2023-10-13 20:19:48 +02:00
|
|
|
"libs": `[":foo_java_library-neverlink"]`,
|
2023-09-20 00:09:10 +02:00
|
|
|
"test": `True`,
|
|
|
|
"sdk_version": `"system_current"`,
|
2023-10-11 12:51:28 +02:00
|
|
|
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
2023-09-20 00:09:10 +02:00
|
|
|
},
|
|
|
|
)}
|
|
|
|
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
|
|
|
Blueprint: bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaAconfigLibraryAsTaggedOutput(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
aconfig_declarations {
|
|
|
|
name: "foo_aconfig_declarations",
|
|
|
|
srcs: [
|
|
|
|
"foo.aconfig",
|
|
|
|
],
|
|
|
|
package: "com.android.foo",
|
|
|
|
}
|
|
|
|
java_library {
|
|
|
|
name: "foo_library",
|
|
|
|
srcs: [":foo_aconfig_library{.generated_srcjars}"],
|
|
|
|
sdk_version: "current",
|
|
|
|
bazel_module: { bp2build_available: true },
|
|
|
|
}
|
|
|
|
java_aconfig_library {
|
|
|
|
name: "foo_aconfig_library",
|
|
|
|
aconfig_declarations: "foo_aconfig_declarations",
|
|
|
|
test: true,
|
|
|
|
}
|
|
|
|
`
|
|
|
|
expectedBazelTargets := []string{
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"aconfig_declarations",
|
|
|
|
"foo_aconfig_declarations",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `["foo.aconfig"]`,
|
|
|
|
"package": `"com.android.foo"`,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"java_aconfig_library",
|
|
|
|
"foo_aconfig_library",
|
|
|
|
AttrNameToString{
|
|
|
|
"aconfig_declarations": `":foo_aconfig_declarations"`,
|
|
|
|
"test": `True`,
|
|
|
|
"sdk_version": `"system_current"`,
|
2023-10-11 12:51:28 +02:00
|
|
|
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
2023-09-20 00:09:10 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
MakeBazelTargetNoRestrictions(
|
|
|
|
"java_library",
|
|
|
|
"foo_library",
|
|
|
|
AttrNameToString{
|
|
|
|
"srcs": `[":foo_aconfig_library.generated_srcjars"]`,
|
|
|
|
"sdk_version": `"current"`,
|
2023-10-11 12:51:28 +02:00
|
|
|
"target_compatible_with": `["//build/bazel_common_rules/platforms/os:android"]`,
|
2023-09-20 00:09:10 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
MakeNeverlinkDuplicateTarget("java_library", "foo_library"),
|
|
|
|
}
|
|
|
|
|
|
|
|
RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{
|
|
|
|
Blueprint: bp,
|
|
|
|
ExpectedBazelTargets: expectedBazelTargets,
|
|
|
|
})
|
|
|
|
}
|