• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package dexpreopt
2
3import "android/soong/android"
4
5func init() {
6	android.InitRegistrationContext.RegisterSingletonType("dexpreopt_tools_zip_singleton", dexpreoptToolsZipSingletonFactory)
7}
8
9func dexpreoptToolsZipSingletonFactory() android.Singleton {
10	return &dexpreoptToolsZipSingleton{}
11}
12
13type dexpreoptToolsZipSingleton struct{}
14
15func (s *dexpreoptToolsZipSingleton) GenerateBuildActions(ctx android.SingletonContext) {
16	// The mac build doesn't build dex2oat, so create the zip file only if the build OS is linux.
17	if !ctx.Config().BuildOS.Linux() {
18		return
19	}
20	global := GetGlobalConfig(ctx)
21	if global.DisablePreopt {
22		return
23	}
24	config := GetCachedGlobalSoongConfig(ctx)
25	if config == nil {
26		return
27	}
28
29	deps := android.Paths{
30		ctx.Config().HostToolPath(ctx, "dexpreopt_gen"),
31		ctx.Config().HostToolPath(ctx, "dexdump"),
32		ctx.Config().HostToolPath(ctx, "oatdump"),
33		config.Profman,
34		config.Dex2oat,
35		config.Aapt,
36		config.SoongZip,
37		config.Zip2zip,
38		config.ManifestCheck,
39		config.ConstructContext,
40		config.UffdGcFlag,
41	}
42
43	out := android.PathForOutput(ctx, "dexpreopt_tools.zip")
44	builder := android.NewRuleBuilder(pctx, ctx)
45
46	cmd := builder.Command().BuiltTool("soong_zip").
47		Flag("-d").
48		FlagWithOutput("-o ", out).
49		Flag("-j")
50
51	for _, dep := range deps {
52		cmd.FlagWithInput("-f ", dep)
53	}
54
55	// This reads through a symlink to include the file it points to. This isn't great for
56	// build reproducibility, will need to be revisited later.
57	cmd.Textf("-f $(realpath %s)", config.Dex2oat)
58
59	builder.Build("dexpreopt_tools_zip", "building dexpreopt_tools.zip")
60
61	ctx.DistForGoal("droidcore", out)
62}
63