Skip to content

Commit

Permalink
Enable C/C++ remote tests on macOS
Browse files Browse the repository at this point in the history
Also ensure that the remote worker doesn't fail executions when the spawn fails, but instead sends back the result of the unsuccessful execution.

Closes bazelbuild#23085.

PiperOrigin-RevId: 680944273
Change-Id: Ic4e0ba5e6f814e89465776e8b06e4ff88e761080
  • Loading branch information
fmeum authored and copybara-github committed Oct 1, 2024
1 parent b4b35af commit 509f79f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 150 deletions.
3 changes: 3 additions & 0 deletions src/test/shell/bazel/remote/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ sh_test(
"@bazel_tools//tools/bash/runfiles",
],
shard_count = 5,
tags = [
"requires-network", # for Bzlmod (apple_support)
],
)

sh_test(
Expand Down
79 changes: 7 additions & 72 deletions src/test/shell/bazel/remote/build_without_the_bytes_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ EOF
function test_cc_tree_remote_executor_download_all() {
# Regression test for https://github.com/bazelbuild/bazel/issues/19988.

if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_tree

bazel build \
Expand All @@ -106,13 +99,6 @@ function test_cc_tree_remote_executor_download_all() {
}

function test_cc_tree_remote_executor_download_minimal() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_tree

bazel build \
Expand All @@ -123,13 +109,6 @@ function test_cc_tree_remote_executor_download_minimal() {
}

function test_cc_tree_remote_cache_download_minimal() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_tree

bazel build \
Expand All @@ -140,13 +119,6 @@ function test_cc_tree_remote_cache_download_minimal() {
}

function test_cc_tree_prefetching_download_minimal() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_tree

bazel build \
Expand Down Expand Up @@ -383,13 +355,6 @@ EOF
function test_downloads_toplevel_runfiles() {
# Test that --remote_download_toplevel fetches only the top level binaries
# and generated runfiles.
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a

cat > a/create_bar.tmpl <<'EOF'
Expand Down Expand Up @@ -434,13 +399,6 @@ EOF
# particular, cc_binary links against a symlinked imported .so file, and only
# the symlink is in the runfiles.
function test_downloads_toplevel_symlink_action() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a

cat > a/bar.cc <<'EOF'
Expand Down Expand Up @@ -569,13 +527,6 @@ EOF
}

function test_download_toplevel_templated_tree_artifact() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a

# We need the top-level output to be a tree artifact generated by a template
Expand Down Expand Up @@ -610,8 +561,13 @@ EOF
--output_groups=compilation_outputs \
//a:main || fail "Failed to build //a:main"

if ! [[ -f bazel-bin/a/_pic_objs/main/dir/foo.pic.o ]]; then
fail "Expected toplevel output bazel-out/a/_pic_objs/main/dir/foo.pic.o to be downloaded"
if [[ "$PLATFORM" == "darwin" ]]; then
expected_object_file=bazel-bin/a/_objs/main/dir/foo.o
else
expected_object_file=bazel-bin/a/_pic_objs/main/dir/foo.pic.o
fi
if ! [[ -f "$expected_object_file" ]]; then
fail "Expected toplevel output $expected_object_file to be downloaded"
fi
}

Expand Down Expand Up @@ -649,13 +605,6 @@ function test_download_toplevel_test_rule() {
# the test.log and test.xml file are downloaded but not the test binary.
# However when building a test then the test binary should be downloaded.

if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a
cat > a/BUILD <<EOF
package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -727,26 +676,12 @@ EOF
}

function test_non_test_toplevel_targets_toplevel() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

do_test_non_test_toplevel_targets --remote_download_toplevel

[[ -f bazel-bin/a/foo.txt ]] || fail "Expected a/foo.txt to be downloaded"
}

function test_non_test_toplevel_targets_minimal() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

do_test_non_test_toplevel_targets --remote_download_minimal

[[ ! -f bazel-bin/a/foo.txt ]] || fail "Expected a/foo.txt to not be downloaded"
Expand Down
84 changes: 6 additions & 78 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,6 @@ EOF
}

function test_cc_binary() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a
cat > a/BUILD <<EOF
package(default_visibility = ["//visibility:public"])
Expand All @@ -335,19 +328,12 @@ EOF
--remote_executor=grpc://localhost:${worker_port} \
//a:test >& $TEST_log \
|| fail "Failed to build //a:test with remote execution"
expect_log "6 processes: 4 internal, 2 remote"
expect_log "[0-9] processes: [0-9] internal, 2 remote\\."
diff bazel-bin/a/test ${TEST_TMPDIR}/test_expected \
|| fail "Remote execution generated different result"
}

function test_cc_test() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a
cat > a/BUILD <<EOF
package(default_visibility = ["//visibility:public"])
Expand All @@ -370,13 +356,6 @@ EOF
}

function test_cc_test_split_xml() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

mkdir -p a
cat > a/BUILD <<EOF
package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -2430,13 +2409,6 @@ EOF
# Older versions of gcov are not supported with bazel coverage and so will be skipped.
# See the above `test_java_rbe_coverage_produces_report` for more information.
function test_cc_rbe_coverage_produces_report() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

# Check to see if intermediate files are supported, otherwise skip.
gcov --help | grep "\-i," || return 0

Expand Down Expand Up @@ -2554,13 +2526,6 @@ EOF
# returned non-empty.
# See the above `test_java_rbe_coverage_produces_report` for more information.
function test_cc_rbe_coverage_produces_report_with_llvm() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

local -r clang=$(which clang)
if [[ ! -x "${clang}" ]]; then
echo "clang not installed. Skipping"
Expand Down Expand Up @@ -3096,13 +3061,6 @@ EOF
}

function test_external_cc_test() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_external_cc_test

bazel test \
Expand All @@ -3112,13 +3070,6 @@ function test_external_cc_test() {
}

function test_external_cc_test_sibling_repository_layout() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_external_cc_test

bazel test \
Expand Down Expand Up @@ -3227,6 +3178,7 @@ function setup_cc_binary_tool_with_dynamic_deps() {
local repo=$1

cat >> MODULE.bazel <<'EOF'
bazel_dep(name = "apple_support", version = "1.17.0")
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
local_repository(
name = "other_repo",
Expand Down Expand Up @@ -3289,62 +3241,38 @@ EOF
}

function test_cc_binary_tool_with_dynamic_deps() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_binary_tool_with_dynamic_deps .

bazel build \
--incompatible_macos_set_install_name \
--remote_executor=grpc://localhost:${worker_port} \
//pkg:rule >& $TEST_log || fail "Build should succeed"
}

function test_cc_binary_tool_with_dynamic_deps_sibling_repository_layout() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_binary_tool_with_dynamic_deps .

bazel build \
--incompatible_macos_set_install_name \
--experimental_sibling_repository_layout \
--remote_executor=grpc://localhost:${worker_port} \
//pkg:rule >& $TEST_log || fail "Build should succeed"
}

function test_external_cc_binary_tool_with_dynamic_deps() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_binary_tool_with_dynamic_deps other_repo

bazel build \
--incompatible_macos_set_install_name \
--remote_executor=grpc://localhost:${worker_port} \
@other_repo//pkg:rule >& $TEST_log || fail "Build should succeed"
}

function test_external_cc_binary_tool_with_dynamic_deps_sibling_repository_layout() {
if [[ "$PLATFORM" == "darwin" ]]; then
# TODO(b/37355380): This test is disabled due to RemoteWorker not supporting
# setting SDKROOT and DEVELOPER_DIR appropriately, as is required of
# action executors in order to select the appropriate Xcode toolchain.
return 0
fi

setup_cc_binary_tool_with_dynamic_deps other_repo

bazel build \
--incompatible_macos_set_install_name \
--experimental_sibling_repository_layout \
--remote_executor=grpc://localhost:${worker_port} \
@other_repo//pkg:rule >& $TEST_log || fail "Build should succeed"
Expand Down

0 comments on commit 509f79f

Please sign in to comment.