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).
194 lines
5.6 KiB
C++
194 lines
5.6 KiB
C++
//===- MultilibBuilder.cpp - MultilibBuilder Implementation -===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Driver/MultilibBuilder.h"
|
|
#include "clang/Driver/CommonArgs.h"
|
|
#include "llvm/ADT/StringMap.h"
|
|
#include "llvm/Support/Path.h"
|
|
#include "llvm/Support/Regex.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace clang;
|
|
using namespace driver;
|
|
|
|
/// normalize Segment to "/foo/bar" or "".
|
|
static void normalizePathSegment(std::string &Segment) {
|
|
StringRef seg = Segment;
|
|
|
|
// Prune trailing "/" or "./"
|
|
while (true) {
|
|
StringRef last = llvm::sys::path::filename(seg);
|
|
if (last != ".")
|
|
break;
|
|
seg = llvm::sys::path::parent_path(seg);
|
|
}
|
|
|
|
if (seg.empty() || seg == "/") {
|
|
Segment.clear();
|
|
return;
|
|
}
|
|
|
|
// Add leading '/'
|
|
if (seg.front() != '/') {
|
|
Segment = "/" + seg.str();
|
|
} else {
|
|
Segment = std::string(seg);
|
|
}
|
|
}
|
|
|
|
MultilibBuilder::MultilibBuilder(StringRef GCC, StringRef OS, StringRef Include)
|
|
: GCCSuffix(GCC), OSSuffix(OS), IncludeSuffix(Include) {
|
|
normalizePathSegment(GCCSuffix);
|
|
normalizePathSegment(OSSuffix);
|
|
normalizePathSegment(IncludeSuffix);
|
|
}
|
|
|
|
MultilibBuilder::MultilibBuilder(StringRef Suffix)
|
|
: MultilibBuilder(Suffix, Suffix, Suffix) {}
|
|
|
|
MultilibBuilder &MultilibBuilder::gccSuffix(StringRef S) {
|
|
GCCSuffix = std::string(S);
|
|
normalizePathSegment(GCCSuffix);
|
|
return *this;
|
|
}
|
|
|
|
MultilibBuilder &MultilibBuilder::osSuffix(StringRef S) {
|
|
OSSuffix = std::string(S);
|
|
normalizePathSegment(OSSuffix);
|
|
return *this;
|
|
}
|
|
|
|
MultilibBuilder &MultilibBuilder::includeSuffix(StringRef S) {
|
|
IncludeSuffix = std::string(S);
|
|
normalizePathSegment(IncludeSuffix);
|
|
return *this;
|
|
}
|
|
|
|
bool MultilibBuilder::isValid() const {
|
|
llvm::StringMap<int> FlagSet;
|
|
for (unsigned I = 0, N = Flags.size(); I != N; ++I) {
|
|
StringRef Flag(Flags[I]);
|
|
auto [SI, Inserted] = FlagSet.try_emplace(Flag.substr(1), I);
|
|
|
|
assert(StringRef(Flag).front() == '-' || StringRef(Flag).front() == '!');
|
|
|
|
if (!Inserted && Flags[I] != Flags[SI->getValue()])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
MultilibBuilder &MultilibBuilder::flag(StringRef Flag, bool Disallow) {
|
|
tools::addMultilibFlag(!Disallow, Flag, Flags);
|
|
return *this;
|
|
}
|
|
|
|
Multilib MultilibBuilder::makeMultilib() const {
|
|
return Multilib(GCCSuffix, OSSuffix, IncludeSuffix, Flags);
|
|
}
|
|
|
|
MultilibSetBuilder &MultilibSetBuilder::Maybe(const MultilibBuilder &M) {
|
|
MultilibBuilder Opposite;
|
|
// Negate positive flags
|
|
for (StringRef Flag : M.flags()) {
|
|
if (Flag.front() == '-')
|
|
Opposite.flag(Flag, /*Disallow=*/true);
|
|
}
|
|
return Either(M, Opposite);
|
|
}
|
|
|
|
MultilibSetBuilder &MultilibSetBuilder::Either(const MultilibBuilder &M1,
|
|
const MultilibBuilder &M2) {
|
|
return Either({M1, M2});
|
|
}
|
|
|
|
MultilibSetBuilder &MultilibSetBuilder::Either(const MultilibBuilder &M1,
|
|
const MultilibBuilder &M2,
|
|
const MultilibBuilder &M3) {
|
|
return Either({M1, M2, M3});
|
|
}
|
|
|
|
MultilibSetBuilder &MultilibSetBuilder::Either(const MultilibBuilder &M1,
|
|
const MultilibBuilder &M2,
|
|
const MultilibBuilder &M3,
|
|
const MultilibBuilder &M4) {
|
|
return Either({M1, M2, M3, M4});
|
|
}
|
|
|
|
MultilibSetBuilder &MultilibSetBuilder::Either(const MultilibBuilder &M1,
|
|
const MultilibBuilder &M2,
|
|
const MultilibBuilder &M3,
|
|
const MultilibBuilder &M4,
|
|
const MultilibBuilder &M5) {
|
|
return Either({M1, M2, M3, M4, M5});
|
|
}
|
|
|
|
static MultilibBuilder compose(const MultilibBuilder &Base,
|
|
const MultilibBuilder &New) {
|
|
SmallString<128> GCCSuffix;
|
|
llvm::sys::path::append(GCCSuffix, "/", Base.gccSuffix(), New.gccSuffix());
|
|
SmallString<128> OSSuffix;
|
|
llvm::sys::path::append(OSSuffix, "/", Base.osSuffix(), New.osSuffix());
|
|
SmallString<128> IncludeSuffix;
|
|
llvm::sys::path::append(IncludeSuffix, "/", Base.includeSuffix(),
|
|
New.includeSuffix());
|
|
|
|
MultilibBuilder Composed(GCCSuffix, OSSuffix, IncludeSuffix);
|
|
|
|
MultilibBuilder::flags_list &Flags = Composed.flags();
|
|
|
|
llvm::append_range(Flags, Base.flags());
|
|
llvm::append_range(Flags, New.flags());
|
|
|
|
return Composed;
|
|
}
|
|
|
|
MultilibSetBuilder &
|
|
MultilibSetBuilder::Either(ArrayRef<MultilibBuilder> MultilibSegments) {
|
|
multilib_list Composed;
|
|
|
|
if (Multilibs.empty())
|
|
llvm::append_range(Multilibs, MultilibSegments);
|
|
else {
|
|
for (const auto &New : MultilibSegments) {
|
|
for (const auto &Base : Multilibs) {
|
|
MultilibBuilder MO = compose(Base, New);
|
|
if (MO.isValid())
|
|
Composed.push_back(MO);
|
|
}
|
|
}
|
|
|
|
Multilibs = Composed;
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
MultilibSetBuilder &MultilibSetBuilder::FilterOut(const char *Regex) {
|
|
llvm::Regex R(Regex);
|
|
#ifndef NDEBUG
|
|
std::string Error;
|
|
if (!R.isValid(Error)) {
|
|
llvm::errs() << Error;
|
|
llvm_unreachable("Invalid regex!");
|
|
}
|
|
#endif
|
|
llvm::erase_if(Multilibs, [&R](const MultilibBuilder &M) {
|
|
return R.match(M.gccSuffix());
|
|
});
|
|
return *this;
|
|
}
|
|
|
|
MultilibSet MultilibSetBuilder::makeMultilibSet() const {
|
|
MultilibSet Result;
|
|
for (const auto &M : Multilibs) {
|
|
Result.push_back(M.makeMultilib());
|
|
}
|
|
return Result;
|
|
}
|