blob: 1740ba8cf7acecd2934c8277dc43745b56f20b00 [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
Justin Yun63e9ec72020-10-29 16:49:43 +0900146 // Make this module available when building for product
147 Product_available *bool
148
Inseob Kim42882742019-07-30 17:55:33 +0900149 // list of .sysprop files which defines the properties.
150 Srcs []string `android:"path"`
Inseob Kimac1e9862019-12-09 18:15:47 +0900151
Inseob Kim89db15d2020-02-03 18:06:46 +0900152 // If set to true, build a variant of the module for the host. Defaults to false.
153 Host_supported *bool
154
Inseob Kimac1e9862019-12-09 18:15:47 +0900155 // Whether public stub exists or not.
156 Public_stub *bool `blueprint:"mutated"`
Jooyung Han379660c2020-04-21 15:24:00 +0900157
158 Cpp struct {
159 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
160 // Forwarded to cc_library.min_sdk_version
161 Min_sdk_version *string
162 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900163}
164
165var (
Inseob Kim42882742019-07-30 17:55:33 +0900166 pctx = android.NewPackageContext("android/soong/sysprop")
Inseob Kimc0907f12019-02-08 21:00:45 +0900167 syspropCcTag = dependencyTag{name: "syspropCc"}
Inseob Kim628d7ef2020-03-21 03:38:32 +0900168
169 syspropLibrariesKey = android.NewOnceKey("syspropLibraries")
170 syspropLibrariesLock sync.Mutex
Inseob Kimc0907f12019-02-08 21:00:45 +0900171)
172
Inseob Kim628d7ef2020-03-21 03:38:32 +0900173func syspropLibraries(config android.Config) *[]string {
174 return config.Once(syspropLibrariesKey, func() interface{} {
175 return &[]string{}
176 }).(*[]string)
177}
178
179func SyspropLibraries(config android.Config) []string {
180 return append([]string{}, *syspropLibraries(config)...)
181}
182
Inseob Kimc0907f12019-02-08 21:00:45 +0900183func init() {
184 android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
185}
186
Inseob Kim42882742019-07-30 17:55:33 +0900187func (m *syspropLibrary) Name() string {
188 return m.BaseModuleName() + "_sysprop_library"
Inseob Kimc0907f12019-02-08 21:00:45 +0900189}
190
Inseob Kimac1e9862019-12-09 18:15:47 +0900191func (m *syspropLibrary) Owner() string {
192 return m.properties.Property_owner
193}
194
Inseob Kim42882742019-07-30 17:55:33 +0900195func (m *syspropLibrary) CcModuleName() string {
196 return "lib" + m.BaseModuleName()
197}
198
Inseob Kimac1e9862019-12-09 18:15:47 +0900199func (m *syspropLibrary) JavaPublicStubName() string {
200 if proptools.Bool(m.properties.Public_stub) {
201 return m.BaseModuleName() + "_public"
202 }
203 return ""
204}
205
Inseob Kim988f53c2019-09-16 15:59:01 +0900206func (m *syspropLibrary) javaGenModuleName() string {
207 return m.BaseModuleName() + "_java_gen"
208}
209
Inseob Kimac1e9862019-12-09 18:15:47 +0900210func (m *syspropLibrary) javaGenPublicStubName() string {
211 return m.BaseModuleName() + "_java_gen_public"
212}
213
Inseob Kim42882742019-07-30 17:55:33 +0900214func (m *syspropLibrary) BaseModuleName() string {
215 return m.ModuleBase.Name()
216}
217
Inseob Kimac1e9862019-12-09 18:15:47 +0900218func (m *syspropLibrary) HasPublicStub() bool {
219 return proptools.Bool(m.properties.Public_stub)
220}
221
Inseob Kim628d7ef2020-03-21 03:38:32 +0900222func (m *syspropLibrary) CurrentSyspropApiFile() android.Path {
223 return m.currentApiFile
224}
225
Inseob Kim42882742019-07-30 17:55:33 +0900226func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Inseob Kim988f53c2019-09-16 15:59:01 +0900227 baseModuleName := m.BaseModuleName()
228
229 for _, syspropFile := range android.PathsForModuleSrc(ctx, m.properties.Srcs) {
230 if syspropFile.Ext() != ".sysprop" {
231 ctx.PropertyErrorf("srcs", "srcs contains non-sysprop file %q", syspropFile.String())
232 }
233 }
234
235 if ctx.Failed() {
236 return
237 }
238
239 m.currentApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-current.txt")
240 m.latestApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-latest.txt")
Inseob Kim42882742019-07-30 17:55:33 +0900241
242 // dump API rule
243 rule := android.NewRuleBuilder()
244 m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt")
245 rule.Command().
246 BuiltTool(ctx, "sysprop_api_dump").
247 Output(m.dumpedApiFile).
248 Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
Inseob Kim988f53c2019-09-16 15:59:01 +0900249 rule.Build(pctx, ctx, baseModuleName+"_api_dump", baseModuleName+" api dump")
Inseob Kim42882742019-07-30 17:55:33 +0900250
251 // check API rule
252 rule = android.NewRuleBuilder()
253
254 // 1. current.txt <-> api_dump.txt
255 msg := fmt.Sprintf(`\n******************************\n`+
256 `API of sysprop_library %s doesn't match with current.txt\n`+
257 `Please update current.txt by:\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900258 `m %s-dump-api && rm -rf %q && cp -f %q %q\n`+
259 `******************************\n`, baseModuleName, baseModuleName,
Inseob Kim42882742019-07-30 17:55:33 +0900260 m.currentApiFile.String(), m.dumpedApiFile.String(), m.currentApiFile.String())
261
262 rule.Command().
263 Text("( cmp").Flag("-s").
264 Input(m.dumpedApiFile).
265 Input(m.currentApiFile).
266 Text("|| ( echo").Flag("-e").
267 Flag(`"` + msg + `"`).
268 Text("; exit 38) )")
269
270 // 2. current.txt <-> latest.txt
271 msg = fmt.Sprintf(`\n******************************\n`+
272 `API of sysprop_library %s doesn't match with latest version\n`+
273 `Please fix the breakage and rebuild.\n`+
Inseob Kim988f53c2019-09-16 15:59:01 +0900274 `******************************\n`, baseModuleName)
Inseob Kim42882742019-07-30 17:55:33 +0900275
276 rule.Command().
277 Text("( ").
278 BuiltTool(ctx, "sysprop_api_checker").
279 Input(m.latestApiFile).
280 Input(m.currentApiFile).
281 Text(" || ( echo").Flag("-e").
282 Flag(`"` + msg + `"`).
283 Text("; exit 38) )")
284
285 m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp")
286
287 rule.Command().
288 Text("touch").
289 Output(m.checkApiFileTimeStamp)
290
Inseob Kim988f53c2019-09-16 15:59:01 +0900291 rule.Build(pctx, ctx, baseModuleName+"_check_api", baseModuleName+" check api")
Inseob Kim42882742019-07-30 17:55:33 +0900292}
293
294func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
295 return android.AndroidMkData{
296 Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
297 // sysprop_library module itself is defined as a FAKE module to perform API check.
298 // Actual implementation libraries are created on LoadHookMutator
299 fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
300 fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name())
301 fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
302 fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
303 fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
304 fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
305 fmt.Fprintf(w, "\ttouch $@\n\n")
Inseob Kim988f53c2019-09-16 15:59:01 +0900306 fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name)
307
308 // dump API rule
309 fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String())
Inseob Kim42882742019-07-30 17:55:33 +0900310
311 // check API rule
312 fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
Inseob Kim42882742019-07-30 17:55:33 +0900313 }}
314}
315
Dan Albertc8060532020-07-22 22:32:17 -0700316func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
317 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +0900318 return fmt.Errorf("sysprop_library is not supposed to be part of apex modules")
319}
320
Inseob Kim42882742019-07-30 17:55:33 +0900321// sysprop_library creates schematized APIs from sysprop description files (.sysprop).
322// Both Java and C++ modules can link against sysprop_library, and API stability check
323// against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh)
324// is performed.
Inseob Kimc0907f12019-02-08 21:00:45 +0900325func syspropLibraryFactory() android.Module {
326 m := &syspropLibrary{}
327
328 m.AddProperties(
Inseob Kim42882742019-07-30 17:55:33 +0900329 &m.properties,
Inseob Kimc0907f12019-02-08 21:00:45 +0900330 )
Inseob Kim42882742019-07-30 17:55:33 +0900331 android.InitAndroidModule(m)
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100332 android.InitApexModule(m)
Inseob Kimc0907f12019-02-08 21:00:45 +0900333 android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
Inseob Kimc0907f12019-02-08 21:00:45 +0900334 return m
335}
336
Inseob Kimac1e9862019-12-09 18:15:47 +0900337type ccLibraryProperties struct {
338 Name *string
339 Srcs []string
340 Soc_specific *bool
341 Device_specific *bool
342 Product_specific *bool
343 Sysprop struct {
344 Platform *bool
345 }
Inseob Kim89db15d2020-02-03 18:06:46 +0900346 Target struct {
347 Android struct {
348 Header_libs []string
349 Shared_libs []string
350 }
351 Host struct {
352 Static_libs []string
353 }
354 }
Inseob Kimac1e9862019-12-09 18:15:47 +0900355 Required []string
356 Recovery *bool
357 Recovery_available *bool
358 Vendor_available *bool
Justin Yun63e9ec72020-10-29 16:49:43 +0900359 Product_available *bool
Inseob Kim89db15d2020-02-03 18:06:46 +0900360 Host_supported *bool
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100361 Apex_available []string
Jooyung Han379660c2020-04-21 15:24:00 +0900362 Min_sdk_version *string
Inseob Kimac1e9862019-12-09 18:15:47 +0900363}
364
365type javaLibraryProperties struct {
366 Name *string
367 Srcs []string
368 Soc_specific *bool
369 Device_specific *bool
370 Product_specific *bool
371 Required []string
372 Sdk_version *string
373 Installable *bool
374 Libs []string
375 Stem *string
376}
377
Inseob Kimc0907f12019-02-08 21:00:45 +0900378func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Inseob Kim42882742019-07-30 17:55:33 +0900379 if len(m.properties.Srcs) == 0 {
Inseob Kim6e93ac92019-03-21 17:43:49 +0900380 ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
381 }
382
Inseob Kim42882742019-07-30 17:55:33 +0900383 missing_api := false
384
385 for _, txt := range []string{"-current.txt", "-latest.txt"} {
386 path := path.Join(ctx.ModuleDir(), "api", m.BaseModuleName()+txt)
387 file := android.ExistentPathForSource(ctx, path)
388 if !file.Valid() {
389 ctx.ModuleErrorf("API file %#v doesn't exist", path)
390 missing_api = true
391 }
392 }
393
394 if missing_api {
395 script := "build/soong/scripts/gen-sysprop-api-files.sh"
396 p := android.ExistentPathForSource(ctx, script)
397
398 if !p.Valid() {
399 panic(fmt.Sprintf("script file %s doesn't exist", script))
400 }
401
402 ctx.ModuleErrorf("One or more api files are missing. "+
403 "You can create them by:\n"+
404 "%s %q %q", script, ctx.ModuleDir(), m.BaseModuleName())
405 return
Inseob Kimc0907f12019-02-08 21:00:45 +0900406 }
407
Inseob Kimac1e9862019-12-09 18:15:47 +0900408 // ctx's Platform or Specific functions represent where this sysprop_library installed.
409 installedInSystem := ctx.Platform() || ctx.SystemExtSpecific()
410 installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific()
Inseob Kimfe612182020-10-20 16:29:55 +0900411 installedInProduct := ctx.ProductSpecific()
Inseob Kimac1e9862019-12-09 18:15:47 +0900412 isOwnerPlatform := false
Inseob Kimfe612182020-10-20 16:29:55 +0900413 var stub string
414
415 if installedInVendorOrOdm {
416 stub = "sysprop-library-stub-vendor"
417 } else if installedInProduct {
418 stub = "sysprop-library-stub-product"
419 } else {
420 stub = "sysprop-library-stub-platform"
421 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900422
Inseob Kimac1e9862019-12-09 18:15:47 +0900423 switch m.Owner() {
Inseob Kimc0907f12019-02-08 21:00:45 +0900424 case "Platform":
425 // Every partition can access platform-defined properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900426 isOwnerPlatform = true
Inseob Kimc0907f12019-02-08 21:00:45 +0900427 case "Vendor":
428 // System can't access vendor's properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900429 if installedInSystem {
Inseob Kimc0907f12019-02-08 21:00:45 +0900430 ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
431 "System can't access sysprop_library owned by Vendor")
432 }
433 case "Odm":
434 // Only vendor can access Odm-defined properties
Inseob Kimac1e9862019-12-09 18:15:47 +0900435 if !installedInVendorOrOdm {
Inseob Kimc0907f12019-02-08 21:00:45 +0900436 ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
437 "Odm-defined properties should be accessed only in Vendor or Odm")
438 }
439 default:
440 ctx.PropertyErrorf("property_owner",
Inseob Kimac1e9862019-12-09 18:15:47 +0900441 "Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
Inseob Kimc0907f12019-02-08 21:00:45 +0900442 }
443
Inseob Kimac1e9862019-12-09 18:15:47 +0900444 ccProps := ccLibraryProperties{}
Inseob Kimc0907f12019-02-08 21:00:45 +0900445 ccProps.Name = proptools.StringPtr(m.CcModuleName())
Inseob Kim42882742019-07-30 17:55:33 +0900446 ccProps.Srcs = m.properties.Srcs
Inseob Kimac1e9862019-12-09 18:15:47 +0900447 ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific())
448 ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific())
449 ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific())
450 ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform)
Inseob Kim89db15d2020-02-03 18:06:46 +0900451 ccProps.Target.Android.Header_libs = []string{"libbase_headers"}
452 ccProps.Target.Android.Shared_libs = []string{"liblog"}
453 ccProps.Target.Host.Static_libs = []string{"libbase", "liblog"}
Inseob Kim42882742019-07-30 17:55:33 +0900454 ccProps.Recovery_available = m.properties.Recovery_available
455 ccProps.Vendor_available = m.properties.Vendor_available
Justin Yun63e9ec72020-10-29 16:49:43 +0900456 ccProps.Product_available = m.properties.Product_available
Inseob Kim89db15d2020-02-03 18:06:46 +0900457 ccProps.Host_supported = m.properties.Host_supported
Paul Duffin7b3de8f2020-03-30 18:00:25 +0100458 ccProps.Apex_available = m.ApexProperties.Apex_available
Jooyung Han379660c2020-04-21 15:24:00 +0900459 ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
Colin Cross84dfc3d2019-09-25 11:33:01 -0700460 ctx.CreateModule(cc.LibraryFactory, &ccProps)
Inseob Kim42882742019-07-30 17:55:33 +0900461
Inseob Kim988f53c2019-09-16 15:59:01 +0900462 scope := "internal"
Inseob Kim988f53c2019-09-16 15:59:01 +0900463
Inseob Kimac1e9862019-12-09 18:15:47 +0900464 // We need to only use public version, if the partition where sysprop_library will be installed
465 // is different from owner.
466
467 if ctx.ProductSpecific() {
468 // Currently product partition can't own any sysprop_library.
Inseob Kim988f53c2019-09-16 15:59:01 +0900469 scope = "public"
Inseob Kimac1e9862019-12-09 18:15:47 +0900470 } else if isOwnerPlatform && installedInVendorOrOdm {
471 // Vendor or Odm should use public version of Platform's sysprop_library.
Inseob Kim988f53c2019-09-16 15:59:01 +0900472 scope = "public"
473 }
474
Inseob Kimac1e9862019-12-09 18:15:47 +0900475 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
Inseob Kim988f53c2019-09-16 15:59:01 +0900476 Srcs: m.properties.Srcs,
477 Scope: scope,
478 Name: proptools.StringPtr(m.javaGenModuleName()),
Inseob Kimac1e9862019-12-09 18:15:47 +0900479 })
480
481 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
482 Name: proptools.StringPtr(m.BaseModuleName()),
483 Srcs: []string{":" + m.javaGenModuleName()},
484 Soc_specific: proptools.BoolPtr(ctx.SocSpecific()),
485 Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()),
486 Product_specific: proptools.BoolPtr(ctx.ProductSpecific()),
487 Installable: m.properties.Installable,
488 Sdk_version: proptools.StringPtr("core_current"),
489 Libs: []string{stub},
490 })
491
492 // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API
493 // and allow any modules (even from different partition) to link against the sysprop_library.
494 // To do that, we create a public stub and expose it to modules with sdk_version: system_*.
495 if isOwnerPlatform && installedInSystem {
496 m.properties.Public_stub = proptools.BoolPtr(true)
497 ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
498 Srcs: m.properties.Srcs,
499 Scope: "public",
500 Name: proptools.StringPtr(m.javaGenPublicStubName()),
501 })
502
503 ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
504 Name: proptools.StringPtr(m.JavaPublicStubName()),
505 Srcs: []string{":" + m.javaGenPublicStubName()},
506 Installable: proptools.BoolPtr(false),
507 Sdk_version: proptools.StringPtr("core_current"),
508 Libs: []string{stub},
509 Stem: proptools.StringPtr(m.BaseModuleName()),
510 })
Inseob Kim988f53c2019-09-16 15:59:01 +0900511 }
Inseob Kim628d7ef2020-03-21 03:38:32 +0900512
Inseob Kim69cf09e2020-05-04 19:28:25 +0900513 if m.ExportedToMake() {
514 syspropLibrariesLock.Lock()
515 defer syspropLibrariesLock.Unlock()
Inseob Kim628d7ef2020-03-21 03:38:32 +0900516
Inseob Kim69cf09e2020-05-04 19:28:25 +0900517 libraries := syspropLibraries(ctx.Config())
518 *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName())
519 }
Inseob Kimc0907f12019-02-08 21:00:45 +0900520}
Inseob Kim988f53c2019-09-16 15:59:01 +0900521
522func syspropDepsMutator(ctx android.BottomUpMutatorContext) {
523 if m, ok := ctx.Module().(*syspropLibrary); ok {
524 ctx.AddReverseDependency(m, nil, m.javaGenModuleName())
Inseob Kimac1e9862019-12-09 18:15:47 +0900525
526 if proptools.Bool(m.properties.Public_stub) {
527 ctx.AddReverseDependency(m, nil, m.javaGenPublicStubName())
528 }
Inseob Kim988f53c2019-09-16 15:59:01 +0900529 }
530}