cb424d7448
verify-patch-sanity.py validates every active recipe .patch has internally- consistent hunk line counts — catching the 'malformed patch at line N' failure at commit/CI/preflight time instead of hours into a cook. This cycle hit that class three times (qtwaylandscanner, sddm, xwayland), each only discovered when cookbook tried to apply the patch. Running it across the repo found 29 latent malformed patches (validated against GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22'). They were harmless only because they sit in vendored recipes (baked, not re- applied) — but would fail on any version-bump re-derivation. --fix recounts the hunk headers (body untouched) and repaired all 29. Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test (test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats (empty placeholders, bare-@@ git hunks).
80 lines
3.1 KiB
C++
80 lines
3.1 KiB
C++
//===------- SARIFDiagnosticPrinter.cpp - Diagnostic Printer---------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This diagnostic client prints out their diagnostic messages in SARIF format.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Frontend/SARIFDiagnosticPrinter.h"
|
|
#include "clang/Basic/DiagnosticOptions.h"
|
|
#include "clang/Basic/Sarif.h"
|
|
#include "clang/Frontend/DiagnosticRenderer.h"
|
|
#include "clang/Frontend/SARIFDiagnostic.h"
|
|
#include "clang/Lex/Lexer.h"
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
#include "llvm/Support/JSON.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
namespace clang {
|
|
|
|
SARIFDiagnosticPrinter::SARIFDiagnosticPrinter(raw_ostream &OS,
|
|
DiagnosticOptions &DiagOpts)
|
|
: OS(OS), DiagOpts(DiagOpts) {}
|
|
|
|
void SARIFDiagnosticPrinter::BeginSourceFile(const LangOptions &LO,
|
|
const Preprocessor *PP) {
|
|
// Build the SARIFDiagnostic utility.
|
|
assert(hasSarifWriter() && "Writer not set!");
|
|
assert(!SARIFDiag && "SARIFDiagnostic already set.");
|
|
SARIFDiag = std::make_unique<SARIFDiagnostic>(OS, LO, DiagOpts, &*Writer);
|
|
// Initialize the SARIF object.
|
|
Writer->createRun("clang", Prefix);
|
|
}
|
|
|
|
void SARIFDiagnosticPrinter::EndSourceFile() {
|
|
assert(SARIFDiag && "SARIFDiagnostic has not been set.");
|
|
Writer->endRun();
|
|
llvm::json::Value Value(Writer->createDocument());
|
|
OS << "\n" << Value << "\n\n";
|
|
OS.flush();
|
|
SARIFDiag.reset();
|
|
}
|
|
|
|
void SARIFDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
|
const Diagnostic &Info) {
|
|
assert(SARIFDiag && "SARIFDiagnostic has not been set.");
|
|
// Default implementation (Warnings/errors count). Keeps track of the
|
|
// number of errors.
|
|
DiagnosticConsumer::HandleDiagnostic(Level, Info);
|
|
|
|
// Render the diagnostic message into a temporary buffer eagerly. We'll use
|
|
// this later as we add the diagnostic to the SARIF object.
|
|
SmallString<100> OutStr;
|
|
Info.FormatDiagnostic(OutStr);
|
|
|
|
llvm::raw_svector_ostream DiagMessageStream(OutStr);
|
|
|
|
// Use a dedicated, simpler path for diagnostics without a valid location.
|
|
// This is important as if the location is missing, we may be emitting
|
|
// diagnostics in a context that lacks language options, a source manager, or
|
|
// other infrastructure necessary when emitting more rich diagnostics.
|
|
if (Info.getLocation().isInvalid()) {
|
|
// FIXME: Enable diagnostics without a source manager
|
|
return;
|
|
}
|
|
|
|
// Assert that the rest of our infrastructure is setup properly.
|
|
assert(Info.hasSourceManager() &&
|
|
"Unexpected diagnostic with no source manager");
|
|
|
|
SARIFDiag->emitDiagnostic(
|
|
FullSourceLoc(Info.getLocation(), Info.getSourceManager()), Level,
|
|
DiagMessageStream.str(), Info.getRanges(), Info.getFixItHints(), &Info);
|
|
}
|
|
} // namespace clang
|