| Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 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 |  | 
|  | 15 | package java | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 | ) | 
|  | 20 |  | 
| Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 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. | 
| Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 24 | func isActiveModule(ctx android.ConfigAndErrorContext, module android.Module) bool { | 
|  | 25 | if !module.Enabled(ctx) { | 
| Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 26 | return false | 
|  | 27 | } | 
| Paul Duffin | e1d3837 | 2021-04-02 10:35:24 +0100 | [diff] [blame] | 28 | return android.IsModulePreferred(module) | 
| Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 29 | } | 
|  | 30 |  | 
| Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 31 | // buildRuleForBootJarsPackageCheck generates the build rule to perform the boot jars package | 
|  | 32 | // check. | 
|  | 33 | func buildRuleForBootJarsPackageCheck(ctx android.ModuleContext, bootDexJarByModule bootDexJarByModule) { | 
| Paul Duffin | 9ffbecc | 2021-06-22 14:48:12 +0100 | [diff] [blame] | 34 | bootDexJars := bootDexJarByModule.bootDexJarsWithoutCoverage() | 
|  | 35 | if len(bootDexJars) == 0 { | 
|  | 36 | return | 
|  | 37 | } | 
|  | 38 |  | 
| Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 39 | timestamp := android.PathForOutput(ctx, "boot-jars-package-check/stamp") | 
|  | 40 |  | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 41 | rule := android.NewRuleBuilder(pctx, ctx) | 
| Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 42 | rule.Command().BuiltTool("check_boot_jars"). | 
| Paul Duffin | 2d8e1a7 | 2020-10-29 12:56:09 +0000 | [diff] [blame] | 43 | Input(ctx.Config().HostToolPath(ctx, "dexdump")). | 
| Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 44 | Input(android.PathForSource(ctx, "build/soong/scripts/check_boot_jars/package_allowed_list.txt")). | 
| Paul Duffin | 9ffbecc | 2021-06-22 14:48:12 +0100 | [diff] [blame] | 45 | Inputs(bootDexJars). | 
| Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 46 | Text("&& touch").Output(timestamp) | 
| Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 47 | rule.Build("boot_jars_package_check", "check boot jar packages") | 
| Paul Duffin | 9a89a2a | 2020-10-28 19:20:06 +0000 | [diff] [blame] | 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 | } |