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