Support new directory structure of PUC-Rio Lua git repo
When installing PUC-Rio Lua from git or local sources, look for source files in root project directory instead of `src`. Default PUC-Rio Lua repo does not contain sources for luac. It lacks lua.hpp, too.
This commit is contained in:
parent
7f6f5b02b5
commit
0e3fc45758
78
hererocks.py
78
hererocks.py
@ -5,6 +5,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import contextlib
|
||||||
import hashlib
|
import hashlib
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
@ -595,6 +596,8 @@ class Lua(Program):
|
|||||||
def __init__(self, version):
|
def __init__(self, version):
|
||||||
super(Lua, self).__init__(version)
|
super(Lua, self).__init__(version)
|
||||||
|
|
||||||
|
self.source_files_prefix = self.get_source_files_prefix()
|
||||||
|
|
||||||
if self.source == "release":
|
if self.source == "release":
|
||||||
self.major_version = self.major_version_from_version()
|
self.major_version = self.major_version_from_version()
|
||||||
else:
|
else:
|
||||||
@ -613,8 +616,28 @@ class Lua(Program):
|
|||||||
self.add_compat_cflags_and_redefines()
|
self.add_compat_cflags_and_redefines()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def major_version_from_source():
|
def get_source_files_prefix():
|
||||||
with open(os.path.join("src", "lua.h")) as lua_h:
|
return "src"
|
||||||
|
|
||||||
|
def get_source_file_path(self, file_name):
|
||||||
|
if self.source_files_prefix is None:
|
||||||
|
return file_name
|
||||||
|
else:
|
||||||
|
return os.path.join(self.source_files_prefix, file_name)
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def in_source_files_prefix(self):
|
||||||
|
if self.source_files_prefix is not None:
|
||||||
|
start_dir = os.getcwd()
|
||||||
|
os.chdir(self.source_files_prefix)
|
||||||
|
|
||||||
|
yield
|
||||||
|
|
||||||
|
if self.source_files_prefix is not None:
|
||||||
|
os.chdir(start_dir)
|
||||||
|
|
||||||
|
def major_version_from_source(self):
|
||||||
|
with open(self.get_source_file_path("lua.h")) as lua_h:
|
||||||
for line in lua_h:
|
for line in lua_h:
|
||||||
match = re.match(r"^\s*#define\s+LUA_VERSION_NUM\s+50(\d)\s*$", line)
|
match = re.match(r"^\s*#define\s+LUA_VERSION_NUM\s+50(\d)\s*$", line)
|
||||||
|
|
||||||
@ -697,14 +720,15 @@ class Lua(Program):
|
|||||||
])
|
])
|
||||||
|
|
||||||
def patch_redefines(self):
|
def patch_redefines(self):
|
||||||
|
luaconf_path = self.get_source_file_path("luaconf.h")
|
||||||
redefines = "\n".join(self.redefines)
|
redefines = "\n".join(self.redefines)
|
||||||
|
|
||||||
with open(os.path.join("src", "luaconf.h"), "rb") as luaconf_h:
|
with open(luaconf_path, "rb") as luaconf_h:
|
||||||
luaconf_src = luaconf_h.read()
|
luaconf_src = luaconf_h.read()
|
||||||
|
|
||||||
body, _, tail = luaconf_src.rpartition(b"#endif")
|
body, _, tail = luaconf_src.rpartition(b"#endif")
|
||||||
|
|
||||||
with open(os.path.join("src", "luaconf.h"), "wb") as luaconf_h:
|
with open(luaconf_path, "wb") as luaconf_h:
|
||||||
luaconf_h.write(body)
|
luaconf_h.write(body)
|
||||||
luaconf_h.write(redefines.encode("UTF-8"))
|
luaconf_h.write(redefines.encode("UTF-8"))
|
||||||
luaconf_h.write(b"\n#endif")
|
luaconf_h.write(b"\n#endif")
|
||||||
@ -1099,6 +1123,13 @@ class RioLua(Lua):
|
|||||||
else:
|
else:
|
||||||
self.dll_file = None
|
self.dll_file = None
|
||||||
|
|
||||||
|
def get_source_files_prefix(self):
|
||||||
|
# When installing PUC-Rio Lua from a git repo or local sources,
|
||||||
|
# use directory structure of its GitHub mirror, where
|
||||||
|
# source files are direcly in project root instead of `src`.
|
||||||
|
if self.source == "release":
|
||||||
|
return "src"
|
||||||
|
|
||||||
def set_identifiers(self):
|
def set_identifiers(self):
|
||||||
super(RioLua, self).set_identifiers()
|
super(RioLua, self).set_identifiers()
|
||||||
|
|
||||||
@ -1254,7 +1285,7 @@ class RioLua(Lua):
|
|||||||
elif using_cl():
|
elif using_cl():
|
||||||
cflags.insert(0, "-DLUA_BUILD_AS_DLL")
|
cflags.insert(0, "-DLUA_BUILD_AS_DLL")
|
||||||
|
|
||||||
os.chdir("src")
|
with self.in_source_files_prefix():
|
||||||
self.handle_patches()
|
self.handle_patches()
|
||||||
objs = []
|
objs = []
|
||||||
luac_objs = ["luac" + objext(), "print" + objext()]
|
luac_objs = ["luac" + objext(), "print" + objext()]
|
||||||
@ -1270,20 +1301,23 @@ class RioLua(Lua):
|
|||||||
run(cc, static_cflags if obj in luac_objs else cflags, cmd_suffix)
|
run(cc, static_cflags if obj in luac_objs else cflags, cmd_suffix)
|
||||||
|
|
||||||
lib_objs = [obj_ for obj_ in objs if obj_ not in luac_objs and (obj_ != "lua" + objext())]
|
lib_objs = [obj_ for obj_ in objs if obj_ not in luac_objs and (obj_ != "lua" + objext())]
|
||||||
luac_objs = ["luac" + objext()]
|
|
||||||
|
|
||||||
if "print" + objext() in objs:
|
if not using_cl():
|
||||||
luac_objs.append("print" + objext())
|
run("ar", "rcu", self.arch_file, lib_objs)
|
||||||
|
run("ranlib", self.arch_file)
|
||||||
|
|
||||||
|
built_luac_objs = [obj for obj in luac_objs if obj in objs]
|
||||||
|
|
||||||
|
# Handle the case when there are no source files for `luac`, likely because installing
|
||||||
|
# from a git repo that does not have them, like the default one.
|
||||||
|
if len(built_luac_objs) > 0:
|
||||||
if using_cl():
|
if using_cl():
|
||||||
run("link", "/nologo", "/out:luac.exe", luac_objs, lib_objs)
|
run("link", "/nologo", "/out:luac.exe", built_luac_objs, lib_objs)
|
||||||
|
|
||||||
if os.path.exists("luac.exe.manifest"):
|
if os.path.exists("luac.exe.manifest"):
|
||||||
run("mt", "/nologo", "-manifest", "luac.exe.manifest", "-outputresource:luac.exe")
|
run("mt", "/nologo", "-manifest", "luac.exe.manifest", "-outputresource:luac.exe")
|
||||||
else:
|
else:
|
||||||
run("ar", "rcu", self.arch_file, lib_objs)
|
run(cc, "-o", self.luac_file, built_luac_objs, self.arch_file, lflags)
|
||||||
run("ranlib", self.arch_file)
|
|
||||||
run(cc, "-o", self.luac_file, luac_objs, self.arch_file, lflags)
|
|
||||||
|
|
||||||
if opts.target == "mingw":
|
if opts.target == "mingw":
|
||||||
run(cc, "-shared", "-o", self.dll_file, lib_objs)
|
run(cc, "-shared", "-o", self.dll_file, lib_objs)
|
||||||
@ -1303,16 +1337,22 @@ class RioLua(Lua):
|
|||||||
else:
|
else:
|
||||||
run(cc, "-o", self.lua_file, "lua.o", self.arch_file, lflags)
|
run(cc, "-o", self.lua_file, "lua.o", self.arch_file, lflags)
|
||||||
|
|
||||||
os.chdir("..")
|
|
||||||
|
|
||||||
def make_install(self):
|
def make_install(self):
|
||||||
os.chdir("src")
|
with self.in_source_files_prefix():
|
||||||
|
luac = self.luac_file
|
||||||
|
|
||||||
|
if not os.path.exists(luac):
|
||||||
|
luac = None
|
||||||
|
|
||||||
copy_files(os.path.join(opts.location, "bin"),
|
copy_files(os.path.join(opts.location, "bin"),
|
||||||
self.lua_file, self.luac_file, self.dll_file)
|
self.lua_file, luac, self.dll_file)
|
||||||
|
|
||||||
lua_hpp = "lua.hpp"
|
lua_hpp = "lua.hpp"
|
||||||
|
|
||||||
if not os.path.exists(lua_hpp):
|
if not os.path.exists(lua_hpp):
|
||||||
|
if self.source_files_prefix is None:
|
||||||
|
lua_hpp = None
|
||||||
|
else:
|
||||||
lua_hpp = "../etc/lua.hpp"
|
lua_hpp = "../etc/lua.hpp"
|
||||||
|
|
||||||
copy_files(os.path.join(opts.location, "include"),
|
copy_files(os.path.join(opts.location, "include"),
|
||||||
@ -1394,13 +1434,11 @@ class LuaJIT(Lua):
|
|||||||
cflags.extend(opts.cflags.split())
|
cflags.extend(opts.cflags.split())
|
||||||
|
|
||||||
if using_cl():
|
if using_cl():
|
||||||
os.chdir("src")
|
with self.in_source_files_prefix():
|
||||||
|
|
||||||
if cflags:
|
if cflags:
|
||||||
self.add_cflags_to_msvcbuild(" ".join(cflags))
|
self.add_cflags_to_msvcbuild(" ".join(cflags))
|
||||||
|
|
||||||
run("msvcbuild.bat")
|
run("msvcbuild.bat")
|
||||||
os.chdir("..")
|
|
||||||
else:
|
else:
|
||||||
if opts.target == "mingw" and program_exists("mingw32-make"):
|
if opts.target == "mingw" and program_exists("mingw32-make"):
|
||||||
make = "mingw32-make"
|
make = "mingw32-make"
|
||||||
@ -1426,7 +1464,7 @@ class LuaJIT(Lua):
|
|||||||
target_arch_file = "lua51.lib"
|
target_arch_file = "lua51.lib"
|
||||||
dll_file = "lua51.dll"
|
dll_file = "lua51.dll"
|
||||||
|
|
||||||
os.chdir("src")
|
with self.in_source_files_prefix():
|
||||||
copy_files(os.path.join(opts.location, "bin"), dll_file)
|
copy_files(os.path.join(opts.location, "bin"), dll_file)
|
||||||
shutil.copy(luajit_file, os.path.join(opts.location, "bin", lua_file))
|
shutil.copy(luajit_file, os.path.join(opts.location, "bin", lua_file))
|
||||||
|
|
||||||
|
|||||||
@ -66,6 +66,11 @@ class TestCLI(unittest.TestCase):
|
|||||||
def test_install_latest_lua_with_luarocks_from_git(self):
|
def test_install_latest_lua_with_luarocks_from_git(self):
|
||||||
self.assertHererocksSuccess(["--lua", "latest", "--luarocks", "https://github.com/mpeterv/luarocks@master"])
|
self.assertHererocksSuccess(["--lua", "latest", "--luarocks", "https://github.com/mpeterv/luarocks@master"])
|
||||||
|
|
||||||
|
def test_install_lua_from_git_with_latest_luarocks(self):
|
||||||
|
self.assertHererocksSuccess(["--lua", "@", "--luarocks", "latest"])
|
||||||
|
self.assertHererocksSuccess(["--show"], ["Programs installed in", "cloned from https://github.com/lua/lua"])
|
||||||
|
self.assertSuccess(["luarocks", "--version"])
|
||||||
|
|
||||||
def test_verbose_install_bleeding_edge_luajit_with_latest_luarocks(self):
|
def test_verbose_install_bleeding_edge_luajit_with_latest_luarocks(self):
|
||||||
self.assertHererocksSuccess(["--luajit", "@v2.1", "--luarocks", "latest", "--verbose"])
|
self.assertHererocksSuccess(["--luajit", "@v2.1", "--luarocks", "latest", "--verbose"])
|
||||||
self.assertSuccess(["lua", "-v"], ["LuaJIT 2.1.0"])
|
self.assertSuccess(["lua", "-v"], ["LuaJIT 2.1.0"])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user