'deps' is a module prop used by some module types, like prebuilt_build_tool: https://cs.android.com/android/platform/superproject/+/master:build/soong/android/prebuilt_build_tool.go;l=25-26;drc=751ae87ed29c67629f068a8590af80023a457294 Use `module_deps` to prevent conflicts in the generated overlay attributes. Bug: 162720644 Test: m bazel_overlay && cd out/soong/bazel_overlay && bazel cquery //... Test: soong_build tests Signed-off-by: Jingwen Chen <jingwen@google.com> Change-Id: Ia075a860983960b2d9121d30ead8f808be7e0c5b
256 lines
4.7 KiB
Go
256 lines
4.7 KiB
Go
// Copyright 2020 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 main
|
|
|
|
import (
|
|
"android/soong/android"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
var buildDir string
|
|
|
|
func setUp() {
|
|
var err error
|
|
buildDir, err = ioutil.TempDir("", "bazel_overlay_test")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func tearDown() {
|
|
os.RemoveAll(buildDir)
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
run := func() int {
|
|
setUp()
|
|
defer tearDown()
|
|
|
|
return m.Run()
|
|
}
|
|
|
|
os.Exit(run())
|
|
}
|
|
|
|
type customModule struct {
|
|
android.ModuleBase
|
|
}
|
|
|
|
func (m *customModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
// nothing for now.
|
|
}
|
|
|
|
func customModuleFactory() android.Module {
|
|
module := &customModule{}
|
|
android.InitAndroidModule(module)
|
|
return module
|
|
}
|
|
|
|
func TestGenerateBazelOverlayFromBlueprint(t *testing.T) {
|
|
testCases := []struct {
|
|
bp string
|
|
expectedBazelTarget string
|
|
}{
|
|
{
|
|
bp: `custom {
|
|
name: "foo",
|
|
}
|
|
`,
|
|
expectedBazelTarget: `soong_module(
|
|
name = "foo",
|
|
module_name = "foo",
|
|
module_type = "custom",
|
|
module_variant = "",
|
|
module_deps = [
|
|
],
|
|
)`,
|
|
},
|
|
{
|
|
bp: `custom {
|
|
name: "foo",
|
|
ramdisk: true,
|
|
}
|
|
`,
|
|
expectedBazelTarget: `soong_module(
|
|
name = "foo",
|
|
module_name = "foo",
|
|
module_type = "custom",
|
|
module_variant = "",
|
|
module_deps = [
|
|
],
|
|
ramdisk = True,
|
|
)`,
|
|
},
|
|
{
|
|
bp: `custom {
|
|
name: "foo",
|
|
owner: "a_string_with\"quotes\"_and_\\backslashes\\\\",
|
|
}
|
|
`,
|
|
expectedBazelTarget: `soong_module(
|
|
name = "foo",
|
|
module_name = "foo",
|
|
module_type = "custom",
|
|
module_variant = "",
|
|
module_deps = [
|
|
],
|
|
owner = "a_string_with\"quotes\"_and_\\backslashes\\\\",
|
|
)`,
|
|
},
|
|
{
|
|
bp: `custom {
|
|
name: "foo",
|
|
required: ["bar"],
|
|
}
|
|
`,
|
|
expectedBazelTarget: `soong_module(
|
|
name = "foo",
|
|
module_name = "foo",
|
|
module_type = "custom",
|
|
module_variant = "",
|
|
module_deps = [
|
|
],
|
|
required = [
|
|
"bar",
|
|
],
|
|
)`,
|
|
},
|
|
{
|
|
bp: `custom {
|
|
name: "foo",
|
|
target_required: ["qux", "bazqux"],
|
|
}
|
|
`,
|
|
expectedBazelTarget: `soong_module(
|
|
name = "foo",
|
|
module_name = "foo",
|
|
module_type = "custom",
|
|
module_variant = "",
|
|
module_deps = [
|
|
],
|
|
target_required = [
|
|
"qux",
|
|
"bazqux",
|
|
],
|
|
)`,
|
|
},
|
|
{
|
|
bp: `custom {
|
|
name: "foo",
|
|
dist: {
|
|
targets: ["goal_foo"],
|
|
tag: ".foo",
|
|
},
|
|
dists: [
|
|
{
|
|
targets: ["goal_bar"],
|
|
tag: ".bar",
|
|
},
|
|
],
|
|
}
|
|
`,
|
|
expectedBazelTarget: `soong_module(
|
|
name = "foo",
|
|
module_name = "foo",
|
|
module_type = "custom",
|
|
module_variant = "",
|
|
module_deps = [
|
|
],
|
|
dist = {
|
|
"tag": ".foo",
|
|
"targets": [
|
|
"goal_foo",
|
|
],
|
|
},
|
|
dists = [
|
|
{
|
|
"tag": ".bar",
|
|
"targets": [
|
|
"goal_bar",
|
|
],
|
|
},
|
|
],
|
|
)`,
|
|
},
|
|
{
|
|
bp: `custom {
|
|
name: "foo",
|
|
required: ["bar"],
|
|
target_required: ["qux", "bazqux"],
|
|
ramdisk: true,
|
|
owner: "custom_owner",
|
|
dists: [
|
|
{
|
|
tag: ".tag",
|
|
targets: ["my_goal"],
|
|
},
|
|
],
|
|
}
|
|
`,
|
|
expectedBazelTarget: `soong_module(
|
|
name = "foo",
|
|
module_name = "foo",
|
|
module_type = "custom",
|
|
module_variant = "",
|
|
module_deps = [
|
|
],
|
|
dists = [
|
|
{
|
|
"tag": ".tag",
|
|
"targets": [
|
|
"my_goal",
|
|
],
|
|
},
|
|
],
|
|
owner = "custom_owner",
|
|
ramdisk = True,
|
|
required = [
|
|
"bar",
|
|
],
|
|
target_required = [
|
|
"qux",
|
|
"bazqux",
|
|
],
|
|
)`,
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
config := android.TestConfig(buildDir, nil, testCase.bp, nil)
|
|
ctx := android.NewTestContext()
|
|
ctx.RegisterModuleType("custom", customModuleFactory)
|
|
ctx.Register(config)
|
|
|
|
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
|
|
android.FailIfErrored(t, errs)
|
|
_, errs = ctx.PrepareBuildActions(config)
|
|
android.FailIfErrored(t, errs)
|
|
|
|
module := ctx.ModuleForTests("foo", "").Module().(*customModule)
|
|
blueprintCtx := ctx.Context.Context
|
|
|
|
actualBazelTarget := generateSoongModuleTarget(blueprintCtx, module)
|
|
if actualBazelTarget != testCase.expectedBazelTarget {
|
|
t.Errorf(
|
|
"Expected generated Bazel target to be '%s', got '%s'",
|
|
testCase.expectedBazelTarget,
|
|
actualBazelTarget,
|
|
)
|
|
}
|
|
}
|
|
}
|