Fetch correct LuaRocks distribution on Windows

This commit is contained in:
mpeterv 2015-10-27 12:39:03 +03:00
parent c33038a268
commit 796aa377d5

View File

@ -13,6 +13,7 @@ import subprocess
import sys import sys
import tarfile import tarfile
import tempfile import tempfile
import zipfile
try: try:
from urllib import urlretrieve from urllib import urlretrieve
@ -124,7 +125,7 @@ def cached_archive_name(name, version):
def capitalize(s): def capitalize(s):
return s[0].upper() + s[1:] return s[0].upper() + s[1:]
def fetch(versions, version, verbose, temp_dir): def fetch(versions, version, verbose, temp_dir, targz=True):
raw_versions, translations, downloads, name, repo = versions raw_versions, translations, downloads, name, repo = versions
if version in translations: if version in translations:
@ -135,7 +136,7 @@ def fetch(versions, version, verbose, temp_dir):
os.makedirs(cache_path) os.makedirs(cache_path)
archive_name = cached_archive_name(name, version) archive_name = cached_archive_name(name, version)
url = downloads + "/" + name + "-" + version + ".tar.gz" url = downloads + "/" + name + "-" + version + (".tar.gz" if targz else "-win32.zip")
message = "Fetching {} from {}".format(capitalize(name), url) message = "Fetching {} from {}".format(capitalize(name), url)
if not os.path.exists(archive_name): if not os.path.exists(archive_name):
@ -144,7 +145,11 @@ def fetch(versions, version, verbose, temp_dir):
else: else:
print(message + " (cached)") print(message + " (cached)")
archive = tarfile.open(archive_name, "r:gz") if targz:
archive = tarfile.open(archive_name, "r:gz")
else:
archive = zipfile.open(archive_name)
archive.extractall(temp_dir) archive.extractall(temp_dir)
archive.close() archive.close()
result_dir = os.path.join(temp_dir, name + "-" + version) result_dir = os.path.join(temp_dir, name + "-" + version)
@ -441,14 +446,15 @@ def install_lua(target_dir, lua_version, is_luajit, compat, verbose, temp_dir):
builder.install(target_dir) builder.install(target_dir)
def install_luarocks(target_dir, luarocks_version, verbose, temp_dir): def install_luarocks(target_dir, luarocks_version, verbose, temp_dir):
fetch(luarocks_versions, luarocks_version, verbose, temp_dir) mingw = get_lua_target() == "mingw"
fetch(luarocks_versions, luarocks_version, verbose, temp_dir, not mingw)
if not os.path.exists(target_dir): if not os.path.exists(target_dir):
os.makedirs(target_dir) os.makedirs(target_dir)
print("Installing LuaRocks") print("Installing LuaRocks")
if get_lua_target() == "mingw": if mingw:
run_command(verbose, "install.bat", "/Q", "/LUA", quote(target_dir), run_command(verbose, "install.bat", "/Q", "/LUA", quote(target_dir),
"/P", quote(target_dir), "/SELFCONTAINED", "/FORCECONFIG", "/MW") "/P", quote(target_dir), "/SELFCONTAINED", "/FORCECONFIG", "/MW")
else: else: