From a73dce4a56447cc9d81224ef9e19a42114765e25 Mon Sep 17 00:00:00 2001 From: Ryan Finnie Date: Fri, 23 Apr 2021 23:26:17 -0700 Subject: [PATCH] Clean up / improve generate_version script (#21674) --- buildroot/bin/generate_version | 58 ++++++++++++++-------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/buildroot/bin/generate_version b/buildroot/bin/generate_version index b88e3de918..70a108b1fe 100755 --- a/buildroot/bin/generate_version +++ b/buildroot/bin/generate_version @@ -4,47 +4,35 @@ # # Make a Version.h file to accompany CUSTOM_VERSION_FILE # +# Authors: jbrazio, thinkyhead, InsanityAutomation, rfinnie +# -DIR=${1:-"Marlin"} +set -e -# MRCC3=$( git merge-base HEAD upstream/bugfix-2.0.x 2>/dev/null ) -# MRCC2=$( git merge-base HEAD upstream/bugfix-1.1.x 2>/dev/null ) -# MRCC1=$( git merge-base HEAD upstream/1.1.x 2>/dev/null ) +DIR="${1:-Marlin}" +READ_FILE="${READ_FILE:-${DIR}/Version.h}" +WRITE_FILE="${WRITE_FILE:-${READ_FILE}}" -# BASE='?' -# if [[ -n $MRCC3 && $MRCC3 != $MRCC2 ]]; then -# BASE=bugfix-2.0.x -# elif [[ -n $MRCC2 ]]; then -# BASE=bugfix-1.1.x -# elif [[ -n $MRCC1 ]]; then -# BASE=1.1.x -# fi +BRANCH="$(git -C "${DIR}" symbolic-ref -q --short HEAD 2>/dev/null || true)" +VERSION="$(git -C "${DIR}" describe --tags --first-parent 2>/dev/null || true)" -BUILDATE=$(date '+%s') -DISTDATE=$(date '+%Y-%m-%d %H:%M') - -BRANCH=$(git -C "${DIR}" symbolic-ref -q --short HEAD) -VERSION=$(git -C "${DIR}" describe --tags --first-parent 2>/dev/null) - -[ -z "${BRANCH}" ] && BRANCH=$(echo "${TRAVIS_BRANCH}") -[ -z "${VERSION}" ] && VERSION=$(git -C "${DIR}" describe --tags --first-parent --always 2>/dev/null) - -SHORT_BUILD_VERSION=$(echo "${BRANCH}") -DETAILED_BUILD_VERSION=$(echo "${BRANCH}-${VERSION}") +STRING_DISTRIBUTION_DATE="${STRING_DISTRIBUTION_DATE:-$(date '+%Y-%m-%d %H:%M')}" +SHORT_BUILD_VERSION="${SHORT_BUILD_VERSION:-${BRANCH}}" +DETAILED_BUILD_VERSION="${DETAILED_BUILD_VERSION:-${BRANCH}-${VERSION}}" # Gets some misc options from their defaults -DEFAULT_MACHINE_UUID=$(awk -F'"' \ - '/#define DEFAULT_MACHINE_UUID/{ print $2 }' < "${DIR}/Version.h") -MACHINE_NAME=$(awk -F'"' \ - '/#define MACHINE_NAME/{ print $2 }' < "${DIR}/Version.h") -PROTOCOL_VERSION=$(awk -F'"' \ - '/#define PROTOCOL_VERSION/{ print $2 }' < "${DIR}/Version.h") -SOURCE_CODE_URL=$(awk -F'"' \ - '/#define SOURCE_CODE_URL/{ print $2 }' < "${DIR}/Version.h") -WEBSITE_URL=$(awk -F'"' \ - '/#define WEBSITE_URL/{ print $2 }' < "${DIR}/Version.h") +DEFAULT_MACHINE_UUID="${DEFAULT_MACHINE_UUID:-$(awk -F'"' \ + '/#define DEFAULT_MACHINE_UUID/{ print $2 }' < "${READ_FILE}")}" +MACHINE_NAME="${MACHINE_NAME:-$(awk -F'"' \ + '/#define MACHINE_NAME/{ print $2 }' < "${READ_FILE}")}" +PROTOCOL_VERSION="${PROTOCOL_VERSION:-$(awk -F'"' \ + '/#define PROTOCOL_VERSION/{ print $2 }' < "${READ_FILE}")}" +SOURCE_CODE_URL="${SOURCE_CODE_URL:-$(awk -F'"' \ + '/#define SOURCE_CODE_URL/{ print $2 }' < "${READ_FILE}")}" +WEBSITE_URL="${WEBSITE_URL:-$(awk -F'"' \ + '/#define WEBSITE_URL/{ print $2 }' < "${READ_FILE}")}" -cat > "${DIR}/Version.h" < "${WRITE_FILE}" < "${DIR}/Version.h" <