diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 14:48:02 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 21:32:39 -0300 |
commit | 3a4459cb5c4e8b1a79524346ce75718e02aaf038 (patch) | |
tree | 0f597d7e195265e40f877e2ae5467657163fc50f /src | |
parent | 3b8d91a9bf9ddc8da1f104d3c3aa20241670e17b (diff) | |
download | luarocks-3a4459cb5c4e8b1a79524346ce75718e02aaf038.tar.gz luarocks-3a4459cb5c4e8b1a79524346ce75718e02aaf038.tar.bz2 luarocks-3a4459cb5c4e8b1a79524346ce75718e02aaf038.zip |
wrapper scripts: honor deps_mode when wrapping scripts
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd/init.lua | 4 | ||||
-rw-r--r-- | src/luarocks/core/cfg.lua | 1 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 15 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 12 | ||||
-rw-r--r-- | src/luarocks/path.lua | 12 | ||||
-rw-r--r-- | 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) | |||
92 | local luarocks_wrapper = "./luarocks" .. ext | 92 | local luarocks_wrapper = "./luarocks" .. ext |
93 | if not fs.exists(luarocks_wrapper) then | 93 | if not fs.exists(luarocks_wrapper) then |
94 | util.printout("Preparing " .. luarocks_wrapper .. " ...") | 94 | util.printout("Preparing " .. luarocks_wrapper .. " ...") |
95 | fs.wrap_script(arg[0], "luarocks", nil, nil, "--project-tree", tree) | 95 | fs.wrap_script(arg[0], "luarocks", "none", nil, nil, "--project-tree", tree) |
96 | end | 96 | end |
97 | 97 | ||
98 | local lua_wrapper = "./lua" .. ext | 98 | local lua_wrapper = "./lua" .. ext |
99 | if not fs.exists(lua_wrapper) then | 99 | if not fs.exists(lua_wrapper) then |
100 | util.printout("Preparing " .. lua_wrapper .. " ...") | 100 | util.printout("Preparing " .. lua_wrapper .. " ...") |
101 | path.use_tree(tree) | 101 | path.use_tree(tree) |
102 | fs.wrap_script(nil, "lua") | 102 | fs.wrap_script(nil, "lua", "all") |
103 | end | 103 | end |
104 | 104 | ||
105 | return true | 105 | 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) | |||
591 | end | 591 | end |
592 | sys_config_file = sdir .. "/" .. name | 592 | sys_config_file = sdir .. "/" .. name |
593 | home_config_file = hdir .. "/" .. name | 593 | home_config_file = hdir .. "/" .. name |
594 | cfg.sysconfdir = sdir | ||
594 | 595 | ||
595 | sys_config_file = sys_config_file:gsub("\\", "/") | 596 | sys_config_file = sys_config_file:gsub("\\", "/") |
596 | home_config_file = home_config_file:gsub("\\", "/") | 597 | 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") | |||
6 | 6 | ||
7 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
8 | local dir = require("luarocks.dir") | 8 | local dir = require("luarocks.dir") |
9 | local path = require("luarocks.path") | ||
9 | local util = require("luarocks.util") | 10 | local util = require("luarocks.util") |
10 | 11 | ||
11 | --- Annotate command string for quiet execution. | 12 | --- Annotate command string for quiet execution. |
@@ -64,27 +65,27 @@ end | |||
64 | -- @param version string: rock version to be used in loader context. | 65 | -- @param version string: rock version to be used in loader context. |
65 | -- @return boolean or (nil, string): True if succeeded, or nil and | 66 | -- @return boolean or (nil, string): True if succeeded, or nil and |
66 | -- an error message. | 67 | -- an error message. |
67 | function unix.wrap_script(file, dest, name, version, ...) | 68 | function unix.wrap_script(file, dest, deps_mode, name, version, ...) |
68 | assert(type(file) == "string" or not file) | 69 | assert(type(file) == "string" or not file) |
69 | assert(type(dest) == "string") | 70 | assert(type(dest) == "string") |
71 | assert(type(deps_mode) == "string") | ||
70 | assert(type(name) == "string" or not name) | 72 | assert(type(name) == "string" or not name) |
71 | assert(type(version) == "string" or not version) | 73 | assert(type(version) == "string" or not version) |
72 | 74 | ||
73 | local wrapname = fs.is_dir(dest) and dest.."/"..dir.base_name(file) or dest | 75 | local wrapname = fs.is_dir(dest) and dest.."/"..dir.base_name(file) or dest |
76 | |||
74 | local wrapper = io.open(wrapname, "w") | 77 | local wrapper = io.open(wrapname, "w") |
75 | if not wrapper then | 78 | if not wrapper then |
76 | return nil, "Could not open "..wrapname.." for writing." | 79 | return nil, "Could not open "..wrapname.." for writing." |
77 | end | 80 | end |
78 | 81 | ||
79 | local lpath, lcpath = cfg.package_paths(cfg.root_dir) | 82 | local lpath, lcpath = path.package_paths(deps_mode) |
80 | lpath = util.cleanup_path(lpath, ";", cfg.lua_version) | ||
81 | lcpath = util.cleanup_path(lcpath, ";", cfg.lua_version) | ||
82 | 83 | ||
83 | local luainit = { | 84 | local luainit = { |
84 | "package.path="..util.LQ(lpath..";").."..package.path", | 85 | "package.path="..util.LQ(lpath..";").."..package.path", |
85 | "package.cpath="..util.LQ(lcpath..";").."..package.cpath", | 86 | "package.cpath="..util.LQ(lcpath..";").."..package.cpath", |
86 | } | 87 | } |
87 | if dest == "luarocks" then | 88 | if dest == "luarocks" or dest == "luarocks-admin" then |
88 | luainit = { | 89 | luainit = { |
89 | "package.path="..util.LQ(package.path), | 90 | "package.path="..util.LQ(package.path), |
90 | "package.cpath="..util.LQ(package.cpath), | 91 | "package.cpath="..util.LQ(package.cpath), |
@@ -103,7 +104,9 @@ function unix.wrap_script(file, dest, name, version, ...) | |||
103 | } | 104 | } |
104 | 105 | ||
105 | wrapper:write("#!/bin/sh\n\n") | 106 | wrapper:write("#!/bin/sh\n\n") |
106 | wrapper:write("LUA_INIT="..fs.Q(table.concat(luainit, ";")).." exec "..table.concat(argv, " ")..' "$@"\n') | 107 | wrapper:write("LUAROCKS_SYSCONFDIR="..fs.Q(cfg.sysconfdir) .. " ") |
108 | wrapper:write("LUA_INIT="..fs.Q(table.concat(luainit, ";")).." ") | ||
109 | wrapper:write("exec "..table.concat(argv, " ")..' "$@"\n') | ||
107 | wrapper:close() | 110 | wrapper:close() |
108 | 111 | ||
109 | if fs.set_permissions(wrapname, "exec", "user") then | 112 | 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") | |||
7 | 7 | ||
8 | local cfg = require("luarocks.core.cfg") | 8 | local cfg = require("luarocks.core.cfg") |
9 | local dir = require("luarocks.dir") | 9 | local dir = require("luarocks.dir") |
10 | local path = require("luarocks.path") | ||
10 | local util = require("luarocks.util") | 11 | local util = require("luarocks.util") |
11 | 12 | ||
12 | -- Monkey patch io.popen and os.execute to make sure quoting | 13 | -- Monkey patch io.popen and os.execute to make sure quoting |
@@ -131,23 +132,21 @@ end | |||
131 | -- @param version string: rock version to be used in loader context. | 132 | -- @param version string: rock version to be used in loader context. |
132 | -- @return boolean or (nil, string): True if succeeded, or nil and | 133 | -- @return boolean or (nil, string): True if succeeded, or nil and |
133 | -- an error message. | 134 | -- an error message. |
134 | function win32.wrap_script(file, dest, name, version, ...) | 135 | function win32.wrap_script(file, dest, deps_mode, name, version, ...) |
135 | assert(type(file) == "string" or not file) | 136 | assert(type(file) == "string" or not file) |
136 | assert(type(dest) == "string") | 137 | assert(type(dest) == "string") |
138 | assert(type(deps_mode) == "string") | ||
137 | assert(type(name) == "string" or not name) | 139 | assert(type(name) == "string" or not name) |
138 | assert(type(version) == "string" or not version) | 140 | assert(type(version) == "string" or not version) |
139 | 141 | ||
140 | local wrapname = fs.is_dir(dest) and dest.."/"..dir.base_name(file) or dest | 142 | local wrapname = fs.is_dir(dest) and dest.."/"..dir.base_name(file) or dest |
141 | wrapname = wrapname..".bat" | 143 | wrapname = wrapname .. ".bat" |
142 | local wrapper = io.open(wrapname, "w") | 144 | local wrapper = io.open(wrapname, "w") |
143 | if not wrapper then | 145 | if not wrapper then |
144 | return nil, "Could not open "..wrapname.." for writing." | 146 | return nil, "Could not open "..wrapname.." for writing." |
145 | end | 147 | end |
146 | 148 | ||
147 | local lpath, lcpath = cfg.package_paths(cfg.root_dir) | 149 | local lpath, lcpath = path.package_paths(deps_mode) |
148 | lpath = util.cleanup_path(lpath, ";", cfg.lua_version) | ||
149 | lcpath = util.cleanup_path(lcpath, ";", cfg.lua_version) | ||
150 | |||
151 | local lpath_var, lcpath_var = util.lua_path_variables() | 150 | local lpath_var, lcpath_var = util.lua_path_variables() |
152 | 151 | ||
153 | local addctx | 152 | local addctx |
@@ -163,6 +162,7 @@ function win32.wrap_script(file, dest, name, version, ...) | |||
163 | } | 162 | } |
164 | 163 | ||
165 | wrapper:write("@echo off\r\n") | 164 | wrapper:write("@echo off\r\n") |
165 | wrapper:write("set "..fs.Qb("LUAROCKS_SYSCONFIG="..cfg.sysconfdir) .. "\r\n") | ||
166 | if dest == "luarocks" then | 166 | if dest == "luarocks" then |
167 | wrapper:write("set "..fs.Qb(lpath_var.."="..package.path) .. "\r\n") | 167 | wrapper:write("set "..fs.Qb(lpath_var.."="..package.path) .. "\r\n") |
168 | wrapper:write("set "..fs.Qb(lcpath_var.."="..package.cpath) .. "\r\n") | 168 | 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) | |||
275 | return namespace | 275 | return namespace |
276 | end | 276 | end |
277 | 277 | ||
278 | function path.package_paths(deps_mode) | ||
279 | local lpaths = {} | ||
280 | local lcpaths = {} | ||
281 | path.map_trees(deps_mode, function(tree) | ||
282 | local root = path.root_dir(tree) | ||
283 | table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?.lua")) | ||
284 | table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?/init.lua")) | ||
285 | table.insert(lcpaths, dir.path(root, cfg.lib_modules_path, "?." .. cfg.lib_extension)) | ||
286 | end) | ||
287 | return table.concat(lpaths, ";"), table.concat(lcpaths, ";") | ||
288 | end | ||
289 | |||
278 | return path | 290 | 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) | |||
315 | 315 | ||
316 | local function install_binary(source, target) | 316 | local function install_binary(source, target) |
317 | if wrap_bin_scripts and fs.is_lua(source) then | 317 | if wrap_bin_scripts and fs.is_lua(source) then |
318 | return target .. (cfg.wrapper_suffix or ""), function() return fs.wrap_script(source, target, name, version) end | 318 | return target .. (cfg.wrapper_suffix or ""), function() |
319 | return fs.wrap_script(source, target, deps_mode, name, version) | ||
320 | end | ||
319 | else | 321 | else |
320 | return target, function() return fs.copy_binary(source, target) end | 322 | return target, function() |
323 | return fs.copy_binary(source, target) | ||
324 | end | ||
321 | end | 325 | end |
322 | end | 326 | end |
323 | 327 | ||