aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-08-02 13:31:19 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-08-02 13:50:01 -0300
commitdcaf10c26714cbc518cbf329d0fb7b71d4241494 (patch)
treee87c537ebc7f4efb3fa8b07a123a440964b57bf5
parentefefb940e9ecfae6ab722a5d2953e0a8f619d65c (diff)
downloadluarocks-dcaf10c26714cbc518cbf329d0fb7b71d4241494.tar.gz
luarocks-dcaf10c26714cbc518cbf329d0fb7b71d4241494.tar.bz2
luarocks-dcaf10c26714cbc518cbf329d0fb7b71d4241494.zip
init: store Lua location in config
This way a user can use `--lua-dir` once, in `luarocks init` and that configuration will be active for the project.
-rw-r--r--src/luarocks/cmd/init.lua29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua
index 6f38b31e..a9511316 100644
--- a/src/luarocks/cmd/init.lua
+++ b/src/luarocks/cmd/init.lua
@@ -4,6 +4,7 @@ local init = {}
4local cfg = require("luarocks.core.cfg") 4local cfg = require("luarocks.core.cfg")
5local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
6local path = require("luarocks.path") 6local path = require("luarocks.path")
7local deps = require("luarocks.deps")
7local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
8local util = require("luarocks.util") 9local util = require("luarocks.util")
9local write_rockspec = require("luarocks.cmd.write_rockspec") 10local write_rockspec = require("luarocks.cmd.write_rockspec")
@@ -69,6 +70,12 @@ function init.command(flags, name, version)
69 util.printerr(err) 70 util.printerr(err)
70 end 71 end
71 end 72 end
73
74 util.printout("Checking your Lua installation ...")
75 local ok, err = deps.check_lua(cfg.variables)
76 if not ok then
77 util.warning(err)
78 end
72 79
73 util.printout("Adding entries to .gitignore ...") 80 util.printout("Adding entries to .gitignore ...")
74 write_gitignore() 81 write_gitignore()
@@ -78,8 +85,24 @@ function init.command(flags, name, version)
78 local config_file = ".luarocks/config-" .. cfg.lua_version .. ".lua" 85 local config_file = ".luarocks/config-" .. cfg.lua_version .. ".lua"
79 if not fs.exists(config_file) then 86 if not fs.exists(config_file) then
80 local fd = io.open(config_file, "w") 87 local fd = io.open(config_file, "w")
81 fd:write("-- add your configuration here\n") 88 fd:write("-- LuaRocks configuration for use with Lua " .. cfg.lua_version .. "\n")
89 fd:write("variables = {\n")
90 local varnames = {
91 "LUA_DIR",
92 "LUA_INCDIR",
93 "LUA_LIBDIR",
94 "LUA_BINDIR",
95 "LUA_INTERPRETER",
96 }
97 for _, varname in ipairs(varnames) do
98 if cfg.variables[varname] then
99 fd:write((" %s = %q,\n"):format(varname, cfg.variables[varname]))
100 end
101 end
102 fd:write("}\n")
82 fd:close() 103 fd:close()
104 else
105 util.printout(config_file .. " already exists. Not overwriting it!")
83 end 106 end
84 107
85 util.printout("Preparing ./lua_modules/ ...") 108 util.printout("Preparing ./lua_modules/ ...")
@@ -93,6 +116,8 @@ function init.command(flags, name, version)
93 if not fs.exists(luarocks_wrapper) then 116 if not fs.exists(luarocks_wrapper) then
94 util.printout("Preparing " .. luarocks_wrapper .. " ...") 117 util.printout("Preparing " .. luarocks_wrapper .. " ...")
95 fs.wrap_script(arg[0], "luarocks", "none", nil, nil, "--project-tree", tree) 118 fs.wrap_script(arg[0], "luarocks", "none", nil, nil, "--project-tree", tree)
119 else
120 util.printout(luarocks_wrapper .. " already exists. Not overwriting it!")
96 end 121 end
97 122
98 local lua_wrapper = "./lua" .. ext 123 local lua_wrapper = "./lua" .. ext
@@ -100,6 +125,8 @@ function init.command(flags, name, version)
100 util.printout("Preparing " .. lua_wrapper .. " ...") 125 util.printout("Preparing " .. lua_wrapper .. " ...")
101 path.use_tree(tree) 126 path.use_tree(tree)
102 fs.wrap_script(nil, "lua", "all") 127 fs.wrap_script(nil, "lua", "all")
128 else
129 util.printout(lua_wrapper .. " already exists. Not overwriting it!")
103 end 130 end
104 131
105 return true 132 return true