| 
				
			 | 
			
			
				@@ -85,100 +85,91 @@ git_lasthash() { 
			 | 
		
	
		
			
			| 
				85
			 | 
			
				85
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				86
			 | 
			
				86
			 | 
			
			
				     # Show last commit hash (with .dirty suffix if needed) 
			 | 
		
	
		
			
			| 
				87
			 | 
			
				87
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				88
			 | 
			
				
			 | 
			
			
				-    # If outside git repo, get it from .mkit/git_lasthash, which 
			 | 
		
	
		
			
			| 
				89
			 | 
			
				
			 | 
			
			
				-    # should have been put there by dist target.  (I.e., this won't 
			 | 
		
	
		
			
			| 
				90
			 | 
			
				
			 | 
			
			
				-    # work if you got outside the git repo in other way than dist 
			 | 
		
	
		
			
			| 
				91
			 | 
			
				
			 | 
			
			
				-    # target, but that's actually expected.) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				88
			 | 
			
			
				+    # We can't do it outside git repo (or without git) but we should 
			 | 
		
	
		
			
			| 
				
			 | 
			
				89
			 | 
			
			
				+    # not be asked to; targets that don't require git should make use 
			 | 
		
	
		
			
			| 
				
			 | 
			
				90
			 | 
			
			
				+    # of cache built by dist target. 
			 | 
		
	
		
			
			| 
				92
			 | 
			
				91
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				93
			 | 
			
				92
			 | 
			
			
				     local last_hash     # last commit hash 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				
			 | 
			
			
				-    if git_present; then    # we are in git repo 
			 | 
		
	
		
			
			| 
				95
			 | 
			
				
			 | 
			
			
				-        last_hash=$(git rev-parse HEAD) 
			 | 
		
	
		
			
			| 
				96
			 | 
			
				
			 | 
			
			
				-        echo -n "$last_hash" 
			 | 
		
	
		
			
			| 
				97
			 | 
			
				
			 | 
			
			
				-        git_bool dirty && echo -n ".dirty" 
			 | 
		
	
		
			
			| 
				98
			 | 
			
				
			 | 
			
			
				-    else    # we are outside (eg. distributor's build dir') 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				
			 | 
			
			
				-        grep . .mkit/git_lasthash || { 
			 | 
		
	
		
			
			| 
				100
			 | 
			
				
			 | 
			
			
				-            echo UNKNOWN 
			 | 
		
	
		
			
			| 
				101
			 | 
			
				
			 | 
			
			
				-            warn "malformed source, could not determine git hash" 
			 | 
		
	
		
			
			| 
				102
			 | 
			
				
			 | 
			
			
				-        } 
			 | 
		
	
		
			
			| 
				103
			 | 
			
				
			 | 
			
			
				-    fi 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+    git_present || { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				94
			 | 
			
			
				+        echo UNKNOWN_HASH 
			 | 
		
	
		
			
			| 
				
			 | 
			
				95
			 | 
			
			
				+        warn "no git present; could not determine last hash" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				96
			 | 
			
			
				+        return 3 
			 | 
		
	
		
			
			| 
				
			 | 
			
				97
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				98
			 | 
			
			
				+    last_hash=$(git rev-parse HEAD) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				99
			 | 
			
			
				+    echo -n "$last_hash" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				100
			 | 
			
			
				+    git_bool dirty && echo -n ".dirty" 
			 | 
		
	
		
			
			| 
				104
			 | 
			
				101
			 | 
			
			
				 } 
			 | 
		
	
		
			
			| 
				105
			 | 
			
				102
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				106
			 | 
			
				103
			 | 
			
			
				 semver() { 
			 | 
		
	
		
			
			| 
				107
			 | 
			
				104
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				108
			 | 
			
				
			 | 
			
			
				-    # Build semver version string with build metadata 
			 | 
		
	
		
			
			| 
				
			 | 
			
				105
			 | 
			
			
				+    # Build proper SemVer version string 
			 | 
		
	
		
			
			| 
				109
			 | 
			
				106
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				110
			 | 
			
				107
			 | 
			
			
				     # Build version string from available info using following 
			 | 
		
	
		
			
			| 
				111
			 | 
			
				108
			 | 
			
			
				     # logic: 
			 | 
		
	
		
			
			| 
				112
			 | 
			
				109
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				113
			 | 
			
				
			 | 
			
			
				-    #  1. use project.version (from mkit.ini) 
			 | 
		
	
		
			
			| 
				114
			 | 
			
				
			 | 
			
			
				-    #  2. if we are in git, override the version with last tag 
			 | 
		
	
		
			
			| 
				115
			 | 
			
				
			 | 
			
			
				-    #  3. if set, add project:prerl (from mkit.ini) as pre-release ID 
			 | 
		
	
		
			
			| 
				
			 | 
			
				110
			 | 
			
			
				+    #  1. Use version from last git tag (or mkit.ini if there is no 
			 | 
		
	
		
			
			| 
				
			 | 
			
				111
			 | 
			
			
				+    #     tag, which is possible on new project) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				112
			 | 
			
			
				+    #  2. if set, add project:prerl (from mkit.ini) as pre-release ID 
			 | 
		
	
		
			
			| 
				116
			 | 
			
				113
			 | 
			
			
				     #     (afer dash) 
			 | 
		
	
		
			
			| 
				117
			 | 
			
				
			 | 
			
			
				-    #  4. if we are at a later commit than the last tag, add branch 
			 | 
		
	
		
			
			| 
				
			 | 
			
				114
			 | 
			
			
				+    #  3. if we are at a later commit than the last tag, add branch 
			 | 
		
	
		
			
			| 
				118
			 | 
			
				115
			 | 
			
			
				     #     name and commit sha1 to build metadata (after plus sign) 
			 | 
		
	
		
			
			| 
				119
			 | 
			
				
			 | 
			
			
				-    #  5. if the tree is "dirty", i.e. has uncommited changes, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				116
			 | 
			
			
				+    #  4. if the tree is "dirty", i.e. has uncommited changes, 
			 | 
		
	
		
			
			| 
				120
			 | 
			
				117
			 | 
			
			
				     #     add "dirty" to build metadata 
			 | 
		
	
		
			
			| 
				121
			 | 
			
				118
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				122
			 | 
			
				119
			 | 
			
			
				     # The version is compatible with SemVer 2.0.0. 
			 | 
		
	
		
			
			| 
				123
			 | 
			
				120
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				124
			 | 
			
				121
			 | 
			
			
				     # Examples: 
			 | 
		
	
		
			
			| 
				125
			 | 
			
				122
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				126
			 | 
			
				
			 | 
			
			
				-    #     myprog v1.0.7                         # all clear 
			 | 
		
	
		
			
			| 
				127
			 | 
			
				
			 | 
			
			
				-    #     myprog v1.0.7-alpha                   # mkit.ini: project:prerl="alpha" 
			 | 
		
	
		
			
			| 
				128
			 | 
			
				
			 | 
			
			
				-    #     myprog v1.0.7-alpha+g1aef811.master   # ^^ + some commits after 
			 | 
		
	
		
			
			| 
				129
			 | 
			
				
			 | 
			
			
				-    #     myprog v1.0.7-alpha+gf14fc4f.api2     # ^^ + on a feature branch 
			 | 
		
	
		
			
			| 
				130
			 | 
			
				
			 | 
			
			
				-    #     myprog v1.0.7-alpha+gf14fc4f.api2.dirty  # ^^ + tree edited 
			 | 
		
	
		
			
			| 
				131
			 | 
			
				
			 | 
			
			
				-    #     myprog v1.0.7-alpha+dirty             # tag OK but tree edited 
			 | 
		
	
		
			
			| 
				132
			 | 
			
				
			 | 
			
			
				-    #     myprog v1.0.7+dirty                   # ^^ but no pre-release id 
			 | 
		
	
		
			
			| 
				
			 | 
			
				123
			 | 
			
			
				+    #     foo v1.0.7                            # all clear; proper release 
			 | 
		
	
		
			
			| 
				
			 | 
			
				124
			 | 
			
			
				+    #     foo v1.0.7-beta                       # mkit.ini: project:prerl="beta" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				125
			 | 
			
			
				+    #     foo v1.0.7-beta+g1aef811.master       # ^^ + some commits after 
			 | 
		
	
		
			
			| 
				
			 | 
			
				126
			 | 
			
			
				+    #     foo v1.0.7-beta+gf14fc4f.api2         # ^^ + on a feature branch 
			 | 
		
	
		
			
			| 
				
			 | 
			
				127
			 | 
			
			
				+    #     foo v1.0.7-beta+gf14fc4f.api2.dirty   # ^^ + tree edited 
			 | 
		
	
		
			
			| 
				
			 | 
			
				128
			 | 
			
			
				+    #     foo v1.0.7-beta+dirty                 # tag OK but tree edited 
			 | 
		
	
		
			
			| 
				
			 | 
			
				129
			 | 
			
			
				+    #     foo v1.0.7+dirty                      # ^^ but no pre-release id 
			 | 
		
	
		
			
			| 
				133
			 | 
			
				130
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				134
			 | 
			
				131
			 | 
			
			
				     # Note that versions with "dirty" should be perceived as kind of 
			 | 
		
	
		
			
			| 
				135
			 | 
			
				132
			 | 
			
			
				     # dangerous outside developer's own machine.  Versions with sha1 are 
			 | 
		
	
		
			
			| 
				136
			 | 
			
				133
			 | 
			
			
				     # safer but must not be released. 
			 | 
		
	
		
			
			| 
				137
			 | 
			
				134
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				138
			 | 
			
				
			 | 
			
			
				-    # I have considered decorating the git commit refs to make them 
			 | 
		
	
		
			
			| 
				139
			 | 
			
				
			 | 
			
			
				-    # sort of sortable (e.g. "r1.g1aef811"), but on second thought, 
			 | 
		
	
		
			
			| 
				140
			 | 
			
				
			 | 
			
			
				-    # I don't think it's good idea to give *any* semantics to meta-data 
			 | 
		
	
		
			
			| 
				141
			 | 
			
				
			 | 
			
			
				-    # at all.  First, there is no rule that r1<r2<r3; a commit can be 
			 | 
		
	
		
			
			| 
				142
			 | 
			
				
			 | 
			
			
				-    # removing what other just added and one change can be split to 
			 | 
		
	
		
			
			| 
				143
			 | 
			
				
			 | 
			
			
				-    # multiple commits.  Also, the whole thing breaks anyway once you 
			 | 
		
	
		
			
			| 
				144
			 | 
			
				
			 | 
			
			
				-    # rebase your branch (no, it's not a sin).  The sole purpose of 
			 | 
		
	
		
			
			| 
				145
			 | 
			
				
			 | 
			
			
				-    # meta-data is to *identify* the code, and provide safe path back 
			 | 
		
	
		
			
			| 
				146
			 | 
			
				
			 | 
			
			
				-    # to tree; commit refs are already perfect for that. 
			 | 
		
	
		
			
			| 
				147
			 | 
			
				
			 | 
			
			
				-    # 
			 | 
		
	
		
			
			| 
				148
			 | 
			
				135
			 | 
			
			
				     # FIXME:  Using project:prerl for release IDs may not be compatible with 
			 | 
		
	
		
			
			| 
				149
			 | 
			
				136
			 | 
			
			
				     #         release strategy implemented in release.sh 
			 | 
		
	
		
			
			| 
				150
			 | 
			
				137
			 | 
			
			
				     # 
			 | 
		
	
		
			
			| 
				151
			 | 
			
				
			 | 
			
			
				-    local version       # version string (final result) 
			 | 
		
	
		
			
			| 
				152
			 | 
			
				
			 | 
			
			
				-    local prerl         # pre-release keyword (from mkit.ini, eg. 'alpha') 
			 | 
		
	
		
			
			| 
				
			 | 
			
				138
			 | 
			
			
				+    local xyz           # base version string 
			 | 
		
	
		
			
			| 
				
			 | 
			
				139
			 | 
			
			
				+    local prerl         # pre-release keyword (from mkit.ini, eg. 'beta') 
			 | 
		
	
		
			
			| 
				153
			 | 
			
				140
			 | 
			
			
				     local latest_tag    # latest git tag 
			 | 
		
	
		
			
			| 
				154
			 | 
			
				141
			 | 
			
			
				     local commit        # commit indicator (CURRENT_BRANCH.gHASH) 
			 | 
		
	
		
			
			| 
				155
			 | 
			
				142
			 | 
			
			
				     local dirty         # 0 if dirty, 1 if clean 
			 | 
		
	
		
			
			| 
				156
			 | 
			
				143
			 | 
			
			
				     local suffix        # version suffix 
			 | 
		
	
		
			
			| 
				157
			 | 
			
				
			 | 
			
			
				-    local_get semver && return 0 
			 | 
		
	
		
			
			| 
				158
			 | 
			
				
			 | 
			
			
				-    version=$(ini 1value project:version) 
			 | 
		
	
		
			
			| 
				159
			 | 
			
				144
			 | 
			
			
				     prerl=$(ini 1value project:prerl) 
			 | 
		
	
		
			
			| 
				160
			 | 
			
				145
			 | 
			
			
				     grep ":" <<<"$prerl" \ 
			 | 
		
	
		
			
			| 
				161
			 | 
			
				146
			 | 
			
			
				      && warn "colon in project:prerl may corrupt version data: $prerl" 
			 | 
		
	
		
			
			| 
				162
			 | 
			
				
			 | 
			
			
				-    if git_present; 
			 | 
		
	
		
			
			| 
				163
			 | 
			
				
			 | 
			
			
				-    then    # we are in git repo... so we can get smart 
			 | 
		
	
		
			
			| 
				164
			 | 
			
				
			 | 
			
			
				-        latest_tag=$(git_fact latest_tag) 
			 | 
		
	
		
			
			| 
				165
			 | 
			
				
			 | 
			
			
				-        if ! git describe --tags --exact-match HEAD >&/dev/null; 
			 | 
		
	
		
			
			| 
				166
			 | 
			
				
			 | 
			
			
				-        then    # we are at a later commit than the last tag 
			 | 
		
	
		
			
			| 
				167
			 | 
			
				
			 | 
			
			
				-            commit="$(git_fact current_branch).g$(git_fact latest_sha)" 
			 | 
		
	
		
			
			| 
				168
			 | 
			
				
			 | 
			
			
				-        fi 
			 | 
		
	
		
			
			| 
				169
			 | 
			
				
			 | 
			
			
				-        git_bool dirty; dirty=$? 
			 | 
		
	
		
			
			| 
				170
			 | 
			
				
			 | 
			
			
				-        test -n "$latest_tag" && version=${latest_tag:1} 
			 | 
		
	
		
			
			| 
				171
			 | 
			
				
			 | 
			
			
				-        case "$dirty:$commit" in 
			 | 
		
	
		
			
			| 
				172
			 | 
			
				
			 | 
			
			
				-            1:)  suffix=""               ;; 
			 | 
		
	
		
			
			| 
				173
			 | 
			
				
			 | 
			
			
				-            0:)  suffix="+dirty"         ;; 
			 | 
		
	
		
			
			| 
				174
			 | 
			
				
			 | 
			
			
				-            1:*) suffix="+$commit"       ;; 
			 | 
		
	
		
			
			| 
				175
			 | 
			
				
			 | 
			
			
				-            0:*) suffix="+$commit.dirty" ;; 
			 | 
		
	
		
			
			| 
				176
			 | 
			
				
			 | 
			
			
				-            *)   suffix=MKIT_BUG 
			 | 
		
	
		
			
			| 
				177
			 | 
			
				
			 | 
			
			
				-                 warn "MKIT_BUG: bad dirt/commit detection" ;; 
			 | 
		
	
		
			
			| 
				178
			 | 
			
				
			 | 
			
			
				-        esac 
			 | 
		
	
		
			
			| 
				179
			 | 
			
				
			 | 
			
			
				-        test -n "$prerl" && suffix="-$prerl$suffix" 
			 | 
		
	
		
			
			| 
				180
			 | 
			
				
			 | 
			
			
				-        version="$version$suffix" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				147
			 | 
			
			
				+    git_present || { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				148
			 | 
			
			
				+        echo UNKNOWN_VERSION 
			 | 
		
	
		
			
			| 
				
			 | 
			
				149
			 | 
			
			
				+        warn "no git present; could not determine SemVer" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				150
			 | 
			
			
				+        return 3 
			 | 
		
	
		
			
			| 
				
			 | 
			
				151
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				152
			 | 
			
			
				+    latest_tag=$(git_fact latest_tag) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				153
			 | 
			
			
				+    case $latest_tag in 
			 | 
		
	
		
			
			| 
				
			 | 
			
				154
			 | 
			
			
				+        v*) xyz=${latest_tag:1} ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				155
			 | 
			
			
				+        "") warn "no tags, using base version from mkit.ini (ok for new project)" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				156
			 | 
			
			
				+            xyz=$(ini 1value project:version) ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				157
			 | 
			
			
				+        *)  warn "bad form of last tag, using base version from mkit.ini: tag is '$latest_tag'" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				158
			 | 
			
			
				+            xyz=$(ini 1value project:version) ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				159
			 | 
			
			
				+    esac 
			 | 
		
	
		
			
			| 
				
			 | 
			
				160
			 | 
			
			
				+    if ! git describe --tags --exact-match HEAD >&/dev/null; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				161
			 | 
			
			
				+    then    # we are at a later commit than the last tag 
			 | 
		
	
		
			
			| 
				
			 | 
			
				162
			 | 
			
			
				+        commit="$(git_fact current_branch).g$(git_fact latest_sha)" 
			 | 
		
	
		
			
			| 
				181
			 | 
			
				163
			 | 
			
			
				     fi 
			 | 
		
	
		
			
			| 
				182
			 | 
			
				
			 | 
			
			
				-    local_putb semver <<<"$version" 
			 | 
		
	
		
			
			| 
				183
			 | 
			
				
			 | 
			
			
				-    echo "$version" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				164
			 | 
			
			
				+    git_bool dirty; dirty=$? 
			 | 
		
	
		
			
			| 
				
			 | 
			
				165
			 | 
			
			
				+    case "$dirty:$commit" in 
			 | 
		
	
		
			
			| 
				
			 | 
			
				166
			 | 
			
			
				+        1:)  suffix=""               ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				167
			 | 
			
			
				+        0:)  suffix="+dirty"         ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				168
			 | 
			
			
				+        1:*) suffix="+$commit"       ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				169
			 | 
			
			
				+        0:*) suffix="+$commit.dirty" ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				170
			 | 
			
			
				+        *)   suffix=MKIT_BUG 
			 | 
		
	
		
			
			| 
				
			 | 
			
				171
			 | 
			
			
				+             warn "MKIT_BUG: bad dirt/commit detection" ;; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				172
			 | 
			
			
				+    esac 
			 | 
		
	
		
			
			| 
				
			 | 
			
				173
			 | 
			
			
				+    test -n "$prerl" && suffix="-$prerl$suffix" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				174
			 | 
			
			
				+    echo "$xyz$suffix" 
			 | 
		
	
		
			
			| 
				184
			 | 
			
				175
			 | 
			
			
				 } 
			 |