Cole Faust | a04b589 | 2024-12-18 15:07:59 -0800 | [diff] [blame^] | 1 | package android |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/google/blueprint" |
| 7 | "github.com/google/blueprint/proptools" |
| 8 | ) |
| 9 | |
| 10 | func init() { |
| 11 | InitRegistrationContext.RegisterModuleType("removed_package", removedPackageModuleFactory) |
| 12 | } |
| 13 | |
| 14 | type removedPackageModuleProps struct { |
| 15 | // The error message to display when this module is built. This is optional, there is a |
| 16 | // reasonable default message. |
| 17 | Message *string |
| 18 | } |
| 19 | |
| 20 | type removedPackageModule struct { |
| 21 | ModuleBase |
| 22 | properties removedPackageModuleProps |
| 23 | } |
| 24 | |
| 25 | // removed_package will cause a build failure when it's included in PRODUCT_PACKAGES. It's needed |
| 26 | // because currently you can add non-existent packages to PRODUCT_PACKAGES, and the build will |
| 27 | // not notice/complain, unless you opt-into enforcement via $(call enforce-product-packages-exist). |
| 28 | // Opting into the enforcement is difficult in some cases, because a package exists on some source |
| 29 | // trees but not on others. removed_package is an intermediate solution that allows you to remove |
| 30 | // a package and still get an error if it remains in PRODUCT_PACKAGES somewhere. |
| 31 | func removedPackageModuleFactory() Module { |
| 32 | m := &removedPackageModule{} |
| 33 | InitAndroidModule(m) |
| 34 | m.AddProperties(&m.properties) |
| 35 | return m |
| 36 | } |
| 37 | |
| 38 | var removedPackageRule = pctx.AndroidStaticRule("removed_package", blueprint.RuleParams{ |
| 39 | Command: "echo $message && false", |
| 40 | }, "message") |
| 41 | |
| 42 | func (m *removedPackageModule) GenerateAndroidBuildActions(ctx ModuleContext) { |
| 43 | // Unchecked module so that checkbuild doesn't fail |
| 44 | ctx.UncheckedModule() |
| 45 | |
| 46 | out := PathForModuleOut(ctx, "out.txt") |
| 47 | message := fmt.Sprintf("%s has been removed, and can no longer be used.", ctx.ModuleName()) |
| 48 | if m.properties.Message != nil { |
| 49 | message = *m.properties.Message |
| 50 | } |
| 51 | ctx.Build(pctx, BuildParams{ |
| 52 | Rule: removedPackageRule, |
| 53 | Output: out, |
| 54 | Args: map[string]string{ |
| 55 | "message": proptools.ShellEscape(message), |
| 56 | }, |
| 57 | }) |
| 58 | |
| 59 | ctx.InstallFile(PathForModuleInstall(ctx, "removed_module"), ctx.ModuleName(), out) |
| 60 | } |