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)
38 if not update_repo(repo_name, repo_dir, revision, no_interaction):
44 def update_repo(repo_name, repo_dir, revision, no_interaction, recurse_i=0):
45 print("Updating %s..." % repo_name)
46 git("config", "rebase.autoStash", "true", repository_path=repo_dir)
49 git("fetch", repository_path=repo_dir)
50 git("checkout", revision, repository_path=repo_dir)
52 git("pull", "--rebase", repository_path=repo_dir)
53 git("submodule", "update", repository_path=repo_dir)
54 except Exception as e:
55 out = getattr(e, "output", b"").decode()
56 if not no_interaction:
57 print("====================================="
58 "\n%s\nEntering a shell in %s to fix that"
59 " just `exit 0` once done, or `exit 255`"
60 " to skip update for that repository"
61 "\n=====================================" % (
65 shell = os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")
67 shell = os.environ.get("SHELL", os.path.realpath("/bin/sh"))
68 subprocess.check_call(shell, cwd=repo_dir)
69 except subprocess.CalledProcessError as e:
70 if e.returncode == 255:
71 print("Skipping '%s' update" % repo_name)
74 # Result of subshell does not really matter
78 return update_repo(repo_name, repo_dir, revision, no_interaction,
82 print("\nCould not rebase %s, please fix and try again."
83 " Error:\n\n%s %s" % (repo_dir, out, e))
88 commit_message = git("show", "--shortstat", repository_path=repo_dir).split("\n")
89 print(u" -> %s%s%s - %s" % (Colors.HEADER, commit_message[0][7:14], Colors.ENDC,
90 commit_message[4].strip()))
95 if __name__ == "__main__":
96 parser = argparse.ArgumentParser(prog="git-update")
98 parser.add_argument("--no-color",
101 help="Do not output ansi colors.")
102 parser.add_argument("--builddir",
104 help="Specifies the build directory where to"
105 " invoke ninja after updating.")
106 parser.add_argument("--no-interaction",
109 help="Do not allow interaction with the user.")
110 parser.add_argument("--manifest",
112 help="Use a android repo manifest to sync repositories"
113 " Note that it will let all repositories in detached state")
114 options = parser.parse_args()
118 if options.no_interaction:
121 if not update_repo('gst-build', SCRIPTDIR, None, options.no_interaction):
123 if not update_subprojects(options.manifest, options.no_interaction):
127 ninja = accept_command(["ninja", "ninja-build"])
129 print("Can't find ninja, other backends are not supported for rebuilding")
132 if not os.path.exists(os.path.join (options.builddir, 'build.ninja')):
133 print("Can't rebuild in %s as no build.ninja file found." % options.builddir)
135 print("Rebuilding all GStreamer modules.")
136 exit(subprocess.call([ninja, '-C', options.builddir]))