blob: e41aef68a1feeb5887a369cd2f185509eefa87db [file] [log] [blame]
Inseob Kimac1e9862019-12-09 18:15:47 +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 java
16
Inseob Kim07def122020-11-23 14:43:02 +090017// This file contains a map to redirect dependencies towards sysprop_library. If a sysprop_library
18// is owned by Platform, and the client module links against system API, the public stub of the
19// sysprop_library should be used. The map will contain public stub names of sysprop_libraries.
20
Inseob Kimac1e9862019-12-09 18:15:47 +090021import (
22 "sync"
23
24 "android/soong/android"
25)
26
27type syspropLibraryInterface interface {
28 BaseModuleName() string
29 Owner() string
30 HasPublicStub() bool
31 JavaPublicStubName() string
32}
33
34var (
35 syspropPublicStubsKey = android.NewOnceKey("syspropPublicStubsJava")
36 syspropPublicStubsLock sync.Mutex
37)
38
39func init() {
40 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
41 ctx.BottomUp("sysprop_java", SyspropMutator).Parallel()
42 })
43}
44
45func syspropPublicStubs(config android.Config) map[string]string {
46 return config.Once(syspropPublicStubsKey, func() interface{} {
47 return make(map[string]string)
48 }).(map[string]string)
49}
50
51// gather list of sysprop libraries owned by platform.
52func SyspropMutator(mctx android.BottomUpMutatorContext) {
53 if m, ok := mctx.Module().(syspropLibraryInterface); ok {
54 if m.Owner() != "Platform" || !m.HasPublicStub() {
55 return
56 }
57
58 syspropPublicStubs := syspropPublicStubs(mctx.Config())
59 syspropPublicStubsLock.Lock()
60 defer syspropPublicStubsLock.Unlock()
61
62 syspropPublicStubs[m.BaseModuleName()] = m.JavaPublicStubName()
63 }
64}