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 ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | // Use singleton type to gather all generated soong modules. |
| 25 | android.RegisterSingletonType("stublibraries", stubLibrariesSingleton) |
| 26 | } |
| 27 | |
| 28 | type stubLibraries struct { |
| 29 | stubLibraryMap map[string]bool |
| 30 | } |
| 31 | |
| 32 | // Check if the module defines stub, or itself is stub |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 33 | func IsStubTarget(m *Module) bool { |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 34 | return m.IsStubs() || m.HasStubsVariants() |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | // Get target file name to be installed from this module |
| 38 | func getInstalledFileName(m *Module) string { |
| 39 | for _, ps := range m.PackagingSpecs() { |
| 40 | if name := ps.FileName(); name != "" { |
| 41 | return name |
| 42 | } |
| 43 | } |
| 44 | return "" |
| 45 | } |
| 46 | |
| 47 | func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) { |
| 48 | // Visit all generated soong modules and store stub library file names. |
| 49 | ctx.VisitAllModules(func(module android.Module) { |
| 50 | if m, ok := module.(*Module); ok { |
Jiyong Park | fa61613 | 2021-04-20 11:36:40 +0900 | [diff] [blame] | 51 | if IsStubTarget(m) { |
Kiyoung Kim | 24dfc1f | 2020-11-16 10:48:44 +0900 | [diff] [blame] | 52 | if name := getInstalledFileName(m); name != "" { |
| 53 | s.stubLibraryMap[name] = true |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | func stubLibrariesSingleton() android.Singleton { |
| 61 | return &stubLibraries{ |
| 62 | stubLibraryMap: make(map[string]bool), |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) { |
| 67 | // Convert stub library file names into Makefile variable. |
| 68 | ctx.Strict("STUB_LIBRARIES", strings.Join(android.SortedStringKeys(s.stubLibraryMap), " ")) |
| 69 | } |