1// 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 ( 18 "sort" 19 "strings" 20 21 "android/soong/android" 22) 23 24func init() { 25 // Use singleton type to gather all generated soong modules. 26 android.RegisterParallelSingletonType("stublibraries", stubLibrariesSingleton) 27} 28 29func stubLibrariesSingleton() android.Singleton { 30 return &stubLibraries{} 31} 32 33type stubLibraries struct { 34 stubLibraries []string 35 vendorStubLibraries []string 36 37 apiListCoverageXmlPaths []string 38} 39 40// Check if the module defines stub, or itself is stub 41func IsStubTarget(info *LinkableInfo) bool { 42 return info != nil && (info.IsStubs || info.HasStubsVariants) 43} 44 45// Get target file name to be installed from this module 46func getInstalledFileName(ctx android.SingletonContext, m android.ModuleProxy) string { 47 for _, ps := range android.OtherModuleProviderOrDefault( 48 ctx, m, android.InstallFilesProvider).PackagingSpecs { 49 if name := ps.FileName(); name != "" { 50 return name 51 } 52 } 53 return "" 54} 55 56func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) { 57 // Visit all generated soong modules and store stub library file names. 58 stubLibraryMap := make(map[string]bool) 59 vendorStubLibraryMap := make(map[string]bool) 60 ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { 61 if linkableInfo, ok := android.OtherModuleProvider(ctx, module, LinkableInfoProvider); ok { 62 if IsStubTarget(linkableInfo) { 63 if name := getInstalledFileName(ctx, module); name != "" { 64 stubLibraryMap[name] = true 65 if linkableInfo.InVendor { 66 vendorStubLibraryMap[name] = true 67 } 68 } 69 } 70 if linkableInfo.CcLibraryInterface && android.IsModulePreferredProxy(ctx, module) { 71 if p := linkableInfo.APIListCoverageXMLPath.String(); p != "" { 72 s.apiListCoverageXmlPaths = append(s.apiListCoverageXmlPaths, p) 73 } 74 } 75 } 76 }) 77 s.stubLibraries = android.SortedKeys(stubLibraryMap) 78 s.vendorStubLibraries = android.SortedKeys(vendorStubLibraryMap) 79 80 android.WriteFileRule(ctx, StubLibrariesFile(ctx), strings.Join(s.stubLibraries, " ")) 81} 82 83func StubLibrariesFile(ctx android.PathContext) android.WritablePath { 84 return android.PathForIntermediates(ctx, "stub_libraries.txt") 85} 86 87func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) { 88 // Convert stub library file names into Makefile variable. 89 ctx.Strict("STUB_LIBRARIES", strings.Join(s.stubLibraries, " ")) 90 ctx.Strict("SOONG_STUB_VENDOR_LIBRARIES", strings.Join(s.vendorStubLibraries, " ")) 91 92 // Export the list of API XML files to Make. 93 sort.Strings(s.apiListCoverageXmlPaths) 94 ctx.Strict("SOONG_CC_API_XML", strings.Join(s.apiListCoverageXmlPaths, " ")) 95} 96