pio: call out to git
import os
import time
+import subprocess
import serial
import serial.tools.list_ports
@@ -30,11 +31,14 @@ elif 'DRONE_COMMIT' in os.environ:
git_version = os.environ.get('DRONE_COMMIT')
else:
try:
- with open('.git/refs/heads/master', 'r') as file:
- git_version = file.read().rstrip()
- except FileNotFoundError:
+ ret = subprocess.run(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE, text=True)
+ full_hash = ret.stdout.strip()
+ git_version = full_hash[:7]
+ except Exception:
pass
+print("GIT_VERSION: " + git_version)
+
projenv.Append(CPPDEFINES=[
("TARGET", env["PIOENV"]),
("GIT_VERSION", git_version)
