Skip to content

Commit

Permalink
Add LuaPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
alalazo committed May 11, 2022
1 parent 0b35a6c commit e7f1c84
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
58 changes: 37 additions & 21 deletions lib/spack/spack/build_systems/lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,50 @@

from llnl.util.filesystem import find

from spack.directives import depends_on, extends
import spack.builder
from spack.directives import buildsystem, depends_on, extends
from spack.multimethod import when
from spack.package import PackageBase
from spack.util.executable import Executable

# Decorator used to record callbacks and phases related to Luarocks
lua = spack.builder.BuilderMeta.make_decorator('lua')


class LuaPackage(PackageBase):
"""Specialized class for lua packages"""

phases = ['unpack', 'generate_luarocks_config', 'preprocess', 'install']
#: This attribute is used in UI queries that need to know the build
#: system base class
build_system_class = 'LuaPackage'

list_depth = 1 # LuaRocks requires at least one level of spidering to find versions
depends_on('lua-lang')
extends('lua', when='^lua')
with when('^lua-luajit'):
extends('lua-luajit')
depends_on('luajit')
depends_on('lua-luajit+lualinks')
with when('^lua-luajit-openresty'):
extends('lua-luajit-openresty')
depends_on('luajit')
depends_on('lua-luajit-openresty+lualinks')

buildsystem('lua')

with when('buildsystem=lua'):
depends_on('lua-lang')
extends('lua', when='^lua')
with when('^lua-luajit'):
extends('lua-luajit')
depends_on('luajit')
depends_on('lua-luajit+lualinks')
with when('^lua-luajit-openresty'):
extends('lua-luajit-openresty')
depends_on('luajit')
depends_on('lua-luajit-openresty+lualinks')

@property
def lua(self):
return Executable(self.spec['lua-lang'].prefix.bin.lua)

@property
def luarocks(self):
lr = Executable(self.spec['lua-lang'].prefix.bin.luarocks)
return lr


class LuaWrapper(spack.builder.BuildWrapper):
def unpack(self, spec, prefix):
if os.path.splitext(self.stage.archive_file)[1] == '.rock':
directory = self.luarocks('unpack', self.stage.archive_file, output=str)
Expand Down Expand Up @@ -80,15 +98,6 @@ def preprocess(self, spec, prefix):
"""Override this to preprocess source before building with luarocks"""
pass

@property
def lua(self):
return Executable(self.spec['lua-lang'].prefix.bin.lua)

@property
def luarocks(self):
lr = Executable(self.spec['lua-lang'].prefix.bin.luarocks)
return lr

def luarocks_args(self):
return []

Expand All @@ -100,3 +109,10 @@ def install(self, spec, prefix):
rocks_args = self.luarocks_args()
rocks_args.append(rock)
self.luarocks('--tree=' + prefix, 'make', *rocks_args)


@spack.builder.builder('lua')
class LuaBuilder(spack.builder.Builder):
phases = ('unpack', 'generate_luarocks_config', 'preprocess', 'install')

PackageWrapper = LuaWrapper
9 changes: 3 additions & 6 deletions var/spack/repos/builtin/packages/lua/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class LuaImplPackage(MakefilePackage):
description="Fetcher to use in the LuaRocks package manager",
)

phases = MakefilePackage.phases + ["add_luarocks"]
#: This attribute is used in UI queries that need to know the build
#: system base class
build_system_class = "LuaImplPackage"

lua_version_override = None

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -107,7 +102,9 @@ def symlink_luajit(self):
)
symlink(real_lib, "liblua" + ext)

def add_luarocks(self, spec, prefix):
@run_after('install')
def add_luarocks(self):
prefix = self.spec.prefix
with working_dir(os.path.join("luarocks", "luarocks")):
configure("--prefix=" + prefix, "--with-lua=" + prefix)
make("build")
Expand Down

0 comments on commit e7f1c84

Please sign in to comment.