Skip to content

Commit 0ce78f6

Browse files
authored
Merge pull request #2648 from shbhmexe/bugfix/preconfigure-download-paths
fix: make preconfigure download paths consistent
2 parents b4143f1 + a31eeaf commit 0ce78f6

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

meson_scripts/init.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def _extract_member(self, member, targetpath, pwd):
289289

290290
if not os.path.exists(filepath) and not os.path.exists(alt_filepath):
291291
try:
292-
urllib.request.urlretrieve(url, commit_sha + ".zip")
292+
urllib.request.urlretrieve(url, filename)
293293
except Exception as e:
294294
print(e)
295295
print("Download of module " + name + " failed.")
@@ -303,8 +303,8 @@ def _extract_member(self, member, targetpath, pwd):
303303
filepath = alt_filepath
304304

305305
# Unzip file
306-
zipf = MyZipFile(filepath)
307-
zipf.extractall(target_dir)
306+
with MyZipFile(filepath) as zipf:
307+
zipf.extractall(target_dir)
308308

309309
# Remove directory if exists
310310
if os.path.exists(alt_name):

preconfigure.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def build_ninja():
3838
# If we are on windows, we don't need to compile ninja, we just download the executable
3939
if os.name == "nt":
4040
ninja_exe_url = "https://github.com/ninja-build/ninja/releases/download/v1.13.0/ninja-win.zip"
41+
ninja_zip_path = os.path.join(sys.path[0], "ninja-win.zip")
4142

4243
# Try to execute ninja, if it fails, download .exe from github
4344
try:
@@ -48,18 +49,18 @@ def build_ninja():
4849
except OSError:
4950
print("Downloading ninja ... ")
5051
try:
51-
urllib.request.urlretrieve(ninja_exe_url, "ninja-win.zip")
52-
except:
52+
urllib.request.urlretrieve(ninja_exe_url, ninja_zip_path)
53+
except Exception as e:
5354
print(e)
5455
print("Download of ninja executable failed.")
5556
print("Get archive at " + ninja_exe_url)
5657
print("extract ninja.exe in the source code root folder.")
5758
print("Run meson.py again.")
5859
sys.exit(1)
5960

60-
zipf = zipfile.ZipFile(sys.path[0] + os.path.sep + "ninja-win.zip")
61-
zipf.extractall(sys.path[0])
62-
remove_file(sys.path[0] + os.path.sep + "ninja-win.zip")
61+
with zipfile.ZipFile(ninja_zip_path) as zipf:
62+
zipf.extractall(sys.path[0])
63+
remove_file(ninja_zip_path)
6364
else:
6465
ninjapath = sys.path[0] + os.path.sep + "externals" + os.path.sep + "ninja"
6566
try:
@@ -75,7 +76,10 @@ def build_ninja():
7576
subprocess.run(
7677
["python3", "configure.py", "--bootstrap"], cwd=ninjapath, env=env
7778
)
78-
shutil.copy(ninjapath + os.path.sep + "ninja", ".")
79+
shutil.copy(
80+
os.path.join(ninjapath, "ninja"),
81+
os.path.join(sys.path[0], "ninja"),
82+
)
7983

8084

8185
def run(

0 commit comments

Comments
 (0)