blob: 766f3e7dc626fcd16da0a2fc842f413ad8200e6c [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
Inseob Kim9da1f812021-06-14 12:03:59 +0900148 // Make this module available when building for ramdisk
149 Ramdisk_available *bool
150
Inseob Kim42882742019-07-30 17:55:33 +0900151 // Make this module available when building for recovery
Jiyong Park854a9442019-02-26 10:27:13 +0900152 Recovery_available *bool
Inseob Kim42882742019-07-30 17:55:33 +0900153
154 // Make this module available when building for vendor
155 Vendor_available *bool
156
Justin Yun63e9ec72020-10-29 16:49:43 +0900157 // Make this module available when building for product
158 Product_available *bool
159
Inseob Kim42882742019-07-30 17:55:33 +0900160 // list of .sysprop files which defines the properties.
161 Srcs []string `android:"path"`
Inseob Kimac1e9862019-12-09 18:15:47 +0900162
Inseob Kim89db15d2020-02-03 18:06:46 +0900163 // If set to true, build a variant of the module for the host. Defaults to false.
164 Host_supported *bool
165
Jooyung Han379660c2020-04-21 15:24:00 +0900166 Cpp struct {
167 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
168 // Forwarded to cc_library.min_sdk_version
169 Min_sdk_version *string
Steven Morelandc43a4ac2023-10-24 21:49:18 +0000170
171 // C compiler flags used to build library
172 Cflags []string
173
174 // Linker flags used to build binary
175 Ldflags []string
Jooyung Han379660c2020-04-21 15:24:00 +0900176 }
Jiyong Park5e914b22021-03-08 10:09:52 +0900177
178 Java struct {
179 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
180 // Forwarded to java_library.min_sdk_version
181 Min_sdk_version *string
182 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900183}
184
185var (
Inseob Kim42882742019-07-30 17:55:33 +0900186 pctx = android.NewPackageContext("android/soong/sysprop")
Inseob Kimc0907f12019-02-08 21:00:45 +0900187 syspropCcTag = dependencyTag{name: "syspropCc"}
Inseob Kim628d7ef2020-03-21 03:38:32 +0900188
189 syspropLibrariesKey = android.NewOnceKey("syspropLibraries")
190 syspropLibrariesLock sync.Mutex
Inseob Kimc0907f12019-02-08 21:00:45 +0900191)
192
Inseob Kim07def122020-11-23 14:43:02 +0900193// List of sysprop_library used by property_contexts to perform type check.
Inseob Kim628d7ef2020-03-21 03:38:32 +0900194func syspropLibraries(config android.Config) *[]string {
195 return config.Once(syspropLibrariesKey, func() interface{} {
196 return &[]string{}
197 }).(*[]string)
198}
199
200func SyspropLibraries(config android.Config) []string {
201 return append([]string{}, *syspropLibraries(config)...)
202}
203
Inseob Kimc0907f12019-02-08 21:00:45 +0900204func init() {
Paul Duffin6e3ce722021-03-18 00:20:11 +0000205 registerSyspropBuildComponents(android.InitRegistrationContext)
206}
207
208func registerSyspropBuildComponents(ctx android.RegistrationContext) {
209 ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory)
Inseob Kimc0907f12019-02-08 21:00:45 +0900210}
211
Inseob Kim42882742019-07-30 17:55:33 +0900212func (m *syspropLibrary) Name() string {
213 return m.BaseModuleName() + "_sysprop_library"
Inseob Kimc0907f12019-02-08 21:00:45 +0900214}
215
Inseob Kimac1e9862019-12-09 18:15:47 +0900216func (m *syspropLibrary) Owner() string {
217 return m.properties.Property_owner
218}
219
Inseob Kim07def122020-11-23 14:43:02 +0900220func (m *syspropLibrary) CcImplementationModuleName() string {
Inseob Kim42882742019-07-30 17:55:33 +0900221 return "lib" + m.BaseModuleName()
222}
223
Colin Cross75ce9ec2021-02-26 16:20:32 -0800224func (m *syspropLibrary) javaPublicStubName() string {
225 return m.BaseModuleName() + "_public"
Inseob Kimac1e9862019-12-09 18:15:47 +0900226}
227
Inseob Kim988f53c2019-09-16 15:59:01 +0900228func (m *syspropLibrary) javaGenModuleName() string {
229 return m.BaseModuleName() + "_java_gen"
230}
231
Inseob Kimac1e9862019-12-09 18:15:47 +0900232func (m *syspropLibrary) javaGenPublicStubName() string {
233 return m.BaseModuleName() + "_java_gen_public"
234}
235
Inseob Kim42882742019-07-30 17:55:33 +0900236func (m *syspropLibrary) BaseModuleName() string {
237 return m.ModuleBase.Name()
238}
239
Inseob Kimc9770d62021-01-15 18:04:20 +0900240func (m *syspropLibrary) CurrentSyspropApiFile() android.OptionalPath {
Inseob Kim628d7ef2020-03-21 03:38:32 +0900241 return m.currentApiFile
242}
243
Inseob Kim07def122020-11-23 14:43:02 +0900244// GenerateAndroidBuildActions of sysprop_library handles API dump and API check.
245// generated java_library will depend on these API files.
Inseob Kim42882742019-07-30 17:55:33 +0900246func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Inseob Kim988f53c2019-09-16 15:59:01 +0900247 baseModuleName := m.BaseModuleName()
Aditya Choudhary26df39f2023-11-29 16:42:42 +0000248 srcs := android.PathsForModuleSrc(ctx, m.properties.Srcs)
249 for _, syspropFile := range srcs {
Inseob Kim988f53c2019-09-16 15:59:01 +0900250 if syspropFile.Ext() != ".sysprop" {
251 ctx.PropertyErrorf("srcs", "srcs contains non-sysprop file %q", syspropFile.String())
252 }
253 }
Colin Cross40213022023-12-13 15:19:49 -0800254 android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: srcs.Strings()})
Inseob Kim988f53c2019-09-16 15:59:01 +0900255
256 if ctx.Failed() {
257 return
258 }
259
Inseob Kimc9770d62021-01-15 18:04:20 +0900260 apiDirectoryPath := path.Join(ctx.ModuleDir(), "api")
261 currentApiFilePath := path.Join(apiDirectoryPath, baseModuleName+"-current.txt")
262 latestApiFilePath := path.Join(apiDirectoryPath, baseModuleName+"-latest.txt")
263 m.currentApiFile = android.ExistentPathForSource(ctx, currentApiFilePath)
264 m.latestApiFile = android.ExistentPathForSource(ctx, latestApiFilePath)
Inseob Kim42882742019-07-30 17:55:33 +0900265
266 // dump API rule
Colin Crossf1a035e2020-11-16 17:32:30 -0800267 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim42882742019-07-30 17:55:33 +0900268 m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt")
269 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800270 BuiltTool("sysprop_api_dump").
Inseob Kim42882742019-07-30 17:55:33 +0900271 Output(m.dumpedApiFile).
Aditya Choudhary26df39f2023-11-29 16:42:42 +0000272 Inputs(srcs)
Colin Crossf1a035e2020-11-16 17:32:30 -0800273 rule.Build(baseModuleName+"_api_dump", baseModuleName+" api dump")
Inseob Kim42882742019-07-30 17:55:33 +0900274
275 // check API rule
Colin Crossf1a035e2020-11-16 17:32:30 -0800276 rule = android.NewRuleBuilder(pctx, ctx)
Inseob Kim42882742019-07-30 17:55:33 +0900277
Inseob Kimc9770d62021-01-15 18:04:20 +0900278 // We allow that the API txt files don't exist, when the sysprop_library only contains internal
279 // properties. But we have to feed current api file and latest api file to the rule builder.
280 // Currently we can't get android.Path representing the null device, so we add any existing API
281 // txt files to implicits, and then directly feed string paths, rather than calling Input(Path)
282 // method.
283 var apiFileList android.Paths
284 currentApiArgument := os.DevNull
285 if m.currentApiFile.Valid() {
286 apiFileList = append(apiFileList, m.currentApiFile.Path())
287 currentApiArgument = m.currentApiFile.String()
288 }
289
290 latestApiArgument := os.DevNull
291 if m.latestApiFile.Valid() {
292 apiFileList = append(apiFileList, m.latestApiFile.Path())
293 latestApiArgument = m.latestApiFile.String()
294 }
295
Inseob Kim07def122020-11-23 14:43:02 +0900296 // 1. compares current.txt to api-dump.txt
297 // current.txt should be identical to api-dump.txt.
Inseob Kim42882742019-07-30 17:55:33 +0900298 msg := fmt.Sprintf(`\n******************************\n`+
299 `API of sysprop_library %s doesn't match with current.txt\n`+
300 `Please update current.txt by:\n`+
Inseob Kimc9770d62021-01-15 18:04:20 +0900301 `m %s-dump-api && mkdir -p %q && rm -rf %q && cp -f %q %q\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900302 `******************************\n`, baseModuleName, baseModuleName,
Inseob Kimc9770d62021-01-15 18:04:20 +0900303 apiDirectoryPath, currentApiFilePath, m.dumpedApiFile.String(), currentApiFilePath)
Inseob Kim42882742019-07-30 17:55:33 +0900304
305 rule.Command().
306 Text("( cmp").Flag("-s").
307 Input(m.dumpedApiFile).
Inseob Kimc9770d62021-01-15 18:04:20 +0900308 Text(currentApiArgument).
Inseob Kim42882742019-07-30 17:55:33 +0900309 Text("|| ( echo").Flag("-e").
310 Flag(`"` + msg + `"`).
311 Text("; exit 38) )")
312
Inseob Kim07def122020-11-23 14:43:02 +0900313 // 2. compares current.txt to latest.txt (frozen API)
314 // current.txt should be compatible with latest.txt
Inseob Kim42882742019-07-30 17:55:33 +0900315 msg = fmt.Sprintf(`\n******************************\n`+
316 `API of sysprop_library %s doesn't match with latest version\n`+
317 `Please fix the breakage and rebuild.\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900318 `******************************\n`, baseModuleName)
Inseob Kim42882742019-07-30 17:55:33 +0900319
320 rule.Command().
321 Text("( ").
Colin Crossf1a035e2020-11-16 17:32:30 -0800322 BuiltTool("sysprop_api_checker").
Inseob Kimc9770d62021-01-15 18:04:20 +0900323 Text(latestApiArgument).
324 Text(currentApiArgument).
Inseob Kim42882742019-07-30 17:55:33 +0900325 Text(" || ( echo").Flag("-e").
326 Flag(`"` + msg + `"`).
Inseob Kimc9770d62021-01-15 18:04:20 +0900327 Text("; exit 38) )").
328 Implicits(apiFileList)
Inseob Kim42882742019-07-30 17:55:33 +0900329
330 m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp")
331
332 rule.Command().
333 Text("touch").
334 Output(m.checkApiFileTimeStamp)
335
Colin Crossf1a035e2020-11-16 17:32:30 -0800336 rule.Build(baseModuleName+"_check_api", baseModuleName+" check api")
Inseob Kim42882742019-07-30 17:55:33 +0900337}
338
339func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
340 return android.AndroidMkData{
341 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
342 // sysprop_library module itself is defined as a FAKE module to perform API check.
343 // Actual implementation libraries are created on LoadHookMutator
Sasha Smundak5c4729d2022-12-01 10:49:23 -0800344 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)", " # sysprop.syspropLibrary")
345 fmt.Fprintln(w, "LOCAL_MODULE :=", m.Name())
Inseob Kim42882742019-07-30 17:55:33 +0900346 fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
347 fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
LaMont Jonesb5099382024-01-10 23:42:36 +0000348 // AconfigUpdateAndroidMkData may have added elements to Extra. Process them here.
349 for _, extra := range data.Extra {
350 extra(w, nil)
351 }
Inseob Kim42882742019-07-30 17:55:33 +0900352 fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
353 fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
354 fmt.Fprintf(w, "\ttouch $@\n\n")
Inseob Kim988f53c2019-09-16 15:59:01 +0900355 fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name)
356
357 // dump API rule
358 fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String())
Inseob Kim42882742019-07-30 17:55:33 +0900359
360 // check API rule
361 fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
Inseob Kim42882742019-07-30 17:55:33 +0900362 }}
363}
364
Jiyong Park45bf82e2020-12-15 22:29:02 +0900365var _ android.ApexModule = (*syspropLibrary)(nil)
366
367// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -0700368func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
369 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900370 return fmt.Errorf("sysprop_library is not supposed to be part of apex modules")
371}
372
Inseob Kim42882742019-07-30 17:55:33 +0900373// sysprop_library creates schematized APIs from sysprop description files (.sysprop).
374// Both Java and C++ modules can link against sysprop_library, and API stability check
375// against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh)
Trevor Radcliffed82e8f62022-06-08 16:16:31 +0000376// is performed. Note that the generated C++ module has its name prefixed with
377// `lib`, and it is this module that should be depended on from other C++
378// modules; i.e., if the sysprop_library module is named `foo`, C++ modules
379// should depend on `libfoo`.
Inseob Kimc0907f12019-02-08 21:00:45 +0900380func syspropLibraryFactory() android.Module {
381 m := &syspropLibrary{}
382
383 m.AddProperties(
Inseob Kim42882742019-07-30 17:55:33 +0900384 &m.properties,
Inseob Kimc0907f12019-02-08 21:00:45 +0900385 )
Inseob Kim42882742019-07-30 17:55:33 +0900386 android.InitAndroidModule(m)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100387 android.InitApexModule(m)
Inseob Kimc0907f12019-02-08 21:00:45 +0900388 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
Inseob Kimc0907f12019-02-08 21:00:45 +0900389 return m
390}
391
Inseob Kimac1e9862019-12-09 18:15:47 +0900392type ccLibraryProperties struct {
393 Name *string
394 Srcs []string
395 Soc_specific *bool
396 Device_specific *bool
397 Product_specific *bool
398 Sysprop struct {
399 Platform *bool
400 }
Inseob Kim89db15d2020-02-03 18:06:46 +0900401 Target struct {
402 Android struct {
403 Header_libs []string
404 Shared_libs []string
405 }
406 Host struct {
407 Static_libs []string
408 }
409 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900410 Required []string
411 Recovery *bool
412 Recovery_available *bool
413 Vendor_available *bool
Justin Yun63e9ec72020-10-29 16:49:43 +0900414 Product_available *bool
Inseob Kim9da1f812021-06-14 12:03:59 +0900415 Ramdisk_available *bool
Inseob Kim89db15d2020-02-03 18:06:46 +0900416 Host_supported *bool
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100417 Apex_available []string
Jooyung Han379660c2020-04-21 15:24:00 +0900418 Min_sdk_version *string
Steven Morelandc43a4ac2023-10-24 21:49:18 +0000419 Cflags []string
420 Ldflags []string
Inseob Kimac1e9862019-12-09 18:15:47 +0900421}
422
423type javaLibraryProperties struct {
Colin Cross75ce9ec2021-02-26 16:20:32 -0800424 Name *string
425 Srcs []string
426 Soc_specific *bool
427 Device_specific *bool
428 Product_specific *bool
429 Required []string
430 Sdk_version *string
431 Installable *bool
432 Libs []string
433 Stem *string
434 SyspropPublicStub string
Jiyong Park5e914b22021-03-08 10:09:52 +0900435 Apex_available []string
436 Min_sdk_version *string
Inseob Kimac1e9862019-12-09 18:15:47 +0900437}
438
Inseob Kimc0907f12019-02-08 21:00:45 +0900439func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Inseob Kim42882742019-07-30 17:55:33 +0900440 if len(m.properties.Srcs) == 0 {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900441 ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
442 }
443
Inseob Kimac1e9862019-12-09 18:15:47 +0900444 // ctx's Platform or Specific functions represent where this sysprop_library installed.
445 installedInSystem := ctx.Platform() || ctx.SystemExtSpecific()
446 installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific()
Inseob Kimfe612182020-10-20 16:29:55 +0900447 installedInProduct := ctx.ProductSpecific()
Inseob Kimac1e9862019-12-09 18:15:47 +0900448 isOwnerPlatform := false
Inseob Kim07def122020-11-23 14:43:02 +0900449 var javaSyspropStub string
Inseob Kimfe612182020-10-20 16:29:55 +0900450
Inseob Kim07def122020-11-23 14:43:02 +0900451 // javaSyspropStub contains stub libraries used by generated APIs, instead of framework stub.
452 // This is to make sysprop_library link against core_current.
Inseob Kimfe612182020-10-20 16:29:55 +0900453 if installedInVendorOrOdm {
Inseob Kim07def122020-11-23 14:43:02 +0900454 javaSyspropStub = "sysprop-library-stub-vendor"
Inseob Kimfe612182020-10-20 16:29:55 +0900455 } else if installedInProduct {
Inseob Kim07def122020-11-23 14:43:02 +0900456 javaSyspropStub = "sysprop-library-stub-product"
Inseob Kimfe612182020-10-20 16:29:55 +0900457 } else {
Inseob Kim07def122020-11-23 14:43:02 +0900458 javaSyspropStub = "sysprop-library-stub-platform"
Inseob Kimfe612182020-10-20 16:29:55 +0900459 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900460
Inseob Kimac1e9862019-12-09 18:15:47 +0900461 switch m.Owner() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900462 case "Platform":
463 // Every partition can access platform-defined properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900464 isOwnerPlatform = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900465 case "Vendor":
466 // System can't access vendor's properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900467 if installedInSystem {
Inseob Kimc0907f12019-02-08 21:00:45 +0900468 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
469 "System can't access sysprop_library owned by Vendor")
470 }
471 case "Odm":
472 // Only vendor can access Odm-defined properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900473 if !installedInVendorOrOdm {
Inseob Kimc0907f12019-02-08 21:00:45 +0900474 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
475 "Odm-defined properties should be accessed only in Vendor or Odm")
476 }
477 default:
478 ctx.PropertyErrorf("property_owner",
Inseob Kimac1e9862019-12-09 18:15:47 +0900479 "Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
Inseob Kimc0907f12019-02-08 21:00:45 +0900480 }
481
Inseob Kim07def122020-11-23 14:43:02 +0900482 // Generate a C++ implementation library.
483 // cc_library can receive *.sysprop files as their srcs, generating sources itself.
Inseob Kimac1e9862019-12-09 18:15:47 +0900484 ccProps := ccLibraryProperties{}
Inseob Kim07def122020-11-23 14:43:02 +0900485 ccProps.Name = proptools.StringPtr(m.CcImplementationModuleName())
Inseob Kim42882742019-07-30 17:55:33 +0900486 ccProps.Srcs = m.properties.Srcs
Inseob Kimac1e9862019-12-09 18:15:47 +0900487 ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific())
488 ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific())
489 ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific())
490 ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform)
Inseob Kim89db15d2020-02-03 18:06:46 +0900491 ccProps.Target.Android.Header_libs = []string{"libbase_headers"}
492 ccProps.Target.Android.Shared_libs = []string{"liblog"}
493 ccProps.Target.Host.Static_libs = []string{"libbase", "liblog"}
Inseob Kim42882742019-07-30 17:55:33 +0900494 ccProps.Recovery_available = m.properties.Recovery_available
495 ccProps.Vendor_available = m.properties.Vendor_available
Justin Yun63e9ec72020-10-29 16:49:43 +0900496 ccProps.Product_available = m.properties.Product_available
Inseob Kim9da1f812021-06-14 12:03:59 +0900497 ccProps.Ramdisk_available = m.properties.Ramdisk_available
Inseob Kim89db15d2020-02-03 18:06:46 +0900498 ccProps.Host_supported = m.properties.Host_supported
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100499 ccProps.Apex_available = m.ApexProperties.Apex_available
Jooyung Han379660c2020-04-21 15:24:00 +0900500 ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
Steven Morelandc43a4ac2023-10-24 21:49:18 +0000501 ccProps.Cflags = m.properties.Cpp.Cflags
502 ccProps.Ldflags = m.properties.Cpp.Ldflags
Colin Cross84dfc3d2019-09-25 11:33:01 -0700503 ctx.CreateModule(cc.LibraryFactory, &ccProps)
Inseob Kim42882742019-07-30 17:55:33 +0900504
Inseob Kim988f53c2019-09-16 15:59:01 +0900505 scope := "internal"
Inseob Kim988f53c2019-09-16 15:59:01 +0900506
Inseob Kimac1e9862019-12-09 18:15:47 +0900507 // We need to only use public version, if the partition where sysprop_library will be installed
508 // is different from owner.
Inseob Kimac1e9862019-12-09 18:15:47 +0900509 if ctx.ProductSpecific() {
Inseob Kim07def122020-11-23 14:43:02 +0900510 // Currently product partition can't own any sysprop_library. So product always uses public.
Inseob Kim988f53c2019-09-16 15:59:01 +0900511 scope = "public"
Inseob Kimac1e9862019-12-09 18:15:47 +0900512 } else if isOwnerPlatform && installedInVendorOrOdm {
513 // Vendor or Odm should use public version of Platform's sysprop_library.
Inseob Kim988f53c2019-09-16 15:59:01 +0900514 scope = "public"
515 }
516
Inseob Kim07def122020-11-23 14:43:02 +0900517 // Generate a Java implementation library.
518 // Contrast to C++, syspropJavaGenRule module will generate srcjar and the srcjar will be fed
519 // to Java implementation library.
Inseob Kimac1e9862019-12-09 18:15:47 +0900520 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
Colin Cross75ce9ec2021-02-26 16:20:32 -0800521 Srcs: m.properties.Srcs,
522 Scope: scope,
523 Name: proptools.StringPtr(m.javaGenModuleName()),
524 Check_api: proptools.StringPtr(ctx.ModuleName()),
Inseob Kimac1e9862019-12-09 18:15:47 +0900525 })
526
527 // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API
528 // and allow any modules (even from different partition) to link against the sysprop_library.
529 // To do that, we create a public stub and expose it to modules with sdk_version: system_*.
Colin Cross75ce9ec2021-02-26 16:20:32 -0800530 var publicStub string
Inseob Kimac1e9862019-12-09 18:15:47 +0900531 if isOwnerPlatform && installedInSystem {
Colin Cross75ce9ec2021-02-26 16:20:32 -0800532 publicStub = m.javaPublicStubName()
533 }
534
535 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
536 Name: proptools.StringPtr(m.BaseModuleName()),
537 Srcs: []string{":" + m.javaGenModuleName()},
538 Soc_specific: proptools.BoolPtr(ctx.SocSpecific()),
539 Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()),
540 Product_specific: proptools.BoolPtr(ctx.ProductSpecific()),
541 Installable: m.properties.Installable,
542 Sdk_version: proptools.StringPtr("core_current"),
543 Libs: []string{javaSyspropStub},
544 SyspropPublicStub: publicStub,
Jiyong Park5e914b22021-03-08 10:09:52 +0900545 Apex_available: m.ApexProperties.Apex_available,
546 Min_sdk_version: m.properties.Java.Min_sdk_version,
Colin Cross75ce9ec2021-02-26 16:20:32 -0800547 })
548
549 if publicStub != "" {
Inseob Kimac1e9862019-12-09 18:15:47 +0900550 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
Colin Cross75ce9ec2021-02-26 16:20:32 -0800551 Srcs: m.properties.Srcs,
552 Scope: "public",
553 Name: proptools.StringPtr(m.javaGenPublicStubName()),
554 Check_api: proptools.StringPtr(ctx.ModuleName()),
Inseob Kimac1e9862019-12-09 18:15:47 +0900555 })
556
557 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
Colin Cross75ce9ec2021-02-26 16:20:32 -0800558 Name: proptools.StringPtr(publicStub),
Inseob Kimac1e9862019-12-09 18:15:47 +0900559 Srcs: []string{":" + m.javaGenPublicStubName()},
560 Installable: proptools.BoolPtr(false),
561 Sdk_version: proptools.StringPtr("core_current"),
Inseob Kim07def122020-11-23 14:43:02 +0900562 Libs: []string{javaSyspropStub},
Inseob Kimac1e9862019-12-09 18:15:47 +0900563 Stem: proptools.StringPtr(m.BaseModuleName()),
564 })
Inseob Kim988f53c2019-09-16 15:59:01 +0900565 }
Inseob Kim628d7ef2020-03-21 03:38:32 +0900566
Inseob Kim07def122020-11-23 14:43:02 +0900567 // syspropLibraries will be used by property_contexts to check types.
568 // Record absolute paths of sysprop_library to prevent soong_namespace problem.
Inseob Kim69cf09e2020-05-04 19:28:25 +0900569 if m.ExportedToMake() {
570 syspropLibrariesLock.Lock()
571 defer syspropLibrariesLock.Unlock()
Inseob Kim628d7ef2020-03-21 03:38:32 +0900572
Inseob Kim69cf09e2020-05-04 19:28:25 +0900573 libraries := syspropLibraries(ctx.Config())
574 *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName())
575 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900576}