From 677dd87ca6f923f38dd9c5f4b1120d76203a72b7 Mon Sep 17 00:00:00 2001 From: Ryan Egesdahl Date: Wed, 12 Apr 2023 21:39:32 +0000 Subject: SERVER-70425 Stash before using git archive --- site_scons/site_tools/distsrc.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'site_scons') diff --git a/site_scons/site_tools/distsrc.py b/site_scons/site_tools/distsrc.py index 83f47f2ab3f..33b63d3d8d4 100644 --- a/site_scons/site_tools/distsrc.py +++ b/site_scons/site_tools/distsrc.py @@ -20,18 +20,19 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -import SCons +import io import os import os.path as ospath -import subprocess import shutil +import subprocess import tarfile import time import zipfile -import io from distutils.spawn import find_executable +import SCons + __distsrc_callbacks = [] @@ -174,6 +175,7 @@ def distsrc_action_generator(source, target, env, for_signature): # This is done in two stages because env.WhereIs doesn't seem to work # correctly on Windows, but we still want to be able to override the PATH # using the env. + git_path = env.WhereIs("git") if not git_path: git_path = find_executable("git") @@ -192,11 +194,22 @@ def distsrc_action_generator(source, target, env, for_signature): print("Invalid file format for distsrc. Must be tar or zip file") env.Exit(1) - git_cmd = ('"%s" archive --format %s --output %s --prefix ${MONGO_DIST_SRC_PREFIX} HEAD' % - (git_path, target_ext, target[0])) + def create_archive(target=None, source=None, env=None): + stash_id = subprocess.check_output([git_path, "stash", "create"]).decode("utf-8").strip() + subprocess.check_call([ + git_path, + "archive", + "--format", + target_ext, + "--output", + str(target[0]), + "--prefix", + env["MONGO_DIST_SRC_PREFIX"], + stash_id, + ]) return [ - SCons.Action.Action(git_cmd, "Running git archive for $TARGET"), + SCons.Action.Action(create_archive, "Creating archive for $TARGET"), SCons.Action.Action( run_distsrc_callbacks, "Running distsrc callbacks for $TARGET", -- cgit v1.2.1