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