diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-03 14:01:00 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-09 16:49:20 -0300 |
commit | 7807b77bd37adc730d1496e4901031c722a34310 (patch) | |
tree | bc075fbeb0b272abfe88806c045eaf42728e016f /src | |
parent | 3707b0245c1952d4a7a2ba2314c552d2195fe128 (diff) | |
download | luarocks-7807b77bd37adc730d1496e4901031c722a34310.tar.gz luarocks-7807b77bd37adc730d1496e4901031c722a34310.tar.bz2 luarocks-7807b77bd37adc730d1496e4901031c722a34310.zip |
init: robustness improvements
Check that Lua settings are usable and regenarate ./lua wrapper when safe.
Should render --reset less necessary.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/cmd/init.lua | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/src/luarocks/cmd/init.lua b/src/luarocks/cmd/init.lua index 7da2122c..281615b9 100644 --- a/src/luarocks/cmd/init.lua +++ b/src/luarocks/cmd/init.lua | |||
@@ -16,8 +16,8 @@ init.help = [[ | |||
16 | <name> is the project name. | 16 | <name> is the project name. |
17 | <version> is an optional project version. | 17 | <version> is an optional project version. |
18 | 18 | ||
19 | --reset Regenerate .luarocks/config-5.x.lua and ./lua wrapper | 19 | --reset Delete .luarocks/config-5.x.lua and ./lua |
20 | if those already exist. | 20 | and generate new ones. |
21 | 21 | ||
22 | Options for specifying rockspec data: | 22 | Options for specifying rockspec data: |
23 | 23 | ||
@@ -64,7 +64,16 @@ function init.command(flags, name, version) | |||
64 | end | 64 | end |
65 | end | 65 | end |
66 | 66 | ||
67 | util.printout("Initializing project " .. name .. " for Lua " .. cfg.lua_version .. " ...") | 67 | util.title("Initializing project '" .. name .. "' for Lua " .. cfg.lua_version .. " ...") |
68 | |||
69 | util.printout("Checking your Lua installation ...") | ||
70 | if not cfg.lua_found then | ||
71 | return nil, "Lua installation is not found." | ||
72 | end | ||
73 | local ok, err = deps.check_lua(cfg.variables) | ||
74 | if not ok then | ||
75 | return nil, err | ||
76 | end | ||
68 | 77 | ||
69 | local has_rockspec = false | 78 | local has_rockspec = false |
70 | for file in fs.dir() do | 79 | for file in fs.dir() do |
@@ -81,27 +90,21 @@ function init.command(flags, name, version) | |||
81 | end | 90 | end |
82 | end | 91 | end |
83 | 92 | ||
84 | util.printout("Checking your Lua installation ...") | ||
85 | local ok, err = deps.check_lua(cfg.variables) | ||
86 | if not ok then | ||
87 | return nil, err | ||
88 | end | ||
89 | |||
90 | local ext = cfg.wrapper_suffix | 93 | local ext = cfg.wrapper_suffix |
91 | local luarocks_wrapper = "luarocks" .. ext | 94 | local luarocks_wrapper = "luarocks" .. ext |
92 | local lua_wrapper = "lua" .. ext | 95 | local lua_wrapper = "lua" .. ext |
93 | 96 | ||
94 | if flags["reset"] then | ||
95 | fs.delete(lua_wrapper) | ||
96 | fs.delete(dir.path(".luarocks", "default_lua_version.lua")) | ||
97 | end | ||
98 | |||
99 | util.printout("Adding entries to .gitignore ...") | 97 | util.printout("Adding entries to .gitignore ...") |
100 | write_gitignore({ luarocks_wrapper, lua_wrapper, "lua_modules" }) | 98 | write_gitignore({ luarocks_wrapper, lua_wrapper, "lua_modules" }) |
101 | 99 | ||
102 | util.printout("Preparing ./.luarocks/ ...") | 100 | util.printout("Preparing ./.luarocks/ ...") |
103 | fs.make_dir(".luarocks") | 101 | fs.make_dir(".luarocks") |
104 | local config_file = ".luarocks/config-" .. cfg.lua_version .. ".lua" | 102 | local config_file = ".luarocks/config-" .. cfg.lua_version .. ".lua" |
103 | |||
104 | if flags["reset"] then | ||
105 | fs.delete(lua_wrapper) | ||
106 | fs.delete(config_file) | ||
107 | end | ||
105 | 108 | ||
106 | local config_tbl, err = persist.load_config_file_if_basic(config_file, cfg) | 109 | local config_tbl, err = persist.load_config_file_if_basic(config_file, cfg) |
107 | if config_tbl then | 110 | if config_tbl then |
@@ -129,9 +132,19 @@ function init.command(flags, name, version) | |||
129 | end | 132 | end |
130 | end | 133 | end |
131 | local ok, err = persist.save_from_table(config_file, config_tbl) | 134 | local ok, err = persist.save_from_table(config_file, config_tbl) |
135 | if ok then | ||
136 | util.printout("Wrote " .. config_file) | ||
137 | else | ||
138 | util.printout("Failed writing " .. config_file .. ": " .. err) | ||
139 | end | ||
132 | else | 140 | else |
133 | util.printout("Will not attempt to overwrite " .. config_file) | 141 | util.printout("Will not attempt to overwrite " .. config_file) |
134 | end | 142 | end |
143 | |||
144 | ok, err = persist.save_default_lua_version(".luarocks", cfg.lua_version) | ||
145 | if not ok then | ||
146 | util.printout("Failed setting default Lua version: " .. err) | ||
147 | end | ||
135 | 148 | ||
136 | util.printout("Preparing ./lua_modules/ ...") | 149 | util.printout("Preparing ./lua_modules/ ...") |
137 | 150 | ||
@@ -147,12 +160,23 @@ function init.command(flags, name, version) | |||
147 | end | 160 | end |
148 | 161 | ||
149 | lua_wrapper = dir.path(".", lua_wrapper) | 162 | lua_wrapper = dir.path(".", lua_wrapper) |
150 | if not fs.exists(lua_wrapper) then | 163 | local write_lua_wrapper = true |
151 | util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...") | 164 | if fs.exists(lua_wrapper) then |
152 | path.use_tree(tree) | 165 | if not util.lua_is_wrapper(lua_wrapper) then |
153 | fs.wrap_script(nil, "lua", "all") | 166 | util.printout(lua_wrapper .. " already exists and does not look like a wrapper script. Not overwriting.") |
154 | else | 167 | write_lua_wrapper = false |
155 | util.printout(lua_wrapper .. " already exists. Not overwriting it!") | 168 | end |
169 | end | ||
170 | |||
171 | if write_lua_wrapper then | ||
172 | local interp = dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter) | ||
173 | if util.check_lua_version(interp, cfg.lua_version) then | ||
174 | util.printout("Preparing " .. lua_wrapper .. " for version " .. cfg.lua_version .. "...") | ||
175 | path.use_tree(tree) | ||
176 | fs.wrap_script(nil, "lua", "all") | ||
177 | else | ||
178 | util.warning("No Lua interpreter detected for version " .. cfg.lua_version .. ". Not creating " .. lua_wrapper) | ||
179 | end | ||
156 | end | 180 | end |
157 | 181 | ||
158 | return true | 182 | return true |