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).
103 lines
2.9 KiB
Python
103 lines
2.9 KiB
Python
#!/usr/bin/env python
|
|
#
|
|
# ===- csv2json.py - Static Analyzer test helper ---*- python -*-===#
|
|
#
|
|
# 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
|
|
#
|
|
# ===------------------------------------------------------------------------===#
|
|
|
|
r"""
|
|
Clang Static Analyzer test helper
|
|
=================================
|
|
|
|
This script converts a CSV file to a JSON file with a specific structure.
|
|
|
|
The JSON file contains a single dictionary. The keys of this dictionary
|
|
are taken from the first column of the CSV. The values are dictionaries
|
|
themselves, mapping the CSV header names (except the first column) to
|
|
the corresponding row values.
|
|
|
|
|
|
Usage:
|
|
csv2json.py <source-file>
|
|
|
|
Example:
|
|
// RUN: %csv2json.py %t | FileCheck %s
|
|
"""
|
|
|
|
import csv
|
|
import sys
|
|
import json
|
|
|
|
|
|
def csv_to_json_dict(csv_filepath):
|
|
"""
|
|
Args:
|
|
csv_filepath: The path to the input CSV file.
|
|
|
|
Raises:
|
|
FileNotFoundError: If the CSV file does not exist.
|
|
csv.Error: If there is an error parsing the CSV file.
|
|
Exception: For any other unexpected errors.
|
|
"""
|
|
try:
|
|
with open(csv_filepath, "r", encoding="utf-8") as csvfile:
|
|
reader = csv.reader(csvfile)
|
|
|
|
# Read the header row (column names)
|
|
try:
|
|
header = next(reader)
|
|
except StopIteration: # Handle empty CSV file
|
|
json.dumps({}, indent=2) # write an empty dict
|
|
return
|
|
|
|
# handle a csv file that contains no rows, not even a header row.
|
|
if not header:
|
|
json.dumps({}, indent=2)
|
|
return
|
|
|
|
other_column_names = [name.strip() for name in header[1:]]
|
|
|
|
data_dict = {}
|
|
|
|
for row in reader:
|
|
if len(row) != len(header):
|
|
raise csv.Error("Inconsistent CSV file")
|
|
exit(1)
|
|
|
|
key = row[0]
|
|
value_map = {}
|
|
|
|
for i, col_name in enumerate(other_column_names):
|
|
# +1 to skip the first column
|
|
value_map[col_name] = row[i + 1].strip()
|
|
|
|
data_dict[key] = value_map
|
|
|
|
return json.dumps(data_dict, indent=2)
|
|
|
|
except FileNotFoundError:
|
|
raise FileNotFoundError(f"Error: CSV file not found at {csv_filepath}")
|
|
except csv.Error as e:
|
|
raise csv.Error(f"Error parsing CSV file: {e}")
|
|
except Exception as e:
|
|
raise Exception(f"An unexpected error occurred: {e}")
|
|
|
|
|
|
def main():
|
|
"""Example usage with error handling."""
|
|
csv_file = sys.argv[1]
|
|
|
|
try:
|
|
print(csv_to_json_dict(csv_file))
|
|
except (FileNotFoundError, csv.Error, Exception) as e:
|
|
print(str(e))
|
|
except:
|
|
print("An error occured")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|