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
|
2017-10-20 10:22:57 +00:00
|
|
|
import sys
|
2016-09-06 02:37:25 +00:00
|
|
|
|
2018-11-12 23:23:14 +00:00
|
|
|
from scripts.common import git
|
|
|
|
from scripts.common import Colors
|
|
|
|
from scripts.common import accept_command
|
2019-04-19 20:38:24 +00:00
|
|
|
from scripts.common import get_meson
|
2016-09-06 02:37:25 +00:00
|
|
|
|
|
|
|
|
2016-11-17 18:55:44 +00:00
|
|
|
SCRIPTDIR = os.path.normpath(os.path.dirname(__file__))
|
2020-06-15 18:28:17 +00:00
|
|
|
# Force a checkout to happen and throw away local changes
|
|
|
|
FORCE_CHECKOUT = False
|
2021-04-08 09:51:07 +00:00
|
|
|
CI = os.environ.get('CI', False)
|
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()
|
2018-08-06 04:33:08 +00:00
|
|
|
remotes = {}
|
2016-09-14 12:54:59 +00:00
|
|
|
for child in root:
|
2018-08-06 04:33:08 +00:00
|
|
|
if child.tag == 'remote':
|
|
|
|
remotes[child.attrib['name']] = child.attrib['fetch']
|
2016-09-14 12:54:59 +00:00
|
|
|
if child.tag == 'project':
|
2018-08-06 04:33:08 +00:00
|
|
|
name = child.attrib['name']
|
2018-11-21 23:29:28 +00:00
|
|
|
path = child.attrib.get('path', name)
|
2016-09-14 12:54:59 +00:00
|
|
|
|
2018-08-06 04:33:08 +00:00
|
|
|
remote = child.attrib.get('remote')
|
|
|
|
if remote:
|
2018-12-06 13:47:04 +00:00
|
|
|
res[path] = [child.attrib["revision"], [os.path.join(remotes[remote], name), child.attrib.get('refname', child.attrib["revision"])]]
|
2018-08-06 04:33:08 +00:00
|
|
|
else:
|
2018-11-21 23:29:28 +00:00
|
|
|
res[path] = [child.attrib["revision"], []]
|
2018-08-06 04:33:08 +00:00
|
|
|
|
|
|
|
return res
|
2016-09-14 12:54:59 +00:00
|
|
|
|
|
|
|
|
2018-11-05 12:52:41 +00:00
|
|
|
def get_branch_name(repo_dir):
|
|
|
|
return git('-C', repo_dir, 'rev-parse', '--symbolic-full-name', 'HEAD').strip()
|
|
|
|
|
|
|
|
|
2018-11-05 12:43:50 +00:00
|
|
|
def ensure_revision_if_necessary(repo_dir, revision):
|
|
|
|
"""
|
|
|
|
Makes sure that @revision is set if the current repo is detached.
|
|
|
|
"""
|
|
|
|
if not revision:
|
2018-11-05 12:52:41 +00:00
|
|
|
if get_branch_name(repo_dir) == 'HEAD':
|
2018-11-05 12:43:50 +00:00
|
|
|
revision = git('-C', repo_dir, 'rev-parse', 'HEAD').strip()
|
|
|
|
|
|
|
|
return revision
|
|
|
|
|
|
|
|
|
2020-06-16 12:57:42 +00:00
|
|
|
def update_subprojects(manifest, no_interaction=False, status=False):
|
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
|
2018-08-06 04:33:08 +00:00
|
|
|
|
|
|
|
revision, args = repos_commits.get(repo_name, [None, []])
|
2020-06-16 12:57:42 +00:00
|
|
|
if not update_repo(repo_name, repo_dir, revision, no_interaction, args, status=status):
|
2020-02-19 15:18:39 +00:00
|
|
|
return False
|
2016-09-29 23:25:42 +00:00
|
|
|
|
|
|
|
return True
|
2016-09-06 02:37:25 +00:00
|
|
|
|
2020-02-19 15:18:39 +00:00
|
|
|
def repo_status(commit_message):
|
|
|
|
status = "clean"
|
|
|
|
for message in commit_message:
|
|
|
|
if message.startswith('??'):
|
|
|
|
status = "%sclean but untracked files%s" % (Colors.WARNING,Colors.ENDC)
|
|
|
|
elif message.startswith(' M'):
|
2020-02-27 08:01:57 +00:00
|
|
|
status = "%shas local modifications%s" % (Colors.WARNING,Colors.ENDC)
|
2020-02-19 15:18:39 +00:00
|
|
|
break;
|
|
|
|
return status
|
|
|
|
|
|
|
|
def check_repo_status(repo_name, worktree_dir):
|
|
|
|
branch_message = git("status", repository_path=worktree_dir).split("\n")
|
|
|
|
commit_message = git("status", "--porcelain", repository_path=worktree_dir).split("\n")
|
|
|
|
|
|
|
|
print(u"%s%s%s - %s - %s" % (Colors.HEADER, repo_name, Colors.ENDC,
|
|
|
|
branch_message[0].strip(), repo_status(commit_message)))
|
|
|
|
return True
|
2016-09-29 23:25:42 +00:00
|
|
|
|
2021-04-08 09:51:07 +00:00
|
|
|
def fatal_git_fetches(repo_dir):
|
|
|
|
'''
|
|
|
|
When running on the CI, we usually have a cache, in which case we don't
|
|
|
|
want the git update to be fatal since we don't want our CI to fail when
|
|
|
|
there's downtime on external repos.
|
|
|
|
'''
|
|
|
|
if not CI:
|
|
|
|
return True
|
|
|
|
remote = git("remote", "get-url", "origin", repository_path=repo_dir)
|
|
|
|
if 'gitlab.freedesktop.org' in remote:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2020-06-16 12:57:42 +00:00
|
|
|
def update_repo(repo_name, repo_dir, revision, no_interaction, fetch_args=[], recurse_i=0, status=False):
|
|
|
|
if status:
|
2020-02-19 15:18:39 +00:00
|
|
|
return check_repo_status(repo_name, repo_dir)
|
2018-11-05 12:43:50 +00:00
|
|
|
revision = ensure_revision_if_necessary(repo_dir, revision)
|
2016-11-09 19:40:58 +00:00
|
|
|
git("config", "rebase.autoStash", "true", repository_path=repo_dir)
|
2021-04-08 09:51:07 +00:00
|
|
|
fatal = fatal_git_fetches(repo_dir)
|
2016-09-29 23:25:42 +00:00
|
|
|
try:
|
|
|
|
if revision:
|
2018-11-05 12:52:41 +00:00
|
|
|
print("Checking out %s in %s" % (revision, repo_name))
|
2021-04-08 09:51:07 +00:00
|
|
|
git("fetch", *fetch_args, repository_path=repo_dir, fatal=fatal)
|
2020-06-15 18:28:17 +00:00
|
|
|
checkout_args = ["--force"] if FORCE_CHECKOUT else []
|
|
|
|
checkout_args += ["--detach", revision]
|
|
|
|
git("checkout", *checkout_args, repository_path=repo_dir)
|
2016-09-29 23:25:42 +00:00
|
|
|
else:
|
2018-11-05 12:52:41 +00:00
|
|
|
print("Updating branch %s in %s" % (get_branch_name(repo_dir), repo_name))
|
2021-04-08 09:51:07 +00:00
|
|
|
git("pull", "--rebase", repository_path=repo_dir, fatal=fatal)
|
2017-01-11 11:59:33 +00:00
|
|
|
git("submodule", "update", 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:
|
2019-11-11 11:41:23 +00:00
|
|
|
if os.name == 'nt':
|
2016-11-07 21:11:07 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2018-06-23 20:01:16 +00:00
|
|
|
commit_message = git("show", "--shortstat", repository_path=repo_dir).split("\n")
|
2016-11-17 18:55:44 +00:00
|
|
|
print(u" -> %s%s%s - %s" % (Colors.HEADER, commit_message[0][7:14], Colors.ENDC,
|
2016-09-29 23:25:42 +00:00
|
|
|
commit_message[4].strip()))
|
2016-09-06 02:37:25 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2019-11-21 10:40:32 +00:00
|
|
|
# Update gst-plugins-rs dependencies
|
|
|
|
def update_cargo(build_dir):
|
|
|
|
cargo_toml = os.path.join('subprojects', 'gst-plugins-rs', 'Cargo.toml')
|
|
|
|
if not os.path.exists(cargo_toml):
|
|
|
|
return True
|
|
|
|
|
|
|
|
cmd = ['cargo', 'update', '--manifest-path', cargo_toml]
|
|
|
|
|
|
|
|
try:
|
|
|
|
ret = subprocess.run(cmd)
|
|
|
|
except FileNotFoundError:
|
|
|
|
# silenty ignore if cargo isn't installed
|
|
|
|
return False
|
|
|
|
|
|
|
|
return ret == 0
|
|
|
|
|
|
|
|
|
2016-09-06 02:37:25 +00:00
|
|
|
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.")
|
2020-06-16 12:57:42 +00:00
|
|
|
parser.add_argument("--status",
|
2020-02-19 15:18:39 +00:00
|
|
|
default=False,
|
|
|
|
action='store_true',
|
|
|
|
help="Check repositories status only.")
|
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()
|
2019-02-05 11:53:49 +00:00
|
|
|
if options.no_color or not Colors.can_enable():
|
2016-09-06 02:37:25 +00:00
|
|
|
Colors.disable()
|
|
|
|
|
2017-10-20 10:22:57 +00:00
|
|
|
if options.no_interaction:
|
|
|
|
sys.stdin.close()
|
|
|
|
|
2018-08-06 04:33:08 +00:00
|
|
|
if options.manifest:
|
2019-04-19 20:38:24 +00:00
|
|
|
meson = get_meson()
|
|
|
|
targets_s = subprocess.check_output(meson + ['subprojects', 'download'])
|
2018-08-06 04:33:08 +00:00
|
|
|
repos_commits = manifest_get_commits(options.manifest)
|
2020-06-15 18:28:17 +00:00
|
|
|
FORCE_CHECKOUT = True
|
2018-08-06 04:33:08 +00:00
|
|
|
else:
|
|
|
|
repos_commits = {}
|
|
|
|
|
|
|
|
revision, args = repos_commits.get('gst-build', [None, []])
|
2020-06-16 12:57:42 +00:00
|
|
|
if not update_repo('gst-build', SCRIPTDIR, None, options.no_interaction, args, status=options.status):
|
2016-11-07 21:17:21 +00:00
|
|
|
exit(1)
|
2020-06-16 12:57:42 +00:00
|
|
|
if not update_subprojects(options.manifest, options.no_interaction, status=options.status):
|
2016-11-07 21:17:39 +00:00
|
|
|
exit(1)
|
2020-06-16 12:57:42 +00:00
|
|
|
if not options.status:
|
2020-02-19 15:18:39 +00:00
|
|
|
update_cargo(options.builddir)
|
2019-11-21 10:40:32 +00:00
|
|
|
|
2016-11-07 21:17:39 +00:00
|
|
|
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]))
|