5 import xml.etree.ElementTree as ET
8 from common import Colors
9 from common import accept_command
12 SCRIPTDIR = os.path.dirname(__file__)
15 def manifest_get_commits(manifest):
17 tree = ET.parse(manifest)
20 if child.tag == 'project':
21 res[child.attrib["name"]] = child.attrib["revision"]
25 def update_subprojects(manifest, no_interaction=False):
27 repos_commits = manifest_get_commits(manifest)
31 subprojects_dir = os.path.join(SCRIPTDIR, "subprojects")
32 for repo_name in os.listdir(subprojects_dir):
33 repo_dir = os.path.normpath(os.path.join(SCRIPTDIR, subprojects_dir, repo_name))
34 if not os.path.exists(os.path.join(repo_dir, '.git')):
36 revision = repos_commits.get(repo_name)
37 if not update_repo(repo_name, repo_dir, revision, no_interaction):
43 def update_repo(repo_name, repo_dir, revision, no_interaction, recurse_i=0):
44 print("Updating %s..." % repo_name)
47 git("fetch", repository_path=repo_dir)
48 git("checkout", revision, repository_path=repo_dir)
50 git("pull", "--rebase", "--autostash", repository_path=repo_dir)
51 except Exception as e:
52 out = getattr(e, "output", b"").decode()
53 if not no_interaction:
54 print("====================================="
55 "\n%s\nEntering a shell in %s to fix that"
56 " just `exit 0` once done, or `exit 255`"
57 " to skip update for that repository"
58 "\n=====================================" % (
62 shell = os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")
64 shell = os.environ.get("SHELL", os.path.realpath("/bin/sh"))
65 subprocess.check_call(shell, cwd=repo_dir)
66 except subprocess.CalledProcessError as e:
67 if e.returncode == 255:
68 print("Skipping '%s' update" % repo_name)
71 # Result of subshell does not really matter
75 return update_repo(repo_name, repo_dir, revision, no_interaction,
79 print("\nCould not rebase %s, please fix and try again."
80 " Error:\n\n%s %s" % (repo_dir, out, e))
85 commit_message = git("show", repository_path=repo_dir).split("\n")
86 print(u" -> %s%s%s — %s" % (Colors.HEADER, commit_message[0][7:14], Colors.ENDC,
87 commit_message[4].strip()))
92 if __name__ == "__main__":
93 parser = argparse.ArgumentParser(prog="git-update")
95 parser.add_argument("--no-color",
98 help="Do not output ansi colors.")
99 parser.add_argument("--builddir",
101 help="Specifies the build directory where to"
102 " invoke ninja after updating.")
103 parser.add_argument("--no-interaction",
106 help="Do not allow interaction with the user.")
107 parser.add_argument("--manifest",
109 help="Use a android repo manifest to sync repositories"
110 " Note that it will let all repositories in detached state")
111 options = parser.parse_args()
115 if not update_repo('gst-build', SCRIPTDIR, None, options.no_interaction):
117 if not update_subprojects(options.manifest, options.no_interaction):
121 ninja = accept_command(["ninja", "ninja-build"])
123 print("Can't find ninja, other backends are not supported for rebuilding")
126 if not os.path.exists(os.path.join (options.builddir, 'build.ninja')):
127 print("Can't rebuild in %s as no build.ninja file found." % options.builddir)
129 print("Rebuilding all GStreamer modules.")
130 exit(subprocess.call([ninja, '-C', options.builddir]))