From cbca13efc6f10476e84180db0774e73149e5ebc6 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 23 Nov 2015 19:20:20 +0300 Subject: [PATCH] Do not fetch simple Lua versions if the build is cached --- hererocks.py | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/hererocks.py b/hererocks.py index 079454a..22d3e33 100755 --- a/hererocks.py +++ b/hererocks.py @@ -145,11 +145,12 @@ def url_to_name(s): def copy_dir(src, dst): shutil.copytree(src, dst, ignore=lambda _, __: {".git"}) -def fetch(versions, version, temp_dir, targz=True): - raw_versions, translations, downloads, name, repo = versions +def translate(versions, version): + return versions[1].get(version, version) - if version in translations: - version = translations[version] +def fetch(versions, version, temp_dir, targz=True): + raw_versions, _, downloads, name, repo = versions + version = translate(versions, version) if version in raw_versions: if not os.path.exists(opts.downloads): @@ -298,25 +299,39 @@ def check_subdir(path, subdir): return path -def build_lua(target_dir, lua_version, temp_dir): - lua_path, parts = fetch(luajit_versions if opts.luajit else lua_versions, lua_version, temp_dir) - - if not os.path.exists(target_dir): - os.makedirs(target_dir) - - message = "Building " + ("LuaJIT" if opts.luajit else "Lua") - cached_build_path = None - +def try_build_cache(target_dir, parts): if opts.builds and parts is not None: parts.extend(map(url_to_name, [opts.target, opts.compat, target_dir])) cached_build_path = os.path.join(opts.builds, "-".join(parts)) if os.path.exists(cached_build_path): - print(message + " (cached)") + print("Building " + capitalize(parts[0]) + " (cached)") os.chdir(cached_build_path) + return cached_build_path, True + else: + return cached_build_path, False + else: + return None, False + +def build_lua(target_dir, lua_version, temp_dir): + versions = luajit_versions if opts.luajit else lua_versions + lua_version = translate(versions, lua_version) + name = versions[3] + + if lua_version in versions[0]: + # Simple Lua version. Check build cache before fetching sources. + cached_build_path, cached = try_build_cache(target_dir, [name, lua_version]) + + if cached: return - print(message) + lua_path, parts = fetch(versions, lua_version, temp_dir) + cached_build_path, cached = try_build_cache(target_dir, parts) + + if cached: + return + + print("Building " + capitalize(name)) nominal_version = detect_lua_version(".") package_path, package_cpath = get_luarocks_paths(target_dir, nominal_version) patch_default_paths(".", package_path, package_cpath) @@ -333,6 +348,9 @@ def build_lua(target_dir, lua_version, temp_dir): def install_lua(target_dir, lua_version, temp_dir): build_lua(target_dir, lua_version, temp_dir) + if not os.path.exists(target_dir): + os.makedirs(target_dir) + if opts.luajit: print("Installing LuaJIT") run_command("make install", "PREFIX=" + quote(target_dir),