diff options
-rw-r--r-- | buildtools/wafsamba/samba_git.py | 34 | ||||
-rw-r--r-- | wscript | 11 |
2 files changed, 44 insertions, 1 deletions
diff --git a/buildtools/wafsamba/samba_git.py b/buildtools/wafsamba/samba_git.py index a48ce129a98..d103aa8a60b 100644 --- a/buildtools/wafsamba/samba_git.py +++ b/buildtools/wafsamba/samba_git.py @@ -1,4 +1,5 @@ import os +import subprocess def find_git(env=None): """Find the git binary.""" @@ -12,3 +13,36 @@ def find_git(env=None): return None + +def read_submodule_status(path, env=None): + """Check status of submodules. + + :param path: Path to git directory + :param env: Optional waf environment + :return: Yields tuples with submodule relpath and status + (one of: 'out-of-date', 'not-checked-out', 'up-to-date') + :raise RuntimeError: raised when parsing of 'git submodule status' output + fails. + """ + if not os.path.isfile(os.path.join(path, ".gitmodules")): + # No point in running git. + return + git = find_git(env) + if git is None: + return + p = subprocess.Popen([git, "submodule", "status"], stdout=subprocess.PIPE, + cwd=path) + (stdout, stderr) = p.communicate(None) + for l in stdout.splitlines(): + l = l.rstrip() + status = l[0] + l = l[1:] + parts = l.split(" ") + if len(parts) > 2 and status in ("-", "+"): + yield (parts[1], "out-of-date") + elif len(parts) == 2 and status == "-": + yield (parts[1], "not-checked-out") + elif len(parts) > 2 and status == " ": + yield (parts[1], "up-to-date") + else: + raise RuntimeError("Unable to parse submodule status: %r, %r" % (status, parts)) @@ -8,7 +8,7 @@ VERSION=None import sys, os, tempfile sys.path.insert(0, srcdir+"/buildtools/wafsamba") -import wafsamba, Options, samba_dist, Scripting, Utils, samba_version +import wafsamba, Options, samba_dist, samba_git, Scripting, Utils, samba_version samba_dist.DIST_DIRS('.') @@ -225,6 +225,7 @@ def ctags(ctx): if os.WEXITSTATUS(status): raise Utils.WafError('ctags failed') + # putting this here enabled build in the list # of commands in --help def build(bld): @@ -320,6 +321,7 @@ def wildcard_cmd(cmd): def main(): from samba_wildcard import wildcard_main + wildcard_main(wildcard_cmd) Scripting.main = main @@ -327,3 +329,10 @@ def reconfigure(ctx): '''reconfigure if config scripts have changed''' import samba_utils samba_utils.reconfigure(ctx) + + +if os.path.isdir(os.path.join(srcdir, ".git")): + # Check if there are submodules that are checked out but out of date. + for submodule, status in samba_git.read_submodule_status(srcdir): + if status == "out-of-date": + raise Utils.WafError("some submodules are out of date. Please run 'git submodule update'") |