cc_cmake_snapshot: improve support for AIDL
- link correct libbinder for AIDL modules - fix building AIDL interfaces with non-empty AidlRoot - don't silently drop non-existent dependencies Bug: 302718225 Test: aosp/3081709 atest binder_sdk_docker_test_clang Change-Id: I181ef5a994f728f8af19134a6697b065a9aee261
This commit is contained in:
parent
d848dcc9e6
commit
1e831bfa87
5 changed files with 64 additions and 19 deletions
|
@ -1,35 +1,51 @@
|
|||
function(add_aidl_library NAME LANG SOURCES AIDLFLAGS)
|
||||
function(add_aidl_library NAME LANG AIDLROOT SOURCES AIDLFLAGS)
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20")
|
||||
cmake_policy(SET CMP0116 NEW)
|
||||
endif()
|
||||
|
||||
# Strip trailing slash
|
||||
get_filename_component(AIDLROOT_TRAILING "${AIDLROOT}" NAME)
|
||||
if ("${AIDLROOT_TRAILING}" STREQUAL "")
|
||||
get_filename_component(AIDLROOT "${AIDLROOT}foo" DIRECTORY)
|
||||
endif()
|
||||
|
||||
set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/.intermediates/${NAME}-source")
|
||||
set(GEN_SOURCES)
|
||||
foreach(SOURCE ${SOURCES})
|
||||
get_filename_component(SOURCE_WE ${SOURCE} NAME_WE)
|
||||
get_filename_component(SOURCE_ABSOLUTE ${SOURCE} ABSOLUTE)
|
||||
get_filename_component(SOURCE_DIR ${SOURCE_ABSOLUTE} DIRECTORY)
|
||||
set(GEN_SOURCE "${GEN_DIR}/${SOURCE_WE}.cpp")
|
||||
foreach (SOURCE ${SOURCES})
|
||||
set(SOURCE_FULL ${AIDLROOT}/${SOURCE})
|
||||
get_filename_component(SOURCE_WLE ${SOURCE} NAME_WLE)
|
||||
get_filename_component(SOURCE_SUBDIR ${SOURCE} DIRECTORY)
|
||||
set(GEN_SOURCE "${GEN_DIR}/${SOURCE_SUBDIR}/${SOURCE_WLE}.cpp")
|
||||
|
||||
file(READ "${SOURCE}" SOURCE_CONTENTS)
|
||||
string(FIND "${SOURCE_CONTENTS}" "@VintfStability" VINTF_MATCH)
|
||||
set(STABILITY_FLAG)
|
||||
if (${VINTF_MATCH} GREATER_EQUAL 0)
|
||||
set(STABILITY_FLAG --stability vintf)
|
||||
endif()
|
||||
|
||||
set(DEPFILE_ARG)
|
||||
if (NOT ${CMAKE_GENERATOR} MATCHES "Unix Makefiles")
|
||||
set(DEPFILE_ARG DEPFILE "${GEN_SOURCE}.d")
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${GEN_SOURCE}"
|
||||
MAIN_DEPENDENCY "${SOURCE_ABSOLUTE}"
|
||||
MAIN_DEPENDENCY "${SOURCE_FULL}"
|
||||
${DEPFILE_ARG}
|
||||
COMMAND "${AIDL_BIN}"
|
||||
ARGS
|
||||
--lang=${LANG}
|
||||
--include="${SOURCE_DIR}"
|
||||
--include="${AIDLROOT}"
|
||||
--dep="${GEN_SOURCE}.d"
|
||||
--out="${GEN_DIR}"
|
||||
--header_out="${GEN_DIR}/include"
|
||||
--ninja
|
||||
--structured
|
||||
--min_sdk_version=current
|
||||
${STABILITY_FLAG}
|
||||
${AIDLFLAGS}
|
||||
"${SOURCE_ABSOLUTE}"
|
||||
"${SOURCE_FULL}"
|
||||
)
|
||||
list(APPEND GEN_SOURCES "${GEN_SOURCE}")
|
||||
endforeach()
|
||||
|
@ -39,9 +55,14 @@ function(add_aidl_library NAME LANG SOURCES AIDLFLAGS)
|
|||
target_include_directories(${NAME}
|
||||
PUBLIC
|
||||
"${GEN_DIR}/include"
|
||||
"${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/ndk/include_${LANG}"
|
||||
)
|
||||
|
||||
if (${LANG} MATCHES "ndk")
|
||||
set(BINDER_LIB_NAME "libbinder_ndk_sdk")
|
||||
else()
|
||||
set(BINDER_LIB_NAME "libbinder_sdk")
|
||||
endif()
|
||||
target_link_libraries(${NAME}
|
||||
libbinder_sdk
|
||||
${BINDER_LIB_NAME}
|
||||
)
|
||||
endfunction()
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
# <<.M.Name>>
|
||||
|
||||
<<setList .M.Name "_SRCS" "${ANDROID_BUILD_TOP}/" (getCompilerProperties .M).AidlInterface.Sources>>
|
||||
<<setList .M.Name "_SRCS" "" (getAidlSources .M)>>
|
||||
|
||||
<<setList .M.Name "_AIDLFLAGS" "" (getCompilerProperties .M).AidlInterface.Flags>>
|
||||
|
||||
add_aidl_library(<<.M.Name>> <<(getCompilerProperties .M).AidlInterface.Lang>> "${<<.M.Name>>_SRCS}" "${<<.M.Name>>_AIDLFLAGS}")
|
||||
add_aidl_library(<<.M.Name>> <<(getCompilerProperties .M).AidlInterface.Lang>>
|
||||
"${ANDROID_BUILD_TOP}/<<.Ctx.OtherModuleDir .M>>/<<(getCompilerProperties .M).AidlInterface.AidlRoot>>"
|
||||
"${<<.M.Name>>_SRCS}"
|
||||
"${<<.M.Name>>_AIDLFLAGS}")
|
||||
add_library(android::<<.M.Name>> ALIAS <<.M.Name>>)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<<$srcs := getSources .M>>
|
||||
<<$includeDirs := getIncludeDirs .Ctx .M>>
|
||||
<<$cflags := (getCompilerProperties .M).Cflags>>
|
||||
<<$deps := mapLibraries (concat5
|
||||
<<$deps := mapLibraries .Ctx .M (concat5
|
||||
(getLinkerProperties .M).Whole_static_libs
|
||||
(getLinkerProperties .M).Static_libs
|
||||
(getLinkerProperties .M).Shared_libs
|
||||
|
|
|
@ -192,13 +192,16 @@ func parseTemplate(templateContents string) *template.Template {
|
|||
},
|
||||
"getExtraLibs": getExtraLibs,
|
||||
"getIncludeDirs": getIncludeDirs,
|
||||
"mapLibraries": func(libs []string, mapping map[string]LibraryMappingProperty) []string {
|
||||
"mapLibraries": func(ctx android.ModuleContext, m *Module, libs []string, mapping map[string]LibraryMappingProperty) []string {
|
||||
var mappedLibs []string
|
||||
for _, lib := range libs {
|
||||
mappedLib, exists := mapping[lib]
|
||||
if exists {
|
||||
lib = mappedLib.Mapped_name
|
||||
} else {
|
||||
if !ctx.OtherModuleExists(lib) {
|
||||
ctx.OtherModuleErrorf(m, "Dependency %s doesn't exist", lib)
|
||||
}
|
||||
lib = "android::" + lib
|
||||
}
|
||||
if lib == "" {
|
||||
|
@ -210,6 +213,21 @@ func parseTemplate(templateContents string) *template.Template {
|
|||
mappedLibs = slices.Compact(mappedLibs)
|
||||
return mappedLibs
|
||||
},
|
||||
"getAidlSources": func(m *Module) []string {
|
||||
aidlInterface := m.compiler.baseCompilerProps().AidlInterface
|
||||
aidlRoot := aidlInterface.AidlRoot + string(filepath.Separator)
|
||||
if aidlInterface.AidlRoot == "" {
|
||||
aidlRoot = ""
|
||||
}
|
||||
var sources []string
|
||||
for _, src := range aidlInterface.Sources {
|
||||
if !strings.HasPrefix(src, aidlRoot) {
|
||||
panic(fmt.Sprintf("Aidl source '%v' doesn't start with '%v'", src, aidlRoot))
|
||||
}
|
||||
sources = append(sources, src[len(aidlRoot):])
|
||||
}
|
||||
return sources
|
||||
},
|
||||
}
|
||||
|
||||
return template.Must(template.New("").Delims("<<", ">>").Funcs(funcMap).Parse(templateContents))
|
||||
|
@ -282,14 +300,14 @@ func (m *CmakeSnapshot) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
var pregeneratedModules []*Module
|
||||
ctx.WalkDeps(func(dep_a android.Module, parent android.Module) bool {
|
||||
moduleName := ctx.OtherModuleName(dep_a)
|
||||
dep, ok := dep_a.(*Module)
|
||||
if !ok {
|
||||
return false // not a cc module
|
||||
}
|
||||
if visited := visitedModules[moduleName]; visited {
|
||||
return false // visit only once
|
||||
}
|
||||
visitedModules[moduleName] = true
|
||||
dep, ok := dep_a.(*Module)
|
||||
if !ok {
|
||||
return false // not a cc module
|
||||
}
|
||||
if mapping, ok := pprop.LibraryMapping[moduleName]; ok {
|
||||
if mapping.Package_pregenerated != "" {
|
||||
pregeneratedModules = append(pregeneratedModules, dep)
|
||||
|
|
|
@ -147,6 +147,9 @@ type BaseCompilerProperties struct {
|
|||
// list of aidl_interface sources
|
||||
Sources []string `blueprint:"mutated"`
|
||||
|
||||
// root directory of AIDL sources
|
||||
AidlRoot string `blueprint:"mutated"`
|
||||
|
||||
// AIDL backend language (e.g. "cpp", "ndk")
|
||||
Lang string `blueprint:"mutated"`
|
||||
|
||||
|
|
Loading…
Reference in a new issue