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