@@ -6,7 +6,7 @@ from waflib import Context, Logs
6
6
7
7
VERSION = '0.1.0'
8
8
APPNAME = 'ndn-nac'
9
- GIT_TAG_PREFIX = 'nac-'
9
+ GIT_TAG_PREFIX = 'ndn- nac-'
10
10
11
11
def options (opt ):
12
12
opt .load (['compiler_cxx' , 'gnu_dirs' ])
@@ -168,43 +168,43 @@ def version(ctx):
168
168
Context .g_module .VERSION_SPLIT = VERSION_BASE .split ('.' )
169
169
170
170
# first, try to get a version string from git
171
- gotVersionFromGit = False
171
+ version_from_git = ''
172
172
try :
173
- cmd = ['git' , 'describe' , '--always' , '--match' , f'{ GIT_TAG_PREFIX } *' ]
174
- out = subprocess .run (cmd , capture_output = True , check = True , text = True ).stdout .strip ()
175
- if out :
176
- gotVersionFromGit = True
177
- if out .startswith (GIT_TAG_PREFIX ):
178
- Context .g_module .VERSION = out .lstrip (GIT_TAG_PREFIX )
173
+ cmd = ['git' , 'describe' , '--abbrev=8' , '--always' , '--match' , f'{ GIT_TAG_PREFIX } *' ]
174
+ version_from_git = subprocess .run (cmd , capture_output = True , check = True , text = True ).stdout .strip ()
175
+ if version_from_git :
176
+ if GIT_TAG_PREFIX and version_from_git .startswith (GIT_TAG_PREFIX ):
177
+ Context .g_module .VERSION = version_from_git [len (GIT_TAG_PREFIX ):]
178
+ elif not GIT_TAG_PREFIX and ('.' in version_from_git or '-' in version_from_git ):
179
+ Context .g_module .VERSION = version_from_git
179
180
else :
180
- # no tags matched
181
- Context .g_module .VERSION = f'{ VERSION_BASE } -commit- { out } '
181
+ # no tags matched (or we are in a shallow clone)
182
+ Context .g_module .VERSION = f'{ VERSION_BASE } +git. { version_from_git } '
182
183
except (OSError , subprocess .SubprocessError ):
183
184
pass
184
185
185
- versionFile = ctx .path .find_node ('VERSION.info' )
186
- if not gotVersionFromGit and versionFile is not None :
186
+ # fallback to the VERSION.info file, if it exists and is not empty
187
+ version_from_file = ''
188
+ version_file = ctx .path .find_node ('VERSION.info' )
189
+ if version_file is not None :
187
190
try :
188
- Context .g_module .VERSION = versionFile .read ()
189
- return
190
- except EnvironmentError :
191
- pass
192
-
193
- # version was obtained from git, update VERSION file if necessary
194
- if versionFile is not None :
195
- try :
196
- if versionFile .read () == Context .g_module .VERSION :
197
- # already up-to-date
198
- return
199
- except EnvironmentError as e :
200
- Logs .warn (f'{ versionFile } exists but is not readable ({ e .strerror } )' )
201
- else :
202
- versionFile = ctx .path .make_node ('VERSION.info' )
191
+ version_from_file = version_file .read ().strip ()
192
+ except OSError as e :
193
+ Logs .warn (f'{ e .filename } exists but is not readable ({ e .strerror } )' )
194
+ if version_from_file and not version_from_git :
195
+ Context .g_module .VERSION = version_from_file
196
+ return
203
197
198
+ # update VERSION.info if necessary
199
+ if version_from_file == Context .g_module .VERSION :
200
+ # already up-to-date
201
+ return
202
+ if version_file is None :
203
+ version_file = ctx .path .make_node ('VERSION.info' )
204
204
try :
205
- versionFile .write (Context .g_module .VERSION )
206
- except EnvironmentError as e :
207
- Logs .warn (f'{ versionFile } is not writable ({ e .strerror } )' )
205
+ version_file .write (Context .g_module .VERSION )
206
+ except OSError as e :
207
+ Logs .warn (f'{ e . filename } is not writable ({ e .strerror } )' )
208
208
209
209
def dist (ctx ):
210
210
ctx .algo = 'tar.xz'
0 commit comments