litex_setup: add automatic update of litex_setup (because it also changes) and be sure we are on master branch before update.
This commit is contained in:
parent
939f546a05
commit
d389005550
|
@ -4,13 +4,14 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
|
import hashlib
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
import requests
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
current_path = os.path.abspath(os.curdir)
|
current_path = os.path.abspath(os.curdir)
|
||||||
|
|
||||||
|
|
||||||
# Repositories -------------------------------------------------------------------------------------
|
# Repositories -------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# name, (url, recursive clone, develop, sha1)
|
# name, (url, recursive clone, develop, sha1)
|
||||||
|
@ -96,8 +97,27 @@ if len(sys.argv) < 2:
|
||||||
print("- update")
|
print("- update")
|
||||||
print("- install (add --user to install to user directory)")
|
print("- install (add --user to install to user directory)")
|
||||||
print("- gcc")
|
print("- gcc")
|
||||||
|
print("- dev (dev mode, disable automatic litex_setup.py update)")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
# Check/Update litex_setup.py
|
||||||
|
|
||||||
|
litex_setup_url = "https://raw.githubusercontent.com/enjoy-digital/litex/master/litex_setup.py"
|
||||||
|
current_sha1 = hashlib.sha1(open(os.path.realpath(__file__)).read().encode("utf-8")).hexdigest()
|
||||||
|
print("[checking litex_setup.py]...")
|
||||||
|
try:
|
||||||
|
r = requests.get(litex_setup_url)
|
||||||
|
if r.status_code != 404:
|
||||||
|
upstream_sha1 = hashlib.sha1(r.content).hexdigest()
|
||||||
|
if current_sha1 != upstream_sha1:
|
||||||
|
if "dev" not in sys.argv[1:]:
|
||||||
|
print("[updating litex_setup.py]...")
|
||||||
|
with open(os.path.realpath(__file__), "wb") as f:
|
||||||
|
f.write(r.content)
|
||||||
|
os.execl(sys.executable, sys.executable, *sys.argv)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Repositories cloning
|
# Repositories cloning
|
||||||
if "init" in sys.argv[1:]:
|
if "init" in sys.argv[1:]:
|
||||||
for name in repos.keys():
|
for name in repos.keys():
|
||||||
|
@ -124,6 +144,7 @@ if "update" in sys.argv[1:]:
|
||||||
# update
|
# update
|
||||||
print("[updating " + name + "]...")
|
print("[updating " + name + "]...")
|
||||||
os.chdir(os.path.join(current_path, name))
|
os.chdir(os.path.join(current_path, name))
|
||||||
|
subprocess.check_call("git checkout master", shell=True)
|
||||||
subprocess.check_call("git pull --ff-only", shell=True)
|
subprocess.check_call("git pull --ff-only", shell=True)
|
||||||
if sha1 is not None:
|
if sha1 is not None:
|
||||||
os.chdir(os.path.join(current_path, name))
|
os.chdir(os.path.join(current_path, name))
|
||||||
|
|
Loading…
Reference in New Issue