Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 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 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 17 | // This file contains a map to redirect dependencies towards sysprop_library. |
| 18 | // As sysprop_library has to support both Java and C++, sysprop_library internally |
| 19 | // generates cc_library and java_library. For example, the following sysprop_library |
| 20 | // |
| 21 | // sysprop_library { |
| 22 | // name: "foo", |
| 23 | // } |
| 24 | // |
| 25 | // will internally generate with prefix "lib" |
| 26 | // |
| 27 | // cc_library { |
| 28 | // name: "libfoo", |
| 29 | // } |
| 30 | // |
| 31 | // When a cc module links against "foo", build system will redirect the |
| 32 | // dependency to "libfoo". To do that, SyspropMutator gathers all sysprop_library, |
| 33 | // records their cc implementation library names to a map. The map will be used in |
| 34 | // cc.Module.DepsMutator. |
| 35 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 36 | import ( |
| 37 | "sync" |
| 38 | |
| 39 | "android/soong/android" |
| 40 | ) |
| 41 | |
| 42 | type syspropLibraryInterface interface { |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 43 | BaseModuleName() string |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 44 | CcImplementationModuleName() string |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | var ( |
| 48 | syspropImplLibrariesKey = android.NewOnceKey("syspropImplLibirares") |
| 49 | syspropImplLibrariesLock sync.Mutex |
| 50 | ) |
| 51 | |
| 52 | func syspropImplLibraries(config android.Config) map[string]string { |
| 53 | return config.Once(syspropImplLibrariesKey, func() interface{} { |
| 54 | return make(map[string]string) |
| 55 | }).(map[string]string) |
| 56 | } |
| 57 | |
| 58 | // gather list of sysprop libraries |
| 59 | func SyspropMutator(mctx android.BottomUpMutatorContext) { |
| 60 | if m, ok := mctx.Module().(syspropLibraryInterface); ok { |
| 61 | syspropImplLibraries := syspropImplLibraries(mctx.Config()) |
| 62 | syspropImplLibrariesLock.Lock() |
| 63 | defer syspropImplLibrariesLock.Unlock() |
| 64 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 65 | // BaseModuleName is the name of sysprop_library |
| 66 | // CcImplementationModuleName is the name of cc_library generated by sysprop_library |
| 67 | syspropImplLibraries[m.BaseModuleName()] = m.CcImplementationModuleName() |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 68 | } |
| 69 | } |