| #!/usr/bin/env bash |
| |
| # Copyright 2016 The Fuchsia Authors |
| # Copyright (c) 2015 Travis Geiselbrecht |
| # |
| # Use of this source code is governed by a MIT-style |
| # license that can be found in the LICENSE file or at |
| # https://opensource.org/licenses/MIT |
| |
| readonly OUTFILE="$1" |
| readonly DEPFILE="$2" |
| readonly GIT_DIR="$3" |
| |
| set -e |
| |
| GIT_REV="git-$(git --git-dir="$GIT_DIR" rev-parse HEAD 2>/dev/null)" |
| if [ -n "$(git --git-dir="$GIT_DIR" status --porcelain --untracked-files=no 2>/dev/null)" ]; then |
| GIT_REV+="-dirty" |
| fi |
| |
| CONTENTS="// This file is generated by $0. DO NOT EDIT! |
| constexpr char kVersionString[] = \"${GIT_REV}\";" |
| |
| # Update the existing file only if it's changed. |
| if [ ! -r "$OUTFILE" ] || [ "$(<"$OUTFILE")" != "$CONTENTS" ]; then |
| echo "$CONTENTS" > "$OUTFILE" |
| fi |
| |
| echo "$OUTFILE: $GIT_DIR/HEAD $GIT_DIR/index" > "$DEPFILE" |