From 62278c174f5f2b1d769d5374b248cc5648401d16 Mon Sep 17 00:00:00 2001 From: James Bartlett Date: Wed, 25 Jan 2023 13:10:56 -0800 Subject: [PATCH] [ci] Fix cquery based compatibility check. Summary: Fixes cquery platform compatibility check to skip targets that are in host or exec configs. These targets were causing the incompatibility stuff to not work, because cquery would view the host config as compatible so they'd still end up in the list. I also realized that the extra bazel query is unnecessary, as cquery supports the same syntax. Test Plan: Tested with D12855, and saw that the incompatible targets don't show up in the list. Reviewers: vihang, zasgar Reviewed By: vihang Signed-off-by: James Bartlett Differential Revision: https://phab.corp.pixielabs.ai/D12931 GitOrigin-RevId: fe118261921499ba7a6789134614f9454eab6df7 --- ci/bazel_build_deps.sh | 13 +++------ ...ery_ignore_non_target_and_incompatible.bzl | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 ci/cquery_ignore_non_target_and_incompatible.bzl diff --git a/ci/bazel_build_deps.sh b/ci/bazel_build_deps.sh index 494bdfee041..ef48dd4e1ff 100755 --- a/ci/bazel_build_deps.sh +++ b/ci/bazel_build_deps.sh @@ -21,8 +21,7 @@ # Go to the root of the repo cd "$(git rev-parse --show-toplevel)" || exit -bazel_query=("bazel" "query" "--keep_going" "--noshow_progress") -bazel_cquery=("bazel" "cquery") +bazel_cquery=("bazel" "cquery" "--keep_going" "--noshow_progress") # A list of patterns that will trigger a full build. poison_patterns=('^Jenkinsfile' '^bazel\/' '^ci\/' '^docker\.properties' '^\.bazelrc' '^BUILD.bazel' '^docker.properties') @@ -138,14 +137,10 @@ function check_bpf_trigger() { done } +starlark_cquery_file="ci/cquery_ignore_non_target_and_incompatible.bzl" function query_compatible_targets() { bazel_config="$1" - query_expr="$("${bazel_query[@]}" "${@:2}" 2> /dev/null | sed -z 's/\n/+/g;s/+$//g')" - - if [ -n "${query_expr}" ]; then - starlark_expr='target.label if "IncompatiblePlatformProvider" not in providers(target) else "__INCOMPATIBLE__"' - "${bazel_cquery[@]}" --config="${bazel_config}" --output=starlark --starlark:expr="${starlark_expr}" "${query_expr}" 2> /dev/null | grep -v "__INCOMPATIBLE__" - fi + "${bazel_cquery[@]}" --config="${bazel_config}" --notool_deps --output=starlark --starlark:file "${starlark_cquery_file}" "${@:2}" | grep -v "^None$" | sort | uniq } compute_targets @@ -173,7 +168,7 @@ cc_bpf_tests="kind(cc_.*, ${bpf_tests})" # Clang:opt (includes non-cc targets: go targets, //src/ui/..., etc.) -query_compatible_targets "clang" "${buildables} ${bpf_excludes}" > bazel_buildables_clang_opt #2>/dev/null +query_compatible_targets "clang" "${buildables} ${bpf_excludes}" > bazel_buildables_clang_opt 2>/dev/null query_compatible_targets "clang" "${tests} ${bpf_excludes}" > bazel_tests_clang_opt 2>/dev/null # Clang:dbg diff --git a/ci/cquery_ignore_non_target_and_incompatible.bzl b/ci/cquery_ignore_non_target_and_incompatible.bzl new file mode 100644 index 00000000000..ca748eebf77 --- /dev/null +++ b/ci/cquery_ignore_non_target_and_incompatible.bzl @@ -0,0 +1,27 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +def format(target): + build_opts = build_options(target) + + # We only want to get targets that are in the target configuration. So we ignore exec and host targets. + if build_opts["//command_line_option:is exec configuration"] or build_opts["//command_line_option:is host configuration"]: + return None + + # Ignore targets that are incompatible with the target configuration. + if providers(target) and "IncompatiblePlatformProvider" in providers(target): + return None + return target.label