BASEDIR=../coverage-reports-base
SOURCEDIR=../coverage
+ifeq ($(UNAME),Darwin)
+# FIXME(richkadel): It appears that --debug is not available on MacOS even when not running
+# under CI.
+NO_LLVM_ASSERTIONS=1
+endif
+
+# The `llvm-cov show` flag `--debug`, used to generate the `counters` output files, is only enabled
+# if LLVM assertions are enabled. Some CI builds disable debug assertions.
+ifndef NO_LLVM_ASSERTIONS
+DEBUG_FLAG=--debug
+endif
+
+# When generating `expected_*` results (using `x.py test --bless`), the `--debug` flag is forced.
+# If assertions are disabled, the command will fail with an error, rather than attempt to generate
+# only partial results.
+ifdef RUSTC_BLESS_TEST
+DEBUG_FLAG=--debug
+endif
+
all: $(patsubst $(SOURCEDIR)/%.rs,%,$(wildcard $(SOURCEDIR)/*.rs))
# Ensure there are no `expected` results for tests that may have been removed or renamed
ifdef RUSTC_BLESS_TEST
rm -f expected_export_coverage.*.json
rm -f expected_show_coverage.*.txt
+ rm -f expected_show_coverage_counters.*.txt
endif
-include clear_expected_if_blessed
"$(TMPDIR)"/$@.profraw \
-o "$(TMPDIR)"/$@.profdata
- # Generate a coverage report using `llvm-cov show`. The output ordering
- # can be non-deterministic, so ignore the return status. If the test fails
- # when comparing the JSON `export`, the `show` output may be useful when
- # debugging.
+ # Generate a coverage report using `llvm-cov show`.
"$(LLVM_BIN_DIR)"/llvm-cov show \
+ $(DEBUG_FLAG) \
--Xdemangler="$(RUST_DEMANGLER)" \
--show-line-counts-or-regions \
--instr-profile="$(TMPDIR)"/$@.profdata \
$(call BIN,"$(TMPDIR)"/$@) \
- > "$(TMPDIR)"/actual_show_coverage.$@.txt
+ > "$(TMPDIR)"/actual_show_coverage.$@.txt \
+ 2> "$(TMPDIR)"/show_coverage_stderr.$@.txt || \
+ ( status=$$? ; \
+ >&2 cat "$(TMPDIR)"/show_coverage_stderr.$@.txt ; \
+ exit $$status \
+ )
+
+ifdef DEBUG_FLAG
+ # The first line (beginning with "Args:" contains hard-coded, build-specific
+ # file paths. Strip that line and keep the remaining lines with counter debug
+ # data.
+ tail -n +2 "$(TMPDIR)"/show_coverage_stderr.$@.txt \
+ > "$(TMPDIR)"/actual_show_coverage_counters.$@.txt
+endif
ifdef RUSTC_BLESS_TEST
- cp "$(TMPDIR)"/actual_show_coverage.$@.txt expected_show_coverage.$@.txt
+ cp "$(TMPDIR)"/actual_show_coverage.$@.txt \
+ expected_show_coverage.$@.txt
+ cp "$(TMPDIR)"/actual_show_coverage_counters.$@.txt \
+ expected_show_coverage_counters.$@.txt
else
# Compare the show coverage output (`--bless` refreshes `typical` files)
# Note `llvm-cov show` output for some programs can vary, but can be ignored
false \
)
+ifdef DEBUG_FLAG
+ $(DIFF) expected_show_coverage_counters.$@.txt "$(TMPDIR)"/actual_show_coverage_counters.$@.txt || \
+ ( grep -q '^\/\/ ignore-llvm-cov-show-diffs' $(SOURCEDIR)/$@.rs && \
+ >&2 echo 'diff failed, but suppressed with `// ignore-llvm-cov-show-diffs` in $(SOURCEDIR)/$@.rs' \
+ ) || \
+ ( >&2 echo 'diff failed, and not suppressed without `// ignore-llvm-cov-show-diffs` in $(SOURCEDIR)/$@.rs'; \
+ >&2 echo '(Ignore anyway until mangled function names in "counters" files are demangled.)' \
+ )
+
+ # FIXME(richkadel): Apply the demangler to the `*_show_coverage_counters.*.txt` files,
+ # so the crate disambiguator differences will be stripped away. At that point, these files
+ # will be less likely to vary, and the last `echo` above (starting with "Ignore anyway")
+ # can be replaced with `false` to fail the test.
+endif
+
endif
# Generate a coverage report in JSON, using `llvm-cov export`, and fail if