blob: 38306adfc61bda5be98417ca54910a7826dc4390 [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"
22 "path"
Inseob Kim628d7ef2020-03-21 03:38:32 +090023 "sync"
Colin Crossf8b860a2019-04-16 14:43:28 -070024
Inseob Kimc0907f12019-02-08 21:00:45 +090025 "github.com/google/blueprint"
26 "github.com/google/blueprint/proptools"
Inseob Kim42882742019-07-30 17:55:33 +090027
28 "android/soong/android"
29 "android/soong/cc"
30 "android/soong/java"
Inseob Kimc0907f12019-02-08 21:00:45 +090031)
32
33type dependencyTag struct {
34 blueprint.BaseDependencyTag
35 name string
36}
37
Inseob Kim988f53c2019-09-16 15:59:01 +090038type syspropGenProperties struct {
39 Srcs []string `android:"path"`
40 Scope string
Inseob Kimac1e9862019-12-09 18:15:47 +090041 Name *string
Inseob Kim988f53c2019-09-16 15:59:01 +090042}
43
44type syspropJavaGenRule struct {
45 android.ModuleBase
46
47 properties syspropGenProperties
48
49 genSrcjars android.Paths
50}
51
52var _ android.OutputFileProducer = (*syspropJavaGenRule)(nil)
53
54var (
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
67func 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 Kim07def122020-11-23 14:43:02 +090076// 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 Kim988f53c2019-09-16 15:59:01 +090078func (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
105func (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
114func syspropJavaGenFactory() android.Module {
115 g := &syspropJavaGenRule{}
116 g.AddProperties(&g.properties)
117 android.InitAndroidModule(g)
118 return g
119}
120
Inseob Kimc0907f12019-02-08 21:00:45 +0900121type syspropLibrary struct {
Inseob Kim42882742019-07-30 17:55:33 +0900122 android.ModuleBase
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100123 android.ApexModuleBase
Inseob Kimc0907f12019-02-08 21:00:45 +0900124
Inseob Kim42882742019-07-30 17:55:33 +0900125 properties syspropLibraryProperties
126
127 checkApiFileTimeStamp android.WritablePath
128 latestApiFile android.Path
129 currentApiFile android.Path
130 dumpedApiFile android.WritablePath
Inseob Kimc0907f12019-02-08 21:00:45 +0900131}
132
133type syspropLibraryProperties struct {
134 // Determine who owns this sysprop library. Possible values are
135 // "Platform", "Vendor", or "Odm"
136 Property_owner string
Inseob Kimf63c2fb2019-03-05 14:22:30 +0900137
138 // list of package names that will be documented and publicized as API
139 Api_packages []string
Inseob Kimc0907f12019-02-08 21:00:45 +0900140
Inseob Kim42882742019-07-30 17:55:33 +0900141 // 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 Park854a9442019-02-26 10:27:13 +0900145 Recovery_available *bool
Inseob Kim42882742019-07-30 17:55:33 +0900146
147 // Make this module available when building for vendor
148 Vendor_available *bool
149
Justin Yun63e9ec72020-10-29 16:49:43 +0900150 // Make this module available when building for product
151 Product_available *bool
152
Inseob Kim42882742019-07-30 17:55:33 +0900153 // list of .sysprop files which defines the properties.
154 Srcs []string `android:"path"`
Inseob Kimac1e9862019-12-09 18:15:47 +0900155
Inseob Kim89db15d2020-02-03 18:06:46 +0900156 // If set to true, build a variant of the module for the host. Defaults to false.
157 Host_supported *bool
158
Inseob Kimac1e9862019-12-09 18:15:47 +0900159 // Whether public stub exists or not.
160 Public_stub *bool `blueprint:"mutated"`
Jooyung Han379660c2020-04-21 15:24:00 +0900161
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 Kimc0907f12019-02-08 21:00:45 +0900167}
168
169var (
Inseob Kim42882742019-07-30 17:55:33 +0900170 pctx = android.NewPackageContext("android/soong/sysprop")
Inseob Kimc0907f12019-02-08 21:00:45 +0900171 syspropCcTag = dependencyTag{name: "syspropCc"}
Inseob Kim628d7ef2020-03-21 03:38:32 +0900172
173 syspropLibrariesKey = android.NewOnceKey("syspropLibraries")
174 syspropLibrariesLock sync.Mutex
Inseob Kimc0907f12019-02-08 21:00:45 +0900175)
176
Inseob Kim07def122020-11-23 14:43:02 +0900177// List of sysprop_library used by property_contexts to perform type check.
Inseob Kim628d7ef2020-03-21 03:38:32 +0900178func syspropLibraries(config android.Config) *[]string {
179 return config.Once(syspropLibrariesKey, func() interface{} {
180 return &[]string{}
181 }).(*[]string)
182}
183
184func SyspropLibraries(config android.Config) []string {
185 return append([]string{}, *syspropLibraries(config)...)
186}
187
Inseob Kimc0907f12019-02-08 21:00:45 +0900188func init() {
189 android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
190}
191
Inseob Kim42882742019-07-30 17:55:33 +0900192func (m *syspropLibrary) Name() string {
193 return m.BaseModuleName() + "_sysprop_library"
Inseob Kimc0907f12019-02-08 21:00:45 +0900194}
195
Inseob Kimac1e9862019-12-09 18:15:47 +0900196func (m *syspropLibrary) Owner() string {
197 return m.properties.Property_owner
198}
199
Inseob Kim07def122020-11-23 14:43:02 +0900200func (m *syspropLibrary) CcImplementationModuleName() string {
Inseob Kim42882742019-07-30 17:55:33 +0900201 return "lib" + m.BaseModuleName()
202}
203
Inseob Kimac1e9862019-12-09 18:15:47 +0900204func (m *syspropLibrary) JavaPublicStubName() string {
205 if proptools.Bool(m.properties.Public_stub) {
206 return m.BaseModuleName() + "_public"
207 }
208 return ""
209}
210
Inseob Kim988f53c2019-09-16 15:59:01 +0900211func (m *syspropLibrary) javaGenModuleName() string {
212 return m.BaseModuleName() + "_java_gen"
213}
214
Inseob Kimac1e9862019-12-09 18:15:47 +0900215func (m *syspropLibrary) javaGenPublicStubName() string {
216 return m.BaseModuleName() + "_java_gen_public"
217}
218
Inseob Kim42882742019-07-30 17:55:33 +0900219func (m *syspropLibrary) BaseModuleName() string {
220 return m.ModuleBase.Name()
221}
222
Inseob Kimac1e9862019-12-09 18:15:47 +0900223func (m *syspropLibrary) HasPublicStub() bool {
224 return proptools.Bool(m.properties.Public_stub)
225}
226
Inseob Kim628d7ef2020-03-21 03:38:32 +0900227func (m *syspropLibrary) CurrentSyspropApiFile() android.Path {
228 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
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 Kim42882742019-07-30 17:55:33 +0900248
249 // dump API rule
Colin Crossf1a035e2020-11-16 17:32:30 -0800250 rule := android.NewRuleBuilder(pctx, ctx)
Inseob Kim42882742019-07-30 17:55:33 +0900251 m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt")
252 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800253 BuiltTool("sysprop_api_dump").
Inseob Kim42882742019-07-30 17:55:33 +0900254 Output(m.dumpedApiFile).
255 Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
Colin Crossf1a035e2020-11-16 17:32:30 -0800256 rule.Build(baseModuleName+"_api_dump", baseModuleName+" api dump")
Inseob Kim42882742019-07-30 17:55:33 +0900257
258 // check API rule
Colin Crossf1a035e2020-11-16 17:32:30 -0800259 rule = android.NewRuleBuilder(pctx, ctx)
Inseob Kim42882742019-07-30 17:55:33 +0900260
Inseob Kim07def122020-11-23 14:43:02 +0900261 // 1. compares current.txt to api-dump.txt
262 // current.txt should be identical to api-dump.txt.
Inseob Kim42882742019-07-30 17:55:33 +0900263 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 Kim988f53c2019-09-16 15:59:01 +0900266 `m %s-dump-api && rm -rf %q && cp -f %q %q\n`+
267 `******************************\n`, baseModuleName, baseModuleName,
Inseob Kim42882742019-07-30 17:55:33 +0900268 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 Kim07def122020-11-23 14:43:02 +0900278 // 2. compares current.txt to latest.txt (frozen API)
279 // current.txt should be compatible with latest.txt
Inseob Kim42882742019-07-30 17:55:33 +0900280 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 Kim988f53c2019-09-16 15:59:01 +0900283 `******************************\n`, baseModuleName)
Inseob Kim42882742019-07-30 17:55:33 +0900284
285 rule.Command().
286 Text("( ").
Colin Crossf1a035e2020-11-16 17:32:30 -0800287 BuiltTool("sysprop_api_checker").
Inseob Kim42882742019-07-30 17:55:33 +0900288 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
Colin Crossf1a035e2020-11-16 17:32:30 -0800300 rule.Build(baseModuleName+"_check_api", baseModuleName+" check api")
Inseob Kim42882742019-07-30 17:55:33 +0900301}
302
303func (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())
Bob Badourb4999222021-01-07 03:34:31 +0000310 data.Entries.WriteLicenseVariables(w)
Inseob Kim42882742019-07-30 17:55:33 +0900311 fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
312 fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
313 fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
314 fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
315 fmt.Fprintf(w, "\ttouch $@\n\n")
Inseob Kim988f53c2019-09-16 15:59:01 +0900316 fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name)
317
318 // dump API rule
319 fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String())
Inseob Kim42882742019-07-30 17:55:33 +0900320
321 // check API rule
322 fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
Inseob Kim42882742019-07-30 17:55:33 +0900323 }}
324}
325
Jiyong Park45bf82e2020-12-15 22:29:02 +0900326var _ android.ApexModule = (*syspropLibrary)(nil)
327
328// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -0700329func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
330 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900331 return fmt.Errorf("sysprop_library is not supposed to be part of apex modules")
332}
333
Inseob Kim42882742019-07-30 17:55:33 +0900334// sysprop_library creates schematized APIs from sysprop description files (.sysprop).
335// Both Java and C++ modules can link against sysprop_library, and API stability check
336// against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh)
337// is performed.
Inseob Kimc0907f12019-02-08 21:00:45 +0900338func syspropLibraryFactory() android.Module {
339 m := &syspropLibrary{}
340
341 m.AddProperties(
Inseob Kim42882742019-07-30 17:55:33 +0900342 &m.properties,
Inseob Kimc0907f12019-02-08 21:00:45 +0900343 )
Inseob Kim42882742019-07-30 17:55:33 +0900344 android.InitAndroidModule(m)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100345 android.InitApexModule(m)
Inseob Kimc0907f12019-02-08 21:00:45 +0900346 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
Inseob Kimc0907f12019-02-08 21:00:45 +0900347 return m
348}
349
Inseob Kimac1e9862019-12-09 18:15:47 +0900350type ccLibraryProperties struct {
351 Name *string
352 Srcs []string
353 Soc_specific *bool
354 Device_specific *bool
355 Product_specific *bool
356 Sysprop struct {
357 Platform *bool
358 }
Inseob Kim89db15d2020-02-03 18:06:46 +0900359 Target struct {
360 Android struct {
361 Header_libs []string
362 Shared_libs []string
363 }
364 Host struct {
365 Static_libs []string
366 }
367 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900368 Required []string
369 Recovery *bool
370 Recovery_available *bool
371 Vendor_available *bool
Justin Yun63e9ec72020-10-29 16:49:43 +0900372 Product_available *bool
Inseob Kim89db15d2020-02-03 18:06:46 +0900373 Host_supported *bool
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100374 Apex_available []string
Jooyung Han379660c2020-04-21 15:24:00 +0900375 Min_sdk_version *string
Inseob Kimac1e9862019-12-09 18:15:47 +0900376}
377
378type javaLibraryProperties struct {
379 Name *string
380 Srcs []string
381 Soc_specific *bool
382 Device_specific *bool
383 Product_specific *bool
384 Required []string
385 Sdk_version *string
386 Installable *bool
387 Libs []string
388 Stem *string
389}
390
Inseob Kimc0907f12019-02-08 21:00:45 +0900391func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Inseob Kim42882742019-07-30 17:55:33 +0900392 if len(m.properties.Srcs) == 0 {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900393 ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
394 }
395
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800396 missingApi := false
Inseob Kim42882742019-07-30 17:55:33 +0900397
398 for _, txt := range []string{"-current.txt", "-latest.txt"} {
399 path := path.Join(ctx.ModuleDir(), "api", m.BaseModuleName()+txt)
400 file := android.ExistentPathForSource(ctx, path)
401 if !file.Valid() {
402 ctx.ModuleErrorf("API file %#v doesn't exist", path)
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800403 missingApi = true
Inseob Kim42882742019-07-30 17:55:33 +0900404 }
405 }
406
Jaewoong Jung18aefc12020-12-21 09:11:10 -0800407 if missingApi {
Inseob Kim42882742019-07-30 17:55:33 +0900408 script := "build/soong/scripts/gen-sysprop-api-files.sh"
409 p := android.ExistentPathForSource(ctx, script)
410
411 if !p.Valid() {
412 panic(fmt.Sprintf("script file %s doesn't exist", script))
413 }
414
415 ctx.ModuleErrorf("One or more api files are missing. "+
416 "You can create them by:\n"+
417 "%s %q %q", script, ctx.ModuleDir(), m.BaseModuleName())
418 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900419 }
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{
Inseob Kim988f53c2019-09-16 15:59:01 +0900495 Srcs: m.properties.Srcs,
496 Scope: scope,
497 Name: proptools.StringPtr(m.javaGenModuleName()),
Inseob Kimac1e9862019-12-09 18:15:47 +0900498 })
499
500 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
501 Name: proptools.StringPtr(m.BaseModuleName()),
502 Srcs: []string{":" + m.javaGenModuleName()},
503 Soc_specific: proptools.BoolPtr(ctx.SocSpecific()),
504 Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()),
505 Product_specific: proptools.BoolPtr(ctx.ProductSpecific()),
506 Installable: m.properties.Installable,
507 Sdk_version: proptools.StringPtr("core_current"),
Inseob Kim07def122020-11-23 14:43:02 +0900508 Libs: []string{javaSyspropStub},
Inseob Kimac1e9862019-12-09 18:15:47 +0900509 })
510
511 // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API
512 // and allow any modules (even from different partition) to link against the sysprop_library.
513 // To do that, we create a public stub and expose it to modules with sdk_version: system_*.
514 if isOwnerPlatform && installedInSystem {
515 m.properties.Public_stub = proptools.BoolPtr(true)
516 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
517 Srcs: m.properties.Srcs,
518 Scope: "public",
519 Name: proptools.StringPtr(m.javaGenPublicStubName()),
520 })
521
522 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
523 Name: proptools.StringPtr(m.JavaPublicStubName()),
524 Srcs: []string{":" + m.javaGenPublicStubName()},
525 Installable: proptools.BoolPtr(false),
526 Sdk_version: proptools.StringPtr("core_current"),
Inseob Kim07def122020-11-23 14:43:02 +0900527 Libs: []string{javaSyspropStub},
Inseob Kimac1e9862019-12-09 18:15:47 +0900528 Stem: proptools.StringPtr(m.BaseModuleName()),
529 })
Inseob Kim988f53c2019-09-16 15:59:01 +0900530 }
Inseob Kim628d7ef2020-03-21 03:38:32 +0900531
Inseob Kim07def122020-11-23 14:43:02 +0900532 // syspropLibraries will be used by property_contexts to check types.
533 // Record absolute paths of sysprop_library to prevent soong_namespace problem.
Inseob Kim69cf09e2020-05-04 19:28:25 +0900534 if m.ExportedToMake() {
535 syspropLibrariesLock.Lock()
536 defer syspropLibrariesLock.Unlock()
Inseob Kim628d7ef2020-03-21 03:38:32 +0900537
Inseob Kim69cf09e2020-05-04 19:28:25 +0900538 libraries := syspropLibraries(ctx.Config())
539 *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName())
540 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900541}
Inseob Kim988f53c2019-09-16 15:59:01 +0900542
Inseob Kim07def122020-11-23 14:43:02 +0900543// syspropDepsMutator adds dependencies from java implementation library to sysprop library.
544// java implementation library then depends on check API rule of sysprop library.
Inseob Kim988f53c2019-09-16 15:59:01 +0900545func syspropDepsMutator(ctx android.BottomUpMutatorContext) {
546 if m, ok := ctx.Module().(*syspropLibrary); ok {
547 ctx.AddReverseDependency(m, nil, m.javaGenModuleName())
Inseob Kimac1e9862019-12-09 18:15:47 +0900548
549 if proptools.Bool(m.properties.Public_stub) {
550 ctx.AddReverseDependency(m, nil, m.javaGenPublicStubName())
551 }
Inseob Kim988f53c2019-09-16 15:59:01 +0900552 }
553}