]> granicus.if.org Git - graphviz/commitdiff
If committer date is not available, set to zero
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 22 Jul 2020 14:15:59 +0000 (16:15 +0200)
committerMagnus Jacobsson <magnus.jacobsson@berotec.se>
Mon, 27 Jul 2020 06:59:21 +0000 (08:59 +0200)
gen_version.py

index 301d1e758b42a3056fc07ec3e57fad6e9a26f577..1bc0ee2a0f9d4ad3e9667901412fb3851effd973 100644 (file)
@@ -21,6 +21,7 @@
 version = '2.44.2-dev'
 
 import os
+import sys
 import subprocess
 
 major_version, minor_version, patch_version = version.split('.')
@@ -30,17 +31,24 @@ try:
 except ValueError:
     # Non-numerical patch version; add committer date
     os.environ['TZ'] = 'UTC'
-    committer_date = subprocess.run(
-        [
-            'git',
-            'log',
-            '-n',
-            '1',
-            '--format=%cd',
-            '--date=format-local:%Y%m%d.%H%M'
-        ],
-        stdout=subprocess.PIPE,
-    ).stdout.decode('utf-8').strip()
-    patch_version += '.' + committer_date
+    try:
+        committer_date = subprocess.run(
+            [
+                'git',
+                'log',
+                '-n',
+                '1',
+                '--format=%cd',
+                '--date=format-local:%Y%m%d.%H%M'
+            ],
+            stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE,
+            check=True,
+        ).stdout.decode('utf-8').strip()
+        patch_version += '.' + committer_date
+    except (subprocess.CalledProcessError, FileNotFoundError):
+        print('Warning: build not started in a Git clone, or Git is not installed: setting version date to 0.', file=sys.stderr)
+
+        patch_version += '.0'
 
 print(f'{major_version}.{minor_version}.{patch_version}')