Skip to content

Commit

Permalink
add Ravi support
Browse files Browse the repository at this point in the history
  • Loading branch information
starius committed Apr 17, 2016
1 parent 1745496 commit dca85db
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
language: python

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8

matrix:
include:
- os: linux
Expand All @@ -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

Expand Down
128 changes: 120 additions & 8 deletions hererocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import re
import shutil
import string
import stat
import subprocess
import sys
import tarfile
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -1628,17 +1727,30 @@ 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)

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
Expand Down
7 changes: 7 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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

0 comments on commit dca85db

Please sign in to comment.