diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-17 01:01:12 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-17 11:16:54 -0300 |
commit | 3612c269f3cd6397c883799b0bea549d5a7d1512 (patch) | |
tree | 779764e493585252944c013ffcaaa96099ffa302 /src | |
parent | 15f4f69f1536b8e7789191c4293d668a7fdccfcc (diff) | |
download | luarocks-3612c269f3cd6397c883799b0bea549d5a7d1512.tar.gz luarocks-3612c269f3cd6397c883799b0bea549d5a7d1512.tar.bz2 luarocks-3612c269f3cd6397c883799b0bea549d5a7d1512.zip |
fix: install build_dependencies on the correct Lua version
When installing build dependencies, do so for the Lua version on which the
LuaRocks program is actually running, and not the one selected by the user via
config or `--lua-version`.
To do that, we temporarily flip the user-selected Lua version. It's a hacky
approach because we have to do this by flipping a bunch of global config
settings, and we may be missing some entries.
This definitely needs a better solution, but this is what can be done somewhat
easily in the current architecture. A full solution needs to address have
several complications (e.g. if you have a build dependency that needs to be
compiled, it will require C headers for another version of LuaRocks, and the
binary might be compiled with a different Lua version than the one the
developer has set up in their machine.)
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/build.lua | 30 | ||||
-rw-r--r-- | src/luarocks/path.lua | 13 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index e545d390..d5c474ca 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -129,7 +129,37 @@ local function process_dependencies(rockspec, opts) | |||
129 | 129 | ||
130 | if not opts.build_only_deps then | 130 | if not opts.build_only_deps then |
131 | if next(rockspec.build_dependencies) then | 131 | if next(rockspec.build_dependencies) then |
132 | |||
133 | local user_lua_version = cfg.lua_version | ||
134 | local running_lua_version = _VERSION:sub(5) | ||
135 | |||
136 | if running_lua_version ~= user_lua_version then | ||
137 | -- Temporarily flip the user-selected Lua version, | ||
138 | -- so that we install build dependencies for the | ||
139 | -- Lua version on which the LuaRocks program is running. | ||
140 | |||
141 | -- HACK: we have to do this by flipping a bunch of | ||
142 | -- global config settings, and this list may not be complete. | ||
143 | cfg.lua_version = running_lua_version | ||
144 | cfg.lua_modules_path = cfg.lua_modules_path:gsub(user_lua_version:gsub("%.", "%%."), running_lua_version) | ||
145 | cfg.lib_modules_path = cfg.lib_modules_path:gsub(user_lua_version:gsub("%.", "%%."), running_lua_version) | ||
146 | cfg.rocks_subdir = cfg.rocks_subdir:gsub(user_lua_version:gsub("%.", "%%."), running_lua_version) | ||
147 | path.use_tree(cfg.root_dir) | ||
148 | end | ||
149 | |||
132 | local ok, err, errcode = deps.fulfill_dependencies(rockspec, "build_dependencies", "all", opts.verify) | 150 | local ok, err, errcode = deps.fulfill_dependencies(rockspec, "build_dependencies", "all", opts.verify) |
151 | |||
152 | path.add_to_package_paths(cfg.root_dir) | ||
153 | |||
154 | if running_lua_version ~= user_lua_version then | ||
155 | -- flip the settings back | ||
156 | cfg.lua_version = user_lua_version | ||
157 | cfg.lua_modules_path = cfg.lua_modules_path:gsub(running_lua_version:gsub("%.", "%%."), user_lua_version) | ||
158 | cfg.lib_modules_path = cfg.lib_modules_path:gsub(running_lua_version:gsub("%.", "%%."), user_lua_version) | ||
159 | cfg.rocks_subdir = cfg.rocks_subdir:gsub(running_lua_version:gsub("%.", "%%."), user_lua_version) | ||
160 | path.use_tree(cfg.root_dir) | ||
161 | end | ||
162 | |||
133 | if err then | 163 | if err then |
134 | return nil, err, errcode | 164 | return nil, err, errcode |
135 | end | 165 | end |
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index a9f04ef0..19657c83 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
@@ -219,13 +219,14 @@ function path.use_tree(tree) | |||
219 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | 219 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) |
220 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | 220 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) |
221 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | 221 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) |
222 | end | ||
222 | 223 | ||
223 | -- TODO Do we want LuaRocks itself to use whatever tree is in use? | 224 | function path.add_to_package_paths(tree) |
224 | -- package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";" | 225 | package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";" |
225 | -- .. dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";" | 226 | .. dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";" |
226 | -- .. package.path | 227 | .. package.path |
227 | -- package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";" | 228 | package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";" |
228 | -- .. package.cpath | 229 | .. package.cpath |
229 | end | 230 | end |
230 | 231 | ||
231 | --- Get the namespace of a locally-installed rock, if any. | 232 | --- Get the namespace of a locally-installed rock, if any. |