aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2020-01-15 18:31:00 -0300
committerHisham Muhammad <hisham@gobolinux.org>2020-01-25 22:04:11 -0300
commit83126ba324846b754ffc5e0345341f01262b3f86 (patch)
tree95657cdd7c0d371dc1c9ed38d6dc6b46668be2c5
parent9499bb875a77cf877c5f316135003dd0d124f2c5 (diff)
downloadluarocks-83126ba324846b754ffc5e0345341f01262b3f86.tar.gz
luarocks-83126ba324846b754ffc5e0345341f01262b3f86.tar.bz2
luarocks-83126ba324846b754ffc5e0345341f01262b3f86.zip
speed up external dependency check
-rw-r--r--src/luarocks/deps.lua59
1 files changed, 39 insertions, 20 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 08f2debb..f80fddb0 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -415,6 +415,21 @@ local function resolve_prefix(prefix, dirs)
415 end 415 end
416end 416end
417 417
418local function add_patterns_for_file(files, file, patterns)
419 -- If it doesn't look like it contains a filename extension
420 if not (file:match("%.[a-z]+$") or file:match("%.[a-z]+%.")) then
421 add_all_patterns(file, patterns, files)
422 else
423 for _, pattern in ipairs(patterns) do
424 local matched = deconstruct_pattern(file, pattern)
425 if matched then
426 add_all_patterns(matched, patterns, files)
427 end
428 end
429 table.insert(files, file)
430 end
431end
432
418local function check_external_dependency_at(prefix, name, ext_files, vars, dirs, err_files, cache) 433local function check_external_dependency_at(prefix, name, ext_files, vars, dirs, err_files, cache)
419 local fs = require("luarocks.fs") 434 local fs = require("luarocks.fs")
420 cache = cache or {} 435 cache = cache or {}
@@ -433,22 +448,27 @@ local function check_external_dependency_at(prefix, name, ext_files, vars, dirs,
433 paths = { dir.path(prefix, dirdata.subdir) } 448 paths = { dir.path(prefix, dirdata.subdir) }
434 end 449 end
435 dirdata.dir = paths[1] 450 dirdata.dir = paths[1]
436 local file = ext_files[dirdata.testfile] 451 local file_or_files = ext_files[dirdata.testfile]
437 if file then 452 if file_or_files then
438 local files = {} 453 local files = {}
439 -- If it doesn't look like it contains a filename extension 454 if type(file_or_files) == "string" then
440 if not (file:match("%.[a-z]+$") or file:match("%.[a-z]+%.")) then 455 add_patterns_for_file(files, file_or_files, dirdata.pattern)
441 add_all_patterns(file, dirdata.pattern, files) 456 elseif type(file_or_files) == "table" then
442 else 457 for _, f in ipairs(file_or_files) do
443 for _, pattern in ipairs(dirdata.pattern) do 458 add_patterns_for_file(files, f, dirdata.pattern)
444 local matched = deconstruct_pattern(file, pattern)
445 if matched then
446 add_all_patterns(matched, dirdata.pattern, files)
447 end
448 end 459 end
449 table.insert(files, file)
450 end 460 end
461
451 local found = false 462 local found = false
463 table.sort(files, function(a, b)
464 if (not a:match("%*")) and b:match("%*") then
465 return true
466 elseif a:match("%*") and (not b:match("%*")) then
467 return false
468 else
469 return a < b
470 end
471 end)
452 for _, f in ipairs(files) do 472 for _, f in ipairs(files) do
453 473
454 -- small convenience hack 474 -- small convenience hack
@@ -458,7 +478,7 @@ local function check_external_dependency_at(prefix, name, ext_files, vars, dirs,
458 478
459 local pattern 479 local pattern
460 if f:match("%*") then 480 if f:match("%*") then
461 pattern = f:gsub("([-.+])", "%%%1"):gsub("%*", ".*") 481 pattern = "^" .. f:gsub("([-.+])", "%%%1"):gsub("%*", ".*") .. "$"
462 f = "matching "..f 482 f = "matching "..f
463 end 483 end
464 484
@@ -467,8 +487,9 @@ local function check_external_dependency_at(prefix, name, ext_files, vars, dirs,
467 if not cache[d] then 487 if not cache[d] then
468 cache[d] = fs.list_dir(d) 488 cache[d] = fs.list_dir(d)
469 end 489 end
490 local match = string.match
470 for _, entry in ipairs(cache[d]) do 491 for _, entry in ipairs(cache[d]) do
471 if entry:match(pattern) then 492 if match(entry, pattern) then
472 found = true 493 found = true
473 break 494 break
474 end 495 end
@@ -677,12 +698,10 @@ function deps.check_lua_libdir(vars)
677 table.insert(libnames, 1, "luajit-" .. cfg.lua_version) 698 table.insert(libnames, 1, "luajit-" .. cfg.lua_version)
678 end 699 end
679 local cache = {} 700 local cache = {}
680 for _, libname in ipairs(libnames) do 701 local ok = check_external_dependency("LUA", { library = libnames }, vars, "build", cache)
681 local ok = check_external_dependency("LUA", { library = libname }, vars, "build", cache) 702 if ok then
682 if ok then 703 vars.LUALIB = vars.LUA_LIBDIR_FILE
683 vars.LUALIB = vars.LUA_LIBDIR_FILE 704 return true
684 return true
685 end
686 end 705 end
687 return nil, "Failed finding Lua library. You may need to configure LUA_LIBDIR.", "dependency" 706 return nil, "Failed finding Lua library. You may need to configure LUA_LIBDIR.", "dependency"
688end 707end