blob: 480f9b7975a0b60a931abb87c2e41f84b9cd9100 [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
15package sysprop
16
17import (
Inseob Kim42882742019-07-30 17:55:33 +090018 "fmt"
19 "io"
20 "path"
Inseob Kim628d7ef2020-03-21 03:38:32 +090021 "sync"
Colin Crossf8b860a2019-04-16 14:43:28 -070022
Inseob Kimc0907f12019-02-08 21:00:45 +090023 "github.com/google/blueprint"
24 "github.com/google/blueprint/proptools"
Inseob Kim42882742019-07-30 17:55:33 +090025
26 "android/soong/android"
27 "android/soong/cc"
28 "android/soong/java"
Inseob Kimc0907f12019-02-08 21:00:45 +090029)
30
31type dependencyTag struct {
32 blueprint.BaseDependencyTag
33 name string
34}
35
Inseob Kim988f53c2019-09-16 15:59:01 +090036type syspropGenProperties struct {
37 Srcs []string `android:"path"`
38 Scope string
Inseob Kimac1e9862019-12-09 18:15:47 +090039 Name *string
Inseob Kim988f53c2019-09-16 15:59:01 +090040}
41
42type syspropJavaGenRule struct {
43 android.ModuleBase
44
45 properties syspropGenProperties
46
47 genSrcjars android.Paths
48}
49
50var _ android.OutputFileProducer = (*syspropJavaGenRule)(nil)
51
52var (
53 syspropJava = pctx.AndroidStaticRule("syspropJava",
54 blueprint.RuleParams{
55 Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
56 `$syspropJavaCmd --scope $scope --java-output-dir $out.tmp $in && ` +
57 `$soongZipCmd -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
58 CommandDeps: []string{
59 "$syspropJavaCmd",
60 "$soongZipCmd",
61 },
62 }, "scope")
63)
64
65func init() {
66 pctx.HostBinToolVariable("soongZipCmd", "soong_zip")
67 pctx.HostBinToolVariable("syspropJavaCmd", "sysprop_java")
68
69 android.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
70 ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
71 })
72}
73
74func (g *syspropJavaGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
75 var checkApiFileTimeStamp android.WritablePath
76
77 ctx.VisitDirectDeps(func(dep android.Module) {
78 if m, ok := dep.(*syspropLibrary); ok {
79 checkApiFileTimeStamp = m.checkApiFileTimeStamp
80 }
81 })
82
83 for _, syspropFile := range android.PathsForModuleSrc(ctx, g.properties.Srcs) {
84 srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
85
86 ctx.Build(pctx, android.BuildParams{
87 Rule: syspropJava,
88 Description: "sysprop_java " + syspropFile.Rel(),
89 Output: srcJarFile,
90 Input: syspropFile,
91 Implicit: checkApiFileTimeStamp,
92 Args: map[string]string{
93 "scope": g.properties.Scope,
94 },
95 })
96
97 g.genSrcjars = append(g.genSrcjars, srcJarFile)
98 }
99}
100
101func (g *syspropJavaGenRule) OutputFiles(tag string) (android.Paths, error) {
102 switch tag {
103 case "":
104 return g.genSrcjars, nil
105 default:
106 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
107 }
108}
109
110func syspropJavaGenFactory() android.Module {
111 g := &syspropJavaGenRule{}
112 g.AddProperties(&g.properties)
113 android.InitAndroidModule(g)
114 return g
115}
116
Inseob Kimc0907f12019-02-08 21:00:45 +0900117type syspropLibrary struct {
Inseob Kim42882742019-07-30 17:55:33 +0900118 android.ModuleBase
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100119 android.ApexModuleBase
Inseob Kimc0907f12019-02-08 21:00:45 +0900120
Inseob Kim42882742019-07-30 17:55:33 +0900121 properties syspropLibraryProperties
122
123 checkApiFileTimeStamp android.WritablePath
124 latestApiFile android.Path
125 currentApiFile android.Path
126 dumpedApiFile android.WritablePath
Inseob Kimc0907f12019-02-08 21:00:45 +0900127}
128
129type syspropLibraryProperties struct {
130 // Determine who owns this sysprop library. Possible values are
131 // "Platform", "Vendor", or "Odm"
132 Property_owner string
Inseob Kimf63c2fb2019-03-05 14:22:30 +0900133
134 // list of package names that will be documented and publicized as API
135 Api_packages []string
Inseob Kimc0907f12019-02-08 21:00:45 +0900136
Inseob Kim42882742019-07-30 17:55:33 +0900137 // If set to true, allow this module to be dexed and installed on devices.
138 Installable *bool
139
140 // Make this module available when building for recovery
Jiyong Park854a9442019-02-26 10:27:13 +0900141 Recovery_available *bool
Inseob Kim42882742019-07-30 17:55:33 +0900142
143 // Make this module available when building for vendor
144 Vendor_available *bool
145
146 // list of .sysprop files which defines the properties.
147 Srcs []string `android:"path"`
Inseob Kimac1e9862019-12-09 18:15:47 +0900148
Inseob Kim89db15d2020-02-03 18:06:46 +0900149 // If set to true, build a variant of the module for the host. Defaults to false.
150 Host_supported *bool
151
Inseob Kimac1e9862019-12-09 18:15:47 +0900152 // Whether public stub exists or not.
153 Public_stub *bool `blueprint:"mutated"`
Jooyung Han379660c2020-04-21 15:24:00 +0900154
155 Cpp struct {
156 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
157 // Forwarded to cc_library.min_sdk_version
158 Min_sdk_version *string
159 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900160}
161
162var (
Inseob Kim42882742019-07-30 17:55:33 +0900163 pctx = android.NewPackageContext("android/soong/sysprop")
Inseob Kimc0907f12019-02-08 21:00:45 +0900164 syspropCcTag = dependencyTag{name: "syspropCc"}
Inseob Kim628d7ef2020-03-21 03:38:32 +0900165
166 syspropLibrariesKey = android.NewOnceKey("syspropLibraries")
167 syspropLibrariesLock sync.Mutex
Inseob Kimc0907f12019-02-08 21:00:45 +0900168)
169
Inseob Kim628d7ef2020-03-21 03:38:32 +0900170func syspropLibraries(config android.Config) *[]string {
171 return config.Once(syspropLibrariesKey, func() interface{} {
172 return &[]string{}
173 }).(*[]string)
174}
175
176func SyspropLibraries(config android.Config) []string {
177 return append([]string{}, *syspropLibraries(config)...)
178}
179
Inseob Kimc0907f12019-02-08 21:00:45 +0900180func init() {
181 android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
182}
183
Inseob Kim42882742019-07-30 17:55:33 +0900184func (m *syspropLibrary) Name() string {
185 return m.BaseModuleName() + "_sysprop_library"
Inseob Kimc0907f12019-02-08 21:00:45 +0900186}
187
Inseob Kimac1e9862019-12-09 18:15:47 +0900188func (m *syspropLibrary) Owner() string {
189 return m.properties.Property_owner
190}
191
Inseob Kim42882742019-07-30 17:55:33 +0900192func (m *syspropLibrary) CcModuleName() string {
193 return "lib" + m.BaseModuleName()
194}
195
Inseob Kimac1e9862019-12-09 18:15:47 +0900196func (m *syspropLibrary) JavaPublicStubName() string {
197 if proptools.Bool(m.properties.Public_stub) {
198 return m.BaseModuleName() + "_public"
199 }
200 return ""
201}
202
Inseob Kim988f53c2019-09-16 15:59:01 +0900203func (m *syspropLibrary) javaGenModuleName() string {
204 return m.BaseModuleName() + "_java_gen"
205}
206
Inseob Kimac1e9862019-12-09 18:15:47 +0900207func (m *syspropLibrary) javaGenPublicStubName() string {
208 return m.BaseModuleName() + "_java_gen_public"
209}
210
Inseob Kim42882742019-07-30 17:55:33 +0900211func (m *syspropLibrary) BaseModuleName() string {
212 return m.ModuleBase.Name()
213}
214
Inseob Kimac1e9862019-12-09 18:15:47 +0900215func (m *syspropLibrary) HasPublicStub() bool {
216 return proptools.Bool(m.properties.Public_stub)
217}
218
Inseob Kim628d7ef2020-03-21 03:38:32 +0900219func (m *syspropLibrary) CurrentSyspropApiFile() android.Path {
220 return m.currentApiFile
221}
222
Inseob Kim42882742019-07-30 17:55:33 +0900223func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Inseob Kim988f53c2019-09-16 15:59:01 +0900224 baseModuleName := m.BaseModuleName()
225
226 for _, syspropFile := range android.PathsForModuleSrc(ctx, m.properties.Srcs) {
227 if syspropFile.Ext() != ".sysprop" {
228 ctx.PropertyErrorf("srcs", "srcs contains non-sysprop file %q", syspropFile.String())
229 }
230 }
231
232 if ctx.Failed() {
233 return
234 }
235
236 m.currentApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-current.txt")
237 m.latestApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-latest.txt")
Inseob Kim42882742019-07-30 17:55:33 +0900238
239 // dump API rule
240 rule := android.NewRuleBuilder()
241 m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt")
242 rule.Command().
243 BuiltTool(ctx, "sysprop_api_dump").
244 Output(m.dumpedApiFile).
245 Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
Inseob Kim988f53c2019-09-16 15:59:01 +0900246 rule.Build(pctx, ctx, baseModuleName+"_api_dump", baseModuleName+" api dump")
Inseob Kim42882742019-07-30 17:55:33 +0900247
248 // check API rule
249 rule = android.NewRuleBuilder()
250
251 // 1. current.txt <-> api_dump.txt
252 msg := fmt.Sprintf(`\n******************************\n`+
253 `API of sysprop_library %s doesn't match with current.txt\n`+
254 `Please update current.txt by:\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900255 `m %s-dump-api && rm -rf %q && cp -f %q %q\n`+
256 `******************************\n`, baseModuleName, baseModuleName,
Inseob Kim42882742019-07-30 17:55:33 +0900257 m.currentApiFile.String(), m.dumpedApiFile.String(), m.currentApiFile.String())
258
259 rule.Command().
260 Text("( cmp").Flag("-s").
261 Input(m.dumpedApiFile).
262 Input(m.currentApiFile).
263 Text("|| ( echo").Flag("-e").
264 Flag(`"` + msg + `"`).
265 Text("; exit 38) )")
266
267 // 2. current.txt <-> latest.txt
268 msg = fmt.Sprintf(`\n******************************\n`+
269 `API of sysprop_library %s doesn't match with latest version\n`+
270 `Please fix the breakage and rebuild.\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900271 `******************************\n`, baseModuleName)
Inseob Kim42882742019-07-30 17:55:33 +0900272
273 rule.Command().
274 Text("( ").
275 BuiltTool(ctx, "sysprop_api_checker").
276 Input(m.latestApiFile).
277 Input(m.currentApiFile).
278 Text(" || ( echo").Flag("-e").
279 Flag(`"` + msg + `"`).
280 Text("; exit 38) )")
281
282 m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp")
283
284 rule.Command().
285 Text("touch").
286 Output(m.checkApiFileTimeStamp)
287
Inseob Kim988f53c2019-09-16 15:59:01 +0900288 rule.Build(pctx, ctx, baseModuleName+"_check_api", baseModuleName+" check api")
Inseob Kim42882742019-07-30 17:55:33 +0900289}
290
291func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
292 return android.AndroidMkData{
293 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
294 // sysprop_library module itself is defined as a FAKE module to perform API check.
295 // Actual implementation libraries are created on LoadHookMutator
296 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
297 fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name())
298 fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
299 fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
300 fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
301 fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
302 fmt.Fprintf(w, "\ttouch $@\n\n")
Inseob Kim988f53c2019-09-16 15:59:01 +0900303 fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name)
304
305 // dump API rule
306 fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String())
Inseob Kim42882742019-07-30 17:55:33 +0900307
308 // check API rule
309 fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
Inseob Kim42882742019-07-30 17:55:33 +0900310 }}
311}
312
Dan Albertc8060532020-07-22 22:32:17 -0700313func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
314 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900315 return fmt.Errorf("sysprop_library is not supposed to be part of apex modules")
316}
317
Inseob Kim42882742019-07-30 17:55:33 +0900318// sysprop_library creates schematized APIs from sysprop description files (.sysprop).
319// Both Java and C++ modules can link against sysprop_library, and API stability check
320// against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh)
321// is performed.
Inseob Kimc0907f12019-02-08 21:00:45 +0900322func syspropLibraryFactory() android.Module {
323 m := &syspropLibrary{}
324
325 m.AddProperties(
Inseob Kim42882742019-07-30 17:55:33 +0900326 &m.properties,
Inseob Kimc0907f12019-02-08 21:00:45 +0900327 )
Inseob Kim42882742019-07-30 17:55:33 +0900328 android.InitAndroidModule(m)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100329 android.InitApexModule(m)
Inseob Kimc0907f12019-02-08 21:00:45 +0900330 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
Inseob Kimc0907f12019-02-08 21:00:45 +0900331 return m
332}
333
Inseob Kimac1e9862019-12-09 18:15:47 +0900334type ccLibraryProperties struct {
335 Name *string
336 Srcs []string
337 Soc_specific *bool
338 Device_specific *bool
339 Product_specific *bool
340 Sysprop struct {
341 Platform *bool
342 }
Inseob Kim89db15d2020-02-03 18:06:46 +0900343 Target struct {
344 Android struct {
345 Header_libs []string
346 Shared_libs []string
347 }
348 Host struct {
349 Static_libs []string
350 }
351 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900352 Required []string
353 Recovery *bool
354 Recovery_available *bool
355 Vendor_available *bool
Inseob Kim89db15d2020-02-03 18:06:46 +0900356 Host_supported *bool
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100357 Apex_available []string
Jooyung Han379660c2020-04-21 15:24:00 +0900358 Min_sdk_version *string
Inseob Kimac1e9862019-12-09 18:15:47 +0900359}
360
361type javaLibraryProperties struct {
362 Name *string
363 Srcs []string
364 Soc_specific *bool
365 Device_specific *bool
366 Product_specific *bool
367 Required []string
368 Sdk_version *string
369 Installable *bool
370 Libs []string
371 Stem *string
372}
373
Inseob Kimc0907f12019-02-08 21:00:45 +0900374func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Inseob Kim42882742019-07-30 17:55:33 +0900375 if len(m.properties.Srcs) == 0 {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900376 ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
377 }
378
Inseob Kim42882742019-07-30 17:55:33 +0900379 missing_api := false
380
381 for _, txt := range []string{"-current.txt", "-latest.txt"} {
382 path := path.Join(ctx.ModuleDir(), "api", m.BaseModuleName()+txt)
383 file := android.ExistentPathForSource(ctx, path)
384 if !file.Valid() {
385 ctx.ModuleErrorf("API file %#v doesn't exist", path)
386 missing_api = true
387 }
388 }
389
390 if missing_api {
391 script := "build/soong/scripts/gen-sysprop-api-files.sh"
392 p := android.ExistentPathForSource(ctx, script)
393
394 if !p.Valid() {
395 panic(fmt.Sprintf("script file %s doesn't exist", script))
396 }
397
398 ctx.ModuleErrorf("One or more api files are missing. "+
399 "You can create them by:\n"+
400 "%s %q %q", script, ctx.ModuleDir(), m.BaseModuleName())
401 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900402 }
403
Inseob Kimac1e9862019-12-09 18:15:47 +0900404 // ctx's Platform or Specific functions represent where this sysprop_library installed.
405 installedInSystem := ctx.Platform() || ctx.SystemExtSpecific()
406 installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific()
407 isOwnerPlatform := false
Inseob Kim42882742019-07-30 17:55:33 +0900408 stub := "sysprop-library-stub-"
Inseob Kimc0907f12019-02-08 21:00:45 +0900409
Inseob Kimac1e9862019-12-09 18:15:47 +0900410 switch m.Owner() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900411 case "Platform":
412 // Every partition can access platform-defined properties
Inseob Kim42882742019-07-30 17:55:33 +0900413 stub += "platform"
Inseob Kimac1e9862019-12-09 18:15:47 +0900414 isOwnerPlatform = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900415 case "Vendor":
416 // System can't access vendor's properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900417 if installedInSystem {
Inseob Kimc0907f12019-02-08 21:00:45 +0900418 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
419 "System can't access sysprop_library owned by Vendor")
420 }
Inseob Kim42882742019-07-30 17:55:33 +0900421 stub += "vendor"
Inseob Kimc0907f12019-02-08 21:00:45 +0900422 case "Odm":
423 // Only vendor can access Odm-defined properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900424 if !installedInVendorOrOdm {
Inseob Kimc0907f12019-02-08 21:00:45 +0900425 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
426 "Odm-defined properties should be accessed only in Vendor or Odm")
427 }
Inseob Kim42882742019-07-30 17:55:33 +0900428 stub += "vendor"
Inseob Kimc0907f12019-02-08 21:00:45 +0900429 default:
430 ctx.PropertyErrorf("property_owner",
Inseob Kimac1e9862019-12-09 18:15:47 +0900431 "Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
Inseob Kimc0907f12019-02-08 21:00:45 +0900432 }
433
Inseob Kimac1e9862019-12-09 18:15:47 +0900434 ccProps := ccLibraryProperties{}
Inseob Kimc0907f12019-02-08 21:00:45 +0900435 ccProps.Name = proptools.StringPtr(m.CcModuleName())
Inseob Kim42882742019-07-30 17:55:33 +0900436 ccProps.Srcs = m.properties.Srcs
Inseob Kimac1e9862019-12-09 18:15:47 +0900437 ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific())
438 ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific())
439 ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific())
440 ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform)
Inseob Kim89db15d2020-02-03 18:06:46 +0900441 ccProps.Target.Android.Header_libs = []string{"libbase_headers"}
442 ccProps.Target.Android.Shared_libs = []string{"liblog"}
443 ccProps.Target.Host.Static_libs = []string{"libbase", "liblog"}
Inseob Kim42882742019-07-30 17:55:33 +0900444 ccProps.Recovery_available = m.properties.Recovery_available
445 ccProps.Vendor_available = m.properties.Vendor_available
Inseob Kim89db15d2020-02-03 18:06:46 +0900446 ccProps.Host_supported = m.properties.Host_supported
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100447 ccProps.Apex_available = m.ApexProperties.Apex_available
Jooyung Han379660c2020-04-21 15:24:00 +0900448 ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
Colin Cross84dfc3d2019-09-25 11:33:01 -0700449 ctx.CreateModule(cc.LibraryFactory, &ccProps)
Inseob Kim42882742019-07-30 17:55:33 +0900450
Inseob Kim988f53c2019-09-16 15:59:01 +0900451 scope := "internal"
Inseob Kim988f53c2019-09-16 15:59:01 +0900452
Inseob Kimac1e9862019-12-09 18:15:47 +0900453 // We need to only use public version, if the partition where sysprop_library will be installed
454 // is different from owner.
455
456 if ctx.ProductSpecific() {
457 // Currently product partition can't own any sysprop_library.
Inseob Kim988f53c2019-09-16 15:59:01 +0900458 scope = "public"
Inseob Kimac1e9862019-12-09 18:15:47 +0900459 } else if isOwnerPlatform && installedInVendorOrOdm {
460 // Vendor or Odm should use public version of Platform's sysprop_library.
Inseob Kim988f53c2019-09-16 15:59:01 +0900461 scope = "public"
462 }
463
Inseob Kimac1e9862019-12-09 18:15:47 +0900464 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
Inseob Kim988f53c2019-09-16 15:59:01 +0900465 Srcs: m.properties.Srcs,
466 Scope: scope,
467 Name: proptools.StringPtr(m.javaGenModuleName()),
Inseob Kimac1e9862019-12-09 18:15:47 +0900468 })
469
470 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
471 Name: proptools.StringPtr(m.BaseModuleName()),
472 Srcs: []string{":" + m.javaGenModuleName()},
473 Soc_specific: proptools.BoolPtr(ctx.SocSpecific()),
474 Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()),
475 Product_specific: proptools.BoolPtr(ctx.ProductSpecific()),
476 Installable: m.properties.Installable,
477 Sdk_version: proptools.StringPtr("core_current"),
478 Libs: []string{stub},
479 })
480
481 // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API
482 // and allow any modules (even from different partition) to link against the sysprop_library.
483 // To do that, we create a public stub and expose it to modules with sdk_version: system_*.
484 if isOwnerPlatform && installedInSystem {
485 m.properties.Public_stub = proptools.BoolPtr(true)
486 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
487 Srcs: m.properties.Srcs,
488 Scope: "public",
489 Name: proptools.StringPtr(m.javaGenPublicStubName()),
490 })
491
492 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
493 Name: proptools.StringPtr(m.JavaPublicStubName()),
494 Srcs: []string{":" + m.javaGenPublicStubName()},
495 Installable: proptools.BoolPtr(false),
496 Sdk_version: proptools.StringPtr("core_current"),
497 Libs: []string{stub},
498 Stem: proptools.StringPtr(m.BaseModuleName()),
499 })
Inseob Kim988f53c2019-09-16 15:59:01 +0900500 }
Inseob Kim628d7ef2020-03-21 03:38:32 +0900501
Inseob Kim69cf09e2020-05-04 19:28:25 +0900502 if m.ExportedToMake() {
503 syspropLibrariesLock.Lock()
504 defer syspropLibrariesLock.Unlock()
Inseob Kim628d7ef2020-03-21 03:38:32 +0900505
Inseob Kim69cf09e2020-05-04 19:28:25 +0900506 libraries := syspropLibraries(ctx.Config())
507 *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName())
508 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900509}
Inseob Kim988f53c2019-09-16 15:59:01 +0900510
511func syspropDepsMutator(ctx android.BottomUpMutatorContext) {
512 if m, ok := ctx.Module().(*syspropLibrary); ok {
513 ctx.AddReverseDependency(m, nil, m.javaGenModuleName())
Inseob Kimac1e9862019-12-09 18:15:47 +0900514
515 if proptools.Bool(m.properties.Public_stub) {
516 ctx.AddReverseDependency(m, nil, m.javaGenPublicStubName())
517 }
Inseob Kim988f53c2019-09-16 15:59:01 +0900518 }
519}