#!/usr/bin/env bash # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2021 Arm Limited or its affiliates and Contributors. All rights reserved. [[ "$TRACE" ]] && set -x set -euo pipefail print_help() { echo 'Usage: manyclangs-build-month MM YYYY' echo '' echo 'manyclangs-build-month is a "set it and forget it" script that builds' echo 'the specified month and produces a .pack file.' } list_month() { MONTH="$1" YEAR="$2" ((NEXT_YEAR=YEAR)) ((NEXT_MONTH=10#$MONTH+1)) if [ $NEXT_MONTH -eq 13 ]; then ((NEXT_YEAR=NEXT_YEAR+1)) ((NEXT_MONTH=1)) fi git-list-between origin/main \ "$MONTH/01/$YEAR" "$NEXT_MONTH/01/$NEXT_YEAR" -- llvm clang } build_month() { BUILD_DIR="$1" MONTH="$2" YEAR="$3" list_month "$MONTH" "$YEAR" | awk '{print $1}' \ | manyclangs-build-commits "$BUILD_DIR" llvm clang } store_month() { BUILD_DIR="$1" MONTH="$2" YEAR="$3" # Include all .o and .h in ./build FIND_COMMAND=(find ./build -type f -name "'*.o'" -or -name "'*.h'" # Also include all LICENSE files, .log files the README and link.sh # available at the root of ./build. '&&' find ./build -maxdepth 1 -type f -name link.sh -or -name README -or -name "'LICENSE*'" -or -name "'*.log'") list_month "$MONTH" "$YEAR" | awk -v root="$(realpath "$BUILD_DIR")/" '{print root$1" "$2}' \ | (cd "$BUILD_DIR/elfshaker" && elfshaker-store-all "${FIND_COMMAND[*]}") } pack_month() { BUILD_DIR="$1" MONTH="$2" YEAR="$3" cd "$BUILD_DIR/elfshaker" elfshaker pack "$YEAR$MONTH" --verbose } main() { MONTH="$1" YEAR="$2" date -d "$MONTH/01/$YEAR" 1>/dev/null || (print_help && exit 1) BUILD_DIR="builds-$YEAR$MONTH" if [ -d "$BUILD_DIR" ]; then echo "$BUILD_DIR already exists! Aborting..." exit 1 fi mkdir -p "$BUILD_DIR/elfshaker/elfshaker_data/packs" echo "Builds will be done in $BUILD_DIR." build_month "$BUILD_DIR" "$MONTH" "$YEAR" store_month "$BUILD_DIR" "$MONTH" "$YEAR" pack_month "$BUILD_DIR" "$MONTH" "$YEAR" echo "Pack is available at $BUILD_DIR/elfshaker/elfshaker_data/packs/$YEAR$MONTH.pack" } case "${1:--h}" in -h | --help) print_help [ $# -ne 0 ] exit $? ;; *) main "$@" ;; esac