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