blob: 0313ecd03507aa481587d77edf2115bff9fe462a [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 sysprop
16
17import (
18 "android/soong/android"
19 "android/soong/cc"
20 "android/soong/java"
Colin Crossf8b860a2019-04-16 14:43:28 -070021
Inseob Kimc0907f12019-02-08 21:00:45 +090022 "github.com/google/blueprint"
23 "github.com/google/blueprint/proptools"
24)
25
26type dependencyTag struct {
27 blueprint.BaseDependencyTag
28 name string
29}
30
31type syspropLibrary struct {
32 java.SdkLibrary
33
34 commonProperties commonProperties
35 syspropLibraryProperties syspropLibraryProperties
36}
37
38type syspropLibraryProperties struct {
39 // Determine who owns this sysprop library. Possible values are
40 // "Platform", "Vendor", or "Odm"
41 Property_owner string
Inseob Kimf63c2fb2019-03-05 14:22:30 +090042
43 // list of package names that will be documented and publicized as API
44 Api_packages []string
Inseob Kimc0907f12019-02-08 21:00:45 +090045}
46
47type commonProperties struct {
Jiyong Park854a9442019-02-26 10:27:13 +090048 Srcs []string
49 Recovery *bool
50 Recovery_available *bool
51 Vendor_available *bool
Inseob Kimc0907f12019-02-08 21:00:45 +090052}
53
54var (
55 Bool = proptools.Bool
56 syspropCcTag = dependencyTag{name: "syspropCc"}
57)
58
59func init() {
60 android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
61}
62
63func (m *syspropLibrary) CcModuleName() string {
64 return "lib" + m.Name()
65}
66
Inseob Kimc0907f12019-02-08 21:00:45 +090067func syspropLibraryFactory() android.Module {
68 m := &syspropLibrary{}
69
70 m.AddProperties(
71 &m.commonProperties,
72 &m.syspropLibraryProperties,
73 )
74 m.InitSdkLibraryProperties()
75 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
76 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
Colin Crossf8b860a2019-04-16 14:43:28 -070077 android.AddLoadHook(m, func(ctx android.LoadHookContext) { m.SdkLibrary.CreateInternalModules(ctx) })
Inseob Kimc0907f12019-02-08 21:00:45 +090078 return m
79}
80
81func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Inseob Kim6e93ac92019-03-21 17:43:49 +090082 if len(m.commonProperties.Srcs) == 0 {
83 ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
84 }
85
86 if len(m.syspropLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +090087 ctx.PropertyErrorf("api_packages", "sysprop_library must specify api_packages")
88 }
89
90 socSpecific := ctx.SocSpecific()
91 deviceSpecific := ctx.DeviceSpecific()
92 productSpecific := ctx.ProductSpecific()
93
94 owner := m.syspropLibraryProperties.Property_owner
95
96 switch owner {
97 case "Platform":
98 // Every partition can access platform-defined properties
99 break
100 case "Vendor":
101 // System can't access vendor's properties
102 if !socSpecific && !deviceSpecific && !productSpecific {
103 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
104 "System can't access sysprop_library owned by Vendor")
105 }
106 case "Odm":
107 // Only vendor can access Odm-defined properties
108 if !socSpecific && !deviceSpecific {
109 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
110 "Odm-defined properties should be accessed only in Vendor or Odm")
111 }
112 default:
113 ctx.PropertyErrorf("property_owner",
114 "Unknown value %s: must be one of Platform, Vendor or Odm", owner)
115 }
116
117 ccProps := struct {
118 Name *string
119 Soc_specific *bool
120 Device_specific *bool
121 Product_specific *bool
122 Sysprop struct {
123 Platform *bool
124 }
125 }{}
126
127 ccProps.Name = proptools.StringPtr(m.CcModuleName())
128 ccProps.Soc_specific = proptools.BoolPtr(socSpecific)
129 ccProps.Device_specific = proptools.BoolPtr(deviceSpecific)
130 ccProps.Product_specific = proptools.BoolPtr(productSpecific)
131 ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
132
133 ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &m.commonProperties, &ccProps)
134}