blob: 2c4cf80ca389c3721d72b25640d9dc035141fc0c [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"
19
20 "github.com/google/blueprint"
21)
22
23var (
24 apiImportNameSuffix = ".apiimport"
25)
26
27func init() {
28 RegisterApiImportsModule(android.InitRegistrationContext)
29}
30
31func RegisterApiImportsModule(ctx android.RegistrationContext) {
32 ctx.RegisterModuleType("api_imports", apiImportsFactory)
33}
34
35type ApiImports struct {
36 android.ModuleBase
37 properties apiImportsProperties
38}
39
40type apiImportsProperties struct {
41 Shared_libs []string // List of C shared libraries from API surfaces
42 Header_libs []string // List of C header libraries from API surfaces
43}
44
45// 'api_imports' is a module which describes modules available from API surfaces.
46// This module is required to get the list of all imported API modules, because
47// it is discouraged to loop and fetch all modules from its type information. The
48// only module with name 'api_imports' will be used from the build.
49func apiImportsFactory() android.Module {
50 module := &ApiImports{}
51 module.AddProperties(&module.properties)
52 android.InitAndroidModule(module)
53 return module
54}
55
56func (imports *ApiImports) GenerateAndroidBuildActions(ctx android.ModuleContext) {
57 // ApiImport module does not generate any build actions
58}
59
60type ApiImportInfo struct {
61 SharedLibs, HeaderLibs map[string]string
62}
63
64var ApiImportsProvider = blueprint.NewMutatorProvider(ApiImportInfo{}, "deps")
65
66// Store module lists into ApiImportInfo and share it over mutator provider.
67func (imports *ApiImports) DepsMutator(ctx android.BottomUpMutatorContext) {
68 generateNameMapWithSuffix := func(names []string) map[string]string {
69 moduleNameMap := make(map[string]string)
70 for _, name := range names {
71 moduleNameMap[name] = name + apiImportNameSuffix
72 }
73
74 return moduleNameMap
75 }
76
77 sharedLibs := generateNameMapWithSuffix(imports.properties.Shared_libs)
78 headerLibs := generateNameMapWithSuffix(imports.properties.Header_libs)
79
80 ctx.SetProvider(ApiImportsProvider, ApiImportInfo{
81 SharedLibs: sharedLibs,
82 HeaderLibs: headerLibs,
83 })
84}
85
86func GetApiImportSuffix() string {
87 return apiImportNameSuffix
88}