结论:新增 vendored LinuxCNC 源码同步验证脚本,去重 source-manifest,并在 native 验证前检查 vendor 与上游源文件字节一致,强化功能来源于 LinuxCNC 源程序的纪律。
86 lines
2.2 KiB
Bash
Executable File
86 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
UPSTREAM_DIR="$ROOT_DIR/../linuxcnc"
|
|
VENDOR_DIR="$ROOT_DIR/vendor/linuxcnc"
|
|
MANIFEST_FILE="$ROOT_DIR/tools/source-manifest.txt"
|
|
|
|
if [[ ! -d "$UPSTREAM_DIR" ]]; then
|
|
echo "missing upstream directory: $UPSTREAM_DIR" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -d "$VENDOR_DIR" ]]; then
|
|
echo "missing vendor directory: $VENDOR_DIR" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$MANIFEST_FILE" ]]; then
|
|
echo "missing manifest: $MANIFEST_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
TMP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
|
|
|
MANIFEST_CLEAN="$TMP_DIR/manifest.clean"
|
|
MANIFEST_SORTED="$TMP_DIR/manifest.sorted"
|
|
VENDOR_SORTED="$TMP_DIR/vendor.sorted"
|
|
|
|
while IFS= read -r src_rel; do
|
|
[[ -z "$src_rel" ]] && continue
|
|
[[ "${src_rel:0:1}" == "#" ]] && continue
|
|
|
|
if [[ "$src_rel" = /* || "$src_rel" == *".."* ]]; then
|
|
echo "invalid manifest path: $src_rel" >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf '%s\n' "$src_rel" >> "$MANIFEST_CLEAN"
|
|
done < "$MANIFEST_FILE"
|
|
|
|
if [[ ! -s "$MANIFEST_CLEAN" ]]; then
|
|
echo "empty manifest: $MANIFEST_FILE" >&2
|
|
exit 1
|
|
fi
|
|
|
|
sort "$MANIFEST_CLEAN" > "$MANIFEST_SORTED"
|
|
|
|
if duplicate_entries="$(uniq -d "$MANIFEST_SORTED")" && [[ -n "$duplicate_entries" ]]; then
|
|
echo "duplicate manifest entries:" >&2
|
|
printf '%s\n' "$duplicate_entries" >&2
|
|
exit 1
|
|
fi
|
|
|
|
find "$VENDOR_DIR" -type f | sed "s#^$VENDOR_DIR/##" | sort > "$VENDOR_SORTED"
|
|
|
|
if extra_vendor="$(comm -23 "$VENDOR_SORTED" "$MANIFEST_SORTED")" && [[ -n "$extra_vendor" ]]; then
|
|
echo "vendor files not listed in manifest:" >&2
|
|
printf '%s\n' "$extra_vendor" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if missing_vendor="$(comm -13 "$VENDOR_SORTED" "$MANIFEST_SORTED")" && [[ -n "$missing_vendor" ]]; then
|
|
echo "manifest files missing from vendor:" >&2
|
|
printf '%s\n' "$missing_vendor" >&2
|
|
exit 1
|
|
fi
|
|
|
|
while IFS= read -r src_rel; do
|
|
upstream_file="$UPSTREAM_DIR/$src_rel"
|
|
vendor_file="$VENDOR_DIR/$src_rel"
|
|
|
|
if [[ ! -f "$upstream_file" ]]; then
|
|
echo "missing upstream file: $src_rel" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! cmp -s "$upstream_file" "$vendor_file"; then
|
|
echo "vendor drift from upstream: $src_rel" >&2
|
|
exit 1
|
|
fi
|
|
done < "$MANIFEST_SORTED"
|
|
|
|
echo "vendor sync validation complete"
|