Move C++ dwp/fission tests to rules_cc. PiperOrigin-RevId: 943211855 Change-Id: I45afcb18335a7a3451627c232a3844ebbca48912
diff --git a/cc/BUILD b/cc/BUILD index 8a34a55..6e68abd 100644 --- a/cc/BUILD +++ b/cc/BUILD
@@ -79,6 +79,7 @@ "//cc/common:srcs", "//cc/private:srcs", "//cc/proto:srcs", + "//cc/settings:srcs", "//cc/toolchains:srcs", "@bazel_skylib//:test_deps", ],
diff --git a/cc/private/BUILD b/cc/private/BUILD index 252792d..cb150f0 100644 --- a/cc/private/BUILD +++ b/cc/private/BUILD
@@ -35,6 +35,7 @@ "*.bzl", ]) + [ "//cc/private/compile:srcs", + "//cc/private/coverage:srcs", "//cc/private/link:srcs", "//cc/private/rules_impl:srcs", "//cc/private/toolchain:srcs",
diff --git a/cc/private/coverage/BUILD.bazel b/cc/private/coverage/BUILD.bazel index d54f53f..7a5370e 100644 --- a/cc/private/coverage/BUILD.bazel +++ b/cc/private/coverage/BUILD.bazel
@@ -13,3 +13,11 @@ }), visibility = ["//visibility:public"], ) + +filegroup( + name = "srcs", + srcs = glob([ + "**", + ]), + visibility = ["//visibility:public"], +)
diff --git a/cc/settings/BUILD b/cc/settings/BUILD index 9cb302f..953ea49 100644 --- a/cc/settings/BUILD +++ b/cc/settings/BUILD
@@ -24,3 +24,11 @@ build_setting_default = ":default_apple_constraint", visibility = ["//visibility:public"], ) + +filegroup( + name = "srcs", + srcs = glob([ + "**/BUILD", + ]), + visibility = ["//visibility:public"], +)
diff --git a/tests/integration/BUILD b/tests/integration/BUILD index c09ac87..b292aa2 100644 --- a/tests/integration/BUILD +++ b/tests/integration/BUILD
@@ -34,6 +34,16 @@ test_script = "cc_shared_library_tests.sh", ) +rules_cc_integration_test( + name = "fission_tests", + target_compatible_with = select({ + "@platforms//os:macos": ["@platforms//:incompatible"], + "@platforms//os:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), + test_script = "fission_tests.sh", +) + VERSION_GATE = [] if bazel_features.cc.cc_common_is_in_rules_cc else ["@platforms//:incompatible"] # copybara-uncomment-this-please # VERSION_GATE = ["@platforms//:incompatible"] # copybara-comment-this-out-please
diff --git a/tests/integration/fission_tests.sh b/tests/integration/fission_tests.sh new file mode 100755 index 0000000..5299da1 --- /dev/null +++ b/tests/integration/fission_tests.sh
@@ -0,0 +1,79 @@ +set -euo pipefail + +source "$(rlocation rules_cc/tests/test_utils.sh)" +source "$(rlocation rules_cc/tests/unittest.bash)" + +function generate_fission_build_files() { + mkdir -p a + cat > a/BUILD << EOF +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") +cc_binary(name = "main", + srcs = ["main.cc"], + deps = [":dep"] +) +cc_library(name = "dep", + srcs = ["dep.cc"] +) +EOF + + cat > a/main.cc << EOF +#include <iostream> +int dep(); +int main(int argc, char** argv) { + dep(); +} +EOF + + cat > a/dep.cc << EOF +int dep() { + return 4; +} +EOF +} + +# Tests that under --fission, non-empty .dwp outputs are generated. +function test_fission_dwp() { + generate_fission_build_files + bazel build --fission=yes //a:main.dwp >& "${TEST_log}" || + fail "Build failed" + maindwp=bazel-bin/a/main.dwp + [[ -e "$maindwp" ]] || fail "main.dwp not found" + [[ -s "$maindwp" ]] || fail "main.dwp is empty" +} + +# Tests that under --fission=no, .dwp outputs exist, but are empty. +function test_nofission_dwp() { + generate_fission_build_files + bazel build --fission=no //a:main.dwp >& "${TEST_log}" || fail "Build failed" + maindwp=bazel-bin/a/main.dwp + [[ -e "$maindwp" ]] || fail "main.dwp not found" + [[ ! -s "$maindwp" ]] || fail "main.dwp is non-empty" +} + +# Tests .dwp outputs are generated by cc_test +function test_cpp_test_fission_dwp() { + mkdir -p a + cat > a/BUILD << EOF +load("@rules_cc//cc:cc_test.bzl", "cc_test") +cc_test( + name = "test", + srcs = ["test.cc"], +) +EOF + + cat > a/test.cc << EOF +#include <iostream> +int main(int argc, char** argv) { + std::cout << "This is a test.\n"; +} +EOF + + bazel build --fission=yes //a:test.dwp >& "${TEST_log}" || + fail "Build failed" + testdwp=bazel-bin/a/test.dwp + [[ -e "$testdwp" ]] || fail "test.dwp not found" + [[ -s "$testdwp" ]] || fail "test.dwp is empty" +} + +run_suite "Integration tests for fission with rules_cc"