| 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" |