summaryrefslogtreecommitdiff
path: root/dexpreopt/dexpreopt_tools_zip.go
blob: c7cf128301bc82efa005a7158e22752916fb47c6 (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
61
62
package dexpreopt

import "android/soong/android"

func init() {
	android.InitRegistrationContext.RegisterSingletonType("dexpreopt_tools_zip_singleton", dexpreoptToolsZipSingletonFactory)
}

func dexpreoptToolsZipSingletonFactory() android.Singleton {
	return &dexpreoptToolsZipSingleton{}
}

type dexpreoptToolsZipSingleton struct{}

func (s *dexpreoptToolsZipSingleton) GenerateBuildActions(ctx android.SingletonContext) {
	// The mac build doesn't build dex2oat, so create the zip file only if the build OS is linux.
	if !ctx.Config().BuildOS.Linux() {
		return
	}
	global := GetGlobalConfig(ctx)
	if global.DisablePreopt {
		return
	}
	config := GetCachedGlobalSoongConfig(ctx)
	if config == nil {
		return
	}

	deps := android.Paths{
		ctx.Config().HostToolPath(ctx, "dexpreopt_gen"),
		ctx.Config().HostToolPath(ctx, "dexdump"),
		ctx.Config().HostToolPath(ctx, "oatdump"),
		config.Profman,
		config.Dex2oat,
		config.Aapt,
		config.SoongZip,
		config.Zip2zip,
		config.ManifestCheck,
		config.ConstructContext,
		config.UffdGcFlag,
	}

	out := android.PathForOutput(ctx, "dexpreopt_tools.zip")
	builder := android.NewRuleBuilder(pctx, ctx)

	cmd := builder.Command().BuiltTool("soong_zip").
		Flag("-d").
		FlagWithOutput("-o ", out).
		Flag("-j")

	for _, dep := range deps {
		cmd.FlagWithInput("-f ", dep)
	}

	// This reads through a symlink to include the file it points to. This isn't great for
	// build reproducibility, will need to be revisited later.
	cmd.Textf("-f $(realpath %s)", config.Dex2oat)

	builder.Build("dexpreopt_tools_zip", "building dexpreopt_tools.zip")

	ctx.DistForGoal("droidcore", out)
}