summaryrefslogtreecommitdiff
path: root/android/removed_package.go
blob: aa54c2a138151248a7d0980d1190430479a822cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package android

import (
	"fmt"

	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"
)

func init() {
	InitRegistrationContext.RegisterModuleType("removed_package", removedPackageModuleFactory)
}

type removedPackageModuleProps struct {
	// The error message to display when this module is built. This is optional, there is a
	// reasonable default message.
	Message *string
}

type removedPackageModule struct {
	ModuleBase
	properties removedPackageModuleProps
}

// removed_package will cause a build failure when it's included in PRODUCT_PACKAGES. It's needed
// because currently you can add non-existent packages to PRODUCT_PACKAGES, and the build will
// not notice/complain, unless you opt-into enforcement via $(call enforce-product-packages-exist).
// Opting into the enforcement is difficult in some cases, because a package exists on some source
// trees but not on others. removed_package is an intermediate solution that allows you to remove
// a package and still get an error if it remains in PRODUCT_PACKAGES somewhere.
func removedPackageModuleFactory() Module {
	m := &removedPackageModule{}
	InitAndroidModule(m)
	m.AddProperties(&m.properties)
	return m
}

var removedPackageRule = pctx.AndroidStaticRule("removed_package", blueprint.RuleParams{
	Command: "echo $message && false",
}, "message")

func (m *removedPackageModule) GenerateAndroidBuildActions(ctx ModuleContext) {
	// Unchecked module so that checkbuild doesn't fail
	ctx.UncheckedModule()

	out := PathForModuleOut(ctx, "out.txt")
	message := fmt.Sprintf("%s has been removed, and can no longer be used.", ctx.ModuleName())
	if m.properties.Message != nil {
		message = *m.properties.Message
	}
	ctx.Build(pctx, BuildParams{
		Rule:   removedPackageRule,
		Output: out,
		Args: map[string]string{
			"message": proptools.ShellEscape(message),
		},
	})

	ctx.InstallFile(PathForModuleInstall(ctx, "removed_module"), ctx.ModuleName(), out)
}