5 import xml.etree.ElementTree as ET
8 from common import Colors
9 from common import accept_command
12 SCRIPTDIR = os.path.normpath(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)
45 git("config", "rebase.autoStash", "true", repository_path=repo_dir)
48 git("fetch", repository_path=repo_dir)
49 git("checkout", revision, repository_path=repo_dir)
51 git("pull", "--rebase", repository_path=repo_dir)
52 git("submodule", "update", repository_path=repo_dir)
53 except Exception as e:
54 out = getattr(e, "output", b"").decode()
55 if not no_interaction:
56 print("====================================="
57 "\n%s\nEntering a shell in %s to fix that"
58 " just `exit 0` once done, or `exit 255`"
59 " to skip update for that repository"
60 "\n=====================================" % (
64 shell = os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")
66 shell = os.environ.get("SHELL", os.path.realpath("/bin/sh"))
67 subprocess.check_call(shell, cwd=repo_dir)
68 except subprocess.CalledProcessError as e:
69 if e.returncode == 255:
70 print("Skipping '%s' update" % repo_name)
73 # Result of subshell does not really matter
77 return update_repo(repo_name, repo_dir, revision, no_interaction,
81 print("\nCould not rebase %s, please fix and try again."
82 " Error:\n\n%s %s" % (repo_dir, out, e))
87 commit_message = git("show", repository_path=repo_dir).split("\n")
88 print(u" -> %s%s%s - %s" % (Colors.HEADER, commit_message[0][7:14], Colors.ENDC,
89 commit_message[4].strip()))
94 if __name__ == "__main__":
95 parser = argparse.ArgumentParser(prog="git-update")
97 parser.add_argument("--no-color",
100 help="Do not output ansi colors.")
101 parser.add_argument("--builddir",
103 help="Specifies the build directory where to"
104 " invoke ninja after updating.")
105 parser.add_argument("--no-interaction",
108 help="Do not allow interaction with the user.")
109 parser.add_argument("--manifest",
111 help="Use a android repo manifest to sync repositories"
112 " Note that it will let all repositories in detached state")
113 options = parser.parse_args()
117 if not update_repo('gst-build', SCRIPTDIR, None, options.no_interaction):
119 if not update_subprojects(options.manifest, options.no_interaction):
123 ninja = accept_command(["ninja", "ninja-build"])
125 print("Can't find ninja, other backends are not supported for rebuilding")
128 if not os.path.exists(os.path.join (options.builddir, 'build.ninja')):
129 print("Can't rebuild in %s as no build.ninja file found." % options.builddir)
131 print("Rebuilding all GStreamer modules.")
132 exit(subprocess.call([ninja, '-C', options.builddir]))