blob: 6e8e306b4f965f06fc539adb42e537cabfcdf044 [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()
78 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
79 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
80
81 return m
82}
83
84func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
85 if m.syspropLibraryProperties.Api_packages == nil {
86 ctx.PropertyErrorf("api_packages", "sysprop_library must specify api_packages")
87 }
88
89 socSpecific := ctx.SocSpecific()
90 deviceSpecific := ctx.DeviceSpecific()
91 productSpecific := ctx.ProductSpecific()
92
93 owner := m.syspropLibraryProperties.Property_owner
94
95 switch owner {
96 case "Platform":
97 // Every partition can access platform-defined properties
98 break
99 case "Vendor":
100 // System can't access vendor's properties
101 if !socSpecific && !deviceSpecific && !productSpecific {
102 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
103 "System can't access sysprop_library owned by Vendor")
104 }
105 case "Odm":
106 // Only vendor can access Odm-defined properties
107 if !socSpecific && !deviceSpecific {
108 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
109 "Odm-defined properties should be accessed only in Vendor or Odm")
110 }
111 default:
112 ctx.PropertyErrorf("property_owner",
113 "Unknown value %s: must be one of Platform, Vendor or Odm", owner)
114 }
115
116 ccProps := struct {
117 Name *string
118 Soc_specific *bool
119 Device_specific *bool
120 Product_specific *bool
121 Sysprop struct {
122 Platform *bool
123 }
124 }{}
125
126 ccProps.Name = proptools.StringPtr(m.CcModuleName())
127 ccProps.Soc_specific = proptools.BoolPtr(socSpecific)
128 ccProps.Device_specific = proptools.BoolPtr(deviceSpecific)
129 ccProps.Product_specific = proptools.BoolPtr(productSpecific)
130 ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
131
132 ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &m.commonProperties, &ccProps)
133}