2016-09-06 02:37:25 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import subprocess
|
2016-09-14 12:54:59 +00:00
|
|
|
import xml.etree.ElementTree as ET
|
2016-09-06 02:37:25 +00:00
|
|
|
|
2016-10-10 23:14:50 +00:00
|
|
|
from common import git
|
|
|
|
from common import Colors
|
2016-11-07 21:17:39 +00:00
|
|
|
from common import accept_command
|
2016-09-06 02:37:25 +00:00
|
|
|
|
|
|
|
|
2016-10-10 23:14:50 +00:00
|
|
|
SCRIPTDIR = os.path.dirname(__file__)
|
2016-09-06 02:37:25 +00:00
|
|
|
|
|
|
|
|
2016-09-14 12:54:59 +00:00
|
|
|
def manifest_get_commits(manifest):
|
|
|
|
res = {}
|
|
|
|
tree = ET.parse(manifest)
|
|
|
|
root = tree.getroot()
|
|
|
|
for child in root:
|
|
|
|
if child.tag == 'project':
|
|
|
|
res[child.attrib["name"]] = child.attrib["revision"]
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
2016-09-29 23:25:42 +00:00
|
|
|
def update_subprojects(manifest, no_interaction=False):
|
2016-09-14 12:54:59 +00:00
|
|
|
if manifest:
|
|
|
|
repos_commits = manifest_get_commits(manifest)
|
|
|
|
else:
|
|
|
|
repos_commits = {}
|
|
|
|
|
2016-09-06 02:37:25 +00:00
|
|
|
subprojects_dir = os.path.join(SCRIPTDIR, "subprojects")
|
|
|
|
for repo_name in os.listdir(subprojects_dir):
|
|
|
|
repo_dir = os.path.normpath(os.path.join(SCRIPTDIR, subprojects_dir, repo_name))
|
|
|
|
if not os.path.exists(os.path.join(repo_dir, '.git')):
|
|
|
|
continue
|
2016-09-29 23:25:42 +00:00
|
|
|
revision = repos_commits.get(repo_name)
|
|
|
|
if not update_repo(repo_name, repo_dir, revision, no_interaction):
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
2016-09-06 02:37:25 +00:00
|
|
|
|
2016-09-29 23:25:42 +00:00
|
|
|
|
|
|
|
def update_repo(repo_name, repo_dir, revision, no_interaction, recurse_i=0):
|
|
|
|
print("Updating %s..." % repo_name)
|
2016-11-09 19:40:58 +00:00
|
|
|
git("config", "rebase.autoStash", "true", repository_path=repo_dir)
|
2016-09-29 23:25:42 +00:00
|
|
|
try:
|
|
|
|
if revision:
|
2016-10-11 00:05:39 +00:00
|
|
|
git("fetch", repository_path=repo_dir)
|
|
|
|
git("checkout", revision, repository_path=repo_dir)
|
2016-09-29 23:25:42 +00:00
|
|
|
else:
|
2016-11-09 19:40:58 +00:00
|
|
|
git("pull", "--rebase", repository_path=repo_dir)
|
2016-09-29 23:25:42 +00:00
|
|
|
except Exception as e:
|
|
|
|
out = getattr(e, "output", b"").decode()
|
|
|
|
if not no_interaction:
|
|
|
|
print("====================================="
|
2016-11-07 21:17:39 +00:00
|
|
|
"\n%s\nEntering a shell in %s to fix that"
|
|
|
|
" just `exit 0` once done, or `exit 255`"
|
2016-11-07 21:11:07 +00:00
|
|
|
" to skip update for that repository"
|
2016-09-29 23:25:42 +00:00
|
|
|
"\n=====================================" % (
|
2016-11-07 21:11:07 +00:00
|
|
|
out, repo_dir))
|
2016-09-29 23:25:42 +00:00
|
|
|
try:
|
2016-11-07 21:11:07 +00:00
|
|
|
if os.name is 'nt':
|
|
|
|
shell = os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")
|
|
|
|
else:
|
|
|
|
shell = os.environ.get("SHELL", os.path.realpath("/bin/sh"))
|
|
|
|
subprocess.check_call(shell, cwd=repo_dir)
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
if e.returncode == 255:
|
|
|
|
print("Skipping '%s' update" % repo_name)
|
|
|
|
return True
|
2016-09-29 23:25:42 +00:00
|
|
|
except:
|
|
|
|
# Result of subshell does not really matter
|
|
|
|
pass
|
|
|
|
|
|
|
|
if recurse_i < 3:
|
|
|
|
return update_repo(repo_name, repo_dir, revision, no_interaction,
|
|
|
|
recurse_i + 1)
|
2016-09-06 02:37:25 +00:00
|
|
|
return False
|
2016-09-29 23:25:42 +00:00
|
|
|
else:
|
|
|
|
print("\nCould not rebase %s, please fix and try again."
|
|
|
|
" Error:\n\n%s %s" % (repo_dir, out, e))
|
2016-09-06 02:37:25 +00:00
|
|
|
|
2016-09-29 23:25:42 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
2016-10-11 00:05:39 +00:00
|
|
|
commit_message = git("show", repository_path=repo_dir).split("\n")
|
2016-09-29 23:25:42 +00:00
|
|
|
print(u" -> %s%s%s — %s" % (Colors.HEADER, commit_message[0][7:14], Colors.ENDC,
|
|
|
|
commit_message[4].strip()))
|
2016-09-06 02:37:25 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(prog="git-update")
|
|
|
|
|
|
|
|
parser.add_argument("--no-color",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="Do not output ansi colors.")
|
2016-11-07 21:17:39 +00:00
|
|
|
parser.add_argument("--builddir",
|
|
|
|
default=None,
|
|
|
|
help="Specifies the build directory where to"
|
|
|
|
" invoke ninja after updating.")
|
2016-09-29 23:25:42 +00:00
|
|
|
parser.add_argument("--no-interaction",
|
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="Do not allow interaction with the user.")
|
2016-09-14 12:54:59 +00:00
|
|
|
parser.add_argument("--manifest",
|
|
|
|
default=None,
|
|
|
|
help="Use a android repo manifest to sync repositories"
|
|
|
|
" Note that it will let all repositories in detached state")
|
2016-09-06 02:37:25 +00:00
|
|
|
options = parser.parse_args()
|
|
|
|
if options.no_color:
|
|
|
|
Colors.disable()
|
|
|
|
|
2016-11-07 21:17:21 +00:00
|
|
|
if not update_repo('gst-build', SCRIPTDIR, None, options.no_interaction):
|
|
|
|
exit(1)
|
2016-11-07 21:17:39 +00:00
|
|
|
if not update_subprojects(options.manifest, options.no_interaction):
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if options.builddir:
|
|
|
|
ninja = accept_command(["ninja", "ninja-build"])
|
|
|
|
if not ninja:
|
|
|
|
print("Can't find ninja, other backends are not supported for rebuilding")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if not os.path.exists(os.path.join (options.builddir, 'build.ninja')):
|
|
|
|
print("Can't rebuild in %s as no build.ninja file found." % options.builddir)
|
|
|
|
|
|
|
|
print("Rebuilding all GStreamer modules.")
|
|
|
|
exit(subprocess.call([ninja, '-C', options.builddir]))
|