blob: a63344fc108743494d4c27d16c2abb85f6a5f77c [file] [log] [blame]
Artur Satayev849f8442020-04-28 14:57:42 +01001/*
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
17package apex
18
19import (
Artur Satayeva4405fa2020-05-14 15:15:01 +010020 "github.com/google/blueprint"
Artur Satayev9af168d2020-06-24 10:17:19 +000021
22 "android/soong/android"
Artur Satayev849f8442020-04-28 14:57:42 +010023)
24
25func init() {
Jooyung Han4495f842023-04-25 16:39:59 +090026 registerApexDepsInfoComponents(android.InitRegistrationContext)
27}
28
29func registerApexDepsInfoComponents(ctx android.RegistrationContext) {
LaMont Jones0c10e4d2023-05-16 00:58:37 +000030 ctx.RegisterParallelSingletonType("apex_depsinfo_singleton", apexDepsInfoSingletonFactory)
Artur Satayev849f8442020-04-28 14:57:42 +010031}
32
33type apexDepsInfoSingleton struct {
Artur Satayev019560f2020-07-02 11:51:47 +000034 allowedApexDepsInfoCheckResult android.OutputPath
Artur Satayev849f8442020-04-28 14:57:42 +010035}
36
37func apexDepsInfoSingletonFactory() android.Singleton {
38 return &apexDepsInfoSingleton{}
39}
40
Artur Satayev019560f2020-07-02 11:51:47 +000041var (
42 // Generate new apex allowed_deps.txt by merging all internal dependencies.
43 generateApexDepsInfoFilesRule = pctx.AndroidStaticRule("generateApexDepsInfoFilesRule", blueprint.RuleParams{
44 Command: "cat $out.rsp | xargs cat" +
45 // Only track non-external dependencies, i.e. those that end up in the binary
46 " | grep -v '(external)'" +
47 // Ignore comments in any of the files
48 " | grep -v '^#'" +
49 " | sort -u -f >$out",
Artur Satayev849f8442020-04-28 14:57:42 +010050 Rspfile: "$out.rsp",
51 RspfileContent: "$in",
Artur Satayev019560f2020-07-02 11:51:47 +000052 })
53
54 // Diff two given lists while ignoring comments in the allowed deps file.
55 diffAllowedApexDepsInfoRule = pctx.AndroidStaticRule("diffAllowedApexDepsInfoRule", blueprint.RuleParams{
56 Description: "Diff ${allowed_deps} and ${new_allowed_deps}",
57 Command: `
58 if grep -v '^#' ${allowed_deps} | diff -B - ${new_allowed_deps}; then
59 touch ${out};
60 else
61 echo -e "\n******************************";
Pedro Loureiro87c88172023-02-07 17:08:35 +000062 echo "ERROR: go/apex-allowed-deps-error contains more information";
Artur Satayev019560f2020-07-02 11:51:47 +000063 echo "******************************";
64 echo "Detected changes to allowed dependencies in updatable modules.";
Artur Satayev8dfcbe42021-03-11 16:45:04 +000065 echo "To fix and update packages/modules/common/build/allowed_deps.txt, please run:";
Mathew Inwood768a0112021-08-02 16:43:05 +010066 echo -e "$$ (croot && packages/modules/common/build/update-apex-allowed-deps.sh)\n";
67 echo "When submitting the generated CL, you must include the following information";
68 echo "in the commit message if you are adding a new dependency:";
Pedro Loureiro87c88172023-02-07 17:08:35 +000069 echo "Apex-Size-Increase: Expected binary size increase for affected APEXes (or the size of the .jar / .so file of the new library)";
70 echo "Previous-Platform-Support: Are the maintainers of the new dependency committed to supporting previous platform releases?";
71 echo "Aosp-First: Is the new dependency being developed AOSP-first or internal?";
72 echo "Test-Info: What’s the testing strategy for the new dependency? Does it have its own tests, and are you adding integration tests? How/when are the tests run?";
Mathew Inwood768a0112021-08-02 16:43:05 +010073 echo "You do not need OWNERS approval to submit the change, but mainline-modularization@";
74 echo "will periodically review additions and may require changes.";
Artur Satayev019560f2020-07-02 11:51:47 +000075 echo -e "******************************\n";
76 exit 1;
77 fi;
78 `,
79 }, "allowed_deps", "new_allowed_deps")
Artur Satayev849f8442020-04-28 14:57:42 +010080)
81
82func (s *apexDepsInfoSingleton) GenerateBuildActions(ctx android.SingletonContext) {
Artur Satayev9af168d2020-06-24 10:17:19 +000083 updatableFlatLists := android.Paths{}
Artur Satayev849f8442020-04-28 14:57:42 +010084 ctx.VisitAllModules(func(module android.Module) {
85 if binaryInfo, ok := module.(android.ApexBundleDepsInfoIntf); ok {
Colin Cross56a83212020-09-15 18:30:11 -070086 apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
87 if path := binaryInfo.FlatListPath(); path != nil {
88 if binaryInfo.Updatable() || apexInfo.Updatable {
89 updatableFlatLists = append(updatableFlatLists, path)
90 }
Artur Satayev849f8442020-04-28 14:57:42 +010091 }
92 }
93 })
94
Artur Satayevb77b0c52021-03-18 11:04:09 +000095 allowedDepsSource := android.ExistentPathForSource(ctx, "packages/modules/common/build/allowed_deps.txt")
Artur Satayev019560f2020-07-02 11:51:47 +000096 newAllowedDeps := android.PathForOutput(ctx, "apex", "depsinfo", "new-allowed-deps.txt")
Artur Satayev019560f2020-07-02 11:51:47 +000097 s.allowedApexDepsInfoCheckResult = android.PathForOutput(ctx, newAllowedDeps.Rel()+".check")
Artur Satayevb77b0c52021-03-18 11:04:09 +000098
99 if !allowedDepsSource.Valid() {
100 // Unbundled projects may not have packages/modules/common/ checked out; ignore those.
101 ctx.Build(pctx, android.BuildParams{
102 Rule: android.Touch,
103 Output: s.allowedApexDepsInfoCheckResult,
104 })
105 } else {
106 allowedDeps := allowedDepsSource.Path()
107
108 ctx.Build(pctx, android.BuildParams{
109 Rule: generateApexDepsInfoFilesRule,
110 Inputs: append(updatableFlatLists, allowedDeps),
111 Output: newAllowedDeps,
112 })
113
114 ctx.Build(pctx, android.BuildParams{
115 Rule: diffAllowedApexDepsInfoRule,
116 Input: newAllowedDeps,
117 Output: s.allowedApexDepsInfoCheckResult,
118 Args: map[string]string{
119 "allowed_deps": allowedDeps.String(),
120 "new_allowed_deps": newAllowedDeps.String(),
121 },
122 })
123 }
Artur Satayev01aa11e2020-07-30 18:26:28 +0100124
125 ctx.Phony("apex-allowed-deps-check", s.allowedApexDepsInfoCheckResult)
Artur Satayev019560f2020-07-02 11:51:47 +0000126}
127
128func (s *apexDepsInfoSingleton) MakeVars(ctx android.MakeVarsContext) {
129 // Export check result to Make. The path is added to droidcore.
130 ctx.Strict("APEX_ALLOWED_DEPS_CHECK", s.allowedApexDepsInfoCheckResult.String())
Artur Satayev849f8442020-04-28 14:57:42 +0100131}