2019-02-08 13:00:45 +01:00
|
|
|
// Copyright (C) 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// sysprop package defines a module named sysprop_library that can implement sysprop as API
|
|
|
|
// See https://source.android.com/devices/architecture/sysprops-apis for details
|
2019-02-08 13:00:45 +01:00
|
|
|
package sysprop
|
|
|
|
|
|
|
|
import (
|
2019-07-30 10:55:33 +02:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"path"
|
2020-03-20 19:38:32 +01:00
|
|
|
"sync"
|
2019-04-16 23:43:28 +02:00
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
"github.com/google/blueprint"
|
|
|
|
"github.com/google/blueprint/proptools"
|
2019-07-30 10:55:33 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
"android/soong/java"
|
2019-02-08 13:00:45 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2019-09-16 08:59:01 +02:00
|
|
|
type syspropGenProperties struct {
|
|
|
|
Srcs []string `android:"path"`
|
|
|
|
Scope string
|
2019-12-09 10:15:47 +01:00
|
|
|
Name *string
|
2019-09-16 08:59:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type syspropJavaGenRule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
|
|
|
|
properties syspropGenProperties
|
|
|
|
|
|
|
|
genSrcjars android.Paths
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ android.OutputFileProducer = (*syspropJavaGenRule)(nil)
|
|
|
|
|
|
|
|
var (
|
|
|
|
syspropJava = pctx.AndroidStaticRule("syspropJava",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` +
|
|
|
|
`$syspropJavaCmd --scope $scope --java-output-dir $out.tmp $in && ` +
|
|
|
|
`$soongZipCmd -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`,
|
|
|
|
CommandDeps: []string{
|
|
|
|
"$syspropJavaCmd",
|
|
|
|
"$soongZipCmd",
|
|
|
|
},
|
|
|
|
}, "scope")
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.HostBinToolVariable("soongZipCmd", "soong_zip")
|
|
|
|
pctx.HostBinToolVariable("syspropJavaCmd", "sysprop_java")
|
|
|
|
|
|
|
|
android.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("sysprop_deps", syspropDepsMutator).Parallel()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// syspropJavaGenRule module generates srcjar containing generated java APIs.
|
|
|
|
// It also depends on check api rule, so api check has to pass to use sysprop_library.
|
2019-09-16 08:59:01 +02:00
|
|
|
func (g *syspropJavaGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|
|
|
var checkApiFileTimeStamp android.WritablePath
|
|
|
|
|
|
|
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
|
|
|
if m, ok := dep.(*syspropLibrary); ok {
|
|
|
|
checkApiFileTimeStamp = m.checkApiFileTimeStamp
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, syspropFile := range android.PathsForModuleSrc(ctx, g.properties.Srcs) {
|
|
|
|
srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar")
|
|
|
|
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: syspropJava,
|
|
|
|
Description: "sysprop_java " + syspropFile.Rel(),
|
|
|
|
Output: srcJarFile,
|
|
|
|
Input: syspropFile,
|
|
|
|
Implicit: checkApiFileTimeStamp,
|
|
|
|
Args: map[string]string{
|
|
|
|
"scope": g.properties.Scope,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
g.genSrcjars = append(g.genSrcjars, srcJarFile)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *syspropJavaGenRule) OutputFiles(tag string) (android.Paths, error) {
|
|
|
|
switch tag {
|
|
|
|
case "":
|
|
|
|
return g.genSrcjars, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func syspropJavaGenFactory() android.Module {
|
|
|
|
g := &syspropJavaGenRule{}
|
|
|
|
g.AddProperties(&g.properties)
|
|
|
|
android.InitAndroidModule(g)
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
type syspropLibrary struct {
|
2019-07-30 10:55:33 +02:00
|
|
|
android.ModuleBase
|
2020-03-30 19:00:25 +02:00
|
|
|
android.ApexModuleBase
|
2019-02-08 13:00:45 +01:00
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
properties syspropLibraryProperties
|
|
|
|
|
|
|
|
checkApiFileTimeStamp android.WritablePath
|
|
|
|
latestApiFile android.Path
|
|
|
|
currentApiFile android.Path
|
|
|
|
dumpedApiFile android.WritablePath
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type syspropLibraryProperties struct {
|
|
|
|
// Determine who owns this sysprop library. Possible values are
|
|
|
|
// "Platform", "Vendor", or "Odm"
|
|
|
|
Property_owner string
|
2019-03-05 06:22:30 +01:00
|
|
|
|
|
|
|
// list of package names that will be documented and publicized as API
|
|
|
|
Api_packages []string
|
2019-02-08 13:00:45 +01:00
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
// If set to true, allow this module to be dexed and installed on devices.
|
|
|
|
Installable *bool
|
|
|
|
|
|
|
|
// Make this module available when building for recovery
|
2019-02-26 02:27:13 +01:00
|
|
|
Recovery_available *bool
|
2019-07-30 10:55:33 +02:00
|
|
|
|
|
|
|
// Make this module available when building for vendor
|
|
|
|
Vendor_available *bool
|
|
|
|
|
2020-10-29 08:49:43 +01:00
|
|
|
// Make this module available when building for product
|
|
|
|
Product_available *bool
|
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
// list of .sysprop files which defines the properties.
|
|
|
|
Srcs []string `android:"path"`
|
2019-12-09 10:15:47 +01:00
|
|
|
|
2020-02-03 10:06:46 +01:00
|
|
|
// If set to true, build a variant of the module for the host. Defaults to false.
|
|
|
|
Host_supported *bool
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
// Whether public stub exists or not.
|
|
|
|
Public_stub *bool `blueprint:"mutated"`
|
2020-04-21 08:24:00 +02:00
|
|
|
|
|
|
|
Cpp struct {
|
|
|
|
// Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
|
|
|
|
// Forwarded to cc_library.min_sdk_version
|
|
|
|
Min_sdk_version *string
|
|
|
|
}
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2019-07-30 10:55:33 +02:00
|
|
|
pctx = android.NewPackageContext("android/soong/sysprop")
|
2019-02-08 13:00:45 +01:00
|
|
|
syspropCcTag = dependencyTag{name: "syspropCc"}
|
2020-03-20 19:38:32 +01:00
|
|
|
|
|
|
|
syspropLibrariesKey = android.NewOnceKey("syspropLibraries")
|
|
|
|
syspropLibrariesLock sync.Mutex
|
2019-02-08 13:00:45 +01:00
|
|
|
)
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// List of sysprop_library used by property_contexts to perform type check.
|
2020-03-20 19:38:32 +01:00
|
|
|
func syspropLibraries(config android.Config) *[]string {
|
|
|
|
return config.Once(syspropLibrariesKey, func() interface{} {
|
|
|
|
return &[]string{}
|
|
|
|
}).(*[]string)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SyspropLibraries(config android.Config) []string {
|
|
|
|
return append([]string{}, *syspropLibraries(config)...)
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func init() {
|
|
|
|
android.RegisterModuleType("sysprop_library", syspropLibraryFactory)
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
func (m *syspropLibrary) Name() string {
|
|
|
|
return m.BaseModuleName() + "_sysprop_library"
|
|
|
|
}
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
func (m *syspropLibrary) Owner() string {
|
|
|
|
return m.properties.Property_owner
|
|
|
|
}
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
func (m *syspropLibrary) CcImplementationModuleName() string {
|
2019-07-30 10:55:33 +02:00
|
|
|
return "lib" + m.BaseModuleName()
|
|
|
|
}
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
func (m *syspropLibrary) JavaPublicStubName() string {
|
|
|
|
if proptools.Bool(m.properties.Public_stub) {
|
|
|
|
return m.BaseModuleName() + "_public"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2019-09-16 08:59:01 +02:00
|
|
|
func (m *syspropLibrary) javaGenModuleName() string {
|
|
|
|
return m.BaseModuleName() + "_java_gen"
|
|
|
|
}
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
func (m *syspropLibrary) javaGenPublicStubName() string {
|
|
|
|
return m.BaseModuleName() + "_java_gen_public"
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
func (m *syspropLibrary) BaseModuleName() string {
|
|
|
|
return m.ModuleBase.Name()
|
|
|
|
}
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
func (m *syspropLibrary) HasPublicStub() bool {
|
|
|
|
return proptools.Bool(m.properties.Public_stub)
|
|
|
|
}
|
|
|
|
|
2020-03-20 19:38:32 +01:00
|
|
|
func (m *syspropLibrary) CurrentSyspropApiFile() android.Path {
|
|
|
|
return m.currentApiFile
|
|
|
|
}
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// GenerateAndroidBuildActions of sysprop_library handles API dump and API check.
|
|
|
|
// generated java_library will depend on these API files.
|
2019-07-30 10:55:33 +02:00
|
|
|
func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2019-09-16 08:59:01 +02:00
|
|
|
baseModuleName := m.BaseModuleName()
|
|
|
|
|
|
|
|
for _, syspropFile := range android.PathsForModuleSrc(ctx, m.properties.Srcs) {
|
|
|
|
if syspropFile.Ext() != ".sysprop" {
|
|
|
|
ctx.PropertyErrorf("srcs", "srcs contains non-sysprop file %q", syspropFile.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
m.currentApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-current.txt")
|
|
|
|
m.latestApiFile = android.PathForSource(ctx, ctx.ModuleDir(), "api", baseModuleName+"-latest.txt")
|
2019-07-30 10:55:33 +02:00
|
|
|
|
|
|
|
// dump API rule
|
|
|
|
rule := android.NewRuleBuilder()
|
|
|
|
m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt")
|
|
|
|
rule.Command().
|
|
|
|
BuiltTool(ctx, "sysprop_api_dump").
|
|
|
|
Output(m.dumpedApiFile).
|
|
|
|
Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs))
|
2019-09-16 08:59:01 +02:00
|
|
|
rule.Build(pctx, ctx, baseModuleName+"_api_dump", baseModuleName+" api dump")
|
2019-07-30 10:55:33 +02:00
|
|
|
|
|
|
|
// check API rule
|
|
|
|
rule = android.NewRuleBuilder()
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// 1. compares current.txt to api-dump.txt
|
|
|
|
// current.txt should be identical to api-dump.txt.
|
2019-07-30 10:55:33 +02:00
|
|
|
msg := fmt.Sprintf(`\n******************************\n`+
|
|
|
|
`API of sysprop_library %s doesn't match with current.txt\n`+
|
|
|
|
`Please update current.txt by:\n`+
|
2019-09-16 08:59:01 +02:00
|
|
|
`m %s-dump-api && rm -rf %q && cp -f %q %q\n`+
|
|
|
|
`******************************\n`, baseModuleName, baseModuleName,
|
2019-07-30 10:55:33 +02:00
|
|
|
m.currentApiFile.String(), m.dumpedApiFile.String(), m.currentApiFile.String())
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("( cmp").Flag("-s").
|
|
|
|
Input(m.dumpedApiFile).
|
|
|
|
Input(m.currentApiFile).
|
|
|
|
Text("|| ( echo").Flag("-e").
|
|
|
|
Flag(`"` + msg + `"`).
|
|
|
|
Text("; exit 38) )")
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// 2. compares current.txt to latest.txt (frozen API)
|
|
|
|
// current.txt should be compatible with latest.txt
|
2019-07-30 10:55:33 +02:00
|
|
|
msg = fmt.Sprintf(`\n******************************\n`+
|
|
|
|
`API of sysprop_library %s doesn't match with latest version\n`+
|
|
|
|
`Please fix the breakage and rebuild.\n`+
|
2019-09-16 08:59:01 +02:00
|
|
|
`******************************\n`, baseModuleName)
|
2019-07-30 10:55:33 +02:00
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("( ").
|
|
|
|
BuiltTool(ctx, "sysprop_api_checker").
|
|
|
|
Input(m.latestApiFile).
|
|
|
|
Input(m.currentApiFile).
|
|
|
|
Text(" || ( echo").Flag("-e").
|
|
|
|
Flag(`"` + msg + `"`).
|
|
|
|
Text("; exit 38) )")
|
|
|
|
|
|
|
|
m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp")
|
|
|
|
|
|
|
|
rule.Command().
|
|
|
|
Text("touch").
|
|
|
|
Output(m.checkApiFileTimeStamp)
|
|
|
|
|
2019-09-16 08:59:01 +02:00
|
|
|
rule.Build(pctx, ctx, baseModuleName+"_check_api", baseModuleName+" check api")
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
func (m *syspropLibrary) AndroidMk() android.AndroidMkData {
|
|
|
|
return android.AndroidMkData{
|
|
|
|
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
|
|
|
|
// sysprop_library module itself is defined as a FAKE module to perform API check.
|
|
|
|
// Actual implementation libraries are created on LoadHookMutator
|
|
|
|
fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
|
|
|
|
fmt.Fprintf(w, "LOCAL_MODULE := %s\n", m.Name())
|
|
|
|
fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n")
|
|
|
|
fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n")
|
|
|
|
fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n")
|
|
|
|
fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String())
|
|
|
|
fmt.Fprintf(w, "\ttouch $@\n\n")
|
2019-09-16 08:59:01 +02:00
|
|
|
fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name)
|
|
|
|
|
|
|
|
// dump API rule
|
|
|
|
fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String())
|
2019-07-30 10:55:33 +02:00
|
|
|
|
|
|
|
// check API rule
|
|
|
|
fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String())
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2020-07-23 07:32:17 +02:00
|
|
|
func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
|
|
|
|
sdkVersion android.ApiLevel) error {
|
2020-04-15 04:03:39 +02:00
|
|
|
return fmt.Errorf("sysprop_library is not supposed to be part of apex modules")
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
// sysprop_library creates schematized APIs from sysprop description files (.sysprop).
|
|
|
|
// Both Java and C++ modules can link against sysprop_library, and API stability check
|
|
|
|
// against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh)
|
|
|
|
// is performed.
|
2019-02-08 13:00:45 +01:00
|
|
|
func syspropLibraryFactory() android.Module {
|
|
|
|
m := &syspropLibrary{}
|
|
|
|
|
|
|
|
m.AddProperties(
|
2019-07-30 10:55:33 +02:00
|
|
|
&m.properties,
|
2019-02-08 13:00:45 +01:00
|
|
|
)
|
2019-07-30 10:55:33 +02:00
|
|
|
android.InitAndroidModule(m)
|
2020-03-30 19:00:25 +02:00
|
|
|
android.InitApexModule(m)
|
2019-02-08 13:00:45 +01:00
|
|
|
android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) })
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
type ccLibraryProperties struct {
|
|
|
|
Name *string
|
|
|
|
Srcs []string
|
|
|
|
Soc_specific *bool
|
|
|
|
Device_specific *bool
|
|
|
|
Product_specific *bool
|
|
|
|
Sysprop struct {
|
|
|
|
Platform *bool
|
|
|
|
}
|
2020-02-03 10:06:46 +01:00
|
|
|
Target struct {
|
|
|
|
Android struct {
|
|
|
|
Header_libs []string
|
|
|
|
Shared_libs []string
|
|
|
|
}
|
|
|
|
Host struct {
|
|
|
|
Static_libs []string
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 10:15:47 +01:00
|
|
|
Required []string
|
|
|
|
Recovery *bool
|
|
|
|
Recovery_available *bool
|
|
|
|
Vendor_available *bool
|
2020-10-29 08:49:43 +01:00
|
|
|
Product_available *bool
|
2020-02-03 10:06:46 +01:00
|
|
|
Host_supported *bool
|
2020-03-30 19:00:25 +02:00
|
|
|
Apex_available []string
|
2020-04-21 08:24:00 +02:00
|
|
|
Min_sdk_version *string
|
2019-12-09 10:15:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type javaLibraryProperties struct {
|
|
|
|
Name *string
|
|
|
|
Srcs []string
|
|
|
|
Soc_specific *bool
|
|
|
|
Device_specific *bool
|
|
|
|
Product_specific *bool
|
|
|
|
Required []string
|
|
|
|
Sdk_version *string
|
|
|
|
Installable *bool
|
|
|
|
Libs []string
|
|
|
|
Stem *string
|
|
|
|
}
|
|
|
|
|
2019-02-08 13:00:45 +01:00
|
|
|
func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
|
2019-07-30 10:55:33 +02:00
|
|
|
if len(m.properties.Srcs) == 0 {
|
2019-03-21 09:43:49 +01:00
|
|
|
ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs")
|
|
|
|
}
|
|
|
|
|
2019-07-30 10:55:33 +02:00
|
|
|
missing_api := false
|
|
|
|
|
|
|
|
for _, txt := range []string{"-current.txt", "-latest.txt"} {
|
|
|
|
path := path.Join(ctx.ModuleDir(), "api", m.BaseModuleName()+txt)
|
|
|
|
file := android.ExistentPathForSource(ctx, path)
|
|
|
|
if !file.Valid() {
|
|
|
|
ctx.ModuleErrorf("API file %#v doesn't exist", path)
|
|
|
|
missing_api = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if missing_api {
|
|
|
|
script := "build/soong/scripts/gen-sysprop-api-files.sh"
|
|
|
|
p := android.ExistentPathForSource(ctx, script)
|
|
|
|
|
|
|
|
if !p.Valid() {
|
|
|
|
panic(fmt.Sprintf("script file %s doesn't exist", script))
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ModuleErrorf("One or more api files are missing. "+
|
|
|
|
"You can create them by:\n"+
|
|
|
|
"%s %q %q", script, ctx.ModuleDir(), m.BaseModuleName())
|
|
|
|
return
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
// ctx's Platform or Specific functions represent where this sysprop_library installed.
|
|
|
|
installedInSystem := ctx.Platform() || ctx.SystemExtSpecific()
|
|
|
|
installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific()
|
2020-10-20 09:29:55 +02:00
|
|
|
installedInProduct := ctx.ProductSpecific()
|
2019-12-09 10:15:47 +01:00
|
|
|
isOwnerPlatform := false
|
2020-11-23 06:43:02 +01:00
|
|
|
var javaSyspropStub string
|
2020-10-20 09:29:55 +02:00
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// javaSyspropStub contains stub libraries used by generated APIs, instead of framework stub.
|
|
|
|
// This is to make sysprop_library link against core_current.
|
2020-10-20 09:29:55 +02:00
|
|
|
if installedInVendorOrOdm {
|
2020-11-23 06:43:02 +01:00
|
|
|
javaSyspropStub = "sysprop-library-stub-vendor"
|
2020-10-20 09:29:55 +02:00
|
|
|
} else if installedInProduct {
|
2020-11-23 06:43:02 +01:00
|
|
|
javaSyspropStub = "sysprop-library-stub-product"
|
2020-10-20 09:29:55 +02:00
|
|
|
} else {
|
2020-11-23 06:43:02 +01:00
|
|
|
javaSyspropStub = "sysprop-library-stub-platform"
|
2020-10-20 09:29:55 +02:00
|
|
|
}
|
2019-02-08 13:00:45 +01:00
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
switch m.Owner() {
|
2019-02-08 13:00:45 +01:00
|
|
|
case "Platform":
|
|
|
|
// Every partition can access platform-defined properties
|
2019-12-09 10:15:47 +01:00
|
|
|
isOwnerPlatform = true
|
2019-02-08 13:00:45 +01:00
|
|
|
case "Vendor":
|
|
|
|
// System can't access vendor's properties
|
2019-12-09 10:15:47 +01:00
|
|
|
if installedInSystem {
|
2019-02-08 13:00:45 +01:00
|
|
|
ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " +
|
|
|
|
"System can't access sysprop_library owned by Vendor")
|
|
|
|
}
|
|
|
|
case "Odm":
|
|
|
|
// Only vendor can access Odm-defined properties
|
2019-12-09 10:15:47 +01:00
|
|
|
if !installedInVendorOrOdm {
|
2019-02-08 13:00:45 +01:00
|
|
|
ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " +
|
|
|
|
"Odm-defined properties should be accessed only in Vendor or Odm")
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ctx.PropertyErrorf("property_owner",
|
2019-12-09 10:15:47 +01:00
|
|
|
"Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// Generate a C++ implementation library.
|
|
|
|
// cc_library can receive *.sysprop files as their srcs, generating sources itself.
|
2019-12-09 10:15:47 +01:00
|
|
|
ccProps := ccLibraryProperties{}
|
2020-11-23 06:43:02 +01:00
|
|
|
ccProps.Name = proptools.StringPtr(m.CcImplementationModuleName())
|
2019-07-30 10:55:33 +02:00
|
|
|
ccProps.Srcs = m.properties.Srcs
|
2019-12-09 10:15:47 +01:00
|
|
|
ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific())
|
|
|
|
ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific())
|
|
|
|
ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific())
|
|
|
|
ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform)
|
2020-02-03 10:06:46 +01:00
|
|
|
ccProps.Target.Android.Header_libs = []string{"libbase_headers"}
|
|
|
|
ccProps.Target.Android.Shared_libs = []string{"liblog"}
|
|
|
|
ccProps.Target.Host.Static_libs = []string{"libbase", "liblog"}
|
2019-07-30 10:55:33 +02:00
|
|
|
ccProps.Recovery_available = m.properties.Recovery_available
|
|
|
|
ccProps.Vendor_available = m.properties.Vendor_available
|
2020-10-29 08:49:43 +01:00
|
|
|
ccProps.Product_available = m.properties.Product_available
|
2020-02-03 10:06:46 +01:00
|
|
|
ccProps.Host_supported = m.properties.Host_supported
|
2020-03-30 19:00:25 +02:00
|
|
|
ccProps.Apex_available = m.ApexProperties.Apex_available
|
2020-04-21 08:24:00 +02:00
|
|
|
ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
|
2019-09-25 20:33:01 +02:00
|
|
|
ctx.CreateModule(cc.LibraryFactory, &ccProps)
|
2019-07-30 10:55:33 +02:00
|
|
|
|
2019-09-16 08:59:01 +02:00
|
|
|
scope := "internal"
|
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
// We need to only use public version, if the partition where sysprop_library will be installed
|
|
|
|
// is different from owner.
|
|
|
|
if ctx.ProductSpecific() {
|
2020-11-23 06:43:02 +01:00
|
|
|
// Currently product partition can't own any sysprop_library. So product always uses public.
|
2019-09-16 08:59:01 +02:00
|
|
|
scope = "public"
|
2019-12-09 10:15:47 +01:00
|
|
|
} else if isOwnerPlatform && installedInVendorOrOdm {
|
|
|
|
// Vendor or Odm should use public version of Platform's sysprop_library.
|
2019-09-16 08:59:01 +02:00
|
|
|
scope = "public"
|
|
|
|
}
|
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// Generate a Java implementation library.
|
|
|
|
// Contrast to C++, syspropJavaGenRule module will generate srcjar and the srcjar will be fed
|
|
|
|
// to Java implementation library.
|
2019-12-09 10:15:47 +01:00
|
|
|
ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
|
2019-09-16 08:59:01 +02:00
|
|
|
Srcs: m.properties.Srcs,
|
|
|
|
Scope: scope,
|
|
|
|
Name: proptools.StringPtr(m.javaGenModuleName()),
|
2019-12-09 10:15:47 +01:00
|
|
|
})
|
2019-09-16 08:59:01 +02:00
|
|
|
|
2019-12-09 10:15:47 +01:00
|
|
|
ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
|
|
|
|
Name: proptools.StringPtr(m.BaseModuleName()),
|
|
|
|
Srcs: []string{":" + m.javaGenModuleName()},
|
|
|
|
Soc_specific: proptools.BoolPtr(ctx.SocSpecific()),
|
|
|
|
Device_specific: proptools.BoolPtr(ctx.DeviceSpecific()),
|
|
|
|
Product_specific: proptools.BoolPtr(ctx.ProductSpecific()),
|
|
|
|
Installable: m.properties.Installable,
|
|
|
|
Sdk_version: proptools.StringPtr("core_current"),
|
2020-11-23 06:43:02 +01:00
|
|
|
Libs: []string{javaSyspropStub},
|
2019-12-09 10:15:47 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// if platform sysprop_library is installed in /system or /system-ext, we regard it as an API
|
|
|
|
// and allow any modules (even from different partition) to link against the sysprop_library.
|
|
|
|
// To do that, we create a public stub and expose it to modules with sdk_version: system_*.
|
|
|
|
if isOwnerPlatform && installedInSystem {
|
|
|
|
m.properties.Public_stub = proptools.BoolPtr(true)
|
|
|
|
ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{
|
|
|
|
Srcs: m.properties.Srcs,
|
|
|
|
Scope: "public",
|
|
|
|
Name: proptools.StringPtr(m.javaGenPublicStubName()),
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{
|
|
|
|
Name: proptools.StringPtr(m.JavaPublicStubName()),
|
|
|
|
Srcs: []string{":" + m.javaGenPublicStubName()},
|
|
|
|
Installable: proptools.BoolPtr(false),
|
|
|
|
Sdk_version: proptools.StringPtr("core_current"),
|
2020-11-23 06:43:02 +01:00
|
|
|
Libs: []string{javaSyspropStub},
|
2019-12-09 10:15:47 +01:00
|
|
|
Stem: proptools.StringPtr(m.BaseModuleName()),
|
|
|
|
})
|
|
|
|
}
|
2020-03-20 19:38:32 +01:00
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// syspropLibraries will be used by property_contexts to check types.
|
|
|
|
// Record absolute paths of sysprop_library to prevent soong_namespace problem.
|
2020-05-04 12:28:25 +02:00
|
|
|
if m.ExportedToMake() {
|
|
|
|
syspropLibrariesLock.Lock()
|
|
|
|
defer syspropLibrariesLock.Unlock()
|
2020-03-20 19:38:32 +01:00
|
|
|
|
2020-05-04 12:28:25 +02:00
|
|
|
libraries := syspropLibraries(ctx.Config())
|
|
|
|
*libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName())
|
|
|
|
}
|
2019-02-08 13:00:45 +01:00
|
|
|
}
|
2019-09-16 08:59:01 +02:00
|
|
|
|
2020-11-23 06:43:02 +01:00
|
|
|
// syspropDepsMutator adds dependencies from java implementation library to sysprop library.
|
|
|
|
// java implementation library then depends on check API rule of sysprop library.
|
2019-09-16 08:59:01 +02:00
|
|
|
func syspropDepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if m, ok := ctx.Module().(*syspropLibrary); ok {
|
|
|
|
ctx.AddReverseDependency(m, nil, m.javaGenModuleName())
|
2019-12-09 10:15:47 +01:00
|
|
|
|
|
|
|
if proptools.Bool(m.properties.Public_stub) {
|
|
|
|
ctx.AddReverseDependency(m, nil, m.javaGenPublicStubName())
|
|
|
|
}
|
2019-09-16 08:59:01 +02:00
|
|
|
}
|
|
|
|
}
|