blob: 892a16c8dad52a513ef2f69a5616c3f243c26653 [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
Inseob Kim07def122020-11-23 14:43:02 +090015// 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 Kimc0907f12019-02-08 21:00:45 +090017package sysprop
18
19import (
Inseob Kim42882742019-07-30 17:55:33 +090020 "fmt"
21 "io"
Inseob Kimc9770d62021-01-15 18:04:20 +090022 "os"
Inseob Kim42882742019-07-30 17:55:33 +090023 "path"
Inseob Kim628d7ef2020-03-21 03:38:32 +090024 "sync"
Colin Crossf8b860a2019-04-16 14:43:28 -070025
Inseob Kimc0907f12019-02-08 21:00:45 +090026 "github.com/google/blueprint"
27 "github.com/google/blueprint/proptools"
Inseob Kim42882742019-07-30 17:55:33 +090028
29 "android/soong/android"
30 "android/soong/cc"
31 "android/soong/java"
Inseob Kimc0907f12019-02-08 21:00:45 +090032)
33
34type dependencyTag struct {
35 blueprint.BaseDependencyTag
36 name string
37}
38
Inseob Kim988f53c2019-09-16 15:59:01 +090039type syspropGenProperties struct {
Colin Cross75ce9ec2021-02-26 16:20:32 -080040 Srcs []string `android:"path"`
41 Scope string
42 Name *string
43 Check_api *string
Inseob Kim988f53c2019-09-16 15:59:01 +090044}
45
46type syspropJavaGenRule struct {
47 android.ModuleBase
48
49 properties syspropGenProperties
50
51 genSrcjars android.Paths
52}
53
54var _ android.OutputFileProducer = (*syspropJavaGenRule)(nil)
55
56var (
57 syspropJava = pctx.AndroidStaticRule("syspropJava",
58 blueprint.RuleParams{
59 Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
60 `$syspropJavaCmd --scope $scope --java-output-dir $out.tmp $in && ` +
61 `$soongZipCmd -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
62 CommandDeps: []string{
63 "$syspropJavaCmd",
64 "$soongZipCmd",
65 },
66 }, "scope")
67)
68
69func init() {
70 pctx.HostBinToolVariable("soongZipCmd", "soong_zip")
71 pctx.HostBinToolVariable("syspropJavaCmd", "sysprop_java")
Inseob Kim988f53c2019-09-16 15:59:01 +090072}
73
Inseob Kim07def122020-11-23 14:43:02 +090074// syspropJavaGenRule module generates srcjar containing generated java APIs.
75// It also depends on check api rule, so api check has to pass to use sysprop_library.
Inseob Kim988f53c2019-09-16 15:59:01 +090076func (g *syspropJavaGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
77 var checkApiFileTimeStamp android.WritablePath
78
79 ctx.VisitDirectDeps(func(dep android.Module) {
80 if m, ok := dep.(*syspropLibrary); ok {
81 checkApiFileTimeStamp = m.checkApiFileTimeStamp
82 }
83 })
84
85 for _, syspropFile := range android.PathsForModuleSrc(ctx, g.properties.Srcs) {
86 srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
87
88 ctx.Build(pctx, android.BuildParams{
89 Rule: syspropJava,
90 Description: "sysprop_java " + syspropFile.Rel(),
91 Output: srcJarFile,
92 Input: syspropFile,
93 Implicit: checkApiFileTimeStamp,
94 Args: map[string]string{
95 "scope": g.properties.Scope,
96 },
97 })
98
99 g.genSrcjars = append(g.genSrcjars, srcJarFile)
100 }
101}
102
Colin Cross75ce9ec2021-02-26 16:20:32 -0800103func (g *syspropJavaGenRule) DepsMutator(ctx android.BottomUpMutatorContext) {
104 // Add a dependency from the stubs to sysprop library so that the generator rule can depend on
105 // the check API rule of the sysprop library.
106 ctx.AddFarVariationDependencies(nil, nil, proptools.String(g.properties.Check_api))
107}
108
Inseob Kim988f53c2019-09-16 15:59:01 +0900109func (g *syspropJavaGenRule) OutputFiles(tag string) (android.Paths, error) {
110 switch tag {
111 case "":
112 return g.genSrcjars, nil
113 default:
114 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
115 }
116}
117
118func syspropJavaGenFactory() android.Module {
119 g := &syspropJavaGenRule{}
120 g.AddProperties(&g.properties)
121 android.InitAndroidModule(g)
122 return g
123}
124
Inseob Kimc0907f12019-02-08 21:00:45 +0900125type syspropLibrary struct {
Inseob Kim42882742019-07-30 17:55:33 +0900126 android.ModuleBase
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100127 android.ApexModuleBase
Inseob Kimc0907f12019-02-08 21:00:45 +0900128
Inseob Kim42882742019-07-30 17:55:33 +0900129 properties syspropLibraryProperties
130
131 checkApiFileTimeStamp android.WritablePath
Inseob Kimc9770d62021-01-15 18:04:20 +0900132 latestApiFile android.OptionalPath
133 currentApiFile android.OptionalPath
Inseob Kim42882742019-07-30 17:55:33 +0900134 dumpedApiFile android.WritablePath
Inseob Kimc0907f12019-02-08 21:00:45 +0900135}
136
137type syspropLibraryProperties struct {
138 // Determine who owns this sysprop library. Possible values are
139 // "Platform", "Vendor", or "Odm"
140 Property_owner string
Inseob Kimf63c2fb2019-03-05 14:22:30 +0900141
142 // list of package names that will be documented and publicized as API
143 Api_packages []string
Inseob Kimc0907f12019-02-08 21:00:45 +0900144
Inseob Kim42882742019-07-30 17:55:33 +0900145 // If set to true, allow this module to be dexed and installed on devices.
146 Installable *bool
147
148 // Make this module available when building for recovery
Jiyong Park854a9442019-02-26 10:27:13 +0900149 Recovery_available *bool
Inseob Kim42882742019-07-30 17:55:33 +0900150
151 // Make this module available when building for vendor
152 Vendor_available *bool
153
Justin Yun63e9ec72020-10-29 16:49:43 +0900154 // Make this module available when building for product
155 Product_available *bool
156
Inseob Kim42882742019-07-30 17:55:33 +0900157 // list of .sysprop files which defines the properties.
158 Srcs []string `android:"path"`
Inseob Kimac1e9862019-12-09 18:15:47 +0900159
Inseob Kim89db15d2020-02-03 18:06:46 +0900160 // If set to true, build a variant of the module for the host. Defaults to false.
161 Host_supported *bool
162
Jooyung Han379660c2020-04-21 15:24:00 +0900163 Cpp struct {
164 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
165 // Forwarded to cc_library.min_sdk_version
166 Min_sdk_version *string
167 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900168
169 Java struct {
170 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
171 // Forwarded to java_library.min_sdk_version
172 Min_sdk_version *string
173 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900174}
175
176var (
Inseob Kim42882742019-07-30 17:55:33 +0900177 pctx = android.NewPackageContext("android/soong/sysprop")
Inseob Kimc0907f12019-02-08 21:00:45 +0900178 syspropCcTag = dependencyTag{name: "syspropCc"}
Inseob Kim628d7ef2020-03-21 03:38:32 +0900179
180 syspropLibrariesKey = android.NewOnceKey("syspropLibraries")
181 syspropLibrariesLock sync.Mutex
Inseob Kimc0907f12019-02-08 21:00:45 +0900182)
183
Inseob Kim07def122020-11-23 14:43:02 +0900184// List of sysprop_library used by property_contexts to perform type check.
Inseob Kim628d7ef2020-03-21 03:38:32 +0900185func syspropLibraries(config android.Config) *[]string {
186 return config.Once(syspropLibrariesKey, func() interface{} {
187 return &[]string{}
188 }).(*[]string)
189}
190
191func SyspropLibraries(config android.Config) []string {
192 return append([]string{}, *syspropLibraries(config)...)
193}
194
Inseob Kimc0907f12019-02-08 21:00:45 +0900195func init() {
196 android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
197}
198
Inseob Kim42882742019-07-30 17:55:33 +0900199func (m *syspropLibrary) Name() string {
200 return m.BaseModuleName() + "_sysprop_library"
Inseob Kimc0907f12019-02-08 21:00:45 +0900201}
202
Inseob Kimac1e9862019-12-09 18:15:47 +0900203func (m *syspropLibrary) Owner() string {
204 return m.properties.Property_owner
205}
206
Inseob Kim07def122020-11-23 14:43:02 +0900207func (m *syspropLibrary) CcImplementationModuleName() string {
Inseob Kim42882742019-07-30 17:55:33 +0900208 return "lib" + m.BaseModuleName()
209}
210
Colin Cross75ce9ec2021-02-26 16:20:32 -0800211func (m *syspropLibrary) javaPublicStubName() string {
212 return m.BaseModuleName() + "_public"
Inseob Kimac1e9862019-12-09 18:15:47 +0900213}
214
Inseob Kim988f53c2019-09-16 15:59:01 +0900215func (m *syspropLibrary) javaGenModuleName() string {
216 return m.BaseModuleName() + "_java_gen"
217}
218
Inseob Kimac1e9862019-12-09 18:15:47 +0900219func (m *syspropLibrary) javaGenPublicStubName() string {
220 return m.BaseModuleName() + "_java_gen_public"
221}
222
Inseob Kim42882742019-07-30 17:55:33 +0900223func (m *syspropLibrary) BaseModuleName() string {
224 return m.ModuleBase.Name()
225}
226
Inseob Kimc9770d62021-01-15 18:04:20 +0900227func (m *syspropLibrary) CurrentSyspropApiFile() android.OptionalPath {
Inseob Kim628d7ef2020-03-21 03:38:32 +0900228 return m.currentApiFile
229}
230
Inseob Kim07def122020-11-23 14:43:02 +0900231// GenerateAndroidBuildActions of sysprop_library handles API dump and API check.
232// generated java_library will depend on these API files.
Inseob Kim42882742019-07-30 17:55:33 +0900233func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Inseob Kim988f53c2019-09-16 15:59:01 +0900234 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
Inseob Kimc9770d62021-01-15 18:04:20 +0900246 apiDirectoryPath := path.Join(ctx.ModuleDir(), "api")
247 currentApiFilePath := path.Join(apiDirectoryPath, baseModuleName+"-current.txt")
248 latestApiFilePath := path.Join(apiDirectoryPath, baseModuleName+"-latest.txt")
249 m.currentApiFile = android.ExistentPathForSource(ctx, currentApiFilePath)
250 m.latestApiFile = android.ExistentPathForSource(ctx, latestApiFilePath)
Inseob Kim42882742019-07-30 17:55:33 +0900251
252 // dump API rule
Colin Crossf1a035e2020-11-16 17:32:30 -0800253 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim42882742019-07-30 17:55:33 +0900254 m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt")
255 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800256 BuiltTool("sysprop_api_dump").
Inseob Kim42882742019-07-30 17:55:33 +0900257 Output(m.dumpedApiFile).
258 Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
Colin Crossf1a035e2020-11-16 17:32:30 -0800259 rule.Build(baseModuleName+"_api_dump", baseModuleName+" api dump")
Inseob Kim42882742019-07-30 17:55:33 +0900260
261 // check API rule
Colin Crossf1a035e2020-11-16 17:32:30 -0800262 rule = android.NewRuleBuilder(pctx, ctx)
Inseob Kim42882742019-07-30 17:55:33 +0900263
Inseob Kimc9770d62021-01-15 18:04:20 +0900264 // We allow that the API txt files don't exist, when the sysprop_library only contains internal
265 // properties. But we have to feed current api file and latest api file to the rule builder.
266 // Currently we can't get android.Path representing the null device, so we add any existing API
267 // txt files to implicits, and then directly feed string paths, rather than calling Input(Path)
268 // method.
269 var apiFileList android.Paths
270 currentApiArgument := os.DevNull
271 if m.currentApiFile.Valid() {
272 apiFileList = append(apiFileList, m.currentApiFile.Path())
273 currentApiArgument = m.currentApiFile.String()
274 }
275
276 latestApiArgument := os.DevNull
277 if m.latestApiFile.Valid() {
278 apiFileList = append(apiFileList, m.latestApiFile.Path())
279 latestApiArgument = m.latestApiFile.String()
280 }
281
Inseob Kim07def122020-11-23 14:43:02 +0900282 // 1. compares current.txt to api-dump.txt
283 // current.txt should be identical to api-dump.txt.
Inseob Kim42882742019-07-30 17:55:33 +0900284 msg := fmt.Sprintf(`\n******************************\n`+
285 `API of sysprop_library %s doesn't match with current.txt\n`+
286 `Please update current.txt by:\n`+
Inseob Kimc9770d62021-01-15 18:04:20 +0900287 `m %s-dump-api && mkdir -p %q && rm -rf %q && cp -f %q %q\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900288 `******************************\n`, baseModuleName, baseModuleName,
Inseob Kimc9770d62021-01-15 18:04:20 +0900289 apiDirectoryPath, currentApiFilePath, m.dumpedApiFile.String(), currentApiFilePath)
Inseob Kim42882742019-07-30 17:55:33 +0900290
291 rule.Command().
292 Text("( cmp").Flag("-s").
293 Input(m.dumpedApiFile).
Inseob Kimc9770d62021-01-15 18:04:20 +0900294 Text(currentApiArgument).
Inseob Kim42882742019-07-30 17:55:33 +0900295 Text("|| ( echo").Flag("-e").
296 Flag(`"` + msg + `"`).
297 Text("; exit 38) )")
298
Inseob Kim07def122020-11-23 14:43:02 +0900299 // 2. compares current.txt to latest.txt (frozen API)
300 // current.txt should be compatible with latest.txt
Inseob Kim42882742019-07-30 17:55:33 +0900301 msg = fmt.Sprintf(`\n******************************\n`+
302 `API of sysprop_library %s doesn't match with latest version\n`+
303 `Please fix the breakage and rebuild.\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900304 `******************************\n`, baseModuleName)
Inseob Kim42882742019-07-30 17:55:33 +0900305
306 rule.Command().
307 Text("( ").
Colin Crossf1a035e2020-11-16 17:32:30 -0800308 BuiltTool("sysprop_api_checker").
Inseob Kimc9770d62021-01-15 18:04:20 +0900309 Text(latestApiArgument).
310 Text(currentApiArgument).
Inseob Kim42882742019-07-30 17:55:33 +0900311 Text(" || ( echo").Flag("-e").
312 Flag(`"` + msg + `"`).
Inseob Kimc9770d62021-01-15 18:04:20 +0900313 Text("; exit 38) )").
314 Implicits(apiFileList)
Inseob Kim42882742019-07-30 17:55:33 +0900315
316 m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp")
317
318 rule.Command().
319 Text("touch").
320 Output(m.checkApiFileTimeStamp)
321
Colin Crossf1a035e2020-11-16 17:32:30 -0800322 rule.Build(baseModuleName+"_check_api", baseModuleName+" check api")
Inseob Kim42882742019-07-30 17:55:33 +0900323}
324
325func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
326 return android.AndroidMkData{
327 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
328 // sysprop_library module itself is defined as a FAKE module to perform API check.
329 // Actual implementation libraries are created on LoadHookMutator
330 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
331 fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name())
Bob Badourb4999222021-01-07 03:34:31 +0000332 data.Entries.WriteLicenseVariables(w)
Inseob Kim42882742019-07-30 17:55:33 +0900333 fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
334 fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
335 fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
336 fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
337 fmt.Fprintf(w, "\ttouch $@\n\n")
Inseob Kim988f53c2019-09-16 15:59:01 +0900338 fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name)
339
340 // dump API rule
341 fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String())
Inseob Kim42882742019-07-30 17:55:33 +0900342
343 // check API rule
344 fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
Inseob Kim42882742019-07-30 17:55:33 +0900345 }}
346}
347
Jiyong Park45bf82e2020-12-15 22:29:02 +0900348var _ android.ApexModule = (*syspropLibrary)(nil)
349
350// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -0700351func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
352 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900353 return fmt.Errorf("sysprop_library is not supposed to be part of apex modules")
354}
355
Inseob Kim42882742019-07-30 17:55:33 +0900356// sysprop_library creates schematized APIs from sysprop description files (.sysprop).
357// Both Java and C++ modules can link against sysprop_library, and API stability check
358// against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh)
359// is performed.
Inseob Kimc0907f12019-02-08 21:00:45 +0900360func syspropLibraryFactory() android.Module {
361 m := &syspropLibrary{}
362
363 m.AddProperties(
Inseob Kim42882742019-07-30 17:55:33 +0900364 &m.properties,
Inseob Kimc0907f12019-02-08 21:00:45 +0900365 )
Inseob Kim42882742019-07-30 17:55:33 +0900366 android.InitAndroidModule(m)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100367 android.InitApexModule(m)
Inseob Kimc0907f12019-02-08 21:00:45 +0900368 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
Inseob Kimc0907f12019-02-08 21:00:45 +0900369 return m
370}
371
Inseob Kimac1e9862019-12-09 18:15:47 +0900372type ccLibraryProperties struct {
373 Name *string
374 Srcs []string
375 Soc_specific *bool
376 Device_specific *bool
377 Product_specific *bool
378 Sysprop struct {
379 Platform *bool
380 }
Inseob Kim89db15d2020-02-03 18:06:46 +0900381 Target struct {
382 Android struct {
383 Header_libs []string
384 Shared_libs []string
385 }
386 Host struct {
387 Static_libs []string
388 }
389 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900390 Required []string
391 Recovery *bool
392 Recovery_available *bool
393 Vendor_available *bool
Justin Yun63e9ec72020-10-29 16:49:43 +0900394 Product_available *bool
Inseob Kim89db15d2020-02-03 18:06:46 +0900395 Host_supported *bool
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100396 Apex_available []string
Jooyung Han379660c2020-04-21 15:24:00 +0900397 Min_sdk_version *string
Inseob Kimac1e9862019-12-09 18:15:47 +0900398}
399
400type javaLibraryProperties struct {
Colin Cross75ce9ec2021-02-26 16:20:32 -0800401 Name *string
402 Srcs []string
403 Soc_specific *bool
404 Device_specific *bool
405 Product_specific *bool
406 Required []string
407 Sdk_version *string
408 Installable *bool
409 Libs []string
410 Stem *string
411 SyspropPublicStub string
Jiyong Park5e914b22021-03-08 10:09:52 +0900412 Apex_available []string
413 Min_sdk_version *string
Inseob Kimac1e9862019-12-09 18:15:47 +0900414}
415
Inseob Kimc0907f12019-02-08 21:00:45 +0900416func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Inseob Kim42882742019-07-30 17:55:33 +0900417 if len(m.properties.Srcs) == 0 {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900418 ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
419 }
420
Inseob Kimac1e9862019-12-09 18:15:47 +0900421 // ctx's Platform or Specific functions represent where this sysprop_library installed.
422 installedInSystem := ctx.Platform() || ctx.SystemExtSpecific()
423 installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific()
Inseob Kimfe612182020-10-20 16:29:55 +0900424 installedInProduct := ctx.ProductSpecific()
Inseob Kimac1e9862019-12-09 18:15:47 +0900425 isOwnerPlatform := false
Inseob Kim07def122020-11-23 14:43:02 +0900426 var javaSyspropStub string
Inseob Kimfe612182020-10-20 16:29:55 +0900427
Inseob Kim07def122020-11-23 14:43:02 +0900428 // javaSyspropStub contains stub libraries used by generated APIs, instead of framework stub.
429 // This is to make sysprop_library link against core_current.
Inseob Kimfe612182020-10-20 16:29:55 +0900430 if installedInVendorOrOdm {
Inseob Kim07def122020-11-23 14:43:02 +0900431 javaSyspropStub = "sysprop-library-stub-vendor"
Inseob Kimfe612182020-10-20 16:29:55 +0900432 } else if installedInProduct {
Inseob Kim07def122020-11-23 14:43:02 +0900433 javaSyspropStub = "sysprop-library-stub-product"
Inseob Kimfe612182020-10-20 16:29:55 +0900434 } else {
Inseob Kim07def122020-11-23 14:43:02 +0900435 javaSyspropStub = "sysprop-library-stub-platform"
Inseob Kimfe612182020-10-20 16:29:55 +0900436 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900437
Inseob Kimac1e9862019-12-09 18:15:47 +0900438 switch m.Owner() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900439 case "Platform":
440 // Every partition can access platform-defined properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900441 isOwnerPlatform = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900442 case "Vendor":
443 // System can't access vendor's properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900444 if installedInSystem {
Inseob Kimc0907f12019-02-08 21:00:45 +0900445 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
446 "System can't access sysprop_library owned by Vendor")
447 }
448 case "Odm":
449 // Only vendor can access Odm-defined properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900450 if !installedInVendorOrOdm {
Inseob Kimc0907f12019-02-08 21:00:45 +0900451 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
452 "Odm-defined properties should be accessed only in Vendor or Odm")
453 }
454 default:
455 ctx.PropertyErrorf("property_owner",
Inseob Kimac1e9862019-12-09 18:15:47 +0900456 "Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
Inseob Kimc0907f12019-02-08 21:00:45 +0900457 }
458
Inseob Kim07def122020-11-23 14:43:02 +0900459 // Generate a C++ implementation library.
460 // cc_library can receive *.sysprop files as their srcs, generating sources itself.
Inseob Kimac1e9862019-12-09 18:15:47 +0900461 ccProps := ccLibraryProperties{}
Inseob Kim07def122020-11-23 14:43:02 +0900462 ccProps.Name = proptools.StringPtr(m.CcImplementationModuleName())
Inseob Kim42882742019-07-30 17:55:33 +0900463 ccProps.Srcs = m.properties.Srcs
Inseob Kimac1e9862019-12-09 18:15:47 +0900464 ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific())
465 ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific())
466 ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific())
467 ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform)
Inseob Kim89db15d2020-02-03 18:06:46 +0900468 ccProps.Target.Android.Header_libs = []string{"libbase_headers"}
469 ccProps.Target.Android.Shared_libs = []string{"liblog"}
470 ccProps.Target.Host.Static_libs = []string{"libbase", "liblog"}
Inseob Kim42882742019-07-30 17:55:33 +0900471 ccProps.Recovery_available = m.properties.Recovery_available
472 ccProps.Vendor_available = m.properties.Vendor_available
Justin Yun63e9ec72020-10-29 16:49:43 +0900473 ccProps.Product_available = m.properties.Product_available
Inseob Kim89db15d2020-02-03 18:06:46 +0900474 ccProps.Host_supported = m.properties.Host_supported
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100475 ccProps.Apex_available = m.ApexProperties.Apex_available
Jooyung Han379660c2020-04-21 15:24:00 +0900476 ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
Colin Cross84dfc3d2019-09-25 11:33:01 -0700477 ctx.CreateModule(cc.LibraryFactory, &ccProps)
Inseob Kim42882742019-07-30 17:55:33 +0900478
Inseob Kim988f53c2019-09-16 15:59:01 +0900479 scope := "internal"
Inseob Kim988f53c2019-09-16 15:59:01 +0900480
Inseob Kimac1e9862019-12-09 18:15:47 +0900481 // We need to only use public version, if the partition where sysprop_library will be installed
482 // is different from owner.
Inseob Kimac1e9862019-12-09 18:15:47 +0900483 if ctx.ProductSpecific() {
Inseob Kim07def122020-11-23 14:43:02 +0900484 // Currently product partition can't own any sysprop_library. So product always uses public.
Inseob Kim988f53c2019-09-16 15:59:01 +0900485 scope = "public"
Inseob Kimac1e9862019-12-09 18:15:47 +0900486 } else if isOwnerPlatform && installedInVendorOrOdm {
487 // Vendor or Odm should use public version of Platform's sysprop_library.
Inseob Kim988f53c2019-09-16 15:59:01 +0900488 scope = "public"
489 }
490
Inseob Kim07def122020-11-23 14:43:02 +0900491 // Generate a Java implementation library.
492 // Contrast to C++, syspropJavaGenRule module will generate srcjar and the srcjar will be fed
493 // to Java implementation library.
Inseob Kimac1e9862019-12-09 18:15:47 +0900494 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
Colin Cross75ce9ec2021-02-26 16:20:32 -0800495 Srcs: m.properties.Srcs,
496 Scope: scope,
497 Name: proptools.StringPtr(m.javaGenModuleName()),
498 Check_api: proptools.StringPtr(ctx.ModuleName()),
Inseob Kimac1e9862019-12-09 18:15:47 +0900499 })
500
501 // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API
502 // and allow any modules (even from different partition) to link against the sysprop_library.
503 // To do that, we create a public stub and expose it to modules with sdk_version: system_*.
Colin Cross75ce9ec2021-02-26 16:20:32 -0800504 var publicStub string
Inseob Kimac1e9862019-12-09 18:15:47 +0900505 if isOwnerPlatform && installedInSystem {
Colin Cross75ce9ec2021-02-26 16:20:32 -0800506 publicStub = m.javaPublicStubName()
507 }
508
509 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
510 Name: proptools.StringPtr(m.BaseModuleName()),
511 Srcs: []string{":" + m.javaGenModuleName()},
512 Soc_specific: proptools.BoolPtr(ctx.SocSpecific()),
513 Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()),
514 Product_specific: proptools.BoolPtr(ctx.ProductSpecific()),
515 Installable: m.properties.Installable,
516 Sdk_version: proptools.StringPtr("core_current"),
517 Libs: []string{javaSyspropStub},
518 SyspropPublicStub: publicStub,
Jiyong Park5e914b22021-03-08 10:09:52 +0900519 Apex_available: m.ApexProperties.Apex_available,
520 Min_sdk_version: m.properties.Java.Min_sdk_version,
Colin Cross75ce9ec2021-02-26 16:20:32 -0800521 })
522
523 if publicStub != "" {
Inseob Kimac1e9862019-12-09 18:15:47 +0900524 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
Colin Cross75ce9ec2021-02-26 16:20:32 -0800525 Srcs: m.properties.Srcs,
526 Scope: "public",
527 Name: proptools.StringPtr(m.javaGenPublicStubName()),
528 Check_api: proptools.StringPtr(ctx.ModuleName()),
Inseob Kimac1e9862019-12-09 18:15:47 +0900529 })
530
531 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
Colin Cross75ce9ec2021-02-26 16:20:32 -0800532 Name: proptools.StringPtr(publicStub),
Inseob Kimac1e9862019-12-09 18:15:47 +0900533 Srcs: []string{":" + m.javaGenPublicStubName()},
534 Installable: proptools.BoolPtr(false),
535 Sdk_version: proptools.StringPtr("core_current"),
Inseob Kim07def122020-11-23 14:43:02 +0900536 Libs: []string{javaSyspropStub},
Inseob Kimac1e9862019-12-09 18:15:47 +0900537 Stem: proptools.StringPtr(m.BaseModuleName()),
538 })
Inseob Kim988f53c2019-09-16 15:59:01 +0900539 }
Inseob Kim628d7ef2020-03-21 03:38:32 +0900540
Inseob Kim07def122020-11-23 14:43:02 +0900541 // syspropLibraries will be used by property_contexts to check types.
542 // Record absolute paths of sysprop_library to prevent soong_namespace problem.
Inseob Kim69cf09e2020-05-04 19:28:25 +0900543 if m.ExportedToMake() {
544 syspropLibrariesLock.Lock()
545 defer syspropLibrariesLock.Unlock()
Inseob Kim628d7ef2020-03-21 03:38:32 +0900546
Inseob Kim69cf09e2020-05-04 19:28:25 +0900547 libraries := syspropLibraries(ctx.Config())
548 *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName())
549 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900550}