From b86f0d72c891bc38a2cff021ae656e4fc8fce7a8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 13 Apr 2020 20:00:57 -0300 Subject: do not call Lua interpreter when making wrapper for luarocks binary Closes #1174. --- binary/all_in_one | 1 + src/luarocks/core/cfg.lua | 4 ++++ src/luarocks/fs/unix.lua | 11 +++++++++++ src/luarocks/fs/win32.lua | 11 +++++++++++ 4 files changed, 27 insertions(+) diff --git a/binary/all_in_one b/binary/all_in_one index 80712b13..3abbafa2 100755 --- a/binary/all_in_one +++ b/binary/all_in_one @@ -156,6 +156,7 @@ local function write_hardcoded_module(dir) SYSTEM = system, PROCESSOR = processor, FORCE_CONFIG = FORCE_CONFIG, + IS_BINARY = true, SYSCONFDIR = if_platform("unix", SYSCONFDIR), diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index b3561422..48aff4d8 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -542,6 +542,10 @@ function cfg.init(detected, warning) cfg.program_series = program_series cfg.major_version = major_version + if hardcoded.IS_BINARY then + cfg.is_binary = true + end + -- Use detected values as defaults, overridable via config files or CLI args cfg.lua_version = detected.lua_version or hardcoded.LUA_VERSION or _VERSION:sub(5) diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index d62a93ca..53903f0c 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -88,12 +88,18 @@ function unix.wrap_script(script, target, deps_mode, name, version, ...) "package.path="..util.LQ(lpath..";").."..package.path", "package.cpath="..util.LQ(lcpath..";").."..package.cpath", } + + local remove_interpreter = false if target == "luarocks" or target == "luarocks-admin" then + if cfg.is_binary then + remove_interpreter = true + end luainit = { "package.path="..util.LQ(package.path), "package.cpath="..util.LQ(package.cpath), } end + if name and version then local addctx = "local k,l,_=pcall(require,"..util.LQ("luarocks.loader")..") _=k " .. "and l.add_context("..util.LQ(name)..","..util.LQ(version)..")" @@ -107,6 +113,11 @@ function unix.wrap_script(script, target, deps_mode, name, version, ...) script and fs.Q(script) or [[$([ "$*" ] || echo -i)]], ... } + if remove_interpreter then + table.remove(argv, 1) + table.remove(argv, 1) + table.remove(argv, 1) + end wrapper:write("#!/bin/sh\n\n") wrapper:write("LUAROCKS_SYSCONFDIR="..fs.Q(cfg.sysconfdir) .. " ") diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index ec75e605..f544393d 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -163,12 +163,18 @@ function win32.wrap_script(script, target, deps_mode, name, version, ...) "package.path="..util.LQ(lpath..";").."..package.path", "package.cpath="..util.LQ(lcpath..";").."..package.cpath", } + + local remove_interpreter = false if target == "luarocks" or target == "luarocks-admin" then + if cfg.is_binary then + remove_interpreter = true + end luainit = { "package.path="..util.LQ(package.path), "package.cpath="..util.LQ(package.cpath), } end + if name and version then local addctx = "local k,l,_=pcall(require,'luarocks.loader') _=k " .. "and l.add_context('"..name.."','"..version.."')" @@ -182,6 +188,11 @@ function win32.wrap_script(script, target, deps_mode, name, version, ...) script and fs.Qb(script) or "%I%", ... } + if remove_interpreter then + table.remove(argv, 1) + table.remove(argv, 1) + table.remove(argv, 1) + end wrapper:write("@echo off\r\n") wrapper:write("setlocal\r\n") -- cgit v1.2.3-55-g6feb