2
2
3
3
"""Checks the submodule commit IDs in integration CMake files."""
4
4
5
+ import argparse
6
+ import configparser
5
7
import os
6
- import subprocess
7
8
import re
8
- import argparse
9
+ import subprocess
9
10
import sys
10
11
11
12
_DESCRIPTION = """
@@ -33,23 +34,32 @@ def main():
33
34
result = subprocess .run (["git" , "submodule" , "status" ],
34
35
stdout = subprocess .PIPE , check = True )
35
36
output = result .stdout .decode ('ascii' )
37
+ if args .check :
38
+ gitconfig = configparser .ConfigParser ()
39
+ gitconfig .read ('.git/config' )
36
40
allsync = True
37
41
with open ("CMakeLists.txt" , "r" ) as fp :
38
42
origcontent = fp .read ()
39
43
content = origcontent
40
44
for match in _PAT_SUBMOD_COMMIT .finditer (output ):
41
45
commit , submodule = match .groups ()
46
+ if args .check :
47
+ locale = ('submodule "external/%s/origin"' % submodule )
48
+ active = gitconfig .get (locale , 'active' )
49
+ if active == 'true' :
50
+ url = gitconfig .get (locale , 'url' )
51
+ _check_submodule_url (content , submodule , url )
42
52
newcontent , nn = _replace_submodule_commit (content , submodule , commit )
43
53
if nn < 1 :
44
54
print ("! Commit for submodule {} was NOT FOUND" .format (submodule ))
45
55
allsync = False
46
56
continue
47
57
sync = (newcontent == content )
48
58
if sync :
49
- print ("+ Commit for submodule {} matches." .format (submodule ))
59
+ print ("+ Commit ID for submodule {} matches." .format (submodule ))
50
60
elif args .update :
51
61
content = newcontent
52
- print ("* Commit for submodule {} had been updated." \
62
+ print ("* Commit for submodule {} has been updated." \
53
63
.format (submodule ))
54
64
else :
55
65
print ("! Commit for submodule {} DOES NOT MATCH!" .format (submodule ))
@@ -66,6 +76,8 @@ def _parse_arguments():
66
76
parser = argparse .ArgumentParser (description = _DESCRIPTION )
67
77
msg = "Whether the commits should be updated in the CMakeLists.txt files"
68
78
parser .add_argument ("-u" , "--update" , action = 'store_true' , help = msg )
79
+ msg = "Check consistency between CMakeLists.txt and submodules"
80
+ parser .add_argument ("-c" , "--check" , action = 'store_true' , help = msg )
69
81
return parser .parse_args ()
70
82
71
83
@@ -82,5 +94,20 @@ def _replace_submodule_commit(content, submodule, commit):
82
94
return newcontent , nsubs
83
95
84
96
97
+ def _check_submodule_url (content , submodule , url ):
98
+ """Checks consistency of the submodule url in the CMakeLists.txt file"""
99
+ submodule_normed = submodule .upper ()
100
+ submodule_normed = re .sub (
101
+ _PAT_SPECIAL_CHAR , _SPECIAL_CHAR_REPLACEMENT , submodule_normed )
102
+ match = re .findall (
103
+ r"set\({}_GIT_REPOSITORY \"({})(\.git)?\"\)" .format (submodule_normed , url ),
104
+ content )
105
+ if (len (match ) == 0 ):
106
+ print ('** {} : mismatch between .git/config and CMakeLists.txt' .format (submodule ))
107
+ else :
108
+ if (match [0 ][1 ] == '.git' ):
109
+ print ("* {} : bare vs non-bare repository address in CMakeLists.txt and .git/config" .format (submodule ))
110
+
111
+
85
112
if __name__ == '__main__' :
86
113
main ()
0 commit comments