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