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