diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2012-09-18 22:20:15 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2012-09-18 22:20:15 -0300 |
commit | 130d5309a85b3962ef354551090f4220c3840841 (patch) | |
tree | ac230653d6d2a8c78bdbbbb65fcca31e7c905f6b | |
parent | 496dc3d8ea8d65082dcfb6d5aa44353c3fd0433d (diff) | |
download | luarocks-130d5309a85b3962ef354551090f4220c3840841.tar.gz luarocks-130d5309a85b3962ef354551090f4220c3840841.tar.bz2 luarocks-130d5309a85b3962ef354551090f4220c3840841.zip |
Deconstruct full library filenames and rebuild them as every possible pattern listed in the patterns list. This is an improvement for issue #81.
-rw-r--r-- | src/luarocks/deps.lua | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index a669ad66..00e796b0 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua | |||
@@ -482,6 +482,31 @@ function fulfill_dependencies(rockspec) | |||
482 | return true | 482 | return true |
483 | end | 483 | end |
484 | 484 | ||
485 | --- If filename matches a pattern, return the capture. | ||
486 | -- For example, given "libfoo.so" and "lib?.so" is a pattern, | ||
487 | -- returns "foo" (which can then be used to build names | ||
488 | -- based on other patterns. | ||
489 | -- @param file string: a filename | ||
490 | -- @param pattern string: a pattern, where ? is to be matched by the filename. | ||
491 | -- @return string The pattern, if found, or nil. | ||
492 | local function deconstruct_pattern(file, pattern) | ||
493 | local depattern = "^"..(pattern:gsub("%.", "%%."):gsub("%*", ".*"):gsub("?", "(.*)")).."$" | ||
494 | return (file:match(depattern)) | ||
495 | end | ||
496 | |||
497 | --- Construct all possible patterns for a name and add to the files array. | ||
498 | -- Run through the patterns array replacing all occurrences of "?" | ||
499 | -- with the given file name and store them in the files array. | ||
500 | -- @param file string A raw name (e.g. "foo") | ||
501 | -- @param array of string An array of patterns with "?" as the wildcard | ||
502 | -- (e.g. {"?.so", "lib?.so"}) | ||
503 | -- @param files The array of constructed names | ||
504 | local function add_all_patterns(file, patterns, files) | ||
505 | for _, pattern in ipairs(patterns) do | ||
506 | table.insert(files, (pattern:gsub("?", file))) | ||
507 | end | ||
508 | end | ||
509 | |||
485 | --- Set up path-related variables for external dependencies. | 510 | --- Set up path-related variables for external dependencies. |
486 | -- For each key in the external_dependencies table in the | 511 | -- For each key in the external_dependencies table in the |
487 | -- rockspec file, four variables are created: <key>_DIR, <key>_BINDIR, | 512 | -- rockspec file, four variables are created: <key>_DIR, <key>_BINDIR, |
@@ -546,10 +571,14 @@ function check_external_deps(rockspec, mode) | |||
546 | if file then | 571 | if file then |
547 | local files = {} | 572 | local files = {} |
548 | if not file:match("%.") then | 573 | if not file:match("%.") then |
574 | add_all_patterns(file, dirdata.pattern, files) | ||
575 | else | ||
549 | for _, pattern in ipairs(dirdata.pattern) do | 576 | for _, pattern in ipairs(dirdata.pattern) do |
550 | table.insert(files, (pattern:gsub("?", file))) | 577 | local matched = deconstruct_pattern(file, pattern) |
578 | if matched then | ||
579 | add_all_patterns(matched, dirdata.pattern, files) | ||
580 | end | ||
551 | end | 581 | end |
552 | else | ||
553 | table.insert(files, file) | 582 | table.insert(files, file) |
554 | end | 583 | end |
555 | local found = false | 584 | local found = false |