blob: 643fe8e94c30008e227e73c3dc2dd8e54683c5ff [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
41 Api_packages []string
42}
43
44type commonProperties struct {
Jiyong Park854a9442019-02-26 10:27:13 +090045 Srcs []string
46 Recovery *bool
47 Recovery_available *bool
48 Vendor_available *bool
Inseob Kimc0907f12019-02-08 21:00:45 +090049}
50
51var (
52 Bool = proptools.Bool
53 syspropCcTag = dependencyTag{name: "syspropCc"}
54)
55
56func init() {
57 android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
58}
59
60func (m *syspropLibrary) CcModuleName() string {
61 return "lib" + m.Name()
62}
63
64func (m *syspropLibrary) SyspropJavaModule() *java.SdkLibrary {
65 return &m.SdkLibrary
66}
67
68func syspropLibraryFactory() android.Module {
69 m := &syspropLibrary{}
70
71 m.AddProperties(
72 &m.commonProperties,
73 &m.syspropLibraryProperties,
74 )
75 m.InitSdkLibraryProperties()
76 android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, "common")
77 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
78
79 return m
80}
81
82func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
83 if m.syspropLibraryProperties.Api_packages == nil {
84 ctx.PropertyErrorf("api_packages", "sysprop_library must specify api_packages")
85 }
86
87 socSpecific := ctx.SocSpecific()
88 deviceSpecific := ctx.DeviceSpecific()
89 productSpecific := ctx.ProductSpecific()
90
91 owner := m.syspropLibraryProperties.Property_owner
92
93 switch owner {
94 case "Platform":
95 // Every partition can access platform-defined properties
96 break
97 case "Vendor":
98 // System can't access vendor's properties
99 if !socSpecific && !deviceSpecific && !productSpecific {
100 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
101 "System can't access sysprop_library owned by Vendor")
102 }
103 case "Odm":
104 // Only vendor can access Odm-defined properties
105 if !socSpecific && !deviceSpecific {
106 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
107 "Odm-defined properties should be accessed only in Vendor or Odm")
108 }
109 default:
110 ctx.PropertyErrorf("property_owner",
111 "Unknown value %s: must be one of Platform, Vendor or Odm", owner)
112 }
113
114 ccProps := struct {
115 Name *string
116 Soc_specific *bool
117 Device_specific *bool
118 Product_specific *bool
119 Sysprop struct {
120 Platform *bool
121 }
122 }{}
123
124 ccProps.Name = proptools.StringPtr(m.CcModuleName())
125 ccProps.Soc_specific = proptools.BoolPtr(socSpecific)
126 ccProps.Device_specific = proptools.BoolPtr(deviceSpecific)
127 ccProps.Product_specific = proptools.BoolPtr(productSpecific)
128 ccProps.Sysprop.Platform = proptools.BoolPtr(owner == "Platform")
129
130 ctx.CreateModule(android.ModuleFactoryAdaptor(cc.LibraryFactory), &m.commonProperties, &ccProps)
131}