blob: f578b507aba159cc2b88b00554b6af6b419f84d3 [file] [log] [blame]
Inseob Kimc0907f12019-02-08 21:00:45 +09001// 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
Inseob Kim07def122020-11-23 14:43:02 +090017// 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 Kimc0907f12019-02-08 21:00:45 +090036import (
37 "sync"
38
39 "android/soong/android"
40)
41
42type syspropLibraryInterface interface {
Inseob Kim42882742019-07-30 17:55:33 +090043 BaseModuleName() string
Inseob Kim07def122020-11-23 14:43:02 +090044 CcImplementationModuleName() string
Inseob Kimc0907f12019-02-08 21:00:45 +090045}
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
Inseob Kim07def122020-11-23 14:43:02 +090065 // 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 Kimc0907f12019-02-08 21:00:45 +090068 }
69}