| 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 |  | 
|  | 29 | type stubLibraries struct { | 
| Jooyung Han | 9582159 | 2023-12-01 16:33:30 +0900 | [diff] [blame] | 30 | stubLibraryMap       map[string]bool | 
|  | 31 | stubVendorLibraryMap map[string]bool | 
| Colin Cross | ceaa532 | 2021-09-28 16:37:50 -0700 | [diff] [blame] | 32 |  | 
|  | 33 | apiListCoverageXmlPaths []string | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 34 | } | 
|  | 35 |  | 
|  | 36 | // Check if the module defines stub, or itself is stub | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 37 | func IsStubTarget(m *Module) bool { | 
| Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 38 | return m.IsStubs() || m.HasStubsVariants() | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 39 | } | 
|  | 40 |  | 
|  | 41 | // Get target file name to be installed from this module | 
| Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 42 | func getInstalledFileName(ctx android.SingletonContext, m *Module) string { | 
|  | 43 | for _, ps := range android.OtherModuleProviderOrDefault( | 
|  | 44 | ctx, m.Module(), android.InstallFilesProvider).PackagingSpecs { | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 45 | if name := ps.FileName(); name != "" { | 
|  | 46 | return name | 
|  | 47 | } | 
|  | 48 | } | 
|  | 49 | return "" | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) { | 
|  | 53 | // Visit all generated soong modules and store stub library file names. | 
|  | 54 | ctx.VisitAllModules(func(module android.Module) { | 
|  | 55 | if m, ok := module.(*Module); ok { | 
| Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 56 | if IsStubTarget(m) { | 
| Yu Liu | d46e5ae | 2024-08-15 18:46:17 +0000 | [diff] [blame] | 57 | if name := getInstalledFileName(ctx, m); name != "" { | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 58 | s.stubLibraryMap[name] = true | 
| Jooyung Han | 9582159 | 2023-12-01 16:33:30 +0900 | [diff] [blame] | 59 | if m.InVendor() { | 
|  | 60 | s.stubVendorLibraryMap[name] = true | 
|  | 61 | } | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 62 | } | 
|  | 63 | } | 
| Spandan Das | 24b3e53 | 2024-08-15 21:33:17 +0000 | [diff] [blame] | 64 | if m.library != nil && android.IsModulePreferred(m) { | 
| Colin Cross | ceaa532 | 2021-09-28 16:37:50 -0700 | [diff] [blame] | 65 | if p := m.library.getAPIListCoverageXMLPath().String(); p != "" { | 
|  | 66 | s.apiListCoverageXmlPaths = append(s.apiListCoverageXmlPaths, p) | 
|  | 67 | } | 
|  | 68 | } | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 69 | } | 
|  | 70 | }) | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | func stubLibrariesSingleton() android.Singleton { | 
|  | 74 | return &stubLibraries{ | 
| Jooyung Han | 9582159 | 2023-12-01 16:33:30 +0900 | [diff] [blame] | 75 | stubLibraryMap:       make(map[string]bool), | 
|  | 76 | stubVendorLibraryMap: make(map[string]bool), | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 77 | } | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) { | 
|  | 81 | // Convert stub library file names into Makefile variable. | 
| Cole Faust | 18994c7 | 2023-02-28 16:02:16 -0800 | [diff] [blame] | 82 | ctx.Strict("STUB_LIBRARIES", strings.Join(android.SortedKeys(s.stubLibraryMap), " ")) | 
| Jooyung Han | 9582159 | 2023-12-01 16:33:30 +0900 | [diff] [blame] | 83 | ctx.Strict("SOONG_STUB_VENDOR_LIBRARIES", strings.Join(android.SortedKeys(s.stubVendorLibraryMap), " ")) | 
| Colin Cross | ceaa532 | 2021-09-28 16:37:50 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | // Export the list of API XML files to Make. | 
|  | 86 | sort.Strings(s.apiListCoverageXmlPaths) | 
|  | 87 | ctx.Strict("SOONG_CC_API_XML", strings.Join(s.apiListCoverageXmlPaths, " ")) | 
| Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 88 | } |