5 import xml.etree.ElementTree as ET
9 from common import Colors
10 from common import accept_command
13 SCRIPTDIR = os.path.normpath(os.path.dirname(__file__))
16 def manifest_get_commits(manifest):
18 tree = ET.parse(manifest)
21 if child.tag == 'project':
22 res[child.attrib["name"]] = child.attrib["revision"]
26 def update_subprojects(manifest, no_interaction=False):
28 repos_commits = manifest_get_commits(manifest)
32 subprojects_dir = os.path.join(SCRIPTDIR, "subprojects")
33 for repo_name in os.listdir(subprojects_dir):
34 repo_dir = os.path.normpath(os.path.join(SCRIPTDIR, subprojects_dir, repo_name))
35 if not os.path.exists(os.path.join(repo_dir, '.git')):
37 revision = repos_commits.get(repo_name)
39 # If we're on a detached head because the revision= value in the
40 # wrap file is a commit, don't try to git pull --rebase because
41 # that will always fail.
42 ret = git('-C', repo_dir, 'rev-parse', '--symbolic-full-name', 'HEAD')
43 if ret.strip() == 'HEAD':
44 revision = git('rev-parse', 'HEAD').strip()
45 if not update_repo(repo_name, repo_dir, revision, no_interaction):
51 def update_repo(repo_name, repo_dir, revision, no_interaction, recurse_i=0):
52 print("Updating %s..." % repo_name)
53 git("config", "rebase.autoStash", "true", repository_path=repo_dir)
56 git("fetch", repository_path=repo_dir)
57 git("checkout", revision, repository_path=repo_dir)
59 git("pull", "--rebase", repository_path=repo_dir)
60 git("submodule", "update", repository_path=repo_dir)
61 except Exception as e:
62 out = getattr(e, "output", b"").decode()
63 if not no_interaction:
64 print("====================================="
65 "\n%s\nEntering a shell in %s to fix that"
66 " just `exit 0` once done, or `exit 255`"
67 " to skip update for that repository"
68 "\n=====================================" % (
72 shell = os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")
74 shell = os.environ.get("SHELL", os.path.realpath("/bin/sh"))
75 subprocess.check_call(shell, cwd=repo_dir)
76 except subprocess.CalledProcessError as e:
77 if e.returncode == 255:
78 print("Skipping '%s' update" % repo_name)
81 # Result of subshell does not really matter
85 return update_repo(repo_name, repo_dir, revision, no_interaction,
89 print("\nCould not rebase %s, please fix and try again."
90 " Error:\n\n%s %s" % (repo_dir, out, e))
95 commit_message = git("show", "--shortstat", repository_path=repo_dir).split("\n")
96 print(u" -> %s%s%s - %s" % (Colors.HEADER, commit_message[0][7:14], Colors.ENDC,
97 commit_message[4].strip()))
102 if __name__ == "__main__":
103 parser = argparse.ArgumentParser(prog="git-update")
105 parser.add_argument("--no-color",
108 help="Do not output ansi colors.")
109 parser.add_argument("--builddir",
111 help="Specifies the build directory where to"
112 " invoke ninja after updating.")
113 parser.add_argument("--no-interaction",
116 help="Do not allow interaction with the user.")
117 parser.add_argument("--manifest",
119 help="Use a android repo manifest to sync repositories"
120 " Note that it will let all repositories in detached state")
121 options = parser.parse_args()
125 if options.no_interaction:
128 if not update_repo('gst-build', SCRIPTDIR, None, options.no_interaction):
130 if not update_subprojects(options.manifest, options.no_interaction):
134 ninja = accept_command(["ninja", "ninja-build"])
136 print("Can't find ninja, other backends are not supported for rebuilding")
139 if not os.path.exists(os.path.join (options.builddir, 'build.ninja')):
140 print("Can't rebuild in %s as no build.ninja file found." % options.builddir)
142 print("Rebuilding all GStreamer modules.")
143 exit(subprocess.call([ninja, '-C', options.builddir]))