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 15package cc 16 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 36import ( 37 "sync" 38 39 "android/soong/android" 40) 41 42type syspropLibraryInterface interface { 43 BaseModuleName() string 44 CcImplementationModuleName() string 45} 46 47var ( 48 syspropImplLibrariesKey = android.NewOnceKey("syspropImplLibirares") 49 syspropImplLibrariesLock sync.Mutex 50) 51 52func 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 59func 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 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() 68 } 69} 70