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