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