summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2016-09-05 16:01:44 -0400
committerAndrew Morrow <acm@mongodb.com>2016-10-21 13:50:22 -0400
commit53cd93fb9b31b3fe0bfa1fc12d64d9caf7b7f662 (patch)
treea8976028a2e25e6d168018f410ed4bd20aa24f19 /site_scons
parentf6e1dfb14413f4de88d236b50047c3b69ad5473c (diff)
downloadmongo-53cd93fb9b31b3fe0bfa1fc12d64d9caf7b7f662.tar.gz
SERVER-26473 Implement the git based decider
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/site_tools/git_decider.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/site_scons/site_tools/git_decider.py b/site_scons/site_tools/git_decider.py
new file mode 100644
index 00000000000..cd69de95085
--- /dev/null
+++ b/site_scons/site_tools/git_decider.py
@@ -0,0 +1,69 @@
+# Copyright 2016 MongoDB Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# If available, uses Git metadata to decide whether files are out of date.
+
+def generate(env, **kwargs):
+
+ # Grab the existing decider functions out of the environment
+ # so we can invoke them when we can't use Git.
+ base_decider = env.decide_target
+ if (base_decider != env.decide_source):
+ raise Exception("Decider environment seems broken")
+
+ from git import Git
+ thisRepo = Git(env.Dir('#').abspath)
+ currentGitState = thisRepo.ls_files('--stage')
+ lines = currentGitState.split('\n')
+
+ file_sha1_map = {}
+ for line in lines:
+ line_content = line.split()
+ file_sha1_map[env.File(line_content[3]).path] = line_content[1]
+
+ for m in thisRepo.ls_files('-m').split('\n'):
+ if (m):
+ del file_sha1_map[env.File(m).path]
+
+ def is_known_to_git(dependency):
+ return str(dependency) in file_sha1_map
+
+ def git_says_file_is_up_to_date(dependency, prev_ni):
+ gitInfoForDep = file_sha1_map[str(dependency)]
+
+ if prev_ni is None:
+ dependency.get_ninfo().csig = gitInfoForDep
+ return False
+
+ if not(hasattr(prev_ni, 'csig')):
+ prev_ni.csig = gitInfoForDep
+
+ result = gitInfoForDep == prev_ni.csig
+ return result
+
+ def MongoGitDecider(dependency, target, prev_ni):
+ if not is_known_to_git(dependency):
+ return base_decider(dependency, target, prev_ni)
+ return not git_says_file_is_up_to_date(dependency, prev_ni)
+
+ env.Decider(MongoGitDecider)
+
+def exists(env):
+ try:
+ from git import Git
+ Git(env.Dir('#').abspath).ls_files('--stage')
+ return True
+ except:
+ return False