1// Copyright 2024 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 build 16 17import ( 18 "os" 19 "slices" 20 "strings" 21) 22 23var androidmk_denylist []string = []string{ 24 "art/", 25 "bionic/", 26 "bootable/", 27 "build/", 28 "cts/", 29 "dalvik/", 30 "developers/", 31 "development/", 32 "device/common/", 33 "device/generic/", 34 "device/google/", 35 "device/google_car/", 36 "device/sample/", 37 "external/", 38 "frameworks/", 39 "hardware/google/", 40 "hardware/interfaces/", 41 "hardware/libhardware/", 42 "hardware/libhardware_legacy/", 43 "hardware/ril/", 44 // Do not block other directories in kernel/, see b/319658303. 45 "kernel/configs/", 46 "kernel/prebuilts/", 47 "kernel/tests/", 48 "libcore/", 49 "libnativehelper/", 50 "packages/", 51 "pdk/", 52 "platform_testing/", 53 "prebuilts/", 54 "sdk/", 55 "system/", 56 "test/", 57 "tools/", 58 "trusty/", 59 "toolchain/", 60} 61 62var androidmk_allowlist []string = []string{ 63 "art/Android.mk", 64 "bootable/deprecated-ota/updater/Android.mk", 65 "tools/vendor/google_prebuilts/arc/Android.mk", 66} 67 68func getAllLines(ctx Context, filename string) []string { 69 bytes, err := os.ReadFile(filename) 70 if err != nil { 71 if os.IsNotExist(err) { 72 return []string{} 73 } else { 74 ctx.Fatalf("Could not read %s: %v", filename, err) 75 } 76 } 77 return strings.Split(strings.Trim(string(bytes), " \n"), "\n") 78} 79 80func blockAndroidMks(ctx Context, androidMks []string) { 81 allowlist_files := []string{ 82 "vendor/google/build/androidmk/allowlist.txt", 83 "device/google/clockwork/build/androidmk/allowlist.txt", 84 "device/google/sdv/androidmk/allowlist.txt", 85 } 86 for _, allowlist_file := range allowlist_files { 87 allowlist := getAllLines(ctx, allowlist_file) 88 androidmk_allowlist = append(androidmk_allowlist, allowlist...) 89 } 90 slices.Sort(androidmk_allowlist) 91 androidmk_allowlist = slices.Compact(androidmk_allowlist) 92 93 denylist := getAllLines(ctx, "vendor/google/build/androidmk/denylist.txt") 94 androidmk_denylist = append(androidmk_denylist, denylist...) 95 96 for _, mkFile := range androidMks { 97 for _, d := range androidmk_denylist { 98 if strings.HasPrefix(mkFile, d) && !slices.Contains(androidmk_allowlist, mkFile) { 99 ctx.Fatalf("Found blocked Android.mk file: %s. "+ 100 "Please see androidmk_denylist.go for the blocked directories and contact build system team if the file should not be blocked.", mkFile) 101 } 102 } 103 } 104} 105 106var external_androidmks []string = []string{ 107 // The Android.mk files in these directories are for NDK build system. 108 "external/fmtlib/", 109 "external/google-breakpad/", 110 "external/googletest/", 111 "external/libaom/", 112 "external/libusb/", 113 "external/libvpx/", 114 "external/libwebm/", 115 "external/libwebsockets/", 116 "external/vulkan-validation-layers/", 117 "external/walt/", 118 "external/webp/", 119 // These directories hold the published Android SDK, used in Unbundled Gradle builds. 120 "prebuilts/fullsdk-darwin", 121 "prebuilts/fullsdk-linux", 122 // wpa_supplicant_8 has been converted to Android.bp and Android.mk files are kept for troubleshooting. 123 "external/wpa_supplicant_8/", 124 // Empty Android.mk in package's top directory 125 "external/proguard/", 126 "external/swig/", 127 "toolchain/", 128} 129 130var art_androidmks = []string{ 131 //"art/", 132} 133 134func ignoreSomeAndroidMks(androidMks []string) (filtered []string) { 135 ignore_androidmks := make([]string, 0, len(external_androidmks)+len(art_androidmks)) 136 ignore_androidmks = append(ignore_androidmks, external_androidmks...) 137 ignore_androidmks = append(ignore_androidmks, art_androidmks...) 138 139 shouldKeep := func(androidmk string) bool { 140 for _, prefix := range ignore_androidmks { 141 if strings.HasPrefix(androidmk, prefix) { 142 return false 143 } 144 } 145 return true 146 } 147 148 for _, l := range androidMks { 149 if shouldKeep(l) { 150 filtered = append(filtered, l) 151 } 152 } 153 return 154} 155