From 072e07a9d5928fd3b1c1dabeac82890713ce172b Mon Sep 17 00:00:00 2001 From: Daniel Thornburgh Date: Fri, 17 Feb 2023 13:43:57 -0800 Subject: [llvm-cov] Optionally fail on missing binary ID This adds the --check-binary-id flag that makes sure that an object file is available for every binary ID mentioned in the given profile. This should help make the tool more robust in CI environments where it's expected that coverage mappings should be available for every object contributing to the profile. Reviewed By: gulfem Differential Revision: https://reviews.llvm.org/D144308 --- llvm/lib/ProfileData/Coverage/CoverageMapping.cpp | 31 ++++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'llvm/lib/ProfileData/Coverage/CoverageMapping.cpp') diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp index 360d30d..d6aec27 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -15,7 +15,9 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallBitVector.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Object/BuildID.h" #include "llvm/ProfileData/Coverage/CoverageMappingReader.h" @@ -382,11 +384,10 @@ Error CoverageMapping::loadFromFile( return Error::success(); } -Expected> -CoverageMapping::load(ArrayRef ObjectFilenames, - StringRef ProfileFilename, vfs::FileSystem &FS, - ArrayRef Arches, StringRef CompilationDir, - const object::BuildIDFetcher *BIDFetcher) { +Expected> CoverageMapping::load( + ArrayRef ObjectFilenames, StringRef ProfileFilename, + vfs::FileSystem &FS, ArrayRef Arches, StringRef CompilationDir, + const object::BuildIDFetcher *BIDFetcher, bool CheckBinaryIDs) { auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename, FS); if (Error E = ProfileReaderOrErr.takeError()) return createFileError(ProfileFilename, std::move(E)); @@ -430,13 +431,19 @@ CoverageMapping::load(ArrayRef ObjectFilenames, for (object::BuildIDRef BinaryID : BinaryIDsToFetch) { std::optional PathOpt = BIDFetcher->fetch(BinaryID); - if (!PathOpt) - continue; - std::string Path = std::move(*PathOpt); - StringRef Arch = Arches.size() == 1 ? Arches.front() : StringRef(); - if (Error E = loadFromFile(Path, Arch, CompilationDir, *ProfileReader, - *Coverage, DataFound)) - return std::move(E); + if (PathOpt) { + std::string Path = std::move(*PathOpt); + StringRef Arch = Arches.size() == 1 ? Arches.front() : StringRef(); + if (Error E = loadFromFile(Path, Arch, CompilationDir, *ProfileReader, + *Coverage, DataFound)) + return std::move(E); + } else if (CheckBinaryIDs) { + return createFileError( + ProfileFilename, + createStringError(errc::no_such_file_or_directory, + "Missing binary ID: " + + llvm::toHex(BinaryID, /*LowerCase=*/true))); + } } } -- cgit v1.1