1// Copyright 2020 Google Inc. All rights reserved.
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
15package java
16
17import (
18	"android/soong/android"
19)
20
21// isActiveModule returns true if the given module should be considered for boot
22// jars, i.e. if it's enabled and the preferred one in case of source and
23// prebuilt alternatives.
24func isActiveModule(ctx android.ConfigAndErrorContext, module android.Module) bool {
25	if !module.Enabled(ctx) {
26		return false
27	}
28	return android.IsModulePreferred(module)
29}
30
31// buildRuleForBootJarsPackageCheck generates the build rule to perform the boot jars package
32// check.
33func buildRuleForBootJarsPackageCheck(ctx android.ModuleContext, bootDexJarByModule bootDexJarByModule) {
34	bootDexJars := bootDexJarByModule.bootDexJarsWithoutCoverage()
35	if len(bootDexJars) == 0 {
36		return
37	}
38
39	timestamp := android.PathForOutput(ctx, "boot-jars-package-check/stamp")
40
41	rule := android.NewRuleBuilder(pctx, ctx)
42	rule.Command().BuiltTool("check_boot_jars").
43		Input(ctx.Config().HostToolPath(ctx, "dexdump")).
44		Input(android.PathForSource(ctx, "build/soong/scripts/check_boot_jars/package_allowed_list.txt")).
45		Inputs(bootDexJars).
46		Text("&& touch").Output(timestamp)
47	rule.Build("boot_jars_package_check", "check boot jar packages")
48
49	// The check-boot-jars phony target depends on the timestamp created if the check succeeds.
50	ctx.Phony("check-boot-jars", timestamp)
51
52	// The droidcore phony target depends on the check-boot-jars phony target
53	ctx.Phony("droidcore", android.PathForPhony(ctx, "check-boot-jars"))
54}
55