diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2020-01-14 18:05:46 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2020-01-14 22:48:08 -0300 |
| commit | 74960d73342da4408aa59373cc3dcd898c7d1eb1 (patch) | |
| tree | 44dd6f93213e7626f2af88e5a7f71ff310f41bea /src | |
| parent | 6f5306ddaae3a14be5f385fa6f97546d6df9de4e (diff) | |
| download | luarocks-74960d73342da4408aa59373cc3dcd898c7d1eb1.tar.gz luarocks-74960d73342da4408aa59373cc3dcd898c7d1eb1.tar.bz2 luarocks-74960d73342da4408aa59373cc3dcd898c7d1eb1.zip | |
cmd: fallback to actual PATH search
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/cmd.lua | 49 | ||||
| -rw-r--r-- | src/luarocks/util.lua | 8 |
2 files changed, 38 insertions, 19 deletions
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index b43faaba..7866cd3c 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
| @@ -172,6 +172,30 @@ local function die(message, exitcode) | |||
| 172 | os.exit(exitcode or cmd.errorcodes.UNSPECIFIED) | 172 | os.exit(exitcode or cmd.errorcodes.UNSPECIFIED) |
| 173 | end | 173 | end |
| 174 | 174 | ||
| 175 | local function search_lua_in_path(lua_version, verbose) | ||
| 176 | local path_sep = (package.config:sub(1, 1) == "\\" and ";" or ":") | ||
| 177 | local all_tried = {} | ||
| 178 | for bindir in os.getenv("PATH"):gmatch("[^"..path_sep.."]+") do | ||
| 179 | local parentdir = bindir:gsub("[\\/][^\\/]+[\\/]?$", "") | ||
| 180 | local detected, tried = util.find_lua(dir.path(parentdir), lua_version) | ||
| 181 | if detected then | ||
| 182 | return detected | ||
| 183 | else | ||
| 184 | table.insert(all_tried, tried) | ||
| 185 | end | ||
| 186 | detected = util.find_lua(bindir, lua_version) | ||
| 187 | if detected then | ||
| 188 | return detected | ||
| 189 | else | ||
| 190 | table.insert(all_tried, tried) | ||
| 191 | end | ||
| 192 | end | ||
| 193 | return nil, "Could not find " .. | ||
| 194 | (lua_version and "Lua " .. lua_version or "Lua") .. | ||
| 195 | " in PATH." .. | ||
| 196 | (verbose and " Tried:\n" .. table.concat(all_tried, "\n") or "") | ||
| 197 | end | ||
| 198 | |||
| 175 | local init_config | 199 | local init_config |
| 176 | do | 200 | do |
| 177 | local detect_config_via_args | 201 | local detect_config_via_args |
| @@ -244,17 +268,9 @@ do | |||
| 244 | end | 268 | end |
| 245 | 269 | ||
| 246 | if lua_version then | 270 | if lua_version then |
| 247 | local path_sep = (package.config:sub(1, 1) == "\\" and ";" or ":") | 271 | local detected = search_lua_in_path(lua_version) |
| 248 | for bindir in os.getenv("PATH"):gmatch("[^"..path_sep.."]+") do | 272 | if detected then |
| 249 | local parentdir = bindir:gsub("[\\/][^\\/]+[\\/]?$", "") | 273 | return detected |
| 250 | local detected = util.find_lua(dir.path(parentdir), lua_version) | ||
| 251 | if detected then | ||
| 252 | return detected | ||
| 253 | end | ||
| 254 | detected = util.find_lua(bindir, lua_version) | ||
| 255 | if detected then | ||
| 256 | return detected | ||
| 257 | end | ||
| 258 | end | 274 | end |
| 259 | return { | 275 | return { |
| 260 | lua_version = lua_version, | 276 | lua_version = lua_version, |
| @@ -535,15 +551,18 @@ function cmd.run_command(description, commands, external_namespace, ...) | |||
| 535 | 551 | ||
| 536 | -- if the Lua interpreter wasn't explicitly found before cfg.init, | 552 | -- if the Lua interpreter wasn't explicitly found before cfg.init, |
| 537 | -- try again now. | 553 | -- try again now. |
| 554 | local tried | ||
| 538 | if not lua_found then | 555 | if not lua_found then |
| 539 | if cfg.variables.LUA_DIR then | 556 | if cfg.variables.LUA_DIR then |
| 540 | lua_found = util.find_lua(cfg.variables.LUA_DIR, cfg.lua_version) | 557 | lua_found, tried = util.find_lua(cfg.variables.LUA_DIR, cfg.lua_version, args.verbose) |
| 558 | else | ||
| 559 | lua_found, tried = search_lua_in_path(cfg.lua_version, args.verbose) | ||
| 541 | end | 560 | end |
| 542 | end | 561 | end |
| 543 | 562 | ||
| 544 | if not lua_found then | 563 | if not lua_found and args.command ~= "config" and args.command ~= "help" then |
| 545 | util.warning("Could not find a Lua " .. cfg.lua_version .. " interpreter in your PATH. " .. | 564 | util.warning(tried .. |
| 546 | "Modules may not install with the correct configurations. " .. | 565 | "\nModules may not install with the correct configurations. " .. |
| 547 | "You may want to specify the path prefix to your build " .. | 566 | "You may want to specify the path prefix to your build " .. |
| 548 | "of Lua " .. cfg.lua_version .. " using --lua-dir") | 567 | "of Lua " .. cfg.lua_version .. " using --lua-dir") |
| 549 | end | 568 | end |
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index ae198daf..8eccace9 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua | |||
| @@ -481,7 +481,7 @@ do | |||
| 481 | end | 481 | end |
| 482 | end | 482 | end |
| 483 | 483 | ||
| 484 | find_lua_bindir = function(prefix, luaver) | 484 | find_lua_bindir = function(prefix, luaver, verbose) |
| 485 | local names = {} | 485 | local names = {} |
| 486 | if luaver then | 486 | if luaver then |
| 487 | insert_lua_variants(names, luaver) | 487 | insert_lua_variants(names, luaver) |
| @@ -517,13 +517,13 @@ do | |||
| 517 | and ("Lua " .. luaver .. " interpreter") | 517 | and ("Lua " .. luaver .. " interpreter") |
| 518 | or "Lua interpreter" | 518 | or "Lua interpreter" |
| 519 | return nil, interp .. " not found at " .. prefix .. "\n" .. | 519 | return nil, interp .. " not found at " .. prefix .. "\n" .. |
| 520 | "Tried:\t" .. table.concat(tried, "\n\t") | 520 | (verbose and "Tried:\t" .. table.concat(tried, "\n\t") or "") |
| 521 | end | 521 | end |
| 522 | end | 522 | end |
| 523 | 523 | ||
| 524 | function util.find_lua(prefix, luaver) | 524 | function util.find_lua(prefix, luaver, verbose) |
| 525 | local lua_interpreter, bindir | 525 | local lua_interpreter, bindir |
| 526 | lua_interpreter, bindir, luaver = find_lua_bindir(prefix, luaver) | 526 | lua_interpreter, bindir, luaver = find_lua_bindir(prefix, luaver, verbose) |
| 527 | if not lua_interpreter then | 527 | if not lua_interpreter then |
| 528 | return nil, bindir | 528 | return nil, bindir |
| 529 | end | 529 | end |
