From dca85db970bfaf88609a400506c12fc7c8e9c7a0 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sun, 17 Apr 2016 23:02:38 +0300 Subject: [PATCH] add Ravi support --- .travis.yml | 10 ++++ hererocks.py | 128 +++++++++++++++++++++++++++++++++++++++++++++++---- test.sh | 7 +++ 3 files changed, 137 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 032b9d4..8b597eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,13 @@ language: python +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 + - g++-4.8 + matrix: include: - os: linux @@ -21,6 +29,8 @@ matrix: language: generic install: + - export CXX=g++-4.8 + - export CC=gcc-4.8 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pip install pyflakes; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then pip install pep8; fi diff --git a/hererocks.py b/hererocks.py index adf72fc..e63d32f 100755 --- a/hererocks.py +++ b/hererocks.py @@ -12,6 +12,7 @@ import re import shutil import string +import stat import subprocess import sys import tarfile @@ -513,16 +514,19 @@ def add_package_paths_redefines(self): "#define LUA_CPATH_DEFAULT \"{}\"".format(package_cpath) ]) + def luaconf_h_path(self): + return os.path.join("src", "luaconf.h") + def patch_redefines(self): redefines = "\n".join(self.redefines) - luaconf_h = open(os.path.join("src", "luaconf.h"), "rb") + luaconf_h = open(self.luaconf_h_path(), "rb") luaconf_src = luaconf_h.read() luaconf_h.close() body, _, tail = luaconf_src.rpartition(b"#endif") - luaconf_h = open(os.path.join("src", "luaconf.h"), "wb") + luaconf_h = open(self.luaconf_h_path(), "wb") luaconf_h.write(body) luaconf_h.write(redefines.encode("UTF-8")) luaconf_h.write(b"\n#endif") @@ -1178,6 +1182,95 @@ def make_install(self): copy_dir("jit", jitlib_path) +class Ravi(Lua): + name = "ravi" + title = "Ravi" + downloads = "https://github.com/dibyendumajumdar/ravi/archive" + win32_zip = False + default_repo = "https://github.com/dibyendumajumdar/ravi/archive" + versions = [ + "0.15.1", + ] + translations = { + "0.15": "0.15.1", + "^": "0.15.1", + "latest": "0.15.1" + } + checksums = { + "ravi-0.15.1.tar.gz" : "c42b4540a37f763904895f7fb5757f0ce0e5185e7c3e5316eb056a1ac505134d", + } + + def __init__(self, version): + super(Ravi, self).__init__(version) + + def get_download_url(self): + return self.downloads + "/" + self.fixed_version + ".tar.gz" + + def luaconf_h_path(self): + return os.path.join("include", "luaconf.h") + + @staticmethod + def major_version_from_version(): + return "5.3" + + @staticmethod + def set_version_suffix(): + pass + + def set_compat(self): + self.compat = "5.2" + + def add_compat_cflags_and_redefines(self): + pass + + def make(self): + os.mkdir("build") + os.chdir("build") + run("cmake", "-DCMAKE_BUILD_TYPE=Release", "..") + run("make") + os.chdir("..") + + def make_install(self): + for d in ["bin", "lib", "include"]: + path = os.path.join(opts.location, d) + if not os.path.exists(path): + os.mkdir(path) + + shutil.copy( + os.path.join("build", exe("ravi")), + os.path.join(opts.location, "bin", exe("ravi")), + ) + + so_file = "libravi.so" + shutil.copy( + os.path.join("build", so_file), + os.path.join(opts.location, "lib", so_file), + ) + + lua_file = os.path.join(opts.location, "bin", exe("lua")) + with open(lua_file, "w") as lua_exe: + lua_exe.write( + """#!/bin/sh +export LD_LIBRARY_PATH="%(lib_dir)s:$LD_LIBRARY_PATH" +exec "%(exe)s" "$@" """ % { + "lib_dir": os.path.join(opts.location, "lib"), + "exe": os.path.join(opts.location, "bin", exe("ravi")), + } + ) + # chmod +x + st = os.stat(lua_file) + os.chmod(lua_file, st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) + + for header in os.listdir("include"): + shutil.copy( + os.path.join("include", header), + os.path.join(opts.location, "include", header), + ) + + if os.name == "nt": + pass + # TODO + class LuaRocks(Program): name = "luarocks" title = "LuaRocks" @@ -1253,7 +1346,10 @@ def get_cmake_generator(lua_identifiers): vs_short_version, vs_year, " Win64" if vs_arch == "x64" else "") def build(self): - lua_identifiers = self.all_identifiers.get("lua", self.all_identifiers.get("LuaJIT")) + lua_identifiers = any( + self.all_identifiers.get(name) + for name in ["lua", "LuaJIT", "ravi"] + ) if lua_identifiers is None: sys.exit("Error: can't install LuaRocks: Lua is not present in {}".format(opts.location)) @@ -1494,6 +1590,9 @@ def main(argv=None): "Versions 2.0.0 - 2.1.0-beta2 are supported. " "When installing from the LuaJIT main git repo its URI can be left out, " "so that '@458a40b' installs from a commit and '@' installs from the master branch.") + parser.add_argument( + "--ravi", help="Version of Ravi to install. " + ) parser.add_argument( "-r", "--luarocks", help="Version of LuaRocks to install. " "As with Lua, a version number (in range 2.0.8 - 2.3.0), '^', git URI with reference or " @@ -1557,13 +1656,13 @@ def main(argv=None): global opts opts = parser.parse_args(argv) - if not opts.lua and not opts.luajit and not opts.luarocks and not opts.show: + if not opts.lua and not opts.luajit and not opts.ravi and not opts.luarocks and not opts.show: parser.error("nothing to do") - if opts.lua and opts.luajit: - parser.error("can't install both PUC-Rio Lua and LuaJIT") + if len([impl for impl in (opts.lua, opts.luajit, opts.ravi) if impl]) > 1: + parser.error("can't install several Lua implementations") - if (opts.lua or opts.luajit or opts.luarocks) and opts.show: + if (opts.lua or opts.luajit or opts.ravi or opts.luarocks) and opts.show: parser.error("can't both install and show") if opts.show: @@ -1573,7 +1672,7 @@ def main(argv=None): if all_identifiers: print("Programs installed in {}:".format(opts.location)) - for program in [RioLua, LuaJIT, LuaRocks]: + for program in [RioLua, LuaJIT, Ravi, LuaRocks]: if program.name in all_identifiers: show_identifiers(all_identifiers[program.name]) else: @@ -1628,6 +1727,8 @@ def main(argv=None): if opts.lua: if "LuaJIT" in identifiers: del identifiers["LuaJIT"] + if "Ravi" in identifiers: + del identifiers["Ravi"] identifiers_changed = RioLua(opts.lua).update_identifiers(identifiers) os.chdir(start_dir) @@ -1635,10 +1736,21 @@ def main(argv=None): if opts.luajit: if "lua" in identifiers: del identifiers["lua"] + if "Ravi" in identifiers: + del identifiers["Ravi"] identifiers_changed = LuaJIT(opts.luajit).update_identifiers(identifiers) os.chdir(start_dir) + if opts.ravi: + if "lua" in identifiers: + del identifiers["lua"] + if "LuaJIT" in identifiers: + del identifiers["LuaJIT"] + + identifiers_changed = Ravi(opts.ravi).update_identifiers(identifiers) + os.chdir(start_dir) + if opts.luarocks: if LuaRocks(opts.luarocks).update_identifiers(identifiers): identifiers_changed = True diff --git a/test.sh b/test.sh index 93a7f77..91930bf 100755 --- a/test.sh +++ b/test.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash + set -ev +set -o pipefail + export PATH="$PWD/test/here/bin:$PATH" HEREROCKS="python hererocks.py test/here --downloads=test/cache --no-git-cache --verbose" @@ -37,3 +40,7 @@ lua -e "assert(coroutine.wrap(string.gmatch('x', '.'))() == 'x')" rm -rf test/here $HEREROCKS -l 5.3 --compat=none --patch --builds=test/builds | tee test/tmp && grep "Building" test/tmp | grep "cached" $HEREROCKS --show + +rm -rf test/here +$HEREROCKS --ravi ^ | tee test/tmp && grep "Building" test/tmp +$HEREROCKS --show