Skip to content

Commit

Permalink
[ci] Fix cquery based compatibility check.
Browse files Browse the repository at this point in the history
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 <[email protected]>

Differential Revision: https://phab.corp.pixielabs.ai/D12931

GitOrigin-RevId: fe118261921499ba7a6789134614f9454eab6df7
  • Loading branch information
JamesMBartlett authored and copybaranaut committed Jan 26, 2023
1 parent 0df6705 commit 62278c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
13 changes: 4 additions & 9 deletions ci/bazel_build_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions ci/cquery_ignore_non_target_and_incompatible.bzl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 62278c1

Please sign in to comment.