-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replacing python commit_id script with bash
- Loading branch information
1 parent
503c146
commit 317eaf3
Showing
2 changed files
with
57 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2018 The ANGLE Project Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
# Generate commit.h with git commit hash. | ||
# | ||
|
||
set -e | ||
|
||
function usage { | ||
echo 'Usage: commit_id.sh check <angle_dir> - check if git is present' | ||
echo ' commit_id.sh gen <angle_dir> <file_to_write> - generate commit.h' | ||
} | ||
|
||
if [ "$#" -lt 2 ] | ||
then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
d="$2" | ||
|
||
if [ "$1" == "check" ] | ||
then | ||
if [ -f "$d/.git/index" ] | ||
then | ||
echo 1 | ||
else | ||
echo 0 | ||
fi | ||
elif [ "$1" == "gen" ] | ||
then | ||
if [ ! "$3" ] | ||
then | ||
usage | ||
exit 1 | ||
fi | ||
output="$(cd "$(dirname "$3")"; pwd -P)/$(basename "$3")" | ||
|
||
( | ||
set +e | ||
cd "$d" | ||
commit_id_size=12 | ||
commit_id=$(git rev-parse --short=$commit_id_size HEAD 2>/dev/null) | ||
commit_date=$(git show -s --format=%ci HEAD 2>/dev/null) | ||
|
||
echo '#define ANGLE_COMMIT_HASH "'"${commit_id:-invalid-hash}"'"' > "$output" | ||
echo '#define ANGLE_COMMIT_HASH_SIZE '"$commit_id_size" >> "$output" | ||
echo '#define ANGLE_COMMIT_DATE "'"${commit_date:-invalid-date}"'"' >> "$output" | ||
|
||
) | ||
else | ||
usage | ||
exit 2 | ||
fi |