#!/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 global 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 { global origin := '"origin/'" } global git_time := $[git log -1 --pretty=format:%ct] #collect the contents global commit := $[git rev-parse HEAD] global commit_short := $[git rev-parse --short HEAD] if test -n $[git status --porcelain] { # append dirty mark '*' if the repository has uncommited changes global commit_short := ""$commit_short"*" } global branch := $[git branch | sed -n '/\* /s///p] global topdir := $[git rev-parse --show-toplevel] global verchanged := $[git blame -L ,1 -sl -- "$topdir/VERSION" | cut -f 1 -d " ] if test $verchanged = 0000000000000000000000000000000000000000 { # uncommited change to VERSION global build_number := '0' } else { global build_number := $[git rev-list --count HEAD "^$verchanged] } global date_string := $git_time matchstr $[uname] { Darwin | FreeBSD { global date_string := $[/bin/date -jr $git_time -u '+%Y-%m-%d %H:%M %Z] } MINGW* { global git_time := $[git log -1 --pretty=format:%ci] global date_string := $[/bin/date --date="$git_time" -u '+%Y-%m-%d %H:%M %Z] } * { global date_string := $[/bin/date --date="@$git_time" -u '+%Y-%m-%d %H:%M %Z] } } if test $[git describe --tags --exact-match !2 > /dev/null] { global tagged_commit := '"true'" } else { global tagged_commit := '"false'" } global fork_master_distance := $[git rev-list HEAD ^"$[echo $origin]master" | wc -l | sed -e 's/[^[:digit:]]//g] global 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 { global build_number := '"-1'" } if test -z $fork_master_distance { global fork_master_distance := '"-1'" } if test -z $fork_master_timestamp { global 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 ")" (CommandList children: [ (C {(echo)} {(DQ ("# This file was autogenerated in base/version_git.sh"))}) (C {(echo)} {(DQ ("struct GitVersionInfo"))}) (C {(echo)} {(DQ (" commit::AbstractString"))}) (C {(echo)} {(DQ (" commit_short::AbstractString"))}) (C {(echo)} {(DQ (" branch::AbstractString"))}) (C {(echo)} {(DQ (" build_number::Int"))}) (C {(echo)} {(DQ (" date_string::AbstractString"))}) (C {(echo)} {(DQ (" tagged_commit::Bool"))}) (C {(echo)} {(DQ (" fork_master_distance::Int"))}) (C {(echo)} {(DQ (" fork_master_timestamp::Float64"))}) (C {(echo)} {(DQ (end))}) (C {(echo)} {(DQ )}) (C {(cd)} {($ VSub_Number "$1")}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Pound "$#"))} {(Lit_Other "=")} {(DQ (2))} {(-a)} {(DQ ($ VSub_Number "$2"))} {(Lit_Other "=")} {(DQ (NO_GIT))} {(Lit_Other "]")} ) terminator: <Op_Semi ";"> ) ] action: [ (C {(echo)} {(DQ ("# Default output if git is not available."))}) (C {(echo)} { (DQ ("const GIT_VERSION_INFO = GitVersionInfo(") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (" ,") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (" ,") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (" ,0 ,") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (" ,true ,0 ,0.)") ) } ) (C {(exit)} {(0)}) ] spids: [-1 120] ) ] spids: [-1 157] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:origin) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (SimpleCommand words: [{(git)} {(config)} {(-l)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [170] ) ] ) (C {(grep)} {(SQ <"remote\\.\\w*\\.url.*JuliaLang/julia">)}) (C {(sed)} {(-n)} {(SQ <"s/remote\\.\\([a-zA-Z]*\\)\\..*/\\1\\//p">)}) ] negated: False ) ] ) left_token: <Left_CommandSub "$("> spids: [163 190] ) } spids: [162] ) ] spids: [162] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$origin"))} {(Lit_Other "]")}) terminator: <Op_Semi ";"> ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:origin) op: Equal rhs: {(DQ (origin/))} spids: [208] ) ] spids: [208] ) ] spids: [-1 205] ) ] spids: [-1 213] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:git_time) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(log)} {(-1)} {(--pretty) (Lit_Other "=") (format) (Lit_Other ":") (Lit_Other "%") (ct)} ) ] ) left_token: <Left_CommandSub "$("> spids: [216 229] ) } spids: [215] ) ] spids: [215] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:commit) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(git)} {(rev-parse)} {(HEAD)})]) left_token: <Left_CommandSub "$("> spids: [236 242] ) } spids: [235] ) ] spids: [235] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:commit_short) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(git)} {(rev-parse)} {(--short)} {(HEAD)})]) left_token: <Left_CommandSub "$("> spids: [245 253] ) } spids: [244] ) ] spids: [244] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-n)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(git)} {(status)} {(--porcelain)})]) left_token: <Left_CommandSub "$("> spids: [262 268] ) ) } {(Lit_Other "]")} ) terminator: <Op_Semi ";"> ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:commit_short) op: Equal rhs: {(DQ ($ VSub_Name "$commit_short")) (Lit_Other "*")} spids: [281] ) ] spids: [281] ) ] spids: [-1 274] ) ] spids: [-1 287] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:branch) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(git)} {(branch)}) (C {(sed)} {(-n)} {(SQ <"/\\* /s///p">)})] negated: False ) ] ) left_token: <Left_CommandSub "$("> spids: [290 304] ) } spids: [289] ) ] spids: [289] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:topdir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(git)} {(rev-parse)} {(--show-toplevel)})]) left_token: <Left_CommandSub "$("> spids: [308 314] ) } spids: [307] ) ] spids: [307] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:verchanged) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(git)} {(blame)} {(-L)} {(Lit_Comma ",") (1)} {(-sl)} {(--)} {(DQ ($ VSub_Name "$topdir") (/VERSION))} ) (C {(cut)} {(-f)} {(1)} {(-d)} {(DQ (" "))}) ] negated: False ) ] ) left_token: <Left_CommandSub "$("> spids: [317 349] ) } spids: [316] ) ] spids: [316] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$verchanged")} {(Lit_Other "=")} {(0000000000000000000000000000000000000000)} {(Lit_Other "]")} ) terminator: <Op_Semi ";"> ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:build_number) op:Equal rhs:{(0)} spids:[371])] spids: [371] ) ] spids: [-1 364] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:build_number) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(rev-list)} {(--count)} {(HEAD)} {(DQ ("^") ($ VSub_Name "$verchanged"))} ) ] ) left_token: <Left_CommandSub "$("> spids: [378 391] ) } spids: [377] ) ] spids: [377] ) ] spids: [374 393] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:date_string) op: Equal rhs: {($ VSub_Name "$git_time")} spids: [396] ) ] spids: [396] ) (Case to_match: { (CommandSubPart command_list: (CommandList children:[(C {(uname)})]) left_token: <Left_CommandSub "$("> spids: [401 403] ) } arms: [ (case_arm pat_list: [{(Darwin)} {(FreeBSD)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:date_string) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(/bin/date)} {(-jr)} {($ VSub_Name "$git_time")} {(-u)} {(SQ <"+%Y-%m-%d %H:%M %Z">)} ) ] ) left_token: <Left_CommandSub "$("> spids: [418 430] ) ) } spids: [416] ) ] spids: [416] ) ] spids: [408 413 434 -1] ) (case_arm pat_list: [{(MINGW) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:git_time) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(log)} {(-1)} {(--pretty) (Lit_Other "=") (format) (Lit_Other ":") (Lit_Other "%") (ci) } ) ] ) left_token: <Left_CommandSub "$("> spids: [443 456] ) } spids: [442] ) ] spids: [442] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:date_string) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(/bin/date)} {(--date) (Lit_Other "=") (DQ ($ VSub_Name "$git_time"))} {(-u)} {(SQ <"+%Y-%m-%d %H:%M %Z">)} ) ] ) left_token: <Left_CommandSub "$("> spids: [461 475] ) ) } spids: [459] ) ] spids: [459] ) ] spids: [437 439 479 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:date_string) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(/bin/date)} {(--date) (Lit_Other "=") (DQ ("@") ($ VSub_Name "$git_time"))} {(-u)} {(SQ <"+%Y-%m-%d %H:%M %Z">)} ) ] ) left_token: <Left_CommandSub "$("> spids: [488 503] ) ) } spids: [486] ) ] spids: [486] ) ] spids: [482 483 507 -1] ) ] spids: [399 405 509] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(git)} {(describe)} {(--tags)} {(--exact-match)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [524] ) ] ) ] ) left_token: <Left_CommandSub "$("> spids: [515 527] ) } {(Lit_Other "]")} ) terminator: <Op_Semi ";"> ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:tagged_commit) op: Equal rhs: {(DQ (true))} spids: [535] ) ] spids: [535] ) ] spids: [-1 532] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:tagged_commit) op: Equal rhs: {(DQ (false))} spids: [543] ) ] spids: [543] ) ] spids: [540 548] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fork_master_distance) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(git)} {(rev-list)} {(HEAD)} {(Lit_Other "^") (DQ (CommandSubPart command_list: (CommandList children: [(C {(echo)} {($ VSub_Name "$origin")})] ) left_token: <Left_CommandSub "$("> spids: [560 564] ) (master) ) } ) (C {(wc)} {(-l)}) (C {(sed)} {(-e)} {(SQ <"s/[^[:digit:]]//g">)}) ] negated: False ) ] ) left_token: <Left_CommandSub "$("> spids: [551 583] ) } spids: [550] ) ] spids: [550] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fork_master_timestamp) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(show)} {(-s)} { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(merge-base)} {(HEAD)} { (CommandSubPart command_list: (CommandList children: [(C {(echo)} {($ VSub_Name "$origin")})] ) left_token: <Left_CommandSub "$("> spids: [600 604] ) (master) } ) ] ) left_token: <Left_CommandSub "$("> spids: [593 606] ) } {(--format) (Lit_Other "=") (format) (Lit_Other ":") (DQ ("%ct"))} ) ] ) left_token: <Left_CommandSub "$("> spids: [586 615] ) } spids: [585] ) ] spids: [585] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$build_number"))} {(Lit_Other "]")}) terminator: <Op_Semi ";"> ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:build_number) op: Equal rhs: {(DQ (-1))} spids: [637] ) ] spids: [637] ) ] spids: [-1 634] ) ] spids: [-1 642] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$fork_master_distance"))} {(Lit_Other "]")} ) terminator: <Op_Semi ";"> ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fork_master_distance) op: Equal rhs: {(DQ (-1))} spids: [660] ) ] spids: [660] ) ] spids: [-1 657] ) ] spids: [-1 665] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$fork_master_timestamp"))} {(Lit_Other "]")} ) terminator: <Op_Semi ";"> ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:fork_master_timestamp) op: Equal rhs: {(DQ (0))} spids: [683] ) ] spids: [683] ) ] spids: [-1 680] ) ] spids: [-1 688] ) (C {(echo)} {(DQ ("const GIT_VERSION_INFO = GitVersionInfo("))}) (C {(echo)} { (DQ (" ") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) ($ VSub_Name "$commit") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (",") ) } ) (C {(echo)} { (DQ (" ") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) ($ VSub_Name "$commit_short") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (",") ) } ) (C {(echo)} { (DQ (" ") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) ($ VSub_Name "$branch") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (",") ) } ) (C {(echo)} {(DQ (" ") ($ VSub_Name "$build_number") (","))}) (C {(echo)} { (DQ (" ") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) ($ VSub_Name "$date_string") (EscapedLiteralPart token:<Lit_EscapedChar "\\\"">) (",") ) } ) (C {(echo)} {(DQ (" ") ($ VSub_Name "$tagged_commit") (","))}) (C {(echo)} {(DQ (" ") ($ VSub_Name "$fork_master_distance") (","))}) (C {(echo)} {(DQ (" ") ($ VSub_Name "$fork_master_timestamp") (.))}) (C {(echo)} {(DQ (")"))}) ] )