platform_build_soong/android/androidmk_test.go
Jooyung Han 12df5fb471 soong: Fix AndroidMk with *Required properties
java.Module is using "Custom" function to write Android.mk.
And if "hostdex" is set to "true", it writes "hostdex" module definition
as well as original module.

As of now, Required/Host_required/Target_required props are filled in
the AndroidMkEntries structure(aosp/939505). But these are not
passed to old AndroidMkData.Custom function.

So, if a java_library declares "hostdex:true" and "required:[...]"
together, "required" is not applied to the "hostdex" variant.

This change copies *Required props from AndroidMkEntries to
AndroidMkData before calling its Custom callback.

Test: m (runs soong unit tests)
Change-Id: I5f85714f721a2a0917ab18072dbea52294c770e7
2019-07-16 02:28:29 +09:00

82 lines
2.2 KiB
Go

// Copyright 2019 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 android
import (
"io"
"reflect"
"testing"
)
type customModule struct {
ModuleBase
data AndroidMkData
}
func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) {
}
func (m *customModule) AndroidMk() AndroidMkData {
return AndroidMkData{
Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) {
m.data = data
},
}
}
func customModuleFactory() Module {
module := &customModule{}
InitAndroidModule(module)
return module
}
func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
config := TestConfig(buildDir, nil)
config.inMake = true // Enable androidmk Singleton
ctx := NewTestContext()
ctx.RegisterSingletonType("androidmk", SingletonFactoryAdaptor(AndroidMkSingleton))
ctx.RegisterModuleType("custom", ModuleFactoryAdaptor(customModuleFactory))
ctx.Register()
bp := `
custom {
name: "foo",
required: ["bar"],
host_required: ["baz"],
target_required: ["qux"],
}
`
ctx.MockFileSystem(map[string][]byte{
"Android.bp": []byte(bp),
})
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
FailIfErrored(t, errs)
_, errs = ctx.PrepareBuildActions(config)
FailIfErrored(t, errs)
m := ctx.ModuleForTests("foo", "").Module().(*customModule)
assertEqual := func(expected interface{}, actual interface{}) {
if !reflect.DeepEqual(expected, actual) {
t.Errorf("%q expected, but got %q", expected, actual)
}
}
assertEqual([]string{"bar"}, m.data.Required)
assertEqual([]string{"baz"}, m.data.Host_required)
assertEqual([]string{"qux"}, m.data.Target_required)
}