Skip to content
Snippets Groups Projects
Commit a614865d authored by Golden's avatar Golden
Browse files

Make comptime.sh conform to POSIX and less redundant, among other improvements

- Shebang now directly calls /bin/sh
- Improved indenting within the comprevision() function
- Quoted several strings to prevent possible argument splitting
- Replaced archaic backtick command statements with more descriptive `"$(...)"` statements
- Replaced direct references to `test` with more readable, but equivalent `[ ... ]` statements
- Replaced the ${str:0:8} bashism with an equivalent statement using POSIX cut
- Moved redundant definitions of the comptime.h body to a single function that takes arguments
parent 9bfc82a1
No related branches found
No related tags found
No related merge requests found
#!/bin/bash -e #!/bin/sh
path="." path="."
if [ x"$1" != x ]; then if [ x"$1" != x ]; then
path="$1" path="$1"
fi fi
versiongit() { version() {
gitbranch=`git rev-parse --abbrev-ref HEAD` cat <<EOF > "$path/comptime.h"
gitversion=`git rev-parse HEAD`
cat <<EOF > $path/comptime.h
// Do not edit! This file was autogenerated // Do not edit! This file was autogenerated
// by the $0 script with git // by the $0 script with git
// //
const char* compbranch = "$gitbranch"; const char* compbranch = "$1";
const char* comprevision = "${gitversion:0:8}"; const char* comprevision = "$2";
EOF EOF
exit 0
} }
versionsvn() { versiongit() {
svnrevision=`svnversion -n $1` gitbranch="$(git rev-parse --abbrev-ref HEAD)"
cat <<EOF > $path/comptime.h gitversion="$(git rev-parse HEAD | cut -c -8)"
version "$gitbranch" "$gitversion";
exit 0
}
// Do not edit! This file was autogenerated versionsvn() {
// by the $0 script with subversion svnrevision="$(svnversion -n $1)"
// version "Subversion" "r$svnrevision";
const char* compbranch = "Subversion"; exit 0
const char* comprevision = "r$svnrevision";
EOF
exit 0
} }
versionfake() { versionfake() {
cat <<EOF > $path/comptime.h version "Unknown" "illegal";
// Do not edit! This file was autogenerated
// by the $0 script with an unknown or nonexist SCM
//
const char* compbranch = "Unknown";
const char* comprevision = "illegal";
EOF
} }
compversion() { compversion() {
touch $path/comptime.c touch "$path/comptime.c"
versionfake versionfake
test -d $path/.svn && versionsvn [ -d "$path/.svn" ] && versionsvn
test -d $path/../.git && versiongit [ -d "$path/../.git" ] && versiongit
exit 1 exit 1
} }
test -f $path/comptime.c && compversion [ -f "$path/comptime.c" ] && compversion
exit 2 exit 2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment