1*333d2b36SAndroid Build Coastguard Worker// Copyright 2019 Google Inc. All rights reserved. 2*333d2b36SAndroid Build Coastguard Worker// 3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*333d2b36SAndroid Build Coastguard Worker// 7*333d2b36SAndroid Build Coastguard Worker// http://www.apache.org/licenses/LICENSE-2.0 8*333d2b36SAndroid Build Coastguard Worker// 9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*333d2b36SAndroid Build Coastguard Worker// limitations under the License. 14*333d2b36SAndroid Build Coastguard Worker 15*333d2b36SAndroid Build Coastguard Workerpackage cc 16*333d2b36SAndroid Build Coastguard Worker 17*333d2b36SAndroid Build Coastguard Workerimport ( 18*333d2b36SAndroid Build Coastguard Worker "fmt" 19*333d2b36SAndroid Build Coastguard Worker "runtime" 20*333d2b36SAndroid Build Coastguard Worker "testing" 21*333d2b36SAndroid Build Coastguard Worker 22*333d2b36SAndroid Build Coastguard Worker "android/soong/android" 23*333d2b36SAndroid Build Coastguard Worker "github.com/google/blueprint" 24*333d2b36SAndroid Build Coastguard Worker) 25*333d2b36SAndroid Build Coastguard Worker 26*333d2b36SAndroid Build Coastguard Workervar prepareForPrebuiltTest = android.GroupFixturePreparers( 27*333d2b36SAndroid Build Coastguard Worker prepareForCcTest, 28*333d2b36SAndroid Build Coastguard Worker android.PrepareForTestWithAndroidMk, 29*333d2b36SAndroid Build Coastguard Worker) 30*333d2b36SAndroid Build Coastguard Worker 31*333d2b36SAndroid Build Coastguard Workerfunc testPrebuilt(t *testing.T, bp string, fs android.MockFS, handlers ...android.FixturePreparer) *android.TestContext { 32*333d2b36SAndroid Build Coastguard Worker t.Helper() 33*333d2b36SAndroid Build Coastguard Worker result := android.GroupFixturePreparers( 34*333d2b36SAndroid Build Coastguard Worker prepareForPrebuiltTest, 35*333d2b36SAndroid Build Coastguard Worker fs.AddToFixture(), 36*333d2b36SAndroid Build Coastguard Worker android.GroupFixturePreparers(handlers...), 37*333d2b36SAndroid Build Coastguard Worker ).RunTestWithBp(t, bp) 38*333d2b36SAndroid Build Coastguard Worker 39*333d2b36SAndroid Build Coastguard Worker return result.TestContext 40*333d2b36SAndroid Build Coastguard Worker} 41*333d2b36SAndroid Build Coastguard Worker 42*333d2b36SAndroid Build Coastguard Workertype configCustomizer func(config android.Config) 43*333d2b36SAndroid Build Coastguard Worker 44*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuilt(t *testing.T) { 45*333d2b36SAndroid Build Coastguard Worker bp := ` 46*333d2b36SAndroid Build Coastguard Worker cc_library { 47*333d2b36SAndroid Build Coastguard Worker name: "liba", 48*333d2b36SAndroid Build Coastguard Worker } 49*333d2b36SAndroid Build Coastguard Worker 50*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 51*333d2b36SAndroid Build Coastguard Worker name: "liba", 52*333d2b36SAndroid Build Coastguard Worker srcs: ["liba.so"], 53*333d2b36SAndroid Build Coastguard Worker prefer: true, 54*333d2b36SAndroid Build Coastguard Worker } 55*333d2b36SAndroid Build Coastguard Worker 56*333d2b36SAndroid Build Coastguard Worker cc_library { 57*333d2b36SAndroid Build Coastguard Worker name: "libb", 58*333d2b36SAndroid Build Coastguard Worker } 59*333d2b36SAndroid Build Coastguard Worker 60*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_static { 61*333d2b36SAndroid Build Coastguard Worker name: "libb", 62*333d2b36SAndroid Build Coastguard Worker srcs: ["libb.a"], 63*333d2b36SAndroid Build Coastguard Worker prefer: true, 64*333d2b36SAndroid Build Coastguard Worker } 65*333d2b36SAndroid Build Coastguard Worker 66*333d2b36SAndroid Build Coastguard Worker cc_library_shared { 67*333d2b36SAndroid Build Coastguard Worker name: "libd", 68*333d2b36SAndroid Build Coastguard Worker } 69*333d2b36SAndroid Build Coastguard Worker 70*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 71*333d2b36SAndroid Build Coastguard Worker name: "libd", 72*333d2b36SAndroid Build Coastguard Worker srcs: ["libd.so"], 73*333d2b36SAndroid Build Coastguard Worker } 74*333d2b36SAndroid Build Coastguard Worker 75*333d2b36SAndroid Build Coastguard Worker cc_library_static { 76*333d2b36SAndroid Build Coastguard Worker name: "libe", 77*333d2b36SAndroid Build Coastguard Worker } 78*333d2b36SAndroid Build Coastguard Worker 79*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_static { 80*333d2b36SAndroid Build Coastguard Worker name: "libe", 81*333d2b36SAndroid Build Coastguard Worker srcs: ["libe.a"], 82*333d2b36SAndroid Build Coastguard Worker } 83*333d2b36SAndroid Build Coastguard Worker 84*333d2b36SAndroid Build Coastguard Worker cc_library { 85*333d2b36SAndroid Build Coastguard Worker name: "libf", 86*333d2b36SAndroid Build Coastguard Worker } 87*333d2b36SAndroid Build Coastguard Worker 88*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library { 89*333d2b36SAndroid Build Coastguard Worker name: "libf", 90*333d2b36SAndroid Build Coastguard Worker static: { 91*333d2b36SAndroid Build Coastguard Worker srcs: ["libf.a"], 92*333d2b36SAndroid Build Coastguard Worker }, 93*333d2b36SAndroid Build Coastguard Worker shared: { 94*333d2b36SAndroid Build Coastguard Worker srcs: ["libf.so"], 95*333d2b36SAndroid Build Coastguard Worker }, 96*333d2b36SAndroid Build Coastguard Worker } 97*333d2b36SAndroid Build Coastguard Worker 98*333d2b36SAndroid Build Coastguard Worker cc_object { 99*333d2b36SAndroid Build Coastguard Worker name: "crtx", 100*333d2b36SAndroid Build Coastguard Worker } 101*333d2b36SAndroid Build Coastguard Worker 102*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_object { 103*333d2b36SAndroid Build Coastguard Worker name: "crtx", 104*333d2b36SAndroid Build Coastguard Worker srcs: ["crtx.o"], 105*333d2b36SAndroid Build Coastguard Worker } 106*333d2b36SAndroid Build Coastguard Worker ` 107*333d2b36SAndroid Build Coastguard Worker 108*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, bp, map[string][]byte{ 109*333d2b36SAndroid Build Coastguard Worker "liba.so": nil, 110*333d2b36SAndroid Build Coastguard Worker "libb.a": nil, 111*333d2b36SAndroid Build Coastguard Worker "libd.so": nil, 112*333d2b36SAndroid Build Coastguard Worker "libe.a": nil, 113*333d2b36SAndroid Build Coastguard Worker "libf.a": nil, 114*333d2b36SAndroid Build Coastguard Worker "libf.so": nil, 115*333d2b36SAndroid Build Coastguard Worker "crtx.o": nil, 116*333d2b36SAndroid Build Coastguard Worker }) 117*333d2b36SAndroid Build Coastguard Worker 118*333d2b36SAndroid Build Coastguard Worker // Verify that all the modules exist and that their dependencies were connected correctly 119*333d2b36SAndroid Build Coastguard Worker liba := ctx.ModuleForTests("liba", "android_arm64_armv8-a_shared").Module() 120*333d2b36SAndroid Build Coastguard Worker libb := ctx.ModuleForTests("libb", "android_arm64_armv8-a_static").Module() 121*333d2b36SAndroid Build Coastguard Worker libd := ctx.ModuleForTests("libd", "android_arm64_armv8-a_shared").Module() 122*333d2b36SAndroid Build Coastguard Worker libe := ctx.ModuleForTests("libe", "android_arm64_armv8-a_static").Module() 123*333d2b36SAndroid Build Coastguard Worker libfStatic := ctx.ModuleForTests("libf", "android_arm64_armv8-a_static").Module() 124*333d2b36SAndroid Build Coastguard Worker libfShared := ctx.ModuleForTests("libf", "android_arm64_armv8-a_shared").Module() 125*333d2b36SAndroid Build Coastguard Worker crtx := ctx.ModuleForTests("crtx", "android_arm64_armv8-a").Module() 126*333d2b36SAndroid Build Coastguard Worker 127*333d2b36SAndroid Build Coastguard Worker prebuiltLiba := ctx.ModuleForTests("prebuilt_liba", "android_arm64_armv8-a_shared").Module() 128*333d2b36SAndroid Build Coastguard Worker prebuiltLibb := ctx.ModuleForTests("prebuilt_libb", "android_arm64_armv8-a_static").Module() 129*333d2b36SAndroid Build Coastguard Worker prebuiltLibd := ctx.ModuleForTests("prebuilt_libd", "android_arm64_armv8-a_shared").Module() 130*333d2b36SAndroid Build Coastguard Worker prebuiltLibe := ctx.ModuleForTests("prebuilt_libe", "android_arm64_armv8-a_static").Module() 131*333d2b36SAndroid Build Coastguard Worker prebuiltLibfStatic := ctx.ModuleForTests("prebuilt_libf", "android_arm64_armv8-a_static").Module() 132*333d2b36SAndroid Build Coastguard Worker prebuiltLibfShared := ctx.ModuleForTests("prebuilt_libf", "android_arm64_armv8-a_shared").Module() 133*333d2b36SAndroid Build Coastguard Worker prebuiltCrtx := ctx.ModuleForTests("prebuilt_crtx", "android_arm64_armv8-a").Module() 134*333d2b36SAndroid Build Coastguard Worker 135*333d2b36SAndroid Build Coastguard Worker hasDep := func(m android.Module, wantDep android.Module) bool { 136*333d2b36SAndroid Build Coastguard Worker t.Helper() 137*333d2b36SAndroid Build Coastguard Worker var found bool 138*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDeps(m, func(dep blueprint.Module) { 139*333d2b36SAndroid Build Coastguard Worker if dep == wantDep { 140*333d2b36SAndroid Build Coastguard Worker found = true 141*333d2b36SAndroid Build Coastguard Worker } 142*333d2b36SAndroid Build Coastguard Worker }) 143*333d2b36SAndroid Build Coastguard Worker return found 144*333d2b36SAndroid Build Coastguard Worker } 145*333d2b36SAndroid Build Coastguard Worker 146*333d2b36SAndroid Build Coastguard Worker if !hasDep(liba, prebuiltLiba) { 147*333d2b36SAndroid Build Coastguard Worker t.Errorf("liba missing dependency on prebuilt_liba") 148*333d2b36SAndroid Build Coastguard Worker } 149*333d2b36SAndroid Build Coastguard Worker 150*333d2b36SAndroid Build Coastguard Worker if !hasDep(libb, prebuiltLibb) { 151*333d2b36SAndroid Build Coastguard Worker t.Errorf("libb missing dependency on prebuilt_libb") 152*333d2b36SAndroid Build Coastguard Worker } 153*333d2b36SAndroid Build Coastguard Worker 154*333d2b36SAndroid Build Coastguard Worker if !hasDep(libd, prebuiltLibd) { 155*333d2b36SAndroid Build Coastguard Worker t.Errorf("libd missing dependency on prebuilt_libd") 156*333d2b36SAndroid Build Coastguard Worker } 157*333d2b36SAndroid Build Coastguard Worker 158*333d2b36SAndroid Build Coastguard Worker if !hasDep(libe, prebuiltLibe) { 159*333d2b36SAndroid Build Coastguard Worker t.Errorf("libe missing dependency on prebuilt_libe") 160*333d2b36SAndroid Build Coastguard Worker } 161*333d2b36SAndroid Build Coastguard Worker 162*333d2b36SAndroid Build Coastguard Worker if !hasDep(libfStatic, prebuiltLibfStatic) { 163*333d2b36SAndroid Build Coastguard Worker t.Errorf("libf static missing dependency on prebuilt_libf") 164*333d2b36SAndroid Build Coastguard Worker } 165*333d2b36SAndroid Build Coastguard Worker 166*333d2b36SAndroid Build Coastguard Worker if !hasDep(libfShared, prebuiltLibfShared) { 167*333d2b36SAndroid Build Coastguard Worker t.Errorf("libf shared missing dependency on prebuilt_libf") 168*333d2b36SAndroid Build Coastguard Worker } 169*333d2b36SAndroid Build Coastguard Worker 170*333d2b36SAndroid Build Coastguard Worker if !hasDep(crtx, prebuiltCrtx) { 171*333d2b36SAndroid Build Coastguard Worker t.Errorf("crtx missing dependency on prebuilt_crtx") 172*333d2b36SAndroid Build Coastguard Worker } 173*333d2b36SAndroid Build Coastguard Worker 174*333d2b36SAndroid Build Coastguard Worker entries := android.AndroidMkInfoForTest(t, ctx, prebuiltLiba).PrimaryInfo 175*333d2b36SAndroid Build Coastguard Worker android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "cc_prebuilt_library_shared", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0]) 176*333d2b36SAndroid Build Coastguard Worker entries = android.AndroidMkInfoForTest(t, ctx, prebuiltLibb).PrimaryInfo 177*333d2b36SAndroid Build Coastguard Worker android.AssertStringEquals(t, "unexpected LOCAL_SOONG_MODULE_TYPE", "cc_prebuilt_library_static", entries.EntryMap["LOCAL_SOONG_MODULE_TYPE"][0]) 178*333d2b36SAndroid Build Coastguard Worker} 179*333d2b36SAndroid Build Coastguard Worker 180*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltLibraryShared(t *testing.T) { 181*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, ` 182*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 183*333d2b36SAndroid Build Coastguard Worker name: "libtest", 184*333d2b36SAndroid Build Coastguard Worker srcs: ["libf.so"], 185*333d2b36SAndroid Build Coastguard Worker strip: { 186*333d2b36SAndroid Build Coastguard Worker none: true, 187*333d2b36SAndroid Build Coastguard Worker }, 188*333d2b36SAndroid Build Coastguard Worker } 189*333d2b36SAndroid Build Coastguard Worker `, map[string][]byte{ 190*333d2b36SAndroid Build Coastguard Worker "libf.so": nil, 191*333d2b36SAndroid Build Coastguard Worker }) 192*333d2b36SAndroid Build Coastguard Worker 193*333d2b36SAndroid Build Coastguard Worker shared := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Module().(*Module) 194*333d2b36SAndroid Build Coastguard Worker assertString(t, shared.OutputFile().Path().Base(), "libtest.so") 195*333d2b36SAndroid Build Coastguard Worker} 196*333d2b36SAndroid Build Coastguard Worker 197*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltLibraryStatic(t *testing.T) { 198*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, ` 199*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_static { 200*333d2b36SAndroid Build Coastguard Worker name: "libtest", 201*333d2b36SAndroid Build Coastguard Worker srcs: ["libf.a"], 202*333d2b36SAndroid Build Coastguard Worker } 203*333d2b36SAndroid Build Coastguard Worker `, map[string][]byte{ 204*333d2b36SAndroid Build Coastguard Worker "libf.a": nil, 205*333d2b36SAndroid Build Coastguard Worker }) 206*333d2b36SAndroid Build Coastguard Worker 207*333d2b36SAndroid Build Coastguard Worker static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module) 208*333d2b36SAndroid Build Coastguard Worker assertString(t, static.OutputFile().Path().Base(), "libf.a") 209*333d2b36SAndroid Build Coastguard Worker} 210*333d2b36SAndroid Build Coastguard Worker 211*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltLibrary(t *testing.T) { 212*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, ` 213*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library { 214*333d2b36SAndroid Build Coastguard Worker name: "libtest", 215*333d2b36SAndroid Build Coastguard Worker static: { 216*333d2b36SAndroid Build Coastguard Worker srcs: ["libf.a"], 217*333d2b36SAndroid Build Coastguard Worker }, 218*333d2b36SAndroid Build Coastguard Worker shared: { 219*333d2b36SAndroid Build Coastguard Worker srcs: ["libf.so"], 220*333d2b36SAndroid Build Coastguard Worker }, 221*333d2b36SAndroid Build Coastguard Worker strip: { 222*333d2b36SAndroid Build Coastguard Worker none: true, 223*333d2b36SAndroid Build Coastguard Worker }, 224*333d2b36SAndroid Build Coastguard Worker } 225*333d2b36SAndroid Build Coastguard Worker `, map[string][]byte{ 226*333d2b36SAndroid Build Coastguard Worker "libf.a": nil, 227*333d2b36SAndroid Build Coastguard Worker "libf.so": nil, 228*333d2b36SAndroid Build Coastguard Worker }) 229*333d2b36SAndroid Build Coastguard Worker 230*333d2b36SAndroid Build Coastguard Worker shared := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Module().(*Module) 231*333d2b36SAndroid Build Coastguard Worker assertString(t, shared.OutputFile().Path().Base(), "libtest.so") 232*333d2b36SAndroid Build Coastguard Worker 233*333d2b36SAndroid Build Coastguard Worker static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module) 234*333d2b36SAndroid Build Coastguard Worker assertString(t, static.OutputFile().Path().Base(), "libf.a") 235*333d2b36SAndroid Build Coastguard Worker} 236*333d2b36SAndroid Build Coastguard Worker 237*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltLibraryStem(t *testing.T) { 238*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, ` 239*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library { 240*333d2b36SAndroid Build Coastguard Worker name: "libfoo", 241*333d2b36SAndroid Build Coastguard Worker stem: "libbar", 242*333d2b36SAndroid Build Coastguard Worker static: { 243*333d2b36SAndroid Build Coastguard Worker srcs: ["libfoo.a"], 244*333d2b36SAndroid Build Coastguard Worker }, 245*333d2b36SAndroid Build Coastguard Worker shared: { 246*333d2b36SAndroid Build Coastguard Worker srcs: ["libfoo.so"], 247*333d2b36SAndroid Build Coastguard Worker }, 248*333d2b36SAndroid Build Coastguard Worker strip: { 249*333d2b36SAndroid Build Coastguard Worker none: true, 250*333d2b36SAndroid Build Coastguard Worker }, 251*333d2b36SAndroid Build Coastguard Worker } 252*333d2b36SAndroid Build Coastguard Worker `, map[string][]byte{ 253*333d2b36SAndroid Build Coastguard Worker "libfoo.a": nil, 254*333d2b36SAndroid Build Coastguard Worker "libfoo.so": nil, 255*333d2b36SAndroid Build Coastguard Worker }) 256*333d2b36SAndroid Build Coastguard Worker 257*333d2b36SAndroid Build Coastguard Worker static := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*Module) 258*333d2b36SAndroid Build Coastguard Worker assertString(t, static.OutputFile().Path().Base(), "libfoo.a") 259*333d2b36SAndroid Build Coastguard Worker 260*333d2b36SAndroid Build Coastguard Worker shared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*Module) 261*333d2b36SAndroid Build Coastguard Worker assertString(t, shared.OutputFile().Path().Base(), "libbar.so") 262*333d2b36SAndroid Build Coastguard Worker} 263*333d2b36SAndroid Build Coastguard Worker 264*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltLibrarySharedStem(t *testing.T) { 265*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, ` 266*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 267*333d2b36SAndroid Build Coastguard Worker name: "libfoo", 268*333d2b36SAndroid Build Coastguard Worker stem: "libbar", 269*333d2b36SAndroid Build Coastguard Worker srcs: ["libfoo.so"], 270*333d2b36SAndroid Build Coastguard Worker strip: { 271*333d2b36SAndroid Build Coastguard Worker none: true, 272*333d2b36SAndroid Build Coastguard Worker }, 273*333d2b36SAndroid Build Coastguard Worker } 274*333d2b36SAndroid Build Coastguard Worker `, map[string][]byte{ 275*333d2b36SAndroid Build Coastguard Worker "libfoo.so": nil, 276*333d2b36SAndroid Build Coastguard Worker }) 277*333d2b36SAndroid Build Coastguard Worker 278*333d2b36SAndroid Build Coastguard Worker shared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*Module) 279*333d2b36SAndroid Build Coastguard Worker assertString(t, shared.OutputFile().Path().Base(), "libbar.so") 280*333d2b36SAndroid Build Coastguard Worker} 281*333d2b36SAndroid Build Coastguard Worker 282*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltSymlinkedHostBinary(t *testing.T) { 283*333d2b36SAndroid Build Coastguard Worker if runtime.GOOS != "linux" { 284*333d2b36SAndroid Build Coastguard Worker t.Skipf("Skipping host prebuilt testing that is only supported on linux not %s", runtime.GOOS) 285*333d2b36SAndroid Build Coastguard Worker } 286*333d2b36SAndroid Build Coastguard Worker 287*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, ` 288*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 289*333d2b36SAndroid Build Coastguard Worker name: "libfoo", 290*333d2b36SAndroid Build Coastguard Worker device_supported: false, 291*333d2b36SAndroid Build Coastguard Worker host_supported: true, 292*333d2b36SAndroid Build Coastguard Worker target: { 293*333d2b36SAndroid Build Coastguard Worker linux_glibc_x86_64: { 294*333d2b36SAndroid Build Coastguard Worker srcs: ["linux_glibc_x86_64/lib64/libfoo.so"], 295*333d2b36SAndroid Build Coastguard Worker }, 296*333d2b36SAndroid Build Coastguard Worker }, 297*333d2b36SAndroid Build Coastguard Worker } 298*333d2b36SAndroid Build Coastguard Worker 299*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_binary { 300*333d2b36SAndroid Build Coastguard Worker name: "foo", 301*333d2b36SAndroid Build Coastguard Worker device_supported: false, 302*333d2b36SAndroid Build Coastguard Worker host_supported: true, 303*333d2b36SAndroid Build Coastguard Worker shared_libs: ["libfoo"], 304*333d2b36SAndroid Build Coastguard Worker target: { 305*333d2b36SAndroid Build Coastguard Worker linux_glibc_x86_64: { 306*333d2b36SAndroid Build Coastguard Worker srcs: ["linux_glibc_x86_64/bin/foo"], 307*333d2b36SAndroid Build Coastguard Worker }, 308*333d2b36SAndroid Build Coastguard Worker }, 309*333d2b36SAndroid Build Coastguard Worker } 310*333d2b36SAndroid Build Coastguard Worker `, map[string][]byte{ 311*333d2b36SAndroid Build Coastguard Worker "libfoo.so": nil, 312*333d2b36SAndroid Build Coastguard Worker "foo": nil, 313*333d2b36SAndroid Build Coastguard Worker }) 314*333d2b36SAndroid Build Coastguard Worker 315*333d2b36SAndroid Build Coastguard Worker fooRule := ctx.ModuleForTests("foo", "linux_glibc_x86_64").Rule("Symlink") 316*333d2b36SAndroid Build Coastguard Worker assertString(t, fooRule.Output.String(), "out/soong/.intermediates/foo/linux_glibc_x86_64/foo") 317*333d2b36SAndroid Build Coastguard Worker assertString(t, fooRule.Args["fromPath"], "$$PWD/linux_glibc_x86_64/bin/foo") 318*333d2b36SAndroid Build Coastguard Worker 319*333d2b36SAndroid Build Coastguard Worker var libfooDep android.Path 320*333d2b36SAndroid Build Coastguard Worker for _, dep := range fooRule.Implicits { 321*333d2b36SAndroid Build Coastguard Worker if dep.Base() == "libfoo.so" { 322*333d2b36SAndroid Build Coastguard Worker libfooDep = dep 323*333d2b36SAndroid Build Coastguard Worker break 324*333d2b36SAndroid Build Coastguard Worker } 325*333d2b36SAndroid Build Coastguard Worker } 326*333d2b36SAndroid Build Coastguard Worker assertString(t, libfooDep.String(), "out/soong/.intermediates/libfoo/linux_glibc_x86_64_shared/libfoo.so") 327*333d2b36SAndroid Build Coastguard Worker} 328*333d2b36SAndroid Build Coastguard Worker 329*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltLibrarySanitized(t *testing.T) { 330*333d2b36SAndroid Build Coastguard Worker bp := `cc_prebuilt_library { 331*333d2b36SAndroid Build Coastguard Worker name: "libtest", 332*333d2b36SAndroid Build Coastguard Worker static: { 333*333d2b36SAndroid Build Coastguard Worker sanitized: { none: { srcs: ["libf.a"], }, hwaddress: { srcs: ["libf.hwasan.a"], }, }, 334*333d2b36SAndroid Build Coastguard Worker }, 335*333d2b36SAndroid Build Coastguard Worker shared: { 336*333d2b36SAndroid Build Coastguard Worker sanitized: { none: { srcs: ["libf.so"], }, hwaddress: { srcs: ["hwasan/libf.so"], }, }, 337*333d2b36SAndroid Build Coastguard Worker }, 338*333d2b36SAndroid Build Coastguard Worker } 339*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_static { 340*333d2b36SAndroid Build Coastguard Worker name: "libtest_static", 341*333d2b36SAndroid Build Coastguard Worker sanitized: { none: { srcs: ["libf.a"], }, hwaddress: { srcs: ["libf.hwasan.a"], }, }, 342*333d2b36SAndroid Build Coastguard Worker } 343*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 344*333d2b36SAndroid Build Coastguard Worker name: "libtest_shared", 345*333d2b36SAndroid Build Coastguard Worker sanitized: { none: { srcs: ["libf.so"], }, hwaddress: { srcs: ["hwasan/libf.so"], }, }, 346*333d2b36SAndroid Build Coastguard Worker }` 347*333d2b36SAndroid Build Coastguard Worker 348*333d2b36SAndroid Build Coastguard Worker fs := map[string][]byte{ 349*333d2b36SAndroid Build Coastguard Worker "libf.a": nil, 350*333d2b36SAndroid Build Coastguard Worker "libf.hwasan.a": nil, 351*333d2b36SAndroid Build Coastguard Worker "libf.so": nil, 352*333d2b36SAndroid Build Coastguard Worker "hwasan/libf.so": nil, 353*333d2b36SAndroid Build Coastguard Worker } 354*333d2b36SAndroid Build Coastguard Worker 355*333d2b36SAndroid Build Coastguard Worker // Without SANITIZE_TARGET. 356*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, bp, fs) 357*333d2b36SAndroid Build Coastguard Worker 358*333d2b36SAndroid Build Coastguard Worker shared_rule := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared").Rule("android/soong/cc.strip") 359*333d2b36SAndroid Build Coastguard Worker assertString(t, shared_rule.Input.String(), "libf.so") 360*333d2b36SAndroid Build Coastguard Worker 361*333d2b36SAndroid Build Coastguard Worker static := ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static").Module().(*Module) 362*333d2b36SAndroid Build Coastguard Worker assertString(t, static.OutputFile().Path().Base(), "libf.a") 363*333d2b36SAndroid Build Coastguard Worker 364*333d2b36SAndroid Build Coastguard Worker shared_rule2 := ctx.ModuleForTests("libtest_shared", "android_arm64_armv8-a_shared").Rule("android/soong/cc.strip") 365*333d2b36SAndroid Build Coastguard Worker assertString(t, shared_rule2.Input.String(), "libf.so") 366*333d2b36SAndroid Build Coastguard Worker 367*333d2b36SAndroid Build Coastguard Worker static2 := ctx.ModuleForTests("libtest_static", "android_arm64_armv8-a_static").Module().(*Module) 368*333d2b36SAndroid Build Coastguard Worker assertString(t, static2.OutputFile().Path().Base(), "libf.a") 369*333d2b36SAndroid Build Coastguard Worker 370*333d2b36SAndroid Build Coastguard Worker // With SANITIZE_TARGET=hwaddress 371*333d2b36SAndroid Build Coastguard Worker ctx = testPrebuilt(t, bp, fs, 372*333d2b36SAndroid Build Coastguard Worker android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 373*333d2b36SAndroid Build Coastguard Worker variables.SanitizeDevice = []string{"hwaddress"} 374*333d2b36SAndroid Build Coastguard Worker }), 375*333d2b36SAndroid Build Coastguard Worker ) 376*333d2b36SAndroid Build Coastguard Worker 377*333d2b36SAndroid Build Coastguard Worker shared_rule = ctx.ModuleForTests("libtest", "android_arm64_armv8-a_shared_hwasan").Rule("android/soong/cc.strip") 378*333d2b36SAndroid Build Coastguard Worker assertString(t, shared_rule.Input.String(), "hwasan/libf.so") 379*333d2b36SAndroid Build Coastguard Worker 380*333d2b36SAndroid Build Coastguard Worker static = ctx.ModuleForTests("libtest", "android_arm64_armv8-a_static_hwasan").Module().(*Module) 381*333d2b36SAndroid Build Coastguard Worker assertString(t, static.OutputFile().Path().Base(), "libf.hwasan.a") 382*333d2b36SAndroid Build Coastguard Worker 383*333d2b36SAndroid Build Coastguard Worker shared_rule2 = ctx.ModuleForTests("libtest_shared", "android_arm64_armv8-a_shared_hwasan").Rule("android/soong/cc.strip") 384*333d2b36SAndroid Build Coastguard Worker assertString(t, shared_rule2.Input.String(), "hwasan/libf.so") 385*333d2b36SAndroid Build Coastguard Worker 386*333d2b36SAndroid Build Coastguard Worker static2 = ctx.ModuleForTests("libtest_static", "android_arm64_armv8-a_static_hwasan").Module().(*Module) 387*333d2b36SAndroid Build Coastguard Worker assertString(t, static2.OutputFile().Path().Base(), "libf.hwasan.a") 388*333d2b36SAndroid Build Coastguard Worker} 389*333d2b36SAndroid Build Coastguard Worker 390*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltBinaryNoSrcsNoError(t *testing.T) { 391*333d2b36SAndroid Build Coastguard Worker const bp = ` 392*333d2b36SAndroid Build Coastguard Workercc_prebuilt_binary { 393*333d2b36SAndroid Build Coastguard Worker name: "bintest", 394*333d2b36SAndroid Build Coastguard Worker srcs: [], 395*333d2b36SAndroid Build Coastguard Worker}` 396*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, bp, map[string][]byte{}) 397*333d2b36SAndroid Build Coastguard Worker mod := ctx.ModuleForTests("bintest", "android_arm64_armv8-a").Module().(*Module) 398*333d2b36SAndroid Build Coastguard Worker android.AssertBoolEquals(t, `expected no srcs to yield no output file`, false, mod.OutputFile().Valid()) 399*333d2b36SAndroid Build Coastguard Worker} 400*333d2b36SAndroid Build Coastguard Worker 401*333d2b36SAndroid Build Coastguard Workerfunc TestPrebuiltBinaryMultipleSrcs(t *testing.T) { 402*333d2b36SAndroid Build Coastguard Worker const bp = ` 403*333d2b36SAndroid Build Coastguard Workercc_prebuilt_binary { 404*333d2b36SAndroid Build Coastguard Worker name: "bintest", 405*333d2b36SAndroid Build Coastguard Worker srcs: ["foo", "bar"], 406*333d2b36SAndroid Build Coastguard Worker}` 407*333d2b36SAndroid Build Coastguard Worker testCcError(t, `Android.bp:4:6: module "bintest" variant "android_arm64_armv8-a": srcs: multiple prebuilt source files`, bp) 408*333d2b36SAndroid Build Coastguard Worker} 409*333d2b36SAndroid Build Coastguard Worker 410*333d2b36SAndroid Build Coastguard Workerfunc TestMultiplePrebuilts(t *testing.T) { 411*333d2b36SAndroid Build Coastguard Worker bp := ` 412*333d2b36SAndroid Build Coastguard Worker // an rdep 413*333d2b36SAndroid Build Coastguard Worker cc_library { 414*333d2b36SAndroid Build Coastguard Worker name: "libfoo", 415*333d2b36SAndroid Build Coastguard Worker shared_libs: ["libbar"], 416*333d2b36SAndroid Build Coastguard Worker } 417*333d2b36SAndroid Build Coastguard Worker 418*333d2b36SAndroid Build Coastguard Worker // multiple variations of dep 419*333d2b36SAndroid Build Coastguard Worker // source 420*333d2b36SAndroid Build Coastguard Worker cc_library { 421*333d2b36SAndroid Build Coastguard Worker name: "libbar", 422*333d2b36SAndroid Build Coastguard Worker } 423*333d2b36SAndroid Build Coastguard Worker // prebuilt "v1" 424*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 425*333d2b36SAndroid Build Coastguard Worker name: "libbar", 426*333d2b36SAndroid Build Coastguard Worker srcs: ["libbar.so"], 427*333d2b36SAndroid Build Coastguard Worker } 428*333d2b36SAndroid Build Coastguard Worker // prebuilt "v2" 429*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 430*333d2b36SAndroid Build Coastguard Worker name: "libbar.v2", 431*333d2b36SAndroid Build Coastguard Worker stem: "libbar", 432*333d2b36SAndroid Build Coastguard Worker source_module_name: "libbar", 433*333d2b36SAndroid Build Coastguard Worker srcs: ["libbar.so"], 434*333d2b36SAndroid Build Coastguard Worker } 435*333d2b36SAndroid Build Coastguard Worker 436*333d2b36SAndroid Build Coastguard Worker // selectors 437*333d2b36SAndroid Build Coastguard Worker apex_contributions { 438*333d2b36SAndroid Build Coastguard Worker name: "myapex_contributions", 439*333d2b36SAndroid Build Coastguard Worker contents: ["%v"], 440*333d2b36SAndroid Build Coastguard Worker } 441*333d2b36SAndroid Build Coastguard Worker all_apex_contributions {name: "all_apex_contributions"} 442*333d2b36SAndroid Build Coastguard Worker ` 443*333d2b36SAndroid Build Coastguard Worker hasDep := func(ctx *android.TestContext, m android.Module, wantDep android.Module) bool { 444*333d2b36SAndroid Build Coastguard Worker t.Helper() 445*333d2b36SAndroid Build Coastguard Worker var found bool 446*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDeps(m, func(dep blueprint.Module) { 447*333d2b36SAndroid Build Coastguard Worker if dep == wantDep { 448*333d2b36SAndroid Build Coastguard Worker found = true 449*333d2b36SAndroid Build Coastguard Worker } 450*333d2b36SAndroid Build Coastguard Worker }) 451*333d2b36SAndroid Build Coastguard Worker return found 452*333d2b36SAndroid Build Coastguard Worker } 453*333d2b36SAndroid Build Coastguard Worker 454*333d2b36SAndroid Build Coastguard Worker testCases := []struct { 455*333d2b36SAndroid Build Coastguard Worker desc string 456*333d2b36SAndroid Build Coastguard Worker selectedDependencyName string 457*333d2b36SAndroid Build Coastguard Worker expectedDependencyName string 458*333d2b36SAndroid Build Coastguard Worker }{ 459*333d2b36SAndroid Build Coastguard Worker { 460*333d2b36SAndroid Build Coastguard Worker desc: "Source library is selected using apex_contributions", 461*333d2b36SAndroid Build Coastguard Worker selectedDependencyName: "libbar", 462*333d2b36SAndroid Build Coastguard Worker expectedDependencyName: "libbar", 463*333d2b36SAndroid Build Coastguard Worker }, 464*333d2b36SAndroid Build Coastguard Worker { 465*333d2b36SAndroid Build Coastguard Worker desc: "Prebuilt library v1 is selected using apex_contributions", 466*333d2b36SAndroid Build Coastguard Worker selectedDependencyName: "prebuilt_libbar", 467*333d2b36SAndroid Build Coastguard Worker expectedDependencyName: "prebuilt_libbar", 468*333d2b36SAndroid Build Coastguard Worker }, 469*333d2b36SAndroid Build Coastguard Worker { 470*333d2b36SAndroid Build Coastguard Worker desc: "Prebuilt library v2 is selected using apex_contributions", 471*333d2b36SAndroid Build Coastguard Worker selectedDependencyName: "prebuilt_libbar.v2", 472*333d2b36SAndroid Build Coastguard Worker expectedDependencyName: "prebuilt_libbar.v2", 473*333d2b36SAndroid Build Coastguard Worker }, 474*333d2b36SAndroid Build Coastguard Worker } 475*333d2b36SAndroid Build Coastguard Worker 476*333d2b36SAndroid Build Coastguard Worker for _, tc := range testCases { 477*333d2b36SAndroid Build Coastguard Worker preparer := android.GroupFixturePreparers( 478*333d2b36SAndroid Build Coastguard Worker android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { 479*333d2b36SAndroid Build Coastguard Worker android.RegisterApexContributionsBuildComponents(ctx) 480*333d2b36SAndroid Build Coastguard Worker }), 481*333d2b36SAndroid Build Coastguard Worker android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "myapex_contributions"), 482*333d2b36SAndroid Build Coastguard Worker ) 483*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, fmt.Sprintf(bp, tc.selectedDependencyName), map[string][]byte{ 484*333d2b36SAndroid Build Coastguard Worker "libbar.so": nil, 485*333d2b36SAndroid Build Coastguard Worker "crtx.o": nil, 486*333d2b36SAndroid Build Coastguard Worker }, preparer) 487*333d2b36SAndroid Build Coastguard Worker libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() 488*333d2b36SAndroid Build Coastguard Worker expectedDependency := ctx.ModuleForTests(tc.expectedDependencyName, "android_arm64_armv8-a_shared").Module() 489*333d2b36SAndroid Build Coastguard Worker android.AssertBoolEquals(t, fmt.Sprintf("expected dependency from %s to %s\n", libfoo.Name(), tc.expectedDependencyName), true, hasDep(ctx, libfoo, expectedDependency)) 490*333d2b36SAndroid Build Coastguard Worker // check that LOCAL_SHARED_LIBRARIES contains libbar and not libbar.v<N> 491*333d2b36SAndroid Build Coastguard Worker entries := android.AndroidMkInfoForTest(t, ctx, libfoo).PrimaryInfo 492*333d2b36SAndroid Build Coastguard Worker android.AssertStringListContains(t, "Version should not be present in LOCAL_SHARED_LIBRARIES", entries.EntryMap["LOCAL_SHARED_LIBRARIES"], "libbar") 493*333d2b36SAndroid Build Coastguard Worker 494*333d2b36SAndroid Build Coastguard Worker // check installation rules 495*333d2b36SAndroid Build Coastguard Worker // the selected soong module should be exported to make 496*333d2b36SAndroid Build Coastguard Worker libbar := ctx.ModuleForTests(tc.expectedDependencyName, "android_arm64_armv8-a_shared").Module() 497*333d2b36SAndroid Build Coastguard Worker android.AssertBoolEquals(t, fmt.Sprintf("dependency %s should be exported to make\n", expectedDependency), true, !libbar.IsHideFromMake()) 498*333d2b36SAndroid Build Coastguard Worker 499*333d2b36SAndroid Build Coastguard Worker // check LOCAL_MODULE of the selected module name 500*333d2b36SAndroid Build Coastguard Worker // the prebuilt should have the same LOCAL_MODULE when exported to make 501*333d2b36SAndroid Build Coastguard Worker entries = android.AndroidMkInfoForTest(t, ctx, libbar).PrimaryInfo 502*333d2b36SAndroid Build Coastguard Worker android.AssertStringEquals(t, "unexpected LOCAL_MODULE", "libbar", entries.EntryMap["LOCAL_MODULE"][0]) 503*333d2b36SAndroid Build Coastguard Worker } 504*333d2b36SAndroid Build Coastguard Worker} 505*333d2b36SAndroid Build Coastguard Worker 506*333d2b36SAndroid Build Coastguard Worker// Setting prefer on multiple prebuilts is an error, unless one of them is also listed in apex_contributions 507*333d2b36SAndroid Build Coastguard Workerfunc TestMultiplePrebuiltsPreferredUsingLegacyFlags(t *testing.T) { 508*333d2b36SAndroid Build Coastguard Worker bp := ` 509*333d2b36SAndroid Build Coastguard Worker // an rdep 510*333d2b36SAndroid Build Coastguard Worker cc_library { 511*333d2b36SAndroid Build Coastguard Worker name: "libfoo", 512*333d2b36SAndroid Build Coastguard Worker shared_libs: ["libbar"], 513*333d2b36SAndroid Build Coastguard Worker } 514*333d2b36SAndroid Build Coastguard Worker 515*333d2b36SAndroid Build Coastguard Worker // multiple variations of dep 516*333d2b36SAndroid Build Coastguard Worker // source 517*333d2b36SAndroid Build Coastguard Worker cc_library { 518*333d2b36SAndroid Build Coastguard Worker name: "libbar", 519*333d2b36SAndroid Build Coastguard Worker } 520*333d2b36SAndroid Build Coastguard Worker // prebuilt "v1" 521*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 522*333d2b36SAndroid Build Coastguard Worker name: "libbar", 523*333d2b36SAndroid Build Coastguard Worker srcs: ["libbar.so"], 524*333d2b36SAndroid Build Coastguard Worker prefer: true, 525*333d2b36SAndroid Build Coastguard Worker } 526*333d2b36SAndroid Build Coastguard Worker // prebuilt "v2" 527*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 528*333d2b36SAndroid Build Coastguard Worker name: "libbar.v2", 529*333d2b36SAndroid Build Coastguard Worker stem: "libbar", 530*333d2b36SAndroid Build Coastguard Worker source_module_name: "libbar", 531*333d2b36SAndroid Build Coastguard Worker srcs: ["libbar.so"], 532*333d2b36SAndroid Build Coastguard Worker prefer: true, 533*333d2b36SAndroid Build Coastguard Worker } 534*333d2b36SAndroid Build Coastguard Worker 535*333d2b36SAndroid Build Coastguard Worker // selectors 536*333d2b36SAndroid Build Coastguard Worker apex_contributions { 537*333d2b36SAndroid Build Coastguard Worker name: "myapex_contributions", 538*333d2b36SAndroid Build Coastguard Worker contents: [%v], 539*333d2b36SAndroid Build Coastguard Worker } 540*333d2b36SAndroid Build Coastguard Worker all_apex_contributions {name: "all_apex_contributions"} 541*333d2b36SAndroid Build Coastguard Worker ` 542*333d2b36SAndroid Build Coastguard Worker hasDep := func(ctx *android.TestContext, m android.Module, wantDep android.Module) bool { 543*333d2b36SAndroid Build Coastguard Worker t.Helper() 544*333d2b36SAndroid Build Coastguard Worker var found bool 545*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDeps(m, func(dep blueprint.Module) { 546*333d2b36SAndroid Build Coastguard Worker if dep == wantDep { 547*333d2b36SAndroid Build Coastguard Worker found = true 548*333d2b36SAndroid Build Coastguard Worker } 549*333d2b36SAndroid Build Coastguard Worker }) 550*333d2b36SAndroid Build Coastguard Worker return found 551*333d2b36SAndroid Build Coastguard Worker } 552*333d2b36SAndroid Build Coastguard Worker 553*333d2b36SAndroid Build Coastguard Worker testCases := []struct { 554*333d2b36SAndroid Build Coastguard Worker desc string 555*333d2b36SAndroid Build Coastguard Worker selectedDependencyName string 556*333d2b36SAndroid Build Coastguard Worker expectedDependencyName string 557*333d2b36SAndroid Build Coastguard Worker expectedErr string 558*333d2b36SAndroid Build Coastguard Worker }{ 559*333d2b36SAndroid Build Coastguard Worker { 560*333d2b36SAndroid Build Coastguard Worker desc: "Multiple prebuilts have prefer: true", 561*333d2b36SAndroid Build Coastguard Worker expectedErr: "Multiple prebuilt modules prebuilt_libbar and prebuilt_libbar.v2 have been marked as preferred for this source module", 562*333d2b36SAndroid Build Coastguard Worker }, 563*333d2b36SAndroid Build Coastguard Worker { 564*333d2b36SAndroid Build Coastguard Worker desc: "Multiple prebuilts have prefer: true. The prebuilt listed in apex_contributions wins.", 565*333d2b36SAndroid Build Coastguard Worker selectedDependencyName: `"prebuilt_libbar"`, 566*333d2b36SAndroid Build Coastguard Worker expectedDependencyName: "prebuilt_libbar", 567*333d2b36SAndroid Build Coastguard Worker }, 568*333d2b36SAndroid Build Coastguard Worker } 569*333d2b36SAndroid Build Coastguard Worker 570*333d2b36SAndroid Build Coastguard Worker for _, tc := range testCases { 571*333d2b36SAndroid Build Coastguard Worker preparer := android.GroupFixturePreparers( 572*333d2b36SAndroid Build Coastguard Worker android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { 573*333d2b36SAndroid Build Coastguard Worker android.RegisterApexContributionsBuildComponents(ctx) 574*333d2b36SAndroid Build Coastguard Worker }), 575*333d2b36SAndroid Build Coastguard Worker android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "myapex_contributions"), 576*333d2b36SAndroid Build Coastguard Worker ) 577*333d2b36SAndroid Build Coastguard Worker if tc.expectedErr != "" { 578*333d2b36SAndroid Build Coastguard Worker preparer = preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(tc.expectedErr)) 579*333d2b36SAndroid Build Coastguard Worker } 580*333d2b36SAndroid Build Coastguard Worker 581*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, fmt.Sprintf(bp, tc.selectedDependencyName), map[string][]byte{ 582*333d2b36SAndroid Build Coastguard Worker "libbar.so": nil, 583*333d2b36SAndroid Build Coastguard Worker "crtx.o": nil, 584*333d2b36SAndroid Build Coastguard Worker }, preparer) 585*333d2b36SAndroid Build Coastguard Worker if tc.expectedErr != "" { 586*333d2b36SAndroid Build Coastguard Worker return // the fixture will assert that the excepted err has been raised 587*333d2b36SAndroid Build Coastguard Worker } 588*333d2b36SAndroid Build Coastguard Worker libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() 589*333d2b36SAndroid Build Coastguard Worker expectedDependency := ctx.ModuleForTests(tc.expectedDependencyName, "android_arm64_armv8-a_shared").Module() 590*333d2b36SAndroid Build Coastguard Worker android.AssertBoolEquals(t, fmt.Sprintf("expected dependency from %s to %s\n", libfoo.Name(), tc.expectedDependencyName), true, hasDep(ctx, libfoo, expectedDependency)) 591*333d2b36SAndroid Build Coastguard Worker } 592*333d2b36SAndroid Build Coastguard Worker} 593*333d2b36SAndroid Build Coastguard Worker 594*333d2b36SAndroid Build Coastguard Worker// If module sdk cannot provide a cc module variant (e.g. static), then the module variant from source should be used 595*333d2b36SAndroid Build Coastguard Workerfunc TestMissingVariantInModuleSdk(t *testing.T) { 596*333d2b36SAndroid Build Coastguard Worker bp := ` 597*333d2b36SAndroid Build Coastguard Worker // an rdep 598*333d2b36SAndroid Build Coastguard Worker cc_library { 599*333d2b36SAndroid Build Coastguard Worker name: "libfoo", 600*333d2b36SAndroid Build Coastguard Worker static_libs: ["libbar"], 601*333d2b36SAndroid Build Coastguard Worker } 602*333d2b36SAndroid Build Coastguard Worker 603*333d2b36SAndroid Build Coastguard Worker // source 604*333d2b36SAndroid Build Coastguard Worker cc_library { 605*333d2b36SAndroid Build Coastguard Worker name: "libbar", 606*333d2b36SAndroid Build Coastguard Worker } 607*333d2b36SAndroid Build Coastguard Worker // prebuilt 608*333d2b36SAndroid Build Coastguard Worker // libbar only exists as a shared library 609*333d2b36SAndroid Build Coastguard Worker cc_prebuilt_library_shared { 610*333d2b36SAndroid Build Coastguard Worker name: "libbar", 611*333d2b36SAndroid Build Coastguard Worker srcs: ["libbar.so"], 612*333d2b36SAndroid Build Coastguard Worker } 613*333d2b36SAndroid Build Coastguard Worker // selectors 614*333d2b36SAndroid Build Coastguard Worker apex_contributions { 615*333d2b36SAndroid Build Coastguard Worker name: "myapex_contributions", 616*333d2b36SAndroid Build Coastguard Worker contents: ["prebuilt_libbar"], 617*333d2b36SAndroid Build Coastguard Worker } 618*333d2b36SAndroid Build Coastguard Worker all_apex_contributions {name: "all_apex_contributions"} 619*333d2b36SAndroid Build Coastguard Worker ` 620*333d2b36SAndroid Build Coastguard Worker hasDep := func(ctx *android.TestContext, m android.Module, wantDep android.Module) bool { 621*333d2b36SAndroid Build Coastguard Worker t.Helper() 622*333d2b36SAndroid Build Coastguard Worker var found bool 623*333d2b36SAndroid Build Coastguard Worker ctx.VisitDirectDeps(m, func(dep blueprint.Module) { 624*333d2b36SAndroid Build Coastguard Worker if dep == wantDep { 625*333d2b36SAndroid Build Coastguard Worker found = true 626*333d2b36SAndroid Build Coastguard Worker } 627*333d2b36SAndroid Build Coastguard Worker }) 628*333d2b36SAndroid Build Coastguard Worker return found 629*333d2b36SAndroid Build Coastguard Worker } 630*333d2b36SAndroid Build Coastguard Worker 631*333d2b36SAndroid Build Coastguard Worker preparer := android.GroupFixturePreparers( 632*333d2b36SAndroid Build Coastguard Worker android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { 633*333d2b36SAndroid Build Coastguard Worker android.RegisterApexContributionsBuildComponents(ctx) 634*333d2b36SAndroid Build Coastguard Worker }), 635*333d2b36SAndroid Build Coastguard Worker android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "myapex_contributions"), 636*333d2b36SAndroid Build Coastguard Worker ) 637*333d2b36SAndroid Build Coastguard Worker ctx := testPrebuilt(t, bp, map[string][]byte{ 638*333d2b36SAndroid Build Coastguard Worker "libbar.so": nil, 639*333d2b36SAndroid Build Coastguard Worker "crtx.o": nil, 640*333d2b36SAndroid Build Coastguard Worker }, preparer) 641*333d2b36SAndroid Build Coastguard Worker libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module() 642*333d2b36SAndroid Build Coastguard Worker sourceLibBar := ctx.ModuleForTests("libbar", "android_arm64_armv8-a_static").Module() 643*333d2b36SAndroid Build Coastguard Worker // Even though the prebuilt is listed in apex_contributions, the prebuilt does not have a static variant. 644*333d2b36SAndroid Build Coastguard Worker // Therefore source of libbar should be used. 645*333d2b36SAndroid Build Coastguard Worker android.AssertBoolEquals(t, fmt.Sprintf("expected dependency from libfoo to source libbar"), true, hasDep(ctx, libfoo, sourceLibBar)) 646*333d2b36SAndroid Build Coastguard Worker} 647