From a203cef159a2101e318d282d42da5d7d2dcf38e4 Mon Sep 17 00:00:00 2001 From: Luc Ma Date: Thu, 14 Oct 2021 20:50:44 +0800 Subject: [PATCH] explicitly provides ssh urls to GitRepo declarations In case of poor cyber condition, git fetches based on ssh protocol instead of https may be a better choice. The only thing that needs is an appropriate url. Also fixes issue 289 Signed-off-by: Luc Ma Components: Framework VK-GL-CTS public issue: 289 Change-Id: I6e121a50cfe3f0361defd34a8b961777e9f5751e --- external/fetch_sources.py | 72 ++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/external/fetch_sources.py b/external/fetch_sources.py index 802e29d..81fd02c 100644 --- a/external/fetch_sources.py +++ b/external/fetch_sources.py @@ -236,47 +236,7 @@ class GitRepo (Source): self.revision = revision self.removeTags = removeTags - def detectProtocol(self, cmdProtocol = None): - # reuse parent repo protocol - proc = subprocess.Popen(['git', 'ls-remote', '--get-url', 'origin'], stdout=subprocess.PIPE, universal_newlines=True) - (stdout, stderr) = proc.communicate() - - if proc.returncode != 0: - raise Exception("Failed to execute 'git ls-remote origin', got %d" % proc.returncode) - if (stdout[:3] == 'ssh') or (stdout[:3] == 'git'): - protocol = 'ssh' - else: - # remote 'origin' doesn't exist, assume 'https' as checkout protocol - protocol = 'https' - return protocol - - def selectUrl(self, cmdProtocol = None): - try: - if cmdProtocol == None: - protocol = self.detectProtocol(cmdProtocol) - else: - protocol = cmdProtocol - except: - # fallback to https on any issues - protocol = 'https' - - if protocol == 'ssh': - if self.sshUrl != None: - url = self.sshUrl - else: - assert self.httpsUrl != None - url = self.httpsUrl - else: - assert protocol == 'https' - url = self.httpsUrl - - assert url != None - return url - - def update (self, cmdProtocol = None, force = False): - fullDstPath = os.path.join(EXTERNAL_DIR, self.baseDir, self.extractDir) - - url = self.selectUrl(cmdProtocol) + def checkout(self, url, fullDstPath, force): if not os.path.exists(os.path.join(fullDstPath, '.git')): execute(["git", "clone", "--no-checkout", url, fullDstPath]) @@ -285,7 +245,7 @@ class GitRepo (Source): for tag in self.removeTags: proc = subprocess.Popen(['git', 'tag', '-l', tag], stdout=subprocess.PIPE) (stdout, stderr) = proc.communicate() - if proc.returncode == 0: + if len(stdout) > 0: execute(["git", "tag", "-d",tag]) force_arg = ['--force'] if force else [] execute(["git", "fetch"] + force_arg + ["--tags", url, "+refs/heads/*:refs/remotes/origin/*"]) @@ -293,6 +253,22 @@ class GitRepo (Source): finally: popWorkingDir() + def update (self, cmdProtocol, force = False): + fullDstPath = os.path.join(EXTERNAL_DIR, self.baseDir, self.extractDir) + url = self.httpsUrl + backupUrl = self.sshUrl + + # If url is none then start with ssh + if cmdProtocol == 'ssh' or url == None: + url = self.sshUrl + backupUrl = self.httpsUrl + + try: + self.checkout(url, fullDstPath, force) + except: + if backupUrl != None: + self.checkout(backupUrl, fullDstPath, force) + def postExtractLibpng (path): shutil.copy(os.path.join(path, "scripts", "pnglibconf.h.prebuilt"), os.path.join(path, "pnglibconf.h")) @@ -316,28 +292,28 @@ PACKAGES = [ "renderdoc"), GitRepo( "https://github.com/KhronosGroup/SPIRV-Tools.git", - None, + "git@github.com:KhronosGroup/SPIRV-Tools.git", "b0ce31fd2d8fdf0bdf87832a63d3da3289202fdf", "spirv-tools"), GitRepo( "https://github.com/KhronosGroup/glslang.git", - None, + "git@github.com:KhronosGroup/glslang.git", "abbe466451ca975fecfdba453ef9073df52aefc5", "glslang", removeTags = ["master-tot"]), GitRepo( "https://github.com/KhronosGroup/SPIRV-Headers.git", - None, + "git@github.com:KhronosGroup/SPIRV-Headers.git", "4995a2f2723c401eb0ea3e10c81298906bf1422b", "spirv-headers"), GitRepo( "https://github.com/KhronosGroup/Vulkan-Docs.git", - None, + "git@github.com:KhronosGroup/Vulkan-Docs.git", "45af5eb1f66898c9f382edc5afd691aeb32c10c0", "vulkan-docs"), GitRepo( "https://github.com/google/amber.git", - None, + "git@github.com:google/amber.git", "615ab4863f7d2e31d3037d0c6a0f641fd6fc0d07", "amber"), ] @@ -352,7 +328,7 @@ def parseArgs (): parser.add_argument('--insecure', dest='insecure', action='store_true', default=False, help="Disable certificate check for external sources." " Minimum python version required " + versionsForInsecureStr) - parser.add_argument('--protocol', dest='protocol', default=None, choices=['ssh', 'https'], + parser.add_argument('--protocol', dest='protocol', default='https', choices=['ssh', 'https'], help="Select protocol to checkout git repositories.") parser.add_argument('--force', dest='force', action='store_true', default=False, help="Pass --force to git fetch and checkout commands") -- 2.7.4