using go for condition in Srcs[] for cc_prebuilt_library_static

336 views
Skip to first unread message

Aditya Singh Rathore

unread,
Jan 11, 2021, 12:07:19 PM1/11/21
to Android Building
I have requirement of using different "src" for my prebuilt static library, based on some condition other than Target_arch.

I have used go file as below

func init() {
android.RegisterModuleType("native_cc_prebuilt_defaults", genNativeDefaultsFactory)
}

func genNativeDefaultsFactory() android.Module{
    module := cc.DefaultsFactory()
    android.AddLoadHook(module, loadBuildConfigCCNative)
    return module
}

func loadBuildConfigCCNative(ctx android.LoadHookContext){
    type props struct {
        Srcs []string
    }
    p := &props{}
    var srcs  []string
    
    conditinal := getEnv(PRODUCT_CONFIG) 
   
    if condition{
        if envIsContains(target_arch, "arm64") {
            srcs = append(srcs ,"path1/arm64/lib.a")
        } else if envIsContains(target_arch, "arm"){
            srcs = append(srcs ,"path1/arm/lib_32.a")
        }
    }else {
        if envIsContains(target_arch, "arm64") {
            srcs = append(srcs ,"path2/arm64/libiqinative.a")
        } else if envIsContains(target_arch, "arm"){
            srcs = append(srcs ,"path2/arm/libiqinative.a")
        }
    }
    p.Srcs = srcs
    ctx.AppendProperties(p)
}

func envIsContains(key1 string, key2 string) bool {

    contained, _ := regexp.MatchString(key2, key1)
    return contained
}


Android.bp

native_cc_prebuilt_defaults{
    name: "my_lib_defaults",
}
 cc_prebuilt_library_static { 
    name : "my_lib",
    compile_multilib: "both",  
    defaults: ["my_lib_defaults"],    
 } 

But when I use "my_lib"

in some other module like below (in some go file for module "libAPVE")

staticLibs = append(staticLibs, "my_lib")

I am recieving following error "Requesting an invalid path" upon building :

internal error: panic in GenerateBuildActions for module "libAPVE" variant "android_arm_armv8-a_cortex-a53_core_shared"
Requesting an invalid path
goroutine 1187053 [running]:
github.com/google/blueprint.newPanicErrorf(0xafad80, 0xcf1780, 0xc02f1b88c0, 0x6e, 0x0, 0x0, 0x0, 0x0, 0x0)
    /workspace/android/build/blueprint/context.go:3566 +0x7b
    /workspace/android/build/blueprint/context.go:2308 +0x39f
panic(0xafad80, 0xcf1780)
    prebuilts/go/linux-x86/src/runtime/panic.go:522 +0x1b5
android/soong/android.OptionalPath.Path(...)
    /workspace/android/build/soong/android/paths.go:180
android/soong/cc.orderStaticModuleDeps(0xc04f88ad80, 0xc007264ac0, 0x4, 0x4, 0xc0357a1480, 0xb, 0x10, 0x7f7cee6ca118, 0x0, 0x0)
    /workspace/android/build/soong/cc/cc.go:919 +0x63e
android/soong/cc.(*Module).depsToPaths(0xc04f88ad80, 0xd359e0, 0xc0980af710, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /workspace/android/build/soong/cc/cc.go:1892 +0x1eb
android/soong/cc.(*Module).GenerateAndroidBuildActions(0xc04f88ad80, 0xd357a0, 0xc037254820)
    /workspace/android/build/soong/cc/cc.go:946 +0xcb
android/soong/android.(*ModuleBase).GenerateBuildActions(0xc04f88ad80, 0xd33700, 0xc03d5e9ba0)
    /workspace/android/build/soong/android/module.go:887 +0x706
    /workspace/android/build/blueprint/context.go:2312 +0x80
    /workspace/android/build/blueprint/context.go:2313 +0x339
    /workspace/android/build/blueprint/context.go:1718 +0x30
    / workspace /android/build/blueprint/context.go:1717 +0x124

Aditya Singh Rathore

unread,
Jan 12, 2021, 1:01:14 PM1/12/21
to Android Building
After further debugging , it looks like p.Srcs is not getting reflected to srcs for ""my_lib""

any help or hint , would be helpful
Reply all
Reply to author
Forward
0 new messages