Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package apex |
| 18 | |
| 19 | import ( |
Artur Satayev | a4405fa | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 20 | "github.com/google/blueprint" |
Artur Satayev | 9af168d | 2020-06-24 10:17:19 +0000 | [diff] [blame] | 21 | |
| 22 | "android/soong/android" |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | func init() { |
| 26 | android.RegisterSingletonType("apex_depsinfo_singleton", apexDepsInfoSingletonFactory) |
| 27 | } |
| 28 | |
| 29 | type apexDepsInfoSingleton struct { |
Artur Satayev | 019560f | 2020-07-02 11:51:47 +0000 | [diff] [blame] | 30 | allowedApexDepsInfoCheckResult android.OutputPath |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | func apexDepsInfoSingletonFactory() android.Singleton { |
| 34 | return &apexDepsInfoSingleton{} |
| 35 | } |
| 36 | |
Artur Satayev | 019560f | 2020-07-02 11:51:47 +0000 | [diff] [blame] | 37 | var ( |
| 38 | // Generate new apex allowed_deps.txt by merging all internal dependencies. |
| 39 | generateApexDepsInfoFilesRule = pctx.AndroidStaticRule("generateApexDepsInfoFilesRule", blueprint.RuleParams{ |
| 40 | Command: "cat $out.rsp | xargs cat" + |
| 41 | // Only track non-external dependencies, i.e. those that end up in the binary |
| 42 | " | grep -v '(external)'" + |
| 43 | // Ignore comments in any of the files |
| 44 | " | grep -v '^#'" + |
| 45 | " | sort -u -f >$out", |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 46 | Rspfile: "$out.rsp", |
| 47 | RspfileContent: "$in", |
Artur Satayev | 019560f | 2020-07-02 11:51:47 +0000 | [diff] [blame] | 48 | }) |
| 49 | |
| 50 | // Diff two given lists while ignoring comments in the allowed deps file. |
| 51 | diffAllowedApexDepsInfoRule = pctx.AndroidStaticRule("diffAllowedApexDepsInfoRule", blueprint.RuleParams{ |
| 52 | Description: "Diff ${allowed_deps} and ${new_allowed_deps}", |
| 53 | Command: ` |
| 54 | if grep -v '^#' ${allowed_deps} | diff -B - ${new_allowed_deps}; then |
| 55 | touch ${out}; |
| 56 | else |
| 57 | echo -e "\n******************************"; |
| 58 | echo "ERROR: go/apex-allowed-deps-error"; |
| 59 | echo "******************************"; |
| 60 | echo "Detected changes to allowed dependencies in updatable modules."; |
Artur Satayev | 8dfcbe4 | 2021-03-11 16:45:04 +0000 | [diff] [blame] | 61 | echo "To fix and update packages/modules/common/build/allowed_deps.txt, please run:"; |
Mathew Inwood | 768a011 | 2021-08-02 16:43:05 +0100 | [diff] [blame] | 62 | echo -e "$$ (croot && packages/modules/common/build/update-apex-allowed-deps.sh)\n"; |
| 63 | echo "When submitting the generated CL, you must include the following information"; |
| 64 | echo "in the commit message if you are adding a new dependency:"; |
| 65 | echo "Apex-Size-Increase:"; |
| 66 | echo "Previous-Platform-Support:"; |
| 67 | echo "Aosp-First:"; |
| 68 | echo "Test-Info:"; |
| 69 | echo "You do not need OWNERS approval to submit the change, but mainline-modularization@"; |
| 70 | echo "will periodically review additions and may require changes."; |
Artur Satayev | 019560f | 2020-07-02 11:51:47 +0000 | [diff] [blame] | 71 | echo -e "******************************\n"; |
| 72 | exit 1; |
| 73 | fi; |
| 74 | `, |
| 75 | }, "allowed_deps", "new_allowed_deps") |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 76 | ) |
| 77 | |
| 78 | func (s *apexDepsInfoSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
Artur Satayev | 9af168d | 2020-06-24 10:17:19 +0000 | [diff] [blame] | 79 | updatableFlatLists := android.Paths{} |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 80 | ctx.VisitAllModules(func(module android.Module) { |
| 81 | if binaryInfo, ok := module.(android.ApexBundleDepsInfoIntf); ok { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 82 | apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) |
| 83 | if path := binaryInfo.FlatListPath(); path != nil { |
| 84 | if binaryInfo.Updatable() || apexInfo.Updatable { |
| 85 | updatableFlatLists = append(updatableFlatLists, path) |
| 86 | } |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | }) |
| 90 | |
Artur Satayev | b77b0c5 | 2021-03-18 11:04:09 +0000 | [diff] [blame] | 91 | allowedDepsSource := android.ExistentPathForSource(ctx, "packages/modules/common/build/allowed_deps.txt") |
Artur Satayev | 019560f | 2020-07-02 11:51:47 +0000 | [diff] [blame] | 92 | newAllowedDeps := android.PathForOutput(ctx, "apex", "depsinfo", "new-allowed-deps.txt") |
Artur Satayev | 019560f | 2020-07-02 11:51:47 +0000 | [diff] [blame] | 93 | s.allowedApexDepsInfoCheckResult = android.PathForOutput(ctx, newAllowedDeps.Rel()+".check") |
Artur Satayev | b77b0c5 | 2021-03-18 11:04:09 +0000 | [diff] [blame] | 94 | |
| 95 | if !allowedDepsSource.Valid() { |
| 96 | // Unbundled projects may not have packages/modules/common/ checked out; ignore those. |
| 97 | ctx.Build(pctx, android.BuildParams{ |
| 98 | Rule: android.Touch, |
| 99 | Output: s.allowedApexDepsInfoCheckResult, |
| 100 | }) |
| 101 | } else { |
| 102 | allowedDeps := allowedDepsSource.Path() |
| 103 | |
| 104 | ctx.Build(pctx, android.BuildParams{ |
| 105 | Rule: generateApexDepsInfoFilesRule, |
| 106 | Inputs: append(updatableFlatLists, allowedDeps), |
| 107 | Output: newAllowedDeps, |
| 108 | }) |
| 109 | |
| 110 | ctx.Build(pctx, android.BuildParams{ |
| 111 | Rule: diffAllowedApexDepsInfoRule, |
| 112 | Input: newAllowedDeps, |
| 113 | Output: s.allowedApexDepsInfoCheckResult, |
| 114 | Args: map[string]string{ |
| 115 | "allowed_deps": allowedDeps.String(), |
| 116 | "new_allowed_deps": newAllowedDeps.String(), |
| 117 | }, |
| 118 | }) |
| 119 | } |
Artur Satayev | 01aa11e | 2020-07-30 18:26:28 +0100 | [diff] [blame] | 120 | |
| 121 | ctx.Phony("apex-allowed-deps-check", s.allowedApexDepsInfoCheckResult) |
Artur Satayev | 019560f | 2020-07-02 11:51:47 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | func (s *apexDepsInfoSingleton) MakeVars(ctx android.MakeVarsContext) { |
| 125 | // Export check result to Make. The path is added to droidcore. |
| 126 | ctx.Strict("APEX_ALLOWED_DEPS_CHECK", s.allowedApexDepsInfoCheckResult.String()) |
Artur Satayev | 849f844 | 2020-04-28 14:57:42 +0100 | [diff] [blame] | 127 | } |