2
0

fetch.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import("lib.detect.find_library")
  2. import("lib.detect.find_tool")
  3. import("core.base.semver")
  4. function _get_python_libs()
  5. local opt = {version = true}
  6. local result = find_tool("python3", opt)
  7. if not result then
  8. result = find_tool("python", opt)
  9. end
  10. local libs = {}
  11. local version = result and result.version
  12. if version then
  13. local py_ver = semver.new(version)
  14. py_ver = py_ver:major() .. py_ver:minor()
  15. table.insert(libs, "python" .. py_ver)
  16. table.insert(libs, "numpy" .. py_ver)
  17. end
  18. return libs
  19. end
  20. function _add_info(linkinfo, result)
  21. table.insert(result.linkdirs, linkinfo.linkdir)
  22. if linkinfo.filename then
  23. local filepath = path.join(linkinfo.linkdir, linkinfo.filename)
  24. if os.isfile(filepath) then
  25. table.insert(result.libfiles, filepath)
  26. end
  27. end
  28. table.insert(result.links, linkinfo.link)
  29. end
  30. function main(package, opt)
  31. if opt.system then
  32. import("libs", {rootdir = package:scriptdir()})
  33. local paths = {
  34. "/usr/lib",
  35. "/usr/lib64",
  36. "/usr/local/lib",
  37. "/usr/lib/x86_64-linux-gnu",
  38. }
  39. local result = {
  40. libfiles = {},
  41. linkdirs = {},
  42. links = {},
  43. }
  44. local opt = {
  45. plat = package:plat(),
  46. kind = package:config("shared") and "shared" or "static",
  47. }
  48. local sub_libs_map = libs.get_sub_libs(package)
  49. sub_libs_map.python = _get_python_libs()
  50. table.insert(sub_libs_map.test, "test_exec_monitor")
  51. local found
  52. libs.for_each(function (libname)
  53. local sub_libs = sub_libs_map[libname]
  54. if sub_libs then
  55. for _, sub_libname in ipairs(sub_libs) do
  56. local linkinfo = find_library("boost_" .. sub_libname, paths, opt)
  57. if linkinfo then
  58. _add_info(linkinfo, result)
  59. found = true
  60. end
  61. end
  62. else
  63. local linkinfo = find_library("boost_" .. libname, paths, opt)
  64. if linkinfo then
  65. _add_info(linkinfo, result)
  66. found = true
  67. end
  68. end
  69. end)
  70. if found then
  71. result.linkdirs = table.unique(result.linkdirs)
  72. return result
  73. end
  74. end
  75. end