-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3651 from jbrazio/feature/generate_version_header…
…_for_marlin Update version header generation script
- Loading branch information
Showing
1 changed file
with
41 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,52 @@ | ||
#!/usr/bin/env bash | ||
# generate_version_header_for_marlin | ||
|
||
DIR="$1" export DIR | ||
OUTFILE="$2" export OUTFILE | ||
|
||
BUILDATE=$(date '+"%s"') | ||
DISTDATE=$(date '+"%Y-%m-%d %H:%M"') | ||
|
||
DIR="$1" | ||
OUTFILE="$2" | ||
|
||
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) | ||
|
||
# Voodoo version tag generator | ||
if [ -z "${VERSION}" ]; then | ||
VERSION=$(git -C "${DIR}" describe --tags --first-parent --always 2>/dev/null) | ||
SHORT_BUILD_VERSION=$(echo "${VERSION}" | sed "s/-.*/${BRANCH}/") | ||
DETAILED_BUILD_VERSION=$(echo "${VERSION}" | sed "s/-/${BRANCH}-/") | ||
else | ||
SHORT_BUILD_VERSION=$(echo "${BRANCH}") | ||
DETAILED_BUILD_VERSION=$(echo "${BRANCH}-${VERSION}") | ||
fi | ||
|
||
# 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") | ||
|
||
cat > "$OUTFILE" <<EOF | ||
/** | ||
* THIS FILE IS AUTOMATICALLY GENERATED DO NOT MANUALLY EDIT IT. | ||
* IT DOES NOT GET COMMITTED TO THE REPOSITORY. | ||
*/ | ||
#define BUILD_UNIX_DATETIME ${BUILDATE} | ||
#define STRING_DISTRIBUTION_DATE ${DISTDATE} | ||
#define PROTOCOL_VERSION "1.0" | ||
#define MACHINE_NAME "Travis CI" | ||
#define SOURCE_CODE_URL "https://github.com/MarlinFirmware/Marlin" | ||
#define DEFAULT_MACHINE_UUID "3442baa1-08ee-435b-8a10-99d185bd43b8" | ||
#define WEBSITE_URL "http://marlinfw.org" | ||
EOF | ||
#define BUILD_UNIX_DATETIME "${BUILDATE}" | ||
#define STRING_DISTRIBUTION_DATE "${DISTDATE}" | ||
( set +e | ||
cd "$DIR" | ||
|
||
BRANCH=`git symbolic-ref -q --short HEAD` | ||
if [ "x$BRANCH" == "x" ] ; then | ||
BRANCH="" | ||
elif [ "x$BRANCH" == "xDevelopment" ] ; then | ||
BRANCH=" dev" | ||
else | ||
BRANCH=" $BRANCH" | ||
fi | ||
|
||
VERSION=`git describe --tags --first-parent 2>/dev/null` | ||
if [ "x$VERSION" != "x" ] ; then | ||
echo "#define SHORT_BUILD_VERSION \"$VERSION\"" | sed "s/-.*/$BRANCH\"/" >>"$OUTFILE" | ||
echo "#define DETAILED_BUILD_VERSION \"$VERSION\"" | sed "s/-/$BRANCH-/" >>"$OUTFILE" | ||
else | ||
VERSION=`git describe --tags --first-parent --always 2>/dev/null` | ||
echo "#define SHORT_BUILD_VERSION \"$BRANCH\"" >>"$OUTFILE" | ||
echo "#define DETAILED_BUILD_VERSION \"${BRANCH}-$VERSION\"" >>"$OUTFILE" | ||
fi | ||
) | ||
#define SHORT_BUILD_VERSION "${SHORT_BUILD_VERSION}" | ||
#define DETAILED_BUILD_VERSION "${DETAILED_BUILD_VERSION}" | ||
#define PROTOCOL_VERSION "${PROTOCOL_VERSION}" | ||
#define MACHINE_NAME "${MACHINE_NAME}" | ||
#define SOURCE_CODE_URL "${SOURCE_CODE_URL}" | ||
#define DEFAULT_MACHINE_UUID "${DEFAULT_MACHINE_UUID}" | ||
#define WEBSITE_URL "${WEBSITE_URL}" | ||
EOF |