赞
踩
android编译系统的Android.mk,里面还有条件判断, 但是到了Android.bp之后, android.bp是类似JSON的纯文本形式. 对于Android.mk里面条件判断部分,在Android.bp里要借助使用go语言文件去进行控制.
在Android.mk中添加的宏开关:
ifeq ($(ENABLE_USER2ENG),true)
LOCAL_CFLAGS += -DALLOW_ADBD_DISABLE_VERITY=1
LOCAL_CFLAGS += -DENABLE_USER2ENG=1
endif
如果要将以上的宏开关添加到Android.bp中去要通过使用go语言书写一个新文件:
比如我的修改是在system/core/fs_mgr/Android.bp
,那么要在添加 system/core/fs_mgr/fs_mgr.go
:
package fs_mgr import ( "android/soong/android" "android/soong/cc" "fmt" ) func init() { // for DEBUG fmt.Println("init start") android.RegisterModuleType("AAA", fs_mgrDefaultsFactory) } func fs_mgrDefaultsFactory() (android.Module) { module := cc.DefaultsFactory() android.AddLoadHook(module, fs_mgrDefaults) return module } func fs_mgrDefaults(ctx android.LoadHookContext) { type props struct { Cflags []string } p := &props{} p.Cflags = globalDefaults(ctx) ctx.AppendProperties(p) } func globalDefaults(ctx android.BaseContext) ([]string) { var cppflags []string fmt.Println("ENABLE_USER2ENG:", ctx.AConfig().IsEnvTrue("ENABLE_USER2ENG")) if ctx.AConfig().IsEnvTrue("ENABLE_USER2ENG") { cppflags = append(cppflags, "-DALLOW_ADBD_DISABLE_VERITY=1", "-DENABLE_USER2ENG=1") } return cppflags }
Android.bp
需要修改的地方:
/// add start bootstrap_go_package { // name and pkgPath need to according to your module name: "soong-fs_mgr", pkgPath: "android/soong/fs_mgr", deps: [ "blueprint", "blueprint-pathtools", "soong", "soong-android", "soong-cc", "soong-genrule", ], srcs: [ // include new add .go file "fs_mgr.go", ], pluginFor: ["soong_build"], } // AAA is a module AAA { name: "BBB", } /// add end cc_defaults { name: "fs_mgr_defaults", defaults: ["BBB"],// new add sanitize: { misc_undefined: ["integer"], }, local_include_dirs: ["include/"], cppflags: ["-Werror", "-DMTK_FSTAB_FLAGS"], }
参照该例子修改时注意AAA
,BBB
的对应关系即可.
refers:
https://blog.csdn.net/weixin_33807284/article/details/86032658
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。