| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1 | // 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 Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 15 | // 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 Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 17 | package sysprop | 
|  | 18 |  | 
|  | 19 | import ( | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 20 | "fmt" | 
|  | 21 | "io" | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 22 | "os" | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 23 | "path" | 
| Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 24 | "sync" | 
| Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 25 |  | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 26 | "android/soong/bazel" | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 27 | "android/soong/sysprop/bp2build" | 
|  | 28 | "android/soong/ui/metrics/bp2build_metrics_proto" | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 29 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 30 | "github.com/google/blueprint" | 
|  | 31 | "github.com/google/blueprint/proptools" | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 32 |  | 
|  | 33 | "android/soong/android" | 
|  | 34 | "android/soong/cc" | 
|  | 35 | "android/soong/java" | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 36 | ) | 
|  | 37 |  | 
|  | 38 | type dependencyTag struct { | 
|  | 39 | blueprint.BaseDependencyTag | 
|  | 40 | name string | 
|  | 41 | } | 
|  | 42 |  | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 43 | type syspropGenProperties struct { | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 44 | Srcs      []string `android:"path"` | 
|  | 45 | Scope     string | 
|  | 46 | Name      *string | 
|  | 47 | Check_api *string | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 48 | } | 
|  | 49 |  | 
|  | 50 | type syspropJavaGenRule struct { | 
|  | 51 | android.ModuleBase | 
|  | 52 |  | 
|  | 53 | properties syspropGenProperties | 
|  | 54 |  | 
|  | 55 | genSrcjars android.Paths | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | var _ android.OutputFileProducer = (*syspropJavaGenRule)(nil) | 
|  | 59 |  | 
|  | 60 | var ( | 
|  | 61 | syspropJava = pctx.AndroidStaticRule("syspropJava", | 
|  | 62 | blueprint.RuleParams{ | 
|  | 63 | Command: `rm -rf $out.tmp && mkdir -p $out.tmp && ` + | 
|  | 64 | `$syspropJavaCmd --scope $scope --java-output-dir $out.tmp $in && ` + | 
|  | 65 | `$soongZipCmd -jar -o $out -C $out.tmp -D $out.tmp && rm -rf $out.tmp`, | 
|  | 66 | CommandDeps: []string{ | 
|  | 67 | "$syspropJavaCmd", | 
|  | 68 | "$soongZipCmd", | 
|  | 69 | }, | 
|  | 70 | }, "scope") | 
|  | 71 | ) | 
|  | 72 |  | 
|  | 73 | func init() { | 
|  | 74 | pctx.HostBinToolVariable("soongZipCmd", "soong_zip") | 
|  | 75 | pctx.HostBinToolVariable("syspropJavaCmd", "sysprop_java") | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 76 | } | 
|  | 77 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 78 | // syspropJavaGenRule module generates srcjar containing generated java APIs. | 
|  | 79 | // It also depends on check api rule, so api check has to pass to use sysprop_library. | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 80 | func (g *syspropJavaGenRule) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 81 | var checkApiFileTimeStamp android.WritablePath | 
|  | 82 |  | 
|  | 83 | ctx.VisitDirectDeps(func(dep android.Module) { | 
|  | 84 | if m, ok := dep.(*syspropLibrary); ok { | 
|  | 85 | checkApiFileTimeStamp = m.checkApiFileTimeStamp | 
|  | 86 | } | 
|  | 87 | }) | 
|  | 88 |  | 
|  | 89 | for _, syspropFile := range android.PathsForModuleSrc(ctx, g.properties.Srcs) { | 
|  | 90 | srcJarFile := android.GenPathWithExt(ctx, "sysprop", syspropFile, "srcjar") | 
|  | 91 |  | 
|  | 92 | ctx.Build(pctx, android.BuildParams{ | 
|  | 93 | Rule:        syspropJava, | 
|  | 94 | Description: "sysprop_java " + syspropFile.Rel(), | 
|  | 95 | Output:      srcJarFile, | 
|  | 96 | Input:       syspropFile, | 
|  | 97 | Implicit:    checkApiFileTimeStamp, | 
|  | 98 | Args: map[string]string{ | 
|  | 99 | "scope": g.properties.Scope, | 
|  | 100 | }, | 
|  | 101 | }) | 
|  | 102 |  | 
|  | 103 | g.genSrcjars = append(g.genSrcjars, srcJarFile) | 
|  | 104 | } | 
|  | 105 | } | 
|  | 106 |  | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 107 | func (g *syspropJavaGenRule) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 108 | // Add a dependency from the stubs to sysprop library so that the generator rule can depend on | 
|  | 109 | // the check API rule of the sysprop library. | 
|  | 110 | ctx.AddFarVariationDependencies(nil, nil, proptools.String(g.properties.Check_api)) | 
|  | 111 | } | 
|  | 112 |  | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 113 | func (g *syspropJavaGenRule) OutputFiles(tag string) (android.Paths, error) { | 
|  | 114 | switch tag { | 
|  | 115 | case "": | 
|  | 116 | return g.genSrcjars, nil | 
|  | 117 | default: | 
|  | 118 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
|  | 119 | } | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | func syspropJavaGenFactory() android.Module { | 
|  | 123 | g := &syspropJavaGenRule{} | 
|  | 124 | g.AddProperties(&g.properties) | 
|  | 125 | android.InitAndroidModule(g) | 
|  | 126 | return g | 
|  | 127 | } | 
|  | 128 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 129 | type syspropLibrary struct { | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 130 | android.ModuleBase | 
| Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 131 | android.ApexModuleBase | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 132 | android.BazelModuleBase | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 133 |  | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 134 | properties syspropLibraryProperties | 
|  | 135 |  | 
|  | 136 | checkApiFileTimeStamp android.WritablePath | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 137 | latestApiFile         android.OptionalPath | 
|  | 138 | currentApiFile        android.OptionalPath | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 139 | dumpedApiFile         android.WritablePath | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 140 | } | 
|  | 141 |  | 
|  | 142 | type syspropLibraryProperties struct { | 
|  | 143 | // Determine who owns this sysprop library. Possible values are | 
|  | 144 | // "Platform", "Vendor", or "Odm" | 
|  | 145 | Property_owner string | 
| Inseob Kim | f63c2fb | 2019-03-05 14:22:30 +0900 | [diff] [blame] | 146 |  | 
|  | 147 | // list of package names that will be documented and publicized as API | 
|  | 148 | Api_packages []string | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 149 |  | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 150 | // If set to true, allow this module to be dexed and installed on devices. | 
|  | 151 | Installable *bool | 
|  | 152 |  | 
| Inseob Kim | 9da1f81 | 2021-06-14 12:03:59 +0900 | [diff] [blame] | 153 | // Make this module available when building for ramdisk | 
|  | 154 | Ramdisk_available *bool | 
|  | 155 |  | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 156 | // Make this module available when building for recovery | 
| Jiyong Park | 854a944 | 2019-02-26 10:27:13 +0900 | [diff] [blame] | 157 | Recovery_available *bool | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 158 |  | 
|  | 159 | // Make this module available when building for vendor | 
|  | 160 | Vendor_available *bool | 
|  | 161 |  | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 162 | // Make this module available when building for product | 
|  | 163 | Product_available *bool | 
|  | 164 |  | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 165 | // list of .sysprop files which defines the properties. | 
|  | 166 | Srcs []string `android:"path"` | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 167 |  | 
| Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 168 | // If set to true, build a variant of the module for the host.  Defaults to false. | 
|  | 169 | Host_supported *bool | 
|  | 170 |  | 
| Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 171 | Cpp struct { | 
|  | 172 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). | 
|  | 173 | // Forwarded to cc_library.min_sdk_version | 
|  | 174 | Min_sdk_version *string | 
| Steven Moreland | c43a4ac | 2023-10-24 21:49:18 +0000 | [diff] [blame] | 175 |  | 
|  | 176 | // C compiler flags used to build library | 
|  | 177 | Cflags []string | 
|  | 178 |  | 
|  | 179 | // Linker flags used to build binary | 
|  | 180 | Ldflags []string | 
| Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 181 | } | 
| Jiyong Park | 5e914b2 | 2021-03-08 10:09:52 +0900 | [diff] [blame] | 182 |  | 
|  | 183 | Java struct { | 
|  | 184 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). | 
|  | 185 | // Forwarded to java_library.min_sdk_version | 
|  | 186 | Min_sdk_version *string | 
|  | 187 | } | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
|  | 190 | var ( | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 191 | pctx         = android.NewPackageContext("android/soong/sysprop") | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 192 | syspropCcTag = dependencyTag{name: "syspropCc"} | 
| Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 193 |  | 
|  | 194 | syspropLibrariesKey  = android.NewOnceKey("syspropLibraries") | 
|  | 195 | syspropLibrariesLock sync.Mutex | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 196 | ) | 
|  | 197 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 198 | // List of sysprop_library used by property_contexts to perform type check. | 
| Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 199 | func syspropLibraries(config android.Config) *[]string { | 
|  | 200 | return config.Once(syspropLibrariesKey, func() interface{} { | 
|  | 201 | return &[]string{} | 
|  | 202 | }).(*[]string) | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | func SyspropLibraries(config android.Config) []string { | 
|  | 206 | return append([]string{}, *syspropLibraries(config)...) | 
|  | 207 | } | 
|  | 208 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 209 | func init() { | 
| Paul Duffin | 6e3ce72 | 2021-03-18 00:20:11 +0000 | [diff] [blame] | 210 | registerSyspropBuildComponents(android.InitRegistrationContext) | 
|  | 211 | } | 
|  | 212 |  | 
|  | 213 | func registerSyspropBuildComponents(ctx android.RegistrationContext) { | 
|  | 214 | ctx.RegisterModuleType("sysprop_library", syspropLibraryFactory) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 215 | } | 
|  | 216 |  | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 217 | func (m *syspropLibrary) Name() string { | 
|  | 218 | return m.BaseModuleName() + "_sysprop_library" | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 219 | } | 
|  | 220 |  | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 221 | func (m *syspropLibrary) Owner() string { | 
|  | 222 | return m.properties.Property_owner | 
|  | 223 | } | 
|  | 224 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 225 | func (m *syspropLibrary) CcImplementationModuleName() string { | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 226 | return "lib" + m.BaseModuleName() | 
|  | 227 | } | 
|  | 228 |  | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 229 | func (m *syspropLibrary) javaPublicStubName() string { | 
|  | 230 | return m.BaseModuleName() + "_public" | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 231 | } | 
|  | 232 |  | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 233 | func (m *syspropLibrary) javaGenModuleName() string { | 
|  | 234 | return m.BaseModuleName() + "_java_gen" | 
|  | 235 | } | 
|  | 236 |  | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 237 | func (m *syspropLibrary) javaGenPublicStubName() string { | 
|  | 238 | return m.BaseModuleName() + "_java_gen_public" | 
|  | 239 | } | 
|  | 240 |  | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 241 | func (m *syspropLibrary) bp2buildJavaImplementationModuleName() string { | 
|  | 242 | return m.BaseModuleName() + "_java_library" | 
|  | 243 | } | 
|  | 244 |  | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 245 | func (m *syspropLibrary) BaseModuleName() string { | 
|  | 246 | return m.ModuleBase.Name() | 
|  | 247 | } | 
|  | 248 |  | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 249 | func (m *syspropLibrary) CurrentSyspropApiFile() android.OptionalPath { | 
| Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 250 | return m.currentApiFile | 
|  | 251 | } | 
|  | 252 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 253 | // GenerateAndroidBuildActions of sysprop_library handles API dump and API check. | 
|  | 254 | // generated java_library will depend on these API files. | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 255 | func (m *syspropLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 256 | baseModuleName := m.BaseModuleName() | 
|  | 257 |  | 
|  | 258 | for _, syspropFile := range android.PathsForModuleSrc(ctx, m.properties.Srcs) { | 
|  | 259 | if syspropFile.Ext() != ".sysprop" { | 
|  | 260 | ctx.PropertyErrorf("srcs", "srcs contains non-sysprop file %q", syspropFile.String()) | 
|  | 261 | } | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 | if ctx.Failed() { | 
|  | 265 | return | 
|  | 266 | } | 
|  | 267 |  | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 268 | apiDirectoryPath := path.Join(ctx.ModuleDir(), "api") | 
|  | 269 | currentApiFilePath := path.Join(apiDirectoryPath, baseModuleName+"-current.txt") | 
|  | 270 | latestApiFilePath := path.Join(apiDirectoryPath, baseModuleName+"-latest.txt") | 
|  | 271 | m.currentApiFile = android.ExistentPathForSource(ctx, currentApiFilePath) | 
|  | 272 | m.latestApiFile = android.ExistentPathForSource(ctx, latestApiFilePath) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 273 |  | 
|  | 274 | // dump API rule | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 275 | rule := android.NewRuleBuilder(pctx, ctx) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 276 | m.dumpedApiFile = android.PathForModuleOut(ctx, "api-dump.txt") | 
|  | 277 | rule.Command(). | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 278 | BuiltTool("sysprop_api_dump"). | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 279 | Output(m.dumpedApiFile). | 
|  | 280 | Inputs(android.PathsForModuleSrc(ctx, m.properties.Srcs)) | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 281 | rule.Build(baseModuleName+"_api_dump", baseModuleName+" api dump") | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 282 |  | 
|  | 283 | // check API rule | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 284 | rule = android.NewRuleBuilder(pctx, ctx) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 285 |  | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 286 | // We allow that the API txt files don't exist, when the sysprop_library only contains internal | 
|  | 287 | // properties. But we have to feed current api file and latest api file to the rule builder. | 
|  | 288 | // Currently we can't get android.Path representing the null device, so we add any existing API | 
|  | 289 | // txt files to implicits, and then directly feed string paths, rather than calling Input(Path) | 
|  | 290 | // method. | 
|  | 291 | var apiFileList android.Paths | 
|  | 292 | currentApiArgument := os.DevNull | 
|  | 293 | if m.currentApiFile.Valid() { | 
|  | 294 | apiFileList = append(apiFileList, m.currentApiFile.Path()) | 
|  | 295 | currentApiArgument = m.currentApiFile.String() | 
|  | 296 | } | 
|  | 297 |  | 
|  | 298 | latestApiArgument := os.DevNull | 
|  | 299 | if m.latestApiFile.Valid() { | 
|  | 300 | apiFileList = append(apiFileList, m.latestApiFile.Path()) | 
|  | 301 | latestApiArgument = m.latestApiFile.String() | 
|  | 302 | } | 
|  | 303 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 304 | // 1. compares current.txt to api-dump.txt | 
|  | 305 | // current.txt should be identical to api-dump.txt. | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 306 | msg := fmt.Sprintf(`\n******************************\n`+ | 
|  | 307 | `API of sysprop_library %s doesn't match with current.txt\n`+ | 
|  | 308 | `Please update current.txt by:\n`+ | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 309 | `m %s-dump-api && mkdir -p %q && rm -rf %q && cp -f %q %q\n`+ | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 310 | `******************************\n`, baseModuleName, baseModuleName, | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 311 | apiDirectoryPath, currentApiFilePath, m.dumpedApiFile.String(), currentApiFilePath) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 312 |  | 
|  | 313 | rule.Command(). | 
|  | 314 | Text("( cmp").Flag("-s"). | 
|  | 315 | Input(m.dumpedApiFile). | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 316 | Text(currentApiArgument). | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 317 | Text("|| ( echo").Flag("-e"). | 
|  | 318 | Flag(`"` + msg + `"`). | 
|  | 319 | Text("; exit 38) )") | 
|  | 320 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 321 | // 2. compares current.txt to latest.txt (frozen API) | 
|  | 322 | // current.txt should be compatible with latest.txt | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 323 | msg = fmt.Sprintf(`\n******************************\n`+ | 
|  | 324 | `API of sysprop_library %s doesn't match with latest version\n`+ | 
|  | 325 | `Please fix the breakage and rebuild.\n`+ | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 326 | `******************************\n`, baseModuleName) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 327 |  | 
|  | 328 | rule.Command(). | 
|  | 329 | Text("( "). | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 330 | BuiltTool("sysprop_api_checker"). | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 331 | Text(latestApiArgument). | 
|  | 332 | Text(currentApiArgument). | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 333 | Text(" || ( echo").Flag("-e"). | 
|  | 334 | Flag(`"` + msg + `"`). | 
| Inseob Kim | c9770d6 | 2021-01-15 18:04:20 +0900 | [diff] [blame] | 335 | Text("; exit 38) )"). | 
|  | 336 | Implicits(apiFileList) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 337 |  | 
|  | 338 | m.checkApiFileTimeStamp = android.PathForModuleOut(ctx, "check_api.timestamp") | 
|  | 339 |  | 
|  | 340 | rule.Command(). | 
|  | 341 | Text("touch"). | 
|  | 342 | Output(m.checkApiFileTimeStamp) | 
|  | 343 |  | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 344 | rule.Build(baseModuleName+"_check_api", baseModuleName+" check api") | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 345 | } | 
|  | 346 |  | 
|  | 347 | func (m *syspropLibrary) AndroidMk() android.AndroidMkData { | 
|  | 348 | return android.AndroidMkData{ | 
|  | 349 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { | 
|  | 350 | // sysprop_library module itself is defined as a FAKE module to perform API check. | 
|  | 351 | // Actual implementation libraries are created on LoadHookMutator | 
| Sasha Smundak | 5c4729d | 2022-12-01 10:49:23 -0800 | [diff] [blame] | 352 | fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)", " # sysprop.syspropLibrary") | 
|  | 353 | fmt.Fprintln(w, "LOCAL_MODULE :=", m.Name()) | 
| Bob Badour | b499922 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 354 | data.Entries.WriteLicenseVariables(w) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 355 | fmt.Fprintf(w, "LOCAL_MODULE_CLASS := FAKE\n") | 
|  | 356 | fmt.Fprintf(w, "LOCAL_MODULE_TAGS := optional\n") | 
|  | 357 | fmt.Fprintf(w, "include $(BUILD_SYSTEM)/base_rules.mk\n\n") | 
|  | 358 | fmt.Fprintf(w, "$(LOCAL_BUILT_MODULE): %s\n", m.checkApiFileTimeStamp.String()) | 
|  | 359 | fmt.Fprintf(w, "\ttouch $@\n\n") | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 360 | fmt.Fprintf(w, ".PHONY: %s-check-api %s-dump-api\n\n", name, name) | 
|  | 361 |  | 
|  | 362 | // dump API rule | 
|  | 363 | fmt.Fprintf(w, "%s-dump-api: %s\n\n", name, m.dumpedApiFile.String()) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 364 |  | 
|  | 365 | // check API rule | 
|  | 366 | fmt.Fprintf(w, "%s-check-api: %s\n\n", name, m.checkApiFileTimeStamp.String()) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 367 | }} | 
|  | 368 | } | 
|  | 369 |  | 
| Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 370 | var _ android.ApexModule = (*syspropLibrary)(nil) | 
|  | 371 |  | 
|  | 372 | // Implements android.ApexModule | 
| Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 373 | func (m *syspropLibrary) ShouldSupportSdkVersion(ctx android.BaseModuleContext, | 
|  | 374 | sdkVersion android.ApiLevel) error { | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 375 | return fmt.Errorf("sysprop_library is not supposed to be part of apex modules") | 
|  | 376 | } | 
|  | 377 |  | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 378 | // sysprop_library creates schematized APIs from sysprop description files (.sysprop). | 
|  | 379 | // Both Java and C++ modules can link against sysprop_library, and API stability check | 
|  | 380 | // against latest APIs (see build/soong/scripts/freeze-sysprop-api-files.sh) | 
| Trevor Radcliffe | d82e8f6 | 2022-06-08 16:16:31 +0000 | [diff] [blame] | 381 | // is performed. Note that the generated C++ module has its name prefixed with | 
|  | 382 | // `lib`, and it is this module that should be depended on from other C++ | 
|  | 383 | // modules; i.e., if the sysprop_library module is named `foo`, C++ modules | 
|  | 384 | // should depend on `libfoo`. | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 385 | func syspropLibraryFactory() android.Module { | 
|  | 386 | m := &syspropLibrary{} | 
|  | 387 |  | 
|  | 388 | m.AddProperties( | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 389 | &m.properties, | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 390 | ) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 391 | android.InitAndroidModule(m) | 
| Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 392 | android.InitApexModule(m) | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 393 | android.InitBazelModule(m) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 394 | android.AddLoadHook(m, func(ctx android.LoadHookContext) { syspropLibraryHook(ctx, m) }) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 395 | return m | 
|  | 396 | } | 
|  | 397 |  | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 398 | type ccLibraryProperties struct { | 
|  | 399 | Name             *string | 
|  | 400 | Srcs             []string | 
|  | 401 | Soc_specific     *bool | 
|  | 402 | Device_specific  *bool | 
|  | 403 | Product_specific *bool | 
|  | 404 | Sysprop          struct { | 
|  | 405 | Platform *bool | 
|  | 406 | } | 
| Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 407 | Target struct { | 
|  | 408 | Android struct { | 
|  | 409 | Header_libs []string | 
|  | 410 | Shared_libs []string | 
|  | 411 | } | 
|  | 412 | Host struct { | 
|  | 413 | Static_libs []string | 
|  | 414 | } | 
|  | 415 | } | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 416 | Required           []string | 
|  | 417 | Recovery           *bool | 
|  | 418 | Recovery_available *bool | 
|  | 419 | Vendor_available   *bool | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 420 | Product_available  *bool | 
| Inseob Kim | 9da1f81 | 2021-06-14 12:03:59 +0900 | [diff] [blame] | 421 | Ramdisk_available  *bool | 
| Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 422 | Host_supported     *bool | 
| Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 423 | Apex_available     []string | 
| Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 424 | Min_sdk_version    *string | 
| Steven Moreland | c43a4ac | 2023-10-24 21:49:18 +0000 | [diff] [blame] | 425 | Cflags             []string | 
|  | 426 | Ldflags            []string | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 427 | Bazel_module       struct { | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 428 | Label *string | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 429 | } | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 430 | } | 
|  | 431 |  | 
|  | 432 | type javaLibraryProperties struct { | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 433 | Name              *string | 
|  | 434 | Srcs              []string | 
|  | 435 | Soc_specific      *bool | 
|  | 436 | Device_specific   *bool | 
|  | 437 | Product_specific  *bool | 
|  | 438 | Required          []string | 
|  | 439 | Sdk_version       *string | 
|  | 440 | Installable       *bool | 
|  | 441 | Libs              []string | 
|  | 442 | Stem              *string | 
|  | 443 | SyspropPublicStub string | 
| Jiyong Park | 5e914b2 | 2021-03-08 10:09:52 +0900 | [diff] [blame] | 444 | Apex_available    []string | 
|  | 445 | Min_sdk_version   *string | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 446 | Bazel_module      struct { | 
|  | 447 | Bp2build_available *bool | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 448 | Label              *string | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 449 | } | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 450 | } | 
|  | 451 |  | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 452 | func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) { | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 453 | if len(m.properties.Srcs) == 0 { | 
| Inseob Kim | 6e93ac9 | 2019-03-21 17:43:49 +0900 | [diff] [blame] | 454 | ctx.PropertyErrorf("srcs", "sysprop_library must specify srcs") | 
|  | 455 | } | 
|  | 456 |  | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 457 | // ctx's Platform or Specific functions represent where this sysprop_library installed. | 
|  | 458 | installedInSystem := ctx.Platform() || ctx.SystemExtSpecific() | 
|  | 459 | installedInVendorOrOdm := ctx.SocSpecific() || ctx.DeviceSpecific() | 
| Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 460 | installedInProduct := ctx.ProductSpecific() | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 461 | isOwnerPlatform := false | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 462 | var javaSyspropStub string | 
| Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 463 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 464 | // javaSyspropStub contains stub libraries used by generated APIs, instead of framework stub. | 
|  | 465 | // This is to make sysprop_library link against core_current. | 
| Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 466 | if installedInVendorOrOdm { | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 467 | javaSyspropStub = "sysprop-library-stub-vendor" | 
| Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 468 | } else if installedInProduct { | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 469 | javaSyspropStub = "sysprop-library-stub-product" | 
| Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 470 | } else { | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 471 | javaSyspropStub = "sysprop-library-stub-platform" | 
| Inseob Kim | fe61218 | 2020-10-20 16:29:55 +0900 | [diff] [blame] | 472 | } | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 473 |  | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 474 | switch m.Owner() { | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 475 | case "Platform": | 
|  | 476 | // Every partition can access platform-defined properties | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 477 | isOwnerPlatform = true | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 478 | case "Vendor": | 
|  | 479 | // System can't access vendor's properties | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 480 | if installedInSystem { | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 481 | ctx.ModuleErrorf("None of soc_specific, device_specific, product_specific is true. " + | 
|  | 482 | "System can't access sysprop_library owned by Vendor") | 
|  | 483 | } | 
|  | 484 | case "Odm": | 
|  | 485 | // Only vendor can access Odm-defined properties | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 486 | if !installedInVendorOrOdm { | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 487 | ctx.ModuleErrorf("Neither soc_speicifc nor device_specific is true. " + | 
|  | 488 | "Odm-defined properties should be accessed only in Vendor or Odm") | 
|  | 489 | } | 
|  | 490 | default: | 
|  | 491 | ctx.PropertyErrorf("property_owner", | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 492 | "Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner()) | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 493 | } | 
|  | 494 |  | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 495 | var label *string | 
|  | 496 | if b, ok := ctx.Module().(android.Bazelable); ok && b.ShouldConvertWithBp2build(ctx) { | 
|  | 497 | // TODO: b/295566168 - this will need to change once build files are checked in to account for | 
|  | 498 | // checked in modules in mixed builds | 
|  | 499 | label = proptools.StringPtr( | 
|  | 500 | fmt.Sprintf("//%s:%s", ctx.ModuleDir(), m.CcImplementationModuleName())) | 
|  | 501 | } | 
|  | 502 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 503 | // Generate a C++ implementation library. | 
|  | 504 | // cc_library can receive *.sysprop files as their srcs, generating sources itself. | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 505 | ccProps := ccLibraryProperties{} | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 506 | ccProps.Name = proptools.StringPtr(m.CcImplementationModuleName()) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 507 | ccProps.Srcs = m.properties.Srcs | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 508 | ccProps.Soc_specific = proptools.BoolPtr(ctx.SocSpecific()) | 
|  | 509 | ccProps.Device_specific = proptools.BoolPtr(ctx.DeviceSpecific()) | 
|  | 510 | ccProps.Product_specific = proptools.BoolPtr(ctx.ProductSpecific()) | 
|  | 511 | ccProps.Sysprop.Platform = proptools.BoolPtr(isOwnerPlatform) | 
| Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 512 | ccProps.Target.Android.Header_libs = []string{"libbase_headers"} | 
|  | 513 | ccProps.Target.Android.Shared_libs = []string{"liblog"} | 
|  | 514 | ccProps.Target.Host.Static_libs = []string{"libbase", "liblog"} | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 515 | ccProps.Recovery_available = m.properties.Recovery_available | 
|  | 516 | ccProps.Vendor_available = m.properties.Vendor_available | 
| Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 517 | ccProps.Product_available = m.properties.Product_available | 
| Inseob Kim | 9da1f81 | 2021-06-14 12:03:59 +0900 | [diff] [blame] | 518 | ccProps.Ramdisk_available = m.properties.Ramdisk_available | 
| Inseob Kim | 89db15d | 2020-02-03 18:06:46 +0900 | [diff] [blame] | 519 | ccProps.Host_supported = m.properties.Host_supported | 
| Paul Duffin | 7b3de8f | 2020-03-30 18:00:25 +0100 | [diff] [blame] | 520 | ccProps.Apex_available = m.ApexProperties.Apex_available | 
| Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 521 | ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version | 
| Steven Moreland | c43a4ac | 2023-10-24 21:49:18 +0000 | [diff] [blame] | 522 | ccProps.Cflags = m.properties.Cpp.Cflags | 
|  | 523 | ccProps.Ldflags = m.properties.Cpp.Ldflags | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 524 | ccProps.Bazel_module.Label = label | 
| Colin Cross | 84dfc3d | 2019-09-25 11:33:01 -0700 | [diff] [blame] | 525 | ctx.CreateModule(cc.LibraryFactory, &ccProps) | 
| Inseob Kim | 4288274 | 2019-07-30 17:55:33 +0900 | [diff] [blame] | 526 |  | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 527 | scope := "internal" | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 528 |  | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 529 | // We need to only use public version, if the partition where sysprop_library will be installed | 
|  | 530 | // is different from owner. | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 531 | if ctx.ProductSpecific() { | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 532 | // Currently product partition can't own any sysprop_library. So product always uses public. | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 533 | scope = "public" | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 534 | } else if isOwnerPlatform && installedInVendorOrOdm { | 
|  | 535 | // Vendor or Odm should use public version of Platform's sysprop_library. | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 536 | scope = "public" | 
|  | 537 | } | 
|  | 538 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 539 | // Generate a Java implementation library. | 
|  | 540 | // Contrast to C++, syspropJavaGenRule module will generate srcjar and the srcjar will be fed | 
|  | 541 | // to Java implementation library. | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 542 | ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{ | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 543 | Srcs:      m.properties.Srcs, | 
|  | 544 | Scope:     scope, | 
|  | 545 | Name:      proptools.StringPtr(m.javaGenModuleName()), | 
|  | 546 | Check_api: proptools.StringPtr(ctx.ModuleName()), | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 547 | }) | 
|  | 548 |  | 
|  | 549 | // if platform sysprop_library is installed in /system or /system-ext, we regard it as an API | 
|  | 550 | // and allow any modules (even from different partition) to link against the sysprop_library. | 
|  | 551 | // To do that, we create a public stub and expose it to modules with sdk_version: system_*. | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 552 | var publicStub string | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 553 | if isOwnerPlatform && installedInSystem { | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 554 | publicStub = m.javaPublicStubName() | 
|  | 555 | } | 
|  | 556 |  | 
|  | 557 | ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{ | 
|  | 558 | Name:              proptools.StringPtr(m.BaseModuleName()), | 
|  | 559 | Srcs:              []string{":" + m.javaGenModuleName()}, | 
|  | 560 | Soc_specific:      proptools.BoolPtr(ctx.SocSpecific()), | 
|  | 561 | Device_specific:   proptools.BoolPtr(ctx.DeviceSpecific()), | 
|  | 562 | Product_specific:  proptools.BoolPtr(ctx.ProductSpecific()), | 
|  | 563 | Installable:       m.properties.Installable, | 
|  | 564 | Sdk_version:       proptools.StringPtr("core_current"), | 
|  | 565 | Libs:              []string{javaSyspropStub}, | 
|  | 566 | SyspropPublicStub: publicStub, | 
| Jiyong Park | 5e914b2 | 2021-03-08 10:09:52 +0900 | [diff] [blame] | 567 | Apex_available:    m.ApexProperties.Apex_available, | 
|  | 568 | Min_sdk_version:   m.properties.Java.Min_sdk_version, | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 569 | Bazel_module: struct { | 
|  | 570 | Bp2build_available *bool | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 571 | Label              *string | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 572 | }{ | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 573 | Label: proptools.StringPtr( | 
|  | 574 | fmt.Sprintf("//%s:%s", ctx.ModuleDir(), m.bp2buildJavaImplementationModuleName())), | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 575 | }, | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 576 | }) | 
|  | 577 |  | 
|  | 578 | if publicStub != "" { | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 579 | ctx.CreateModule(syspropJavaGenFactory, &syspropGenProperties{ | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 580 | Srcs:      m.properties.Srcs, | 
|  | 581 | Scope:     "public", | 
|  | 582 | Name:      proptools.StringPtr(m.javaGenPublicStubName()), | 
|  | 583 | Check_api: proptools.StringPtr(ctx.ModuleName()), | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 584 | }) | 
|  | 585 |  | 
|  | 586 | ctx.CreateModule(java.LibraryFactory, &javaLibraryProperties{ | 
| Colin Cross | 75ce9ec | 2021-02-26 16:20:32 -0800 | [diff] [blame] | 587 | Name:        proptools.StringPtr(publicStub), | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 588 | Srcs:        []string{":" + m.javaGenPublicStubName()}, | 
|  | 589 | Installable: proptools.BoolPtr(false), | 
|  | 590 | Sdk_version: proptools.StringPtr("core_current"), | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 591 | Libs:        []string{javaSyspropStub}, | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 592 | Stem:        proptools.StringPtr(m.BaseModuleName()), | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 593 | Bazel_module: struct { | 
|  | 594 | Bp2build_available *bool | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 595 | Label              *string | 
| Liz Kammer | 12dc96e | 2023-08-11 14:16:05 -0400 | [diff] [blame] | 596 | }{ | 
|  | 597 | Bp2build_available: proptools.BoolPtr(false), | 
|  | 598 | }, | 
| Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 599 | }) | 
| Inseob Kim | 988f53c | 2019-09-16 15:59:01 +0900 | [diff] [blame] | 600 | } | 
| Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 601 |  | 
| Inseob Kim | 07def12 | 2020-11-23 14:43:02 +0900 | [diff] [blame] | 602 | // syspropLibraries will be used by property_contexts to check types. | 
|  | 603 | // Record absolute paths of sysprop_library to prevent soong_namespace problem. | 
| Inseob Kim | 69cf09e | 2020-05-04 19:28:25 +0900 | [diff] [blame] | 604 | if m.ExportedToMake() { | 
|  | 605 | syspropLibrariesLock.Lock() | 
|  | 606 | defer syspropLibrariesLock.Unlock() | 
| Inseob Kim | 628d7ef | 2020-03-21 03:38:32 +0900 | [diff] [blame] | 607 |  | 
| Inseob Kim | 69cf09e | 2020-05-04 19:28:25 +0900 | [diff] [blame] | 608 | libraries := syspropLibraries(ctx.Config()) | 
|  | 609 | *libraries = append(*libraries, "//"+ctx.ModuleDir()+":"+ctx.ModuleName()) | 
|  | 610 | } | 
| Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 611 | } | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 612 |  | 
|  | 613 | // TODO(b/240463568): Additional properties will be added for API validation | 
| Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 614 | func (m *syspropLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 615 | if m.Owner() != "Platform" { | 
|  | 616 | ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "Only sysprop libraries owned by platform are supported at this time") | 
|  | 617 | return | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 618 | } | 
| Trevor Radcliffe | 9b81d79 | 2023-09-29 15:22:52 +0000 | [diff] [blame] | 619 | labels := bp2build.SyspropLibraryLabels{ | 
|  | 620 | SyspropLibraryLabel:  m.BaseModuleName(), | 
|  | 621 | CcSharedLibraryLabel: m.CcImplementationModuleName(), | 
|  | 622 | CcStaticLibraryLabel: cc.BazelLabelNameForStaticModule(m.CcImplementationModuleName()), | 
|  | 623 | JavaLibraryLabel:     m.bp2buildJavaImplementationModuleName(), | 
|  | 624 | } | 
|  | 625 | bp2build.Bp2buildBaseSyspropLibrary(ctx, labels.SyspropLibraryLabel, bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs))) | 
|  | 626 | bp2build.Bp2buildSyspropCc(ctx, labels, m.properties.Cpp.Min_sdk_version) | 
|  | 627 | bp2build.Bp2buildSyspropJava(ctx, labels, m.properties.Java.Min_sdk_version) | 
| Trevor Radcliffe | ad3d123 | 2022-09-01 16:25:10 +0000 | [diff] [blame] | 628 | } |