blob: 3f2709e291197b82e9abd89340e6e5ef45885f36 [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()
Sundong Ahn80a87b32019-05-13 15:02:50 +090075 m.SetNoDist()
Inseob Kimc0907f12019-02-08 21:00:45 +090076 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
77 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
Colin Crossf8b860a2019-04-16 14:43:28 -070078 android.AddLoadHook(m, func(ctx android.LoadHookContext) { m.SdkLibrary.CreateInternalModules(ctx) })
Inseob Kimc0907f12019-02-08 21:00:45 +090079 return m
80}
81
82func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Inseob Kim6e93ac92019-03-21 17:43:49 +090083 if len(m.commonProperties.Srcs) == 0 {
84 ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
85 }
86
87 if len(m.syspropLibraryProperties.Api_packages) == 0 {
Inseob Kimc0907f12019-02-08 21:00:45 +090088 ctx.PropertyErrorf("api_packages", "sysprop_library must specify api_packages")
89 }
90
91 socSpecific := ctx.SocSpecific()
92 deviceSpecific := ctx.DeviceSpecific()
93 productSpecific := ctx.ProductSpecific()
94
95 owner := m.syspropLibraryProperties.Property_owner
96
97 switch owner {
98 case "Platform":
99 // Every partition can access platform-defined properties
100 break
101 case "Vendor":
102 // System can't access vendor's properties
103 if !socSpecific && !deviceSpecific && !productSpecific {
104 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
105 "System can't access sysprop_library owned by Vendor")
106 }
107 case "Odm":
108 // Only vendor can access Odm-defined properties
109 if !socSpecific && !deviceSpecific {
110 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
111 "Odm-defined properties should be accessed only in Vendor or Odm")
112 }
113 default:
114 ctx.PropertyErrorf("property_owner",
115 "Unknown value %s: must be one of Platform, Vendor or Odm", owner)
116 }
117
118 ccProps := struct {
119 Name *string
120 Soc_specific *bool
121 Device_specific *bool
122 Product_specific *bool
123 Sysprop struct {
124 Platform *bool
125 }
126 }{}
127
128 ccProps.Name = proptools.StringPtr(m.CcModuleName())
129 ccProps.Soc_specific = proptools.BoolPtr(socSpecific)
130 ccProps.Device_specific = proptools.BoolPtr(deviceSpecific)
131 ccProps.Product_specific = proptools.BoolPtr(productSpecific)
132 ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
133
134 ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &m.commonProperties, &ccProps)
135}