[commit: ghc] wip/windows-cleanup: gitlab-ci: Clone haddock from its upstream repository (b974386)

git at git.haskell.org git at git.haskell.org
Sun Jan 6 04:30:18 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/windows-cleanup
Link       : http://ghc.haskell.org/trac/ghc/changeset/b974386fece4b4fc0fcbb1342be2b129f32ce784/ghc

>---------------------------------------------------------------

commit b974386fece4b4fc0fcbb1342be2b129f32ce784
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Sat Jan 5 14:16:56 2019 -0500

    gitlab-ci: Clone haddock from its upstream repository
    
    This ensures that changes requiring haddock changes can be built under CI.


>---------------------------------------------------------------

b974386fece4b4fc0fcbb1342be2b129f32ce784
 .gitlab-ci.yml            |  2 +-
 .gitlab/fix-submodules.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 87a5333..ab79622 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -119,7 +119,7 @@ validate-x86_64-darwin:
     LANG: "en_US.UTF-8"
   before_script:
     - git clean -xdf && git submodule foreach git clean -xdf
-    - python .gitlab/fix-submodules.py
+    - python3 .gitlab/fix-submodules.py
     - git submodule sync --recursive
     - git submodule update --init --recursive
     - git checkout .gitmodules
diff --git a/.gitlab/fix-submodules.py b/.gitlab/fix-submodules.py
old mode 100644
new mode 100755
index 2ff8e41..621d692
--- a/.gitlab/fix-submodules.py
+++ b/.gitlab/fix-submodules.py
@@ -1,8 +1,54 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
 
+"""
+Fix submodule upstream URLs. This ensures that CI builds of GHC forks
+clone their submodules from its usual location. Otherwise users would need to
+fork all submodules before their CI builds would succeed.
+"""
+
+from typing import List, Dict
+from pathlib import Path
 import re
 
 x = open('.gitmodules').read()
 x = re.sub(r"url *= *\.\.", "url = https://gitlab.haskell.org/ghc", x)
 open('.gitmodules', 'w').write(x)
 
+import subprocess
+
+def get_configs(config_file: Path) -> Dict[str, str]:
+    args = ['git', 'config', '-f', config_file.as_posix(), '--list']
+    out = subprocess.check_output(args)
+    configs = {}
+    for line in out.decode('UTF-8').split('\n'):
+        if '=' in line:
+            k,v = line.split('=')
+            configs[k] = v
+
+    return configs
+
+def set_config(config_file: Path, key: str, value: str) -> None:
+    args = ['git', 'config', '-f', config_file.as_posix(), '--replace', key, value]
+    subprocess.check_call(args)
+
+upstreams = {
+    'utils/haddock': 'https://github.com/haskell/haddock'
+}
+
+modules_config = Path('.gitmodules')
+
+def main():
+    for k,v in get_configs(modules_config).items():
+        match = re.match('submodule\.(.+)\.url', k)
+        if match is not None:
+            submod = match.group(1)
+            if submod in upstreams:
+                url = upstreams[submod]
+            else:
+                url = re.sub('\.\.', 'https://gitlab.haskell.org/ghc', v)
+
+            print('Using {submod} from {url}'.format(submod=submod, url=url))
+            set_config(modules_config, k, url)
+
+if __name__ == '__main__':
+    main()



More information about the ghc-commits mailing list