Start using Providers instead of direct module access
Export information about static libraries, shared libraries and exported flags through Providers instead of accessing the module directly. Much more is left to be converted, but this significantly simplifies the dependencies on libraries with stubs by making it easy for a module to masquerade as another by simply exporting the providers from the other module. Instead of depending on all the versions of a library and then picking which one to use later, it can depend only on the implementation variant and then select the right SharedLibraryInfo from the variant. Test: m checkbuild Test: only expected changes to build.ninja Change-Id: I1fd9eb4d251cf96ed8398d586efc3e0817663c76
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -2890,59 +2889,6 @@ func parseModuleDeps(text string) (modulesInOrder []android.Path, allDeps map[an
|
||||
return modulesInOrder, allDeps
|
||||
}
|
||||
|
||||
func TestLinkReordering(t *testing.T) {
|
||||
for _, testCase := range staticLinkDepOrderTestCases {
|
||||
errs := []string{}
|
||||
|
||||
// parse testcase
|
||||
_, givenTransitiveDeps := parseModuleDeps(testCase.inStatic)
|
||||
expectedModuleNames, expectedTransitiveDeps := parseModuleDeps(testCase.outOrdered)
|
||||
if testCase.allOrdered == "" {
|
||||
// allow the test case to skip specifying allOrdered
|
||||
testCase.allOrdered = testCase.outOrdered
|
||||
}
|
||||
_, expectedAllDeps := parseModuleDeps(testCase.allOrdered)
|
||||
_, givenAllSharedDeps := parseModuleDeps(testCase.inShared)
|
||||
|
||||
// For each module whose post-reordered dependencies were specified, validate that
|
||||
// reordering the inputs produces the expected outputs.
|
||||
for _, moduleName := range expectedModuleNames {
|
||||
moduleDeps := givenTransitiveDeps[moduleName]
|
||||
givenSharedDeps := givenAllSharedDeps[moduleName]
|
||||
orderedAllDeps, orderedDeclaredDeps := orderDeps(moduleDeps, givenSharedDeps, givenTransitiveDeps)
|
||||
|
||||
correctAllOrdered := expectedAllDeps[moduleName]
|
||||
if !reflect.DeepEqual(orderedAllDeps, correctAllOrdered) {
|
||||
errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedAllDeps."+
|
||||
"\nin static:%q"+
|
||||
"\nin shared:%q"+
|
||||
"\nmodule: %v"+
|
||||
"\nexpected: %s"+
|
||||
"\nactual: %s",
|
||||
testCase.inStatic, testCase.inShared, moduleName, correctAllOrdered, orderedAllDeps))
|
||||
}
|
||||
|
||||
correctOutputDeps := expectedTransitiveDeps[moduleName]
|
||||
if !reflect.DeepEqual(correctOutputDeps, orderedDeclaredDeps) {
|
||||
errs = append(errs, fmt.Sprintf("orderDeps returned incorrect orderedDeclaredDeps."+
|
||||
"\nin static:%q"+
|
||||
"\nin shared:%q"+
|
||||
"\nmodule: %v"+
|
||||
"\nexpected: %s"+
|
||||
"\nactual: %s",
|
||||
testCase.inStatic, testCase.inShared, moduleName, correctOutputDeps, orderedDeclaredDeps))
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
sort.Strings(errs)
|
||||
for _, err := range errs {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) {
|
||||
for _, moduleName := range moduleNames {
|
||||
module := ctx.ModuleForTests(moduleName, variant).Module().(*Module)
|
||||
@@ -2977,8 +2923,8 @@ func TestStaticLibDepReordering(t *testing.T) {
|
||||
|
||||
variant := "android_arm64_armv8-a_static"
|
||||
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
|
||||
actual := moduleA.depsInLinkOrder
|
||||
expected := getOutputPaths(ctx, variant, []string{"c", "b", "d"})
|
||||
actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
|
||||
expected := getOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("staticDeps orderings were not propagated correctly"+
|
||||
@@ -3011,8 +2957,8 @@ func TestStaticLibDepReorderingWithShared(t *testing.T) {
|
||||
|
||||
variant := "android_arm64_armv8-a_static"
|
||||
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
|
||||
actual := moduleA.depsInLinkOrder
|
||||
expected := getOutputPaths(ctx, variant, []string{"c", "b"})
|
||||
actual := ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo).TransitiveStaticLibrariesForOrdering.ToList()
|
||||
expected := getOutputPaths(ctx, variant, []string{"a", "c", "b"})
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("staticDeps orderings did not account for shared libs"+
|
||||
@@ -3048,12 +2994,12 @@ func TestLlndkLibrary(t *testing.T) {
|
||||
`)
|
||||
actual := ctx.ModuleVariantsForTests("libllndk.llndk")
|
||||
expected := []string{
|
||||
"android_vendor.VER_arm64_armv8-a_shared",
|
||||
"android_vendor.VER_arm64_armv8-a_shared_1",
|
||||
"android_vendor.VER_arm64_armv8-a_shared_2",
|
||||
"android_vendor.VER_arm_armv7-a-neon_shared",
|
||||
"android_vendor.VER_arm64_armv8-a_shared",
|
||||
"android_vendor.VER_arm_armv7-a-neon_shared_1",
|
||||
"android_vendor.VER_arm_armv7-a-neon_shared_2",
|
||||
"android_vendor.VER_arm_armv7-a-neon_shared",
|
||||
}
|
||||
checkEquals(t, "variants for llndk stubs", expected, actual)
|
||||
|
||||
@@ -3582,7 +3528,7 @@ func TestStaticDepsOrderWithStubs(t *testing.T) {
|
||||
cc_binary {
|
||||
name: "mybin",
|
||||
srcs: ["foo.c"],
|
||||
static_libs: ["libfooB"],
|
||||
static_libs: ["libfooC", "libfooB"],
|
||||
static_executable: true,
|
||||
stl: "none",
|
||||
}
|
||||
@@ -3603,8 +3549,8 @@ func TestStaticDepsOrderWithStubs(t *testing.T) {
|
||||
},
|
||||
}`)
|
||||
|
||||
mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Module().(*Module)
|
||||
actual := mybin.depsInLinkOrder
|
||||
mybin := ctx.ModuleForTests("mybin", "android_arm64_armv8-a").Rule("ld")
|
||||
actual := mybin.Implicits[:2]
|
||||
expected := getOutputPaths(ctx, "android_arm64_armv8-a_static", []string{"libfooB", "libfooC"})
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
|
Reference in New Issue
Block a user