blob: 47c6cb9a19746a75c84c95e3fc307626ffcc6434 [file] [log] [blame]
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +09001// Copyright 2020 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 cc
16
17import (
Colin Crossceaa5322021-09-28 16:37:50 -070018 "sort"
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090019 "strings"
20
21 "android/soong/android"
22)
23
24func init() {
25 // Use singleton type to gather all generated soong modules.
LaMont Jones0c10e4d2023-05-16 00:58:37 +000026 android.RegisterParallelSingletonType("stublibraries", stubLibrariesSingleton)
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090027}
28
29type stubLibraries struct {
Jooyung Han95821592023-12-01 16:33:30 +090030 stubLibraryMap map[string]bool
31 stubVendorLibraryMap map[string]bool
Colin Crossceaa5322021-09-28 16:37:50 -070032
33 apiListCoverageXmlPaths []string
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090034}
35
36// Check if the module defines stub, or itself is stub
Jiyong Parkfa616132021-04-20 11:36:40 +090037func IsStubTarget(m *Module) bool {
Colin Cross203b4212021-04-26 17:19:41 -070038 return m.IsStubs() || m.HasStubsVariants()
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090039}
40
41// Get target file name to be installed from this module
42func getInstalledFileName(m *Module) string {
43 for _, ps := range m.PackagingSpecs() {
44 if name := ps.FileName(); name != "" {
45 return name
46 }
47 }
48 return ""
49}
50
51func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) {
52 // Visit all generated soong modules and store stub library file names.
53 ctx.VisitAllModules(func(module android.Module) {
54 if m, ok := module.(*Module); ok {
Jiyong Parkfa616132021-04-20 11:36:40 +090055 if IsStubTarget(m) {
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090056 if name := getInstalledFileName(m); name != "" {
57 s.stubLibraryMap[name] = true
Jooyung Han95821592023-12-01 16:33:30 +090058 if m.InVendor() {
59 s.stubVendorLibraryMap[name] = true
60 }
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090061 }
62 }
Colin Crossceaa5322021-09-28 16:37:50 -070063 if m.library != nil {
64 if p := m.library.getAPIListCoverageXMLPath().String(); p != "" {
65 s.apiListCoverageXmlPaths = append(s.apiListCoverageXmlPaths, p)
66 }
67 }
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090068 }
69 })
70}
71
72func stubLibrariesSingleton() android.Singleton {
73 return &stubLibraries{
Jooyung Han95821592023-12-01 16:33:30 +090074 stubLibraryMap: make(map[string]bool),
75 stubVendorLibraryMap: make(map[string]bool),
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090076 }
77}
78
79func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) {
80 // Convert stub library file names into Makefile variable.
Cole Faust18994c72023-02-28 16:02:16 -080081 ctx.Strict("STUB_LIBRARIES", strings.Join(android.SortedKeys(s.stubLibraryMap), " "))
Jooyung Han95821592023-12-01 16:33:30 +090082 ctx.Strict("SOONG_STUB_VENDOR_LIBRARIES", strings.Join(android.SortedKeys(s.stubVendorLibraryMap), " "))
Colin Crossceaa5322021-09-28 16:37:50 -070083
84 // Export the list of API XML files to Make.
85 sort.Strings(s.apiListCoverageXmlPaths)
86 ctx.Strict("SOONG_CC_API_XML", strings.Join(s.apiListCoverageXmlPaths, " "))
Kiyoung Kim24dfc1f2020-11-16 10:48:44 +090087}