blob: 6674d3e57086518855f7ecda4c8dea055e35f89d [file] [log] [blame]
Kiyoung Kim487689e2022-07-26 09:48:22 +09001// Copyright 2022 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package multitree
16
17import (
18 "android/soong/android"
Kiyoung Kim22e6b502022-08-31 14:05:45 +090019 "strings"
Kiyoung Kim487689e2022-07-26 09:48:22 +090020
21 "github.com/google/blueprint"
22)
23
24var (
25 apiImportNameSuffix = ".apiimport"
26)
27
28func init() {
29 RegisterApiImportsModule(android.InitRegistrationContext)
Kiyoung Kim22e6b502022-08-31 14:05:45 +090030 android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
Kiyoung Kim487689e2022-07-26 09:48:22 +090031}
32
33func RegisterApiImportsModule(ctx android.RegistrationContext) {
34 ctx.RegisterModuleType("api_imports", apiImportsFactory)
35}
36
37type ApiImports struct {
38 android.ModuleBase
39 properties apiImportsProperties
40}
41
42type apiImportsProperties struct {
43 Shared_libs []string // List of C shared libraries from API surfaces
44 Header_libs []string // List of C header libraries from API surfaces
45}
46
47// 'api_imports' is a module which describes modules available from API surfaces.
48// This module is required to get the list of all imported API modules, because
49// it is discouraged to loop and fetch all modules from its type information. The
50// only module with name 'api_imports' will be used from the build.
51func apiImportsFactory() android.Module {
52 module := &ApiImports{}
53 module.AddProperties(&module.properties)
54 android.InitAndroidModule(module)
55 return module
56}
57
58func (imports *ApiImports) GenerateAndroidBuildActions(ctx android.ModuleContext) {
59 // ApiImport module does not generate any build actions
60}
61
62type ApiImportInfo struct {
63 SharedLibs, HeaderLibs map[string]string
64}
65
66var ApiImportsProvider = blueprint.NewMutatorProvider(ApiImportInfo{}, "deps")
67
68// Store module lists into ApiImportInfo and share it over mutator provider.
69func (imports *ApiImports) DepsMutator(ctx android.BottomUpMutatorContext) {
70 generateNameMapWithSuffix := func(names []string) map[string]string {
71 moduleNameMap := make(map[string]string)
72 for _, name := range names {
73 moduleNameMap[name] = name + apiImportNameSuffix
74 }
75
76 return moduleNameMap
77 }
78
79 sharedLibs := generateNameMapWithSuffix(imports.properties.Shared_libs)
80 headerLibs := generateNameMapWithSuffix(imports.properties.Header_libs)
81
82 ctx.SetProvider(ApiImportsProvider, ApiImportInfo{
83 SharedLibs: sharedLibs,
84 HeaderLibs: headerLibs,
85 })
86}
87
88func GetApiImportSuffix() string {
89 return apiImportNameSuffix
90}
Kiyoung Kim22e6b502022-08-31 14:05:45 +090091
92func makeVarsProvider(ctx android.MakeVarsContext) {
93 ctx.VisitAllModules(func(m android.Module) {
94 if i, ok := m.(*ApiImports); ok {
95 ctx.Strict("API_IMPORTED_SHARED_LIBRARIES", strings.Join(i.properties.Shared_libs, " "))
96 ctx.Strict("API_IMPORTED_HEADER_LIBRARIES", strings.Join(i.properties.Header_libs, " "))
97 }
98 })
99}