@@ -67,10 +67,9 @@ def init_submodules(method = 'auto'):
6767 alt_name_medi = base_path + 'medi'
6868 alt_name_codi = base_path + 'codi'
6969 alt_name_opdi = base_path + 'opdi'
70- alt_name_meson = base_path + 'meson'
71- alt_name_ninja = base_path + 'ninja'
72- alt_name_mpp = cur_dir + os .path .sep + 'subprojects' + os .path .sep + 'Mutationpp'
73-
70+ alt_name_meson = base_path + 'meson'
71+ alt_name_ninja = base_path + 'ninja'
72+ alt_name_mpp = cur_dir + os .path .sep + 'subprojects' + os .path .sep + 'Mutationpp'
7473
7574 if method == 'auto' :
7675 is_git = is_git_directory (cur_dir )
@@ -100,6 +99,7 @@ def init_submodules(method = 'auto'):
10099 download_module (ninja_name , alt_name_ninja , github_repo_ninja , sha_version_ninja )
101100 download_module (mpp_name , alt_name_mpp , github_repo_mpp , sha_version_mpp )
102101
102+
103103def is_git_directory (path = '.' ):
104104 try :
105105 p = subprocess .call (["git" , "branch" ], stderr = subprocess .STDOUT , stdout = open (os .devnull , 'w' ), cwd = path )
@@ -111,6 +111,7 @@ def is_git_directory(path = '.'):
111111 return False
112112 return p == 0
113113
114+
114115def submodule_status (path , sha_commit ):
115116
116117 if not os .path .exists (path + os .path .sep + sha_commit ):
@@ -124,7 +125,6 @@ def submodule_status(path, sha_commit):
124125 # ' ' : Correct version of submodule is initialized
125126 status_indicator = status [0 ][0 ]
126127
127-
128128 if status_indicator == '+' :
129129 # Write a warning that the sha tags do not match
130130 sys .stderr .write ('WARNING: the currently checked out submodule commit in '
@@ -139,11 +139,10 @@ def submodule_status(path, sha_commit):
139139 cur_sha_commit = status [1 :].split (' ' )[0 ]
140140 if (cur_sha_commit != sha_commit ):
141141 print ('SHA-1 tag stored in index does not match SHA tag stored in this script.' )
142-
143-
142+
144143
145144def download_module (name , alt_name , git_repo , commit_sha ):
146-
145+
147146 # ZipFile does not preserve file permissions.
148147 # This is a workaround for that problem:
149148 # https://stackoverflow.com/questions/39296101/python-zipfile-removes-execute-permissions-from-binaries
@@ -159,50 +158,62 @@ def _extract_member(self, member, targetpath, pwd):
159158 os .chmod (targetpath , attr )
160159 return targetpath
161160
162- if not os .path .exists (alt_name + os .path .sep + commit_sha ):
161+ # Where to download the module into
162+ target_dir = os .path .dirname (alt_name )
163+
164+ # File tag used to mark modules downloaded by this method.
165+ module_identifier = os .path .join (alt_name , commit_sha )
166+
167+ if not os .path .exists (module_identifier ):
163168
164169 if os .path .exists (alt_name ) and os .listdir (alt_name ):
165170 print ('Directory ' + alt_name + ' is not empty' )
166171 print ('Maybe submodules are already cloned with git?' )
167172 sys .exit (1 )
168-
173+
169174 else :
170175 print ('Downloading ' + name + ' \' ' + commit_sha + '\' ' )
171-
176+
172177 filename = commit_sha + '.zip'
178+ filepath = os .path .join (sys .path [0 ], filename )
179+ alt_filename = name + "-" + filename
180+ alt_filepath = os .path .join (sys .path [0 ], alt_filename )
173181
174182 url = git_repo + '/archive/' + filename
175183
176- if not os .path .exists (sys . path [ 0 ] + os .path .sep + filename ):
184+ if not os .path .exists (filepath ) and not os .path .exists ( alt_filepath ):
177185 try :
178186 urllib .request .urlretrieve (url , commit_sha + '.zip' )
179- except RuntimeError as e :
187+ except Exception as e :
180188 print (e )
181189 print ('Download of module ' + name + ' failed.' )
182190 print ('Get archive at ' + url )
183191 print ('and place it in the source code root folder' )
184192 print ('Run meson.py again' )
185193 sys .exit ()
186-
187- # Unzip file
188- zipf = MyZipFile (sys .path [0 ] + os .path .sep + filename )
189- zipf .extractall (sys .path [0 ] + os .path .sep + 'externals' )
190-
194+
195+ # Detect filename (changes have been noted)
196+ if not os .path .exists (filepath ):
197+ filepath = alt_filepath
198+
199+ # Unzip file
200+ zipf = MyZipFile (filepath )
201+ zipf .extractall (target_dir )
202+
191203 # Remove directory if exists
192204 if os .path .exists (alt_name ):
193205 os .rmdir (alt_name )
194206
195- os .rename (sys . path [ 0 ] + os .path .sep + 'externals' + os . path . sep + name + '-' + commit_sha , alt_name )
207+ os .rename (os .path .join ( target_dir , name + '-' + commit_sha ) , alt_name )
196208
197209 # Delete zip file
198- remove_file (sys . path [ 0 ] + os . path . sep + filename )
210+ remove_file (filepath )
199211
200212 # Create identifier
201- f = open (alt_name + os . path . sep + commit_sha , 'w' )
213+ f = open (module_identifier , 'w' )
202214 f .close ()
203215
204216
205-
206217if __name__ == '__main__' :
207218 if sys .version_info [0 ] < 3 :
208219 raise Exception ("Script must be run using Python 3" )
0 commit comments