#!/bin/sh # This file is a part of Julia. License is MIT: https://julialang.org/license # This file collects git info and create a julia file with the GIT_VERSION_INFO struct echo "# This file was autogenerated in base/version_git.sh" echo "struct GitVersionInfo" echo " commit::AbstractString" echo " commit_short::AbstractString" echo " branch::AbstractString" echo " build_number::Int" echo " date_string::AbstractString" echo " tagged_commit::Bool" echo " fork_master_distance::Int" echo " fork_master_timestamp::Float64" echo "end" echo "" cd $1 # If the script didn't ask not to use git info if test "$Argc" = "2" -a $2 = "NO_GIT" { # this comment is used in base/Makefile to distinguish boilerplate echo "# Default output if git is not available." echo "const GIT_VERSION_INFO = GitVersionInfo(\"\" ,\"\" ,\"\" ,0 ,\"\" ,true ,0 ,0.)" exit 0 } # Collect temporary variables setglobal origin = $[git config -l !2 >/dev/null | grep 'remote\.\w*\.url.*JuliaLang/julia' | sed -n 's/remote\.\([a-zA-Z]*\)\..*/\1\//p] if test -z $origin { setglobal origin = '"origin/'" } setglobal git_time = $[git log -1 --pretty=format:%ct] #collect the contents setglobal commit = $[git rev-parse HEAD] setglobal commit_short = $[git rev-parse --short HEAD] if test -n $[git status --porcelain] { # append dirty mark '*' if the repository has uncommited changes setglobal commit_short = ""$commit_short"*" } setglobal branch = $[git branch | sed -n '/\* /s///p] setglobal topdir = $[git rev-parse --show-toplevel] setglobal verchanged = $[git blame -L ,1 -sl -- "$topdir/VERSION" | cut -f 1 -d " ] if test $verchanged = 0000000000000000000000000000000000000000 { # uncommited change to VERSION setglobal build_number = '0' } else { setglobal build_number = $[git rev-list --count HEAD "^$verchanged] } setglobal date_string = $git_time match $[uname] { with Darwin | FreeBSD setglobal date_string = $[/bin/date -jr $git_time -u '+%Y-%m-%d %H:%M %Z] with MINGW* setglobal git_time = $[git log -1 --pretty=format:%ci] setglobal date_string = $[/bin/date --date="$git_time" -u '+%Y-%m-%d %H:%M %Z] with * setglobal date_string = $[/bin/date --date="@$git_time" -u '+%Y-%m-%d %H:%M %Z] } if test $[git describe --tags --exact-match !2 > /dev/null] { setglobal tagged_commit = '"true'" } else { setglobal tagged_commit = '"false'" } setglobal fork_master_distance = $[git rev-list HEAD ^"$[echo $origin]master" | wc -l | sed -e 's/[^[:digit:]]//g] setglobal fork_master_timestamp = $[git show -s $[git merge-base HEAD $[echo $origin]master] --format=format:"%ct] # Check for errrors and emit default value for missing numbers. if test -z $build_number { setglobal build_number = '"-1'" } if test -z $fork_master_distance { setglobal fork_master_distance = '"-1'" } if test -z $fork_master_timestamp { setglobal fork_master_timestamp = '"0'" } echo "const GIT_VERSION_INFO = GitVersionInfo(" echo " \"$commit\"," echo " \"$commit_short\"," echo " \"$branch\"," echo " $build_number," echo " \"$date_string\"," echo " $tagged_commit," echo " $fork_master_distance," echo " $fork_master_timestamp." echo ")"