2021-03-11 09:07:46 +01: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.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2024-01-19 01:22:22 +01:00
|
|
|
"fmt"
|
2021-03-11 09:07:46 +01:00
|
|
|
"testing"
|
2021-03-11 09:10:19 +01:00
|
|
|
|
|
|
|
"android/soong/android"
|
2021-03-11 09:07:46 +01:00
|
|
|
)
|
|
|
|
|
2021-03-29 01:04:10 +02:00
|
|
|
func getModuleHeaderJarsAsRelativeToTopPaths(result *android.TestResult, moduleNames ...string) []string {
|
2021-03-11 09:10:19 +01:00
|
|
|
paths := []string{}
|
|
|
|
for _, moduleName := range moduleNames {
|
|
|
|
module := result.Module(moduleName, "android_common")
|
2023-12-14 23:46:23 +01:00
|
|
|
info, _ := android.SingletonModuleProvider(result, module, JavaInfoProvider)
|
2021-03-29 01:04:10 +02:00
|
|
|
paths = append(paths, info.HeaderJars.RelativeToTop().Strings()...)
|
2021-03-11 09:10:19 +01:00
|
|
|
}
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
|
|
|
var addSourceSystemModules = android.FixtureAddTextFile("source/Android.bp", `
|
2021-03-11 09:07:46 +01:00
|
|
|
java_system_modules {
|
|
|
|
name: "system-modules",
|
|
|
|
libs: ["system-module1", "system-module2"],
|
|
|
|
}
|
|
|
|
java_library {
|
|
|
|
name: "system-module1",
|
|
|
|
srcs: ["a.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
}
|
|
|
|
java_library {
|
|
|
|
name: "system-module2",
|
|
|
|
srcs: ["b.java"],
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "none",
|
|
|
|
}
|
2021-03-11 09:10:19 +01:00
|
|
|
`)
|
2021-03-11 09:07:46 +01:00
|
|
|
|
2021-03-11 09:10:19 +01:00
|
|
|
func TestJavaSystemModules(t *testing.T) {
|
2021-03-29 03:06:19 +02:00
|
|
|
result := android.GroupFixturePreparers(prepareForJavaTest, addSourceSystemModules).RunTest(t)
|
2021-03-11 09:07:46 +01:00
|
|
|
|
2021-03-11 09:10:19 +01:00
|
|
|
// check the existence of the source module
|
|
|
|
sourceSystemModules := result.ModuleForTests("system-modules", "android_common")
|
|
|
|
sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
|
2021-03-11 09:07:46 +01:00
|
|
|
|
2021-03-11 09:10:19 +01:00
|
|
|
// The expected paths are the header jars from the source input modules.
|
2021-03-29 01:04:10 +02:00
|
|
|
expectedSourcePaths := getModuleHeaderJarsAsRelativeToTopPaths(result, "system-module1", "system-module2")
|
|
|
|
android.AssertArrayString(t, "source system modules inputs", expectedSourcePaths, sourceInputs.RelativeToTop().Strings())
|
2021-03-11 09:07:46 +01:00
|
|
|
}
|
|
|
|
|
2021-03-11 09:10:19 +01:00
|
|
|
var addPrebuiltSystemModules = android.FixtureAddTextFile("prebuilts/Android.bp", `
|
2021-03-11 09:07:46 +01:00
|
|
|
java_system_modules_import {
|
|
|
|
name: "system-modules",
|
|
|
|
libs: ["system-module1", "system-module2"],
|
|
|
|
}
|
|
|
|
java_import {
|
|
|
|
name: "system-module1",
|
|
|
|
jars: ["a.jar"],
|
|
|
|
}
|
|
|
|
java_import {
|
|
|
|
name: "system-module2",
|
|
|
|
jars: ["b.jar"],
|
|
|
|
}
|
2021-03-11 09:10:19 +01:00
|
|
|
`)
|
2021-03-11 09:07:46 +01:00
|
|
|
|
2021-03-11 09:10:19 +01:00
|
|
|
func TestJavaSystemModulesImport(t *testing.T) {
|
2021-03-29 03:06:19 +02:00
|
|
|
result := android.GroupFixturePreparers(prepareForJavaTest, addPrebuiltSystemModules).RunTest(t)
|
2021-03-11 09:07:46 +01:00
|
|
|
|
2021-03-11 09:10:19 +01:00
|
|
|
// check the existence of the renamed prebuilt module
|
|
|
|
prebuiltSystemModules := result.ModuleForTests("system-modules", "android_common")
|
|
|
|
prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
|
2021-03-11 09:07:46 +01:00
|
|
|
|
2021-03-11 09:10:19 +01:00
|
|
|
// The expected paths are the header jars from the renamed prebuilt input modules.
|
2021-03-29 01:04:10 +02:00
|
|
|
expectedPrebuiltPaths := getModuleHeaderJarsAsRelativeToTopPaths(result, "system-module1", "system-module2")
|
|
|
|
android.AssertArrayString(t, "renamed prebuilt system modules inputs", expectedPrebuiltPaths, prebuiltInputs.RelativeToTop().Strings())
|
2021-03-11 09:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestJavaSystemModulesMixSourceAndPrebuilt(t *testing.T) {
|
2021-03-29 03:06:19 +02:00
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
2021-03-11 09:10:19 +01:00
|
|
|
addSourceSystemModules,
|
|
|
|
addPrebuiltSystemModules,
|
2021-03-29 03:06:19 +02:00
|
|
|
).RunTest(t)
|
2021-03-11 09:10:19 +01:00
|
|
|
|
|
|
|
// check the existence of the source module
|
|
|
|
sourceSystemModules := result.ModuleForTests("system-modules", "android_common")
|
|
|
|
sourceInputs := sourceSystemModules.Rule("jarsTosystemModules").Inputs
|
|
|
|
|
|
|
|
// The expected paths are the header jars from the source input modules.
|
2021-03-29 01:04:10 +02:00
|
|
|
expectedSourcePaths := getModuleHeaderJarsAsRelativeToTopPaths(result, "system-module1", "system-module2")
|
|
|
|
android.AssertArrayString(t, "source system modules inputs", expectedSourcePaths, sourceInputs.RelativeToTop().Strings())
|
2021-03-11 09:10:19 +01:00
|
|
|
|
|
|
|
// check the existence of the renamed prebuilt module
|
|
|
|
prebuiltSystemModules := result.ModuleForTests("prebuilt_system-modules", "android_common")
|
|
|
|
prebuiltInputs := prebuiltSystemModules.Rule("jarsTosystemModules").Inputs
|
|
|
|
|
|
|
|
// The expected paths are the header jars from the renamed prebuilt input modules.
|
2021-03-29 01:04:10 +02:00
|
|
|
expectedPrebuiltPaths := getModuleHeaderJarsAsRelativeToTopPaths(result, "prebuilt_system-module1", "prebuilt_system-module2")
|
|
|
|
android.AssertArrayString(t, "prebuilt system modules inputs", expectedPrebuiltPaths, prebuiltInputs.RelativeToTop().Strings())
|
2021-03-11 09:07:46 +01:00
|
|
|
}
|
2024-01-19 01:22:22 +01:00
|
|
|
|
|
|
|
func TestMultipleSystemModulesPrebuilts(t *testing.T) {
|
|
|
|
bp := `
|
|
|
|
// an rdep
|
|
|
|
java_library {
|
|
|
|
name: "foo",
|
|
|
|
sdk_version: "none",
|
|
|
|
system_modules: "my_system_modules",
|
|
|
|
}
|
|
|
|
|
|
|
|
// multiple variations of java_system_modules
|
|
|
|
// source
|
|
|
|
java_system_modules {
|
|
|
|
name: "my_system_modules",
|
|
|
|
libs: ["bar"],
|
|
|
|
}
|
|
|
|
java_library {
|
|
|
|
name: "bar",
|
|
|
|
srcs: ["bar.java"],
|
|
|
|
}
|
|
|
|
// prebuilt "v1"
|
|
|
|
java_system_modules_import {
|
|
|
|
name: "my_system_modules.v1",
|
|
|
|
source_module_name: "my_system_modules",
|
|
|
|
libs: ["bar.v1"],
|
|
|
|
}
|
|
|
|
java_import {
|
|
|
|
name: "bar.v1",
|
|
|
|
source_module_name: "bar",
|
|
|
|
jars: ["bar.v1.jar"],
|
|
|
|
}
|
|
|
|
// prebuilt "v2"
|
|
|
|
java_system_modules_import {
|
|
|
|
name: "my_system_modules.v2",
|
|
|
|
source_module_name: "my_system_modules",
|
|
|
|
libs: ["bar.v2"],
|
|
|
|
}
|
|
|
|
java_import {
|
|
|
|
name: "bar.v2",
|
|
|
|
source_module_name: "bar",
|
|
|
|
jars: ["bar.v2.jar"],
|
|
|
|
}
|
|
|
|
|
|
|
|
// selectors
|
|
|
|
apex_contributions {
|
|
|
|
name: "myapex_contributions",
|
|
|
|
contents: ["%v"],
|
|
|
|
}
|
|
|
|
`
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
selectedDependencyName string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Source system_modules is selected using apex_contributions",
|
|
|
|
selectedDependencyName: "my_system_modules",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Prebuilt system_modules v1 is selected using apex_contributions",
|
|
|
|
selectedDependencyName: "prebuilt_my_system_modules.v1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Prebuilt system_modules v2 is selected using apex_contributions",
|
|
|
|
selectedDependencyName: "prebuilt_my_system_modules.v2",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
res := android.GroupFixturePreparers(
|
|
|
|
prepareForJavaTest,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.BuildFlags = map[string]string{
|
|
|
|
"RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "myapex_contributions",
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).RunTestWithBp(t, fmt.Sprintf(bp, tc.selectedDependencyName))
|
|
|
|
|
|
|
|
// check that rdep gets the correct variation of system_modules
|
|
|
|
hasDep := CheckModuleHasDependency(t, res.TestContext, "foo", "android_common", tc.selectedDependencyName)
|
|
|
|
android.AssertBoolEquals(t, fmt.Sprintf("expected dependency from foo to %s\n", tc.selectedDependencyName), true, hasDep)
|
|
|
|
}
|
|
|
|
}
|