Make KC CTS checkout protocol selectable.
authorAlexander Galazin <alexander.galazin@arm.com>
Thu, 8 Dec 2016 08:34:17 +0000 (09:34 +0100)
committerAlexander Galazin <alexander.galazin@arm.com>
Fri, 9 Dec 2016 19:16:08 +0000 (20:16 +0100)
The script will use the parent repo protocol by default.
SSH or HTPPS can be explicitly request from the command line.

Allowed alternatives:
* python external/fetch_kc_cts.py - checkout via parent repo protocol.
* python external/fetch_kc_cts.py --protocol=ssh - checkout via SSH.
* python external/fetch_kc_cts.py --protocol=https - checkout via HTTPS.

Fixes OpenGL OSS-CTS issue #21

Change-Id: Ie30bfc08abb0ddbfa4e381c261e18f9758d36950

external/fetch_kc_cts.py
external/fetch_sources.py

index 40b7664f4b13d9d00e83ee5bdf0b5de462c1a4f3..5373671cd16a0c6389013704e1df6db24a8a3724 100644 (file)
@@ -37,6 +37,7 @@ SHA1 = "c9a3540e50d7d407284d929b45c5fa2dd6b2fc8b"
 PACKAGES = [
        GitRepo(
                "https://gitlab.khronos.org/opengl/kc-cts.git",
+               "git@gitlab.khronos.org:opengl/kc-cts.git",
                SHA1,
                "kc-cts"),
 ]
@@ -48,4 +49,4 @@ if __name__ == "__main__":
                if args.clean:
                        pkg.clean()
                else:
-                       pkg.update()
+                       pkg.update(args.protocol)
index 03a1dc3f5e5eeea6217ac04eb039cbbeb75c51cc..bb14093c25bc2a2926a0e9198db3801e95abf90b 100644 (file)
@@ -61,7 +61,7 @@ class SourcePackage (Source):
                Source.clean(self)
                self.removeArchives()
 
-       def update (self):
+       def update (self, cmdProtocol = None):
                if not self.isArchiveUpToDate():
                        self.fetchAndVerifyArchive()
 
@@ -149,20 +149,51 @@ class SourcePackage (Source):
                        self.postExtract(dstPath)
 
 class GitRepo (Source):
-       def __init__(self, url, revision, baseDir, extractDir = "src"):
+       def __init__(self, httpsUrl, sshUrl, revision, baseDir, extractDir = "src"):
                Source.__init__(self, baseDir, extractDir)
-               self.url                = url
+               self.httpsUrl   = httpsUrl
+               self.sshUrl             = sshUrl
                self.revision   = revision
 
-       def update (self):
+       def selectUrl(self, cmdProtocol = None):
+               if cmdProtocol == None:
+                       # reuse parent repo protocol
+                       proc = subprocess.Popen(['git', 'ls-remote', '--get-url', 'origin'], stdout=subprocess.PIPE)
+                       (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':
+                               protocol = 'ssh'
+                       else:
+                               assert stdout[:5] == 'https'
+                               protocol = 'https'
+               else:
+                       protocol = cmdProtocol
+
+               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):
                fullDstPath = os.path.join(EXTERNAL_DIR, self.baseDir, self.extractDir)
 
+               url = self.selectUrl(cmdProtocol)
                if not os.path.exists(fullDstPath):
-                       execute(["git", "clone", "--no-checkout", self.url, fullDstPath])
+                       execute(["git", "clone", "--no-checkout", url, fullDstPath])
 
                pushWorkingDir(fullDstPath)
                try:
-                       execute(["git", "fetch", self.url, "+refs/heads/*:refs/remotes/origin/*"])
+                       execute(["git", "fetch", url, "+refs/heads/*:refs/remotes/origin/*"])
                        execute(["git", "checkout", self.revision])
                finally:
                        popWorkingDir()
@@ -185,14 +216,17 @@ PACKAGES = [
                postExtract = postExtractLibpng),
        GitRepo(
                "https://github.com/KhronosGroup/SPIRV-Tools.git",
+               None,
                "5c19de25107d496a15c7869b3e1dab0a0f85913d",
                "spirv-tools"),
        GitRepo(
                "https://github.com/KhronosGroup/glslang.git",
+               None,
                "e3aa654c4b0c761b28d7864192ca8ceea6faf70a",
                "glslang"),
        GitRepo(
                "https://github.com/KhronosGroup/SPIRV-Headers.git",
+               None,
                "bd47a9abaefac00be692eae677daed1b977e625c",
                "spirv-headers"),
 ]
@@ -201,6 +235,8 @@ def parseArgs ():
        parser = argparse.ArgumentParser(description = "Fetch external sources")
        parser.add_argument('--clean', dest='clean', action='store_true', default=False,
                                                help='Remove sources instead of fetching')
+       parser.add_argument('--protocol', dest='protocol', default=None, choices=['ssh', 'https'],
+                                               help="Select protocol to checkout git repositories.")
        return parser.parse_args()
 
 if __name__ == "__main__":
@@ -210,4 +246,4 @@ if __name__ == "__main__":
                if args.clean:
                        pkg.clean()
                else:
-                       pkg.update()
+                       pkg.update(args.protocol)