From 3a4459cb5c4e8b1a79524346ce75718e02aaf038 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 1 Jul 2018 14:48:02 -0300 Subject: wrapper scripts: honor deps_mode when wrapping scripts --- src/luarocks/cmd/init.lua | 4 ++-- src/luarocks/core/cfg.lua | 1 + src/luarocks/fs/unix.lua | 15 +++++++++------ src/luarocks/fs/win32.lua | 12 ++++++------ src/luarocks/path.lua | 12 ++++++++++++ src/luarocks/repos.lua | 8 ++++++-- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua index 9722dfdd..6f38b31e 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.lua @@ -92,14 +92,14 @@ function init.command(flags, name, version) local luarocks_wrapper = "./luarocks" .. ext if not fs.exists(luarocks_wrapper) then util.printout("Preparing " .. luarocks_wrapper .. " ...") - fs.wrap_script(arg[0], "luarocks", nil, nil, "--project-tree", tree) + fs.wrap_script(arg[0], "luarocks", "none", nil, nil, "--project-tree", tree) end local lua_wrapper = "./lua" .. ext if not fs.exists(lua_wrapper) then util.printout("Preparing " .. lua_wrapper .. " ...") path.use_tree(tree) - fs.wrap_script(nil, "lua") + fs.wrap_script(nil, "lua", "all") end return true diff --git a/src/luarocks/core/cfg.lua b/src/luarocks/core/cfg.lua index ee9af258..e160d69b 100644 --- a/src/luarocks/core/cfg.lua +++ b/src/luarocks/core/cfg.lua @@ -591,6 +591,7 @@ function cfg.init(lua_data, project_dir, warning) end sys_config_file = sdir .. "/" .. name home_config_file = hdir .. "/" .. name + cfg.sysconfdir = sdir sys_config_file = sys_config_file:gsub("\\", "/") home_config_file = home_config_file:gsub("\\", "/") diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 4ca68ce5..d6f3f0ae 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -6,6 +6,7 @@ local fs = require("luarocks.fs") local cfg = require("luarocks.core.cfg") local dir = require("luarocks.dir") +local path = require("luarocks.path") local util = require("luarocks.util") --- Annotate command string for quiet execution. @@ -64,27 +65,27 @@ end -- @param version string: rock version to be used in loader context. -- @return boolean or (nil, string): True if succeeded, or nil and -- an error message. -function unix.wrap_script(file, dest, name, version, ...) +function unix.wrap_script(file, dest, deps_mode, name, version, ...) assert(type(file) == "string" or not file) assert(type(dest) == "string") + assert(type(deps_mode) == "string") assert(type(name) == "string" or not name) assert(type(version) == "string" or not version) local wrapname = fs.is_dir(dest) and dest.."/"..dir.base_name(file) or dest + local wrapper = io.open(wrapname, "w") if not wrapper then return nil, "Could not open "..wrapname.." for writing." end - local lpath, lcpath = cfg.package_paths(cfg.root_dir) - lpath = util.cleanup_path(lpath, ";", cfg.lua_version) - lcpath = util.cleanup_path(lcpath, ";", cfg.lua_version) + local lpath, lcpath = path.package_paths(deps_mode) local luainit = { "package.path="..util.LQ(lpath..";").."..package.path", "package.cpath="..util.LQ(lcpath..";").."..package.cpath", } - if dest == "luarocks" then + if dest == "luarocks" or dest == "luarocks-admin" then luainit = { "package.path="..util.LQ(package.path), "package.cpath="..util.LQ(package.cpath), @@ -103,7 +104,9 @@ function unix.wrap_script(file, dest, name, version, ...) } wrapper:write("#!/bin/sh\n\n") - wrapper:write("LUA_INIT="..fs.Q(table.concat(luainit, ";")).." exec "..table.concat(argv, " ")..' "$@"\n') + wrapper:write("LUAROCKS_SYSCONFDIR="..fs.Q(cfg.sysconfdir) .. " ") + wrapper:write("LUA_INIT="..fs.Q(table.concat(luainit, ";")).." ") + wrapper:write("exec "..table.concat(argv, " ")..' "$@"\n') wrapper:close() if fs.set_permissions(wrapname, "exec", "user") then diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 46a11fa0..7b3755d6 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -7,6 +7,7 @@ local fs = require("luarocks.fs") local cfg = require("luarocks.core.cfg") local dir = require("luarocks.dir") +local path = require("luarocks.path") local util = require("luarocks.util") -- Monkey patch io.popen and os.execute to make sure quoting @@ -131,23 +132,21 @@ end -- @param version string: rock version to be used in loader context. -- @return boolean or (nil, string): True if succeeded, or nil and -- an error message. -function win32.wrap_script(file, dest, name, version, ...) +function win32.wrap_script(file, dest, deps_mode, name, version, ...) assert(type(file) == "string" or not file) assert(type(dest) == "string") + assert(type(deps_mode) == "string") assert(type(name) == "string" or not name) assert(type(version) == "string" or not version) local wrapname = fs.is_dir(dest) and dest.."/"..dir.base_name(file) or dest - wrapname = wrapname..".bat" + wrapname = wrapname .. ".bat" local wrapper = io.open(wrapname, "w") if not wrapper then return nil, "Could not open "..wrapname.." for writing." end - local lpath, lcpath = cfg.package_paths(cfg.root_dir) - lpath = util.cleanup_path(lpath, ";", cfg.lua_version) - lcpath = util.cleanup_path(lcpath, ";", cfg.lua_version) - + local lpath, lcpath = path.package_paths(deps_mode) local lpath_var, lcpath_var = util.lua_path_variables() local addctx @@ -163,6 +162,7 @@ function win32.wrap_script(file, dest, name, version, ...) } wrapper:write("@echo off\r\n") + wrapper:write("set "..fs.Qb("LUAROCKS_SYSCONFIG="..cfg.sysconfdir) .. "\r\n") if dest == "luarocks" then wrapper:write("set "..fs.Qb(lpath_var.."="..package.path) .. "\r\n") wrapper:write("set "..fs.Qb(lcpath_var.."="..package.cpath) .. "\r\n") diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 8fe6da8d..8e82beeb 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -275,4 +275,16 @@ function path.read_namespace(name, version, tree) return namespace end +function path.package_paths(deps_mode) + local lpaths = {} + local lcpaths = {} + path.map_trees(deps_mode, function(tree) + local root = path.root_dir(tree) + table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?.lua")) + table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?/init.lua")) + table.insert(lcpaths, dir.path(root, cfg.lib_modules_path, "?." .. cfg.lib_extension)) + end) + return table.concat(lpaths, ";"), table.concat(lcpaths, ";") +end + return path diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 454ec79f..dd2a5142 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -315,9 +315,13 @@ function repos.deploy_files(name, version, wrap_bin_scripts, deps_mode) local function install_binary(source, target) if wrap_bin_scripts and fs.is_lua(source) then - return target .. (cfg.wrapper_suffix or ""), function() return fs.wrap_script(source, target, name, version) end + return target .. (cfg.wrapper_suffix or ""), function() + return fs.wrap_script(source, target, deps_mode, name, version) + end else - return target, function() return fs.copy_binary(source, target) end + return target, function() + return fs.copy_binary(source, target) + end end end -- cgit v1.2.3-55-g6feb