Merge "Make the bazel sandwich ignore targets that don't exist" into main am: 7997b3bb1c am: b0cc257a43 am: 5001403125 am: 471c0c2cc6 am: 76f5fac4b5

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2691027

Change-Id: Iccf7de8bc72e1f3cbbca2559b70f3b0110b45147
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Cole Faust
2023-08-03 20:29:27 +00:00
committed by Automerger Merge Worker
2 changed files with 22 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"runtime"
"sort"
"strings"
@@ -1054,9 +1055,23 @@ var (
func GetBazelSandwichCqueryRequests(config Config) ([]cqueryKey, error) {
result := make([]cqueryKey, 0, len(allowlists.BazelSandwichTargets))
labelRegex := regexp.MustCompile("^@?//([a-zA-Z0-9/_-]+):[a-zA-Z0-9_-]+$")
// Note that bazel "targets" are different from soong "targets", the bazel targets are
// synonymous with soong modules, and soong targets are a configuration a module is built in.
for _, target := range allowlists.BazelSandwichTargets {
match := labelRegex.FindStringSubmatch(target.Label)
if match == nil {
return nil, fmt.Errorf("invalid label, must match `^@?//([a-zA-Z0-9/_-]+):[a-zA-Z0-9_-]+$`: %s", target.Label)
}
if _, err := os.Stat(absolutePath(match[1])); err != nil {
if os.IsNotExist(err) {
// Ignore bazel sandwich targets that don't exist.
continue
} else {
return nil, err
}
}
var soongTarget Target
if target.Host {
soongTarget = config.BuildOSTarget

View File

@@ -52,6 +52,10 @@ function copy_directory {
cp -R "$REAL_TOP/$dir" "$MOCK_TOP/$parent"
}
function delete_directory {
rm -rf "$MOCK_TOP/$1"
}
function symlink_file {
local file="$1"
@@ -138,6 +142,9 @@ function create_mock_bazel {
copy_directory build/bazel
copy_directory build/bazel_common_rules
# This requires pulling more tools into the mock top to build partitions
delete_directory build/bazel/examples/partitions
symlink_directory packages/modules/common/build
symlink_directory prebuilts/bazel
symlink_directory prebuilts/clang