Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
Colin Cross | ceaa532 | 2021-09-28 16:37:50 -0700 | [diff] [blame] | 18 | "sort" |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 19 | "strings" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | // Use singleton type to gather all generated soong modules. |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 26 | android.RegisterParallelSingletonType("stublibraries", stubLibrariesSingleton) |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 27 | } |
| 28 | |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 29 | func stubLibrariesSingleton() android.Singleton { |
| 30 | return &stubLibraries{} |
| 31 | } |
| 32 | |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 33 | type stubLibraries struct { |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 34 | stubLibraries []string |
| 35 | vendorStubLibraries []string |
Colin Cross | ceaa532 | 2021-09-28 16:37:50 -0700 | [diff] [blame] | 36 | |
| 37 | apiListCoverageXmlPaths []string |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // Check if the module defines stub, or itself is stub |
Yu Liu | 68a70b7 | 2025-01-08 22:54:44 +0000 | [diff] [blame] | 41 | func IsStubTarget(info *LinkableInfo) bool { |
| 42 | return info != nil && (info.IsStubs || info.HasStubsVariants) |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // Get target file name to be installed from this module |
Yu Liu | 367827f | 2025-02-15 00:18:33 +0000 | [diff] [blame^] | 46 | func getInstalledFileName(ctx android.SingletonContext, m android.ModuleProxy) string { |
Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 47 | for _, ps := range android.OtherModuleProviderOrDefault( |
Yu Liu | 367827f | 2025-02-15 00:18:33 +0000 | [diff] [blame^] | 48 | ctx, m, android.InstallFilesProvider).PackagingSpecs { |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 49 | if name := ps.FileName(); name != "" { |
| 50 | return name |
| 51 | } |
| 52 | } |
| 53 | return "" |
| 54 | } |
| 55 | |
| 56 | func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) { |
| 57 | // Visit all generated soong modules and store stub library file names. |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 58 | stubLibraryMap := make(map[string]bool) |
| 59 | vendorStubLibraryMap := make(map[string]bool) |
Yu Liu | 367827f | 2025-02-15 00:18:33 +0000 | [diff] [blame^] | 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 != "" { |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 64 | stubLibraryMap[name] = true |
Yu Liu | 367827f | 2025-02-15 00:18:33 +0000 | [diff] [blame^] | 65 | if linkableInfo.InVendor { |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 66 | vendorStubLibraryMap[name] = true |
Jooyung Han | 9582159 | 2023-12-01 16:33:30 +0900 | [diff] [blame] | 67 | } |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 68 | } |
| 69 | } |
Yu Liu | 367827f | 2025-02-15 00:18:33 +0000 | [diff] [blame^] | 70 | if linkableInfo.CcLibraryInterface && android.IsModulePreferredProxy(ctx, module) { |
| 71 | if p := linkableInfo.APIListCoverageXMLPath.String(); p != "" { |
Colin Cross | ceaa532 | 2021-09-28 16:37:50 -0700 | [diff] [blame] | 72 | s.apiListCoverageXmlPaths = append(s.apiListCoverageXmlPaths, p) |
| 73 | } |
| 74 | } |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 75 | } |
| 76 | }) |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 77 | s.stubLibraries = android.SortedKeys(stubLibraryMap) |
| 78 | s.vendorStubLibraries = android.SortedKeys(vendorStubLibraryMap) |
| 79 | |
| 80 | android.WriteFileRule(ctx, StubLibrariesFile(ctx), strings.Join(s.stubLibraries, " ")) |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 81 | } |
| 82 | |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 83 | func StubLibrariesFile(ctx android.PathContext) android.WritablePath { |
| 84 | return android.PathForIntermediates(ctx, "stub_libraries.txt") |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) { |
| 88 | // Convert stub library file names into Makefile variable. |
Cole Faust | b43793e | 2024-12-13 16:53:36 -0800 | [diff] [blame] | 89 | ctx.Strict("STUB_LIBRARIES", strings.Join(s.stubLibraries, " ")) |
| 90 | ctx.Strict("SOONG_STUB_VENDOR_LIBRARIES", strings.Join(s.vendorStubLibraries, " ")) |
Colin Cross | ceaa532 | 2021-09-28 16:37:50 -0700 | [diff] [blame] | 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, " ")) |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 95 | } |