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 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 15 | // sysprop package defines a module named sysprop_library that can implement sysprop as API |
| 16 | // See https://source.android.com/devices/architecture/sysprops-apis for details |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 17 | package sysprop |
| 18 | |
| 19 | import ( |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 20 | "fmt" |
| 21 | "io" |
| 22 | "path" |
Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 23 | "sync" |
Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 24 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 25 | "github.com/google/blueprint" |
| 26 | "github.com/google/blueprint/proptools" |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 27 | |
| 28 | "android/soong/android" |
| 29 | "android/soong/cc" |
| 30 | "android/soong/java" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | type dependencyTag struct { |
| 34 | blueprint.BaseDependencyTag |
| 35 | name string |
| 36 | } |
| 37 | |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 38 | type syspropGenProperties struct { |
| 39 | Srcs []string `android:"path"` |
| 40 | Scope string |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 41 | Name *string |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | type syspropJavaGenRule struct { |
| 45 | android.ModuleBase |
| 46 | |
| 47 | properties syspropGenProperties |
| 48 | |
| 49 | genSrcjars android.Paths |
| 50 | } |
| 51 | |
| 52 | var _ android.OutputFileProducer = (*syspropJavaGenRule)(nil) |
| 53 | |
| 54 | var ( |
| 55 | syspropJava = pctx.AndroidStaticRule("syspropJava", |
| 56 | blueprint.RuleParams{ |
| 57 | Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` + |
| 58 | `$syspropJavaCmd --scope $scope --java-output-dir $out.tmp $in && ` + |
| 59 | `$soongZipCmd -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`, |
| 60 | CommandDeps: []string{ |
| 61 | "$syspropJavaCmd", |
| 62 | "$soongZipCmd", |
| 63 | }, |
| 64 | }, "scope") |
| 65 | ) |
| 66 | |
| 67 | func init() { |
| 68 | pctx.HostBinToolVariable("soongZipCmd", "soong_zip") |
| 69 | pctx.HostBinToolVariable("syspropJavaCmd", "sysprop_java") |
| 70 | |
| 71 | android.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
| 72 | ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel() |
| 73 | }) |
| 74 | } |
| 75 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 76 | // syspropJavaGenRule module generates srcjar containing generated java APIs. |
| 77 | // It also depends on check api rule, so api check has to pass to use sysprop_library. |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 78 | func (g *syspropJavaGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 79 | var checkApiFileTimeStamp android.WritablePath |
| 80 | |
| 81 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 82 | if m, ok := dep.(*syspropLibrary); ok { |
| 83 | checkApiFileTimeStamp = m.checkApiFileTimeStamp |
| 84 | } |
| 85 | }) |
| 86 | |
| 87 | for _, syspropFile := range android.PathsForModuleSrc(ctx, g.properties.Srcs) { |
| 88 | srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar") |
| 89 | |
| 90 | ctx.Build(pctx, android.BuildParams{ |
| 91 | Rule: syspropJava, |
| 92 | Description: "sysprop_java " + syspropFile.Rel(), |
| 93 | Output: srcJarFile, |
| 94 | Input: syspropFile, |
| 95 | Implicit: checkApiFileTimeStamp, |
| 96 | Args: map[string]string{ |
| 97 | "scope": g.properties.Scope, |
| 98 | }, |
| 99 | }) |
| 100 | |
| 101 | g.genSrcjars = append(g.genSrcjars, srcJarFile) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func (g *syspropJavaGenRule) OutputFiles(tag string) (android.Paths, error) { |
| 106 | switch tag { |
| 107 | case "": |
| 108 | return g.genSrcjars, nil |
| 109 | default: |
| 110 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | func syspropJavaGenFactory() android.Module { |
| 115 | g := &syspropJavaGenRule{} |
| 116 | g.AddProperties(&g.properties) |
| 117 | android.InitAndroidModule(g) |
| 118 | return g |
| 119 | } |
| 120 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 121 | type syspropLibrary struct { |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 122 | android.ModuleBase |
Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 123 | android.ApexModuleBase |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 124 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 125 | properties syspropLibraryProperties |
| 126 | |
| 127 | checkApiFileTimeStamp android.WritablePath |
| 128 | latestApiFile android.Path |
| 129 | currentApiFile android.Path |
| 130 | dumpedApiFile android.WritablePath |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | type syspropLibraryProperties struct { |
| 134 | // Determine who owns this sysprop library. Possible values are |
| 135 | // "Platform", "Vendor", or "Odm" |
| 136 | Property_owner string |
Inseob Kim | f63c2fb | 2019-03-05 14:22:30 +0900 | [diff] [blame] | 137 | |
| 138 | // list of package names that will be documented and publicized as API |
| 139 | Api_packages []string |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 140 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 141 | // If set to true, allow this module to be dexed and installed on devices. |
| 142 | Installable *bool |
| 143 | |
| 144 | // Make this module available when building for recovery |
Jiyong Park | 854a944 | 2019-02-26 10:27:13 +0900 | [diff] [blame] | 145 | Recovery_available *bool |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 146 | |
| 147 | // Make this module available when building for vendor |
| 148 | Vendor_available *bool |
| 149 | |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 150 | // Make this module available when building for product |
| 151 | Product_available *bool |
| 152 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 153 | // list of .sysprop files which defines the properties. |
| 154 | Srcs []string `android:"path"` |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 155 | |
Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 156 | // If set to true, build a variant of the module for the host. Defaults to false. |
| 157 | Host_supported *bool |
| 158 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 159 | // Whether public stub exists or not. |
| 160 | Public_stub *bool `blueprint:"mutated"` |
Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 161 | |
| 162 | Cpp struct { |
| 163 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 164 | // Forwarded to cc_library.min_sdk_version |
| 165 | Min_sdk_version *string |
| 166 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | var ( |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 170 | pctx = android.NewPackageContext("android/soong/sysprop") |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 171 | syspropCcTag = dependencyTag{name: "syspropCc"} |
Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 172 | |
| 173 | syspropLibrariesKey = android.NewOnceKey("syspropLibraries") |
| 174 | syspropLibrariesLock sync.Mutex |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 175 | ) |
| 176 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 177 | // List of sysprop_library used by property_contexts to perform type check. |
Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 178 | func syspropLibraries(config android.Config) *[]string { |
| 179 | return config.Once(syspropLibrariesKey, func() interface{} { |
| 180 | return &[]string{} |
| 181 | }).(*[]string) |
| 182 | } |
| 183 | |
| 184 | func SyspropLibraries(config android.Config) []string { |
| 185 | return append([]string{}, *syspropLibraries(config)...) |
| 186 | } |
| 187 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 188 | func init() { |
| 189 | android.RegisterModuleType("sysprop_library", syspropLibraryFactory) |
| 190 | } |
| 191 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 192 | func (m *syspropLibrary) Name() string { |
| 193 | return m.BaseModuleName() + "_sysprop_library" |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 194 | } |
| 195 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 196 | func (m *syspropLibrary) Owner() string { |
| 197 | return m.properties.Property_owner |
| 198 | } |
| 199 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 200 | func (m *syspropLibrary) CcImplementationModuleName() string { |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 201 | return "lib" + m.BaseModuleName() |
| 202 | } |
| 203 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 204 | func (m *syspropLibrary) JavaPublicStubName() string { |
| 205 | if proptools.Bool(m.properties.Public_stub) { |
| 206 | return m.BaseModuleName() + "_public" |
| 207 | } |
| 208 | return "" |
| 209 | } |
| 210 | |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 211 | func (m *syspropLibrary) javaGenModuleName() string { |
| 212 | return m.BaseModuleName() + "_java_gen" |
| 213 | } |
| 214 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 215 | func (m *syspropLibrary) javaGenPublicStubName() string { |
| 216 | return m.BaseModuleName() + "_java_gen_public" |
| 217 | } |
| 218 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 219 | func (m *syspropLibrary) BaseModuleName() string { |
| 220 | return m.ModuleBase.Name() |
| 221 | } |
| 222 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 223 | func (m *syspropLibrary) HasPublicStub() bool { |
| 224 | return proptools.Bool(m.properties.Public_stub) |
| 225 | } |
| 226 | |
Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 227 | func (m *syspropLibrary) CurrentSyspropApiFile() android.Path { |
| 228 | return m.currentApiFile |
| 229 | } |
| 230 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 231 | // GenerateAndroidBuildActions of sysprop_library handles API dump and API check. |
| 232 | // generated java_library will depend on these API files. |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 233 | func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 234 | baseModuleName := m.BaseModuleName() |
| 235 | |
| 236 | for _, syspropFile := range android.PathsForModuleSrc(ctx, m.properties.Srcs) { |
| 237 | if syspropFile.Ext() != ".sysprop" { |
| 238 | ctx.PropertyErrorf("srcs", "srcs contains non-sysprop file %q", syspropFile.String()) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if ctx.Failed() { |
| 243 | return |
| 244 | } |
| 245 | |
| 246 | m.currentApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-current.txt") |
| 247 | m.latestApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-latest.txt") |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 248 | |
| 249 | // dump API rule |
| 250 | rule := android.NewRuleBuilder() |
| 251 | m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt") |
| 252 | rule.Command(). |
| 253 | BuiltTool(ctx, "sysprop_api_dump"). |
| 254 | Output(m.dumpedApiFile). |
| 255 | Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs)) |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 256 | rule.Build(pctx, ctx, baseModuleName+"_api_dump", baseModuleName+" api dump") |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 257 | |
| 258 | // check API rule |
| 259 | rule = android.NewRuleBuilder() |
| 260 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 261 | // 1. compares current.txt to api-dump.txt |
| 262 | // current.txt should be identical to api-dump.txt. |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 263 | msg := fmt.Sprintf(`\n******************************\n`+ |
| 264 | `API of sysprop_library %s doesn't match with current.txt\n`+ |
| 265 | `Please update current.txt by:\n`+ |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 266 | `m %s-dump-api && rm -rf %q && cp -f %q %q\n`+ |
| 267 | `******************************\n`, baseModuleName, baseModuleName, |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 268 | m.currentApiFile.String(), m.dumpedApiFile.String(), m.currentApiFile.String()) |
| 269 | |
| 270 | rule.Command(). |
| 271 | Text("( cmp").Flag("-s"). |
| 272 | Input(m.dumpedApiFile). |
| 273 | Input(m.currentApiFile). |
| 274 | Text("|| ( echo").Flag("-e"). |
| 275 | Flag(`"` + msg + `"`). |
| 276 | Text("; exit 38) )") |
| 277 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 278 | // 2. compares current.txt to latest.txt (frozen API) |
| 279 | // current.txt should be compatible with latest.txt |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 280 | msg = fmt.Sprintf(`\n******************************\n`+ |
| 281 | `API of sysprop_library %s doesn't match with latest version\n`+ |
| 282 | `Please fix the breakage and rebuild.\n`+ |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 283 | `******************************\n`, baseModuleName) |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 284 | |
| 285 | rule.Command(). |
| 286 | Text("( "). |
| 287 | BuiltTool(ctx, "sysprop_api_checker"). |
| 288 | Input(m.latestApiFile). |
| 289 | Input(m.currentApiFile). |
| 290 | Text(" || ( echo").Flag("-e"). |
| 291 | Flag(`"` + msg + `"`). |
| 292 | Text("; exit 38) )") |
| 293 | |
| 294 | m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp") |
| 295 | |
| 296 | rule.Command(). |
| 297 | Text("touch"). |
| 298 | Output(m.checkApiFileTimeStamp) |
| 299 | |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 300 | rule.Build(pctx, ctx, baseModuleName+"_check_api", baseModuleName+" check api") |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | func (m *syspropLibrary) AndroidMk() android.AndroidMkData { |
| 304 | return android.AndroidMkData{ |
| 305 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { |
| 306 | // sysprop_library module itself is defined as a FAKE module to perform API check. |
| 307 | // Actual implementation libraries are created on LoadHookMutator |
| 308 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)") |
| 309 | fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name()) |
| 310 | fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n") |
| 311 | fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n") |
| 312 | fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n") |
| 313 | fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String()) |
| 314 | fmt.Fprintf(w, "\ttouch $@\n\n") |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 315 | fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name) |
| 316 | |
| 317 | // dump API rule |
| 318 | fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String()) |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 319 | |
| 320 | // check API rule |
| 321 | fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String()) |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 322 | }} |
| 323 | } |
| 324 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 325 | func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 326 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 327 | return fmt.Errorf("sysprop_library is not supposed to be part of apex modules") |
| 328 | } |
| 329 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 330 | // sysprop_library creates schematized APIs from sysprop description files (.sysprop). |
| 331 | // Both Java and C++ modules can link against sysprop_library, and API stability check |
| 332 | // against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh) |
| 333 | // is performed. |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 334 | func syspropLibraryFactory() android.Module { |
| 335 | m := &syspropLibrary{} |
| 336 | |
| 337 | m.AddProperties( |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 338 | &m.properties, |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 339 | ) |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 340 | android.InitAndroidModule(m) |
Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 341 | android.InitApexModule(m) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 342 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) }) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 343 | return m |
| 344 | } |
| 345 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 346 | type ccLibraryProperties struct { |
| 347 | Name *string |
| 348 | Srcs []string |
| 349 | Soc_specific *bool |
| 350 | Device_specific *bool |
| 351 | Product_specific *bool |
| 352 | Sysprop struct { |
| 353 | Platform *bool |
| 354 | } |
Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 355 | Target struct { |
| 356 | Android struct { |
| 357 | Header_libs []string |
| 358 | Shared_libs []string |
| 359 | } |
| 360 | Host struct { |
| 361 | Static_libs []string |
| 362 | } |
| 363 | } |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 364 | Required []string |
| 365 | Recovery *bool |
| 366 | Recovery_available *bool |
| 367 | Vendor_available *bool |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 368 | Product_available *bool |
Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 369 | Host_supported *bool |
Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 370 | Apex_available []string |
Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 371 | Min_sdk_version *string |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | type javaLibraryProperties struct { |
| 375 | Name *string |
| 376 | Srcs []string |
| 377 | Soc_specific *bool |
| 378 | Device_specific *bool |
| 379 | Product_specific *bool |
| 380 | Required []string |
| 381 | Sdk_version *string |
| 382 | Installable *bool |
| 383 | Libs []string |
| 384 | Stem *string |
| 385 | } |
| 386 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 387 | func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) { |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 388 | if len(m.properties.Srcs) == 0 { |
Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 389 | ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs") |
| 390 | } |
| 391 | |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 392 | missing_api := false |
| 393 | |
| 394 | for _, txt := range []string{"-current.txt", "-latest.txt"} { |
| 395 | path := path.Join(ctx.ModuleDir(), "api", m.BaseModuleName()+txt) |
| 396 | file := android.ExistentPathForSource(ctx, path) |
| 397 | if !file.Valid() { |
| 398 | ctx.ModuleErrorf("API file %#v doesn't exist", path) |
| 399 | missing_api = true |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | if missing_api { |
| 404 | script := "build/soong/scripts/gen-sysprop-api-files.sh" |
| 405 | p := android.ExistentPathForSource(ctx, script) |
| 406 | |
| 407 | if !p.Valid() { |
| 408 | panic(fmt.Sprintf("script file %s doesn't exist", script)) |
| 409 | } |
| 410 | |
| 411 | ctx.ModuleErrorf("One or more api files are missing. "+ |
| 412 | "You can create them by:\n"+ |
| 413 | "%s %q %q", script, ctx.ModuleDir(), m.BaseModuleName()) |
| 414 | return |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 415 | } |
| 416 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 417 | // ctx's Platform or Specific functions represent where this sysprop_library installed. |
| 418 | installedInSystem := ctx.Platform() || ctx.SystemExtSpecific() |
| 419 | installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific() |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 420 | installedInProduct := ctx.ProductSpecific() |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 421 | isOwnerPlatform := false |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 422 | var javaSyspropStub string |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 423 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 424 | // javaSyspropStub contains stub libraries used by generated APIs, instead of framework stub. |
| 425 | // This is to make sysprop_library link against core_current. |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 426 | if installedInVendorOrOdm { |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 427 | javaSyspropStub = "sysprop-library-stub-vendor" |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 428 | } else if installedInProduct { |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 429 | javaSyspropStub = "sysprop-library-stub-product" |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 430 | } else { |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 431 | javaSyspropStub = "sysprop-library-stub-platform" |
Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 432 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 433 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 434 | switch m.Owner() { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 435 | case "Platform": |
| 436 | // Every partition can access platform-defined properties |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 437 | isOwnerPlatform = true |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 438 | case "Vendor": |
| 439 | // System can't access vendor's properties |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 440 | if installedInSystem { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 441 | ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " + |
| 442 | "System can't access sysprop_library owned by Vendor") |
| 443 | } |
| 444 | case "Odm": |
| 445 | // Only vendor can access Odm-defined properties |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 446 | if !installedInVendorOrOdm { |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 447 | ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " + |
| 448 | "Odm-defined properties should be accessed only in Vendor or Odm") |
| 449 | } |
| 450 | default: |
| 451 | ctx.PropertyErrorf("property_owner", |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 452 | "Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner()) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 453 | } |
| 454 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 455 | // Generate a C++ implementation library. |
| 456 | // cc_library can receive *.sysprop files as their srcs, generating sources itself. |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 457 | ccProps := ccLibraryProperties{} |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 458 | ccProps.Name = proptools.StringPtr(m.CcImplementationModuleName()) |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 459 | ccProps.Srcs = m.properties.Srcs |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 460 | ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific()) |
| 461 | ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific()) |
| 462 | ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific()) |
| 463 | ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform) |
Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 464 | ccProps.Target.Android.Header_libs = []string{"libbase_headers"} |
| 465 | ccProps.Target.Android.Shared_libs = []string{"liblog"} |
| 466 | ccProps.Target.Host.Static_libs = []string{"libbase", "liblog"} |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 467 | ccProps.Recovery_available = m.properties.Recovery_available |
| 468 | ccProps.Vendor_available = m.properties.Vendor_available |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 469 | ccProps.Product_available = m.properties.Product_available |
Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 470 | ccProps.Host_supported = m.properties.Host_supported |
Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 471 | ccProps.Apex_available = m.ApexProperties.Apex_available |
Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 472 | ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version |
Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 473 | ctx.CreateModule(cc.LibraryFactory, &ccProps) |
Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 474 | |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 475 | scope := "internal" |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 476 | |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 477 | // We need to only use public version, if the partition where sysprop_library will be installed |
| 478 | // is different from owner. |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 479 | if ctx.ProductSpecific() { |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 480 | // Currently product partition can't own any sysprop_library. So product always uses public. |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 481 | scope = "public" |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 482 | } else if isOwnerPlatform && installedInVendorOrOdm { |
| 483 | // Vendor or Odm should use public version of Platform's sysprop_library. |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 484 | scope = "public" |
| 485 | } |
| 486 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 487 | // Generate a Java implementation library. |
| 488 | // Contrast to C++, syspropJavaGenRule module will generate srcjar and the srcjar will be fed |
| 489 | // to Java implementation library. |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 490 | ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{ |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 491 | Srcs: m.properties.Srcs, |
| 492 | Scope: scope, |
| 493 | Name: proptools.StringPtr(m.javaGenModuleName()), |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 494 | }) |
| 495 | |
| 496 | ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{ |
| 497 | Name: proptools.StringPtr(m.BaseModuleName()), |
| 498 | Srcs: []string{":" + m.javaGenModuleName()}, |
| 499 | Soc_specific: proptools.BoolPtr(ctx.SocSpecific()), |
| 500 | Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()), |
| 501 | Product_specific: proptools.BoolPtr(ctx.ProductSpecific()), |
| 502 | Installable: m.properties.Installable, |
| 503 | Sdk_version: proptools.StringPtr("core_current"), |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 504 | Libs: []string{javaSyspropStub}, |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 505 | }) |
| 506 | |
| 507 | // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API |
| 508 | // and allow any modules (even from different partition) to link against the sysprop_library. |
| 509 | // To do that, we create a public stub and expose it to modules with sdk_version: system_*. |
| 510 | if isOwnerPlatform && installedInSystem { |
| 511 | m.properties.Public_stub = proptools.BoolPtr(true) |
| 512 | ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{ |
| 513 | Srcs: m.properties.Srcs, |
| 514 | Scope: "public", |
| 515 | Name: proptools.StringPtr(m.javaGenPublicStubName()), |
| 516 | }) |
| 517 | |
| 518 | ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{ |
| 519 | Name: proptools.StringPtr(m.JavaPublicStubName()), |
| 520 | Srcs: []string{":" + m.javaGenPublicStubName()}, |
| 521 | Installable: proptools.BoolPtr(false), |
| 522 | Sdk_version: proptools.StringPtr("core_current"), |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 523 | Libs: []string{javaSyspropStub}, |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 524 | Stem: proptools.StringPtr(m.BaseModuleName()), |
| 525 | }) |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 526 | } |
Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 527 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 528 | // syspropLibraries will be used by property_contexts to check types. |
| 529 | // Record absolute paths of sysprop_library to prevent soong_namespace problem. |
Inseob Kim | 69cf09e | 2020-05-04 19:28:25 +0900 | [diff] [blame] | 530 | if m.ExportedToMake() { |
| 531 | syspropLibrariesLock.Lock() |
| 532 | defer syspropLibrariesLock.Unlock() |
Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 533 | |
Inseob Kim | 69cf09e | 2020-05-04 19:28:25 +0900 | [diff] [blame] | 534 | libraries := syspropLibraries(ctx.Config()) |
| 535 | *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName()) |
| 536 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 537 | } |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 538 | |
Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 539 | // syspropDepsMutator adds dependencies from java implementation library to sysprop library. |
| 540 | // java implementation library then depends on check API rule of sysprop library. |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 541 | func syspropDepsMutator(ctx android.BottomUpMutatorContext) { |
| 542 | if m, ok := ctx.Module().(*syspropLibrary); ok { |
| 543 | ctx.AddReverseDependency(m, nil, m.javaGenModuleName()) |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 544 | |
| 545 | if proptools.Bool(m.properties.Public_stub) { |
| 546 | ctx.AddReverseDependency(m, nil, m.javaGenPublicStubName()) |
| 547 | } |
Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 548 | } |
| 549 | } |