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