mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 10:26:52 +08:00
px4.py: case the script is run outside of the cloned repo, get it from remote
This commit is contained in:
+13
-3
@@ -63,14 +63,24 @@ def get_version():
|
|||||||
px4_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
px4_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
if os.path.isdir(os.path.join(px4_dir, '.git')):
|
if os.path.isdir(os.path.join(px4_dir, '.git')):
|
||||||
# Get the version using "git describe".
|
# If inside a clone PX4 Firmware repository, get version from "git describe"
|
||||||
cmd = 'git describe --abbrev=0 --tags'.split()
|
cmd = 'git describe --abbrev=0 --tags'
|
||||||
try:
|
try:
|
||||||
version = subprocess.check_output(
|
version = subprocess.check_output(
|
||||||
cmd, cwd=px4_dir).decode().strip()
|
cmd, cwd=px4_dir, shell=True).decode().strip()
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print('Unable to get version number from git tags')
|
print('Unable to get version number from git tags')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
else:
|
||||||
|
# Else, get it from remote repo tags (requires network access)
|
||||||
|
cmd = "git ls-remote --tags git://github.com/PX4/Firmware.git | cut -d/ -f3- | sort -n -t. -k1,1 -k2,2 -k3,3 | awk '/^v[^{]*$/{version=$1}END{print version}'"
|
||||||
|
|
||||||
|
try:
|
||||||
|
version = subprocess.check_output(
|
||||||
|
cmd, cwd=px4_dir, shell=True).decode().strip()
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
print('Unable to get version number from git remote tags')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user