From bb53750d330ba9edc590f3b6e0b4c1b23a6c7d62 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 5 May 2015 22:05:14 +0000 Subject: [PATCH 1/5] Simplify instructions for checking out submodules. Signed-off-by: Jelmer Vernooij --- third_party/wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/wscript b/third_party/wscript index 4f63477..d41b906 100644 --- a/third_party/wscript +++ b/third_party/wscript @@ -31,7 +31,7 @@ def find_third_party_module(conf, module, package): os.path.isfile(os.path.join(conf.srcdir, ".gitmodule"))): raise Utils.WafError("""\ Unable to find Python module '%s'. Please install the system package or check \ -out the relevant submodule by running 'git submodule init; git submodule update'. +out the relevant submodule by running 'git submodule update --init'. """ % module) else: raise Utils.WafError("""\ -- 2.1.4 From d524dc459346a0fb54ed807e43909758e75ce988 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 18 May 2015 17:15:15 +0000 Subject: [PATCH 2/5] Drop bzr VCS support. Signed-Off-By: Jelmer Vernooij --- buildtools/wafsamba/samba_dist.py | 6 ---- buildtools/wafsamba/samba_version.py | 53 ------------------------------------ 2 files changed, 59 deletions(-) diff --git a/buildtools/wafsamba/samba_dist.py b/buildtools/wafsamba/samba_dist.py index aecacb7..654a168 100644 --- a/buildtools/wafsamba/samba_dist.py +++ b/buildtools/wafsamba/samba_dist.py @@ -86,12 +86,6 @@ def vcs_dir_contents(path): env = dict(os.environ) env["GIT_DIR"] = os.path.join(repo, ".git") break - elif os.path.isdir(os.path.join(repo, ".bzr")): - ls_files_cmd = [ 'bzr', 'ls', '--recursive', '--versioned', - os_path_relpath(path, repo)] - cwd = repo - env = None - break repo = os.path.dirname(repo) if repo == "/": raise Exception("unsupported or no vcs for %s" % path) diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py index 67ff232..1f5be49 100644 --- a/buildtools/wafsamba/samba_version.py +++ b/buildtools/wafsamba/samba_version.py @@ -3,57 +3,6 @@ import Utils import samba_utils import sys -def bzr_version_summary(path): - try: - import bzrlib - except ImportError: - return ("BZR-UNKNOWN", {}) - - import bzrlib.ui - bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal( - sys.stdin, sys.stdout, sys.stderr) - from bzrlib import branch, osutils, workingtree - from bzrlib.plugin import load_plugins - load_plugins() - - b = branch.Branch.open(path) - (revno, revid) = b.last_revision_info() - rev = b.repository.get_revision(revid) - - fields = { - "BZR_REVISION_ID": revid, - "BZR_REVNO": revno, - "COMMIT_DATE": osutils.format_date_with_offset_in_original_timezone(rev.timestamp, - rev.timezone or 0), - "COMMIT_TIME": int(rev.timestamp), - "BZR_BRANCH": rev.properties.get("branch-nick", ""), - } - - # If possible, retrieve the git sha - try: - from bzrlib.plugins.git.object_store import get_object_store - except ImportError: - # No git plugin - ret = "BZR-%d" % revno - else: - store = get_object_store(b.repository) - store.lock_read() - try: - full_rev = store._lookup_revision_sha1(revid) - finally: - store.unlock() - fields["GIT_COMMIT_ABBREV"] = full_rev[:7] - fields["GIT_COMMIT_FULLREV"] = full_rev - ret = "GIT-" + fields["GIT_COMMIT_ABBREV"] - - if workingtree.WorkingTree.open(path).has_changes(): - fields["COMMIT_IS_CLEAN"] = 0 - ret += "+" - else: - fields["COMMIT_IS_CLEAN"] = 1 - return (ret, fields) - - def git_version_summary(path, env=None): # Get version from GIT if not 'GIT' in env and os.path.exists("/usr/bin/git"): @@ -200,8 +149,6 @@ also accepted as dictionary entries here self.vcs_fields = {} elif os.path.exists(os.path.join(path, ".git")): suffix, self.vcs_fields = git_version_summary(path, env=env) - elif os.path.exists(os.path.join(path, ".bzr")): - suffix, self.vcs_fields = bzr_version_summary(path) elif os.path.exists(os.path.join(path, ".distversion")): suffix, self.vcs_fields = distversion_version_summary(path) else: -- 2.1.4 From b1a9b901483742671d95c70020a43028d12cee1d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 18 May 2015 17:37:51 +0000 Subject: [PATCH 3/5] Factor out function for finding Git binary. Signed-Off-By: Jelmer Vernooij --- buildtools/wafsamba/samba_git.py | 14 ++++++++++++++ buildtools/wafsamba/samba_version.py | 11 +++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 buildtools/wafsamba/samba_git.py diff --git a/buildtools/wafsamba/samba_git.py b/buildtools/wafsamba/samba_git.py new file mode 100644 index 0000000..a48ce12 --- /dev/null +++ b/buildtools/wafsamba/samba_git.py @@ -0,0 +1,14 @@ +import os + +def find_git(env=None): + """Find the git binary.""" + if env is not None and 'GIT' in env: + return env['GIT'] + + # Get version from GIT + if os.path.exists("/usr/bin/git"): + # this is useful when doing make dist without configuring + return "/usr/bin/git" + + return None + diff --git a/buildtools/wafsamba/samba_version.py b/buildtools/wafsamba/samba_version.py index 1f5be49..bb0be96 100644 --- a/buildtools/wafsamba/samba_version.py +++ b/buildtools/wafsamba/samba_version.py @@ -1,17 +1,16 @@ import os import Utils import samba_utils -import sys +from samba_git import find_git def git_version_summary(path, env=None): - # Get version from GIT - if not 'GIT' in env and os.path.exists("/usr/bin/git"): - # this is useful when doing make dist without configuring - env.GIT = "/usr/bin/git" + git = find_git(env) - if not 'GIT' in env: + if git is None: return ("GIT-UNKNOWN", {}) + env.GIT = git + environ = dict(os.environ) environ["GIT_DIR"] = '%s/.git' % path environ["GIT_WORK_TREE"] = path -- 2.1.4 From 0f98219f7aaf75a033882e84237d03f0525e95c1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 18 May 2015 20:00:30 +0000 Subject: [PATCH 4/5] Make waf fail if submodules are out of date. Instead, suggest the user run 'git submodule update'. This should prevent users from accidentally building Samba against outdated or too new versions of the bundled third party libraries after switching branches. I've opted to make this an error rather than actually running 'git submodule update' directly, as the latter could cause unpredictable behaviour. If we find that manually updating submodules is too cumbersome, we can always change this. The normal mode of operation for developers should not involve any submodules at all, but system versions of these libraries. Signed-off-by: Jelmer Vernooij --- buildtools/wafsamba/samba_git.py | 34 ++++++++++++++++++++++++++++++++++ wscript | 11 ++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/buildtools/wafsamba/samba_git.py b/buildtools/wafsamba/samba_git.py index a48ce12..d103aa8 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)) diff --git a/wscript b/wscript index 8cf22f8..7700c32 100644 --- a/wscript +++ b/wscript @@ -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'") -- 2.1.4 From 72111a56a80bc9c25fa2e24baa6f758e81f9fc8b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 18 May 2015 20:19:23 +0000 Subject: [PATCH 5/5] Factor out submodule presence checking. Signed-off-by: Jelmer Vernooij --- buildtools/wafsamba/samba_git.py | 11 ++++++++++- third_party/wscript | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/buildtools/wafsamba/samba_git.py b/buildtools/wafsamba/samba_git.py index d103aa8..c58a579 100644 --- a/buildtools/wafsamba/samba_git.py +++ b/buildtools/wafsamba/samba_git.py @@ -14,6 +14,15 @@ def find_git(env=None): return None +def has_submodules(path): + """Check whether a source directory is git-versioned and has submodules. + + :param path: Path to Samba source directory + """ + return (os.path.isdir(os.path.join(path, ".git")) and + os.path.isfile(os.path.join(path, ".gitmodules"))) + + def read_submodule_status(path, env=None): """Check status of submodules. @@ -24,7 +33,7 @@ def read_submodule_status(path, env=None): :raise RuntimeError: raised when parsing of 'git submodule status' output fails. """ - if not os.path.isfile(os.path.join(path, ".gitmodules")): + if not has_submodules(path): # No point in running git. return git = find_git(env) diff --git a/third_party/wscript b/third_party/wscript index d41b906..d5b9df7 100644 --- a/third_party/wscript +++ b/third_party/wscript @@ -1,5 +1,6 @@ #!/usr/bin/env python +import samba_git import Utils import os import sys @@ -27,8 +28,7 @@ def find_third_party_module(conf, module, package): try: __import__(module) except ImportError: - if (os.path.isdir(os.path.join(conf.srcdir, ".git")) and - os.path.isfile(os.path.join(conf.srcdir, ".gitmodule"))): + if samba_git.has_submodules(conf.srcdir): raise Utils.WafError("""\ Unable to find Python module '%s'. Please install the system package or check \ out the relevant submodule by running 'git submodule update --init'. -- 2.1.4