diff options
| author | ruki <[email protected]> | 2018-11-01 22:41:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-01 10:09:54 +0800 |
| commit | d130b8049af3250f3504580d146e3c54ed052a5f (patch) | |
| tree | 04ea83d88c2c8ac658c514da7aef4074303366e8 | |
| parent | 06481639fce5515f1708e23367aab5bfa20f0e53 (diff) | |
improve to find package from prefix directories
| -rw-r--r-- | xmake/actions/require/impl/action/install.lua | 6 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_package.lua | 124 |
2 files changed, 62 insertions, 68 deletions
diff --git a/xmake/actions/require/impl/action/install.lua b/xmake/actions/require/impl/action/install.lua index 42643b7ba..c36a92bea 100644 --- a/xmake/actions/require/impl/action/install.lua +++ b/xmake/actions/require/impl/action/install.lua @@ -116,7 +116,11 @@ function main(package) end -- fetch package and force to flush the cache - assert(package:fetch({force = true}), "fetch %s failed!", tipname) + local fetchinfo = package:fetch({force = true}) + if option.get("verbose") then + print(fetchinfo) + end + assert(fetchinfo, "fetch %s failed!", tipname) -- trace cprint("${green}ok") diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua index 58dac1b57..c1c30394b 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -133,7 +133,7 @@ function sandbox_lib_detect_find_package._find_from_packagedirs(name, opt) return result end --- find package from the prefix directories +-- find package from the prefix directories (maybe only include and no links) function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) -- get the prefix directories @@ -172,33 +172,57 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) table.insert(packagedirs, path.join(global.directory(), "prefix", "info", platsubdirs, "debug", packagepath)) end local prefixfile = find_file("info.txt", packagedirs) + if not prefixfile then + return + end - -- get the include and link directories - local links = {} - local linkdirs = {} - local includedirs = {} - local prefixinfo = (prefixfile and os.isfile(prefixfile) and io.load(prefixfile)) or nil - if prefixinfo then + -- load prefix info + local prefixinfo = io.load(prefixfile) + if not prefixinfo then + return + end - -- get prefix directory of this package - local prefixdir = path.translate(path.directory(path.directory(path.directory(path.directory(prefixfile)))):gsub("[/\\]prefix[/\\]info[/\\]", "/prefix/")) + -- get prefix directory of this package + local prefixdir = path.translate(path.directory(path.directory(path.directory(path.directory(prefixfile)))):gsub("[/\\]prefix[/\\]info[/\\]", "/prefix/")) - -- get link and include directories - for _, includedir in ipairs(table.wrap(prefixinfo.includedirs)) do - table.insert(includedirs, path.join(prefixdir, includedir)) - end - for _, linkdir in ipairs(table.wrap(prefixinfo.linkdirs)) do - table.insert(linkdirs, path.join(prefixdir, linkdir)) - end - if prefixinfo.links then - table.join2(links, prefixinfo.links) + -- save includedirs to result (maybe only include and no links) + local result = {} + local includedirs = {} + for _, includedir in ipairs(table.wrap(prefixinfo.includedirs)) do + table.insert(includedirs, path.join(prefixdir, includedir)) + end + if #includedirs == 0 then + table.insert(includedirs, path.join(prefixdir, "include")) + end + result.includedirs = table.unique(includedirs) + + -- get links and link directories + local links = {} + local linkdirs = {} + for _, linkdir in ipairs(table.wrap(prefixinfo.linkdirs)) do + table.insert(linkdirs, path.join(prefixdir, linkdir)) + end + if prefixinfo.links then + table.join2(links, prefixinfo.links) + end + if prefixinfo.installed and (not prefixinfo.linkdirs or not prefixinfo.links) then + local found = false + for _, line in ipairs(prefixinfo.installed) do + line = line:trim() + if line:endswith(".lib") or line:endswith(".a") then + found = true + if not prefixinfo.linkdirs then + table.insert(linkdirs, path.join(prefixdir, path.directory(line))) + end + if not prefixinfo.links then + table.insert(links, target.linkname(path.filename(line))) + end + end end - if prefixinfo.installed and (not prefixinfo.linkdirs or not prefixinfo.links) then - local found = false + if not found then for _, line in ipairs(prefixinfo.installed) do line = line:trim() - if line:endswith(".lib") or line:endswith(".a") then - found = true + if line:endswith(".so") or line:endswith(".dylib") then if not prefixinfo.linkdirs then table.insert(linkdirs, path.join(prefixdir, path.directory(line))) end @@ -207,38 +231,12 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) end end end - if not found then - for _, line in ipairs(prefixinfo.installed) do - line = line:trim() - if line:endswith(".so") or line:endswith(".dylib") then - if not prefixinfo.linkdirs then - table.insert(linkdirs, path.join(prefixdir, path.directory(line))) - end - if not prefixinfo.links then - table.insert(links, target.linkname(path.filename(line))) - end - end - end - end end + end - -- add root include and link directories - if #linkdirs == 0 then - table.insert(linkdirs, path.join(prefixdir, "lib")) - end - if #includedirs == 0 then - table.insert(includedirs, path.join(prefixdir, "include")) - end - else - -- add root include and link directories - for _, prefixdir in ipairs(prefixdirs) do - if #linkdirs == 0 then - table.insert(linkdirs, path.join(prefixdir, "lib")) - end - if #includedirs == 0 then - table.insert(includedirs, path.join(prefixdir, "include")) - end - end + -- add root include and link directories + if #linkdirs == 0 then + table.insert(linkdirs, path.join(prefixdir, "lib")) end -- uses name as links directly .e.g libname.a @@ -250,30 +248,22 @@ function sandbox_lib_detect_find_package._find_from_prefixdirs(name, opt) local find_library = import("lib.detect.find_library") -- find library - local result = nil for _, link in ipairs(links) do local libinfo = find_library(link, linkdirs) if libinfo then - result = result or {} result.links = table.join(result.links or {}, libinfo.link) result.linkdirs = table.join(result.linkdirs or {}, libinfo.linkdir) end end - - -- save results - if result and result.links then - - -- make unique directories + -- make unique links + if result.links then result.links = table.unique(result.links) - result.includedirs = table.unique(includedirs) + end - -- inherit the other prefix variables - if prefixinfo then - for name, values in pairs(prefixinfo) do - if name ~= "links" and name ~= "linkdirs" and name ~= "includedirs" and name ~= "installed" and name ~= "prefixdir" then - result[name] = values - end - end + -- inherit the other prefix variables + for name, values in pairs(prefixinfo) do + if name ~= "links" and name ~= "linkdirs" and name ~= "includedirs" and name ~= "installed" and name ~= "prefixdir" then + result[name] = values end end |
