Fix missing space in ppr_cmd for HsCmdArrForm
[ghc.git] / .gitlab / fix-submodules.py
1 #!/usr/bin/env python3
2
3 """
4 Fix submodule upstream URLs. This ensures that CI builds of GHC forks
5 clone their submodules from its usual location. Otherwise users would need to
6 fork all submodules before their CI builds would succeed.
7 """
8
9 from pathlib import Path
10 import re
11
12 x = open('.gitmodules').read()
13 x = re.sub(r"url *= *\.\.", "url = https://gitlab.haskell.org/ghc", x)
14 open('.gitmodules', 'w').write(x)
15
16 import subprocess
17
18 def get_configs(config_file):
19 args = ['git', 'config', '-f', config_file.as_posix(), '--list']
20 out = subprocess.check_output(args)
21 configs = {}
22 for line in out.decode('UTF-8').split('\n'):
23 if '=' in line:
24 k,v = line.split('=')
25 configs[k] = v
26
27 return configs
28
29 def set_config(config_file, key, value):
30 args = ['git', 'config', '-f', config_file.as_posix(), '--replace', key, value]
31 subprocess.check_call(args)
32
33 upstreams = {
34 'utils/haddock': 'https://github.com/haskell/haddock'
35 }
36
37 modules_config = Path('.gitmodules')
38
39 def main():
40 for k,v in get_configs(modules_config).items():
41 match = re.match('submodule\.(.+)\.url', k)
42 if match is not None:
43 submod = match.group(1)
44 if submod in upstreams:
45 url = upstreams[submod]
46 else:
47 url = re.sub('\.\.', 'https://gitlab.haskell.org/ghc', v)
48
49 print('Using {submod} from {url}'.format(submod=submod, url=url))
50 set_config(modules_config, k, url)
51
52 if __name__ == '__main__':
53 main()