monkey.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. -- imports
  2. import("core.base.option")
  3. import("core.platform.platform")
  4. import("packages", {alias = "get_packages"})
  5. -- the options
  6. local options =
  7. {
  8. {'v', "verbose", "k", nil, "Enable verbose information." }
  9. , {'D', "diagnosis", "k", nil, "Enable diagnosis information." }
  10. , {nil, "shallow", "k", nil, "Only install the root packages." }
  11. , {'k', "kind", "kv", nil, "Enable static/shared library." }
  12. , {'p', "plat", "kv", nil, "Set the given platform." }
  13. , {'a', "arch", "kv", nil, "Set the given architecture." }
  14. , {'m', "mode", "kv", nil, "Set the given mode." }
  15. , {nil, "cflags", "kv", nil, "Set the cflags." }
  16. , {nil, "cxxflags", "kv", nil, "Set the cxxflags." }
  17. , {nil, "ldflags", "kv", nil, "Set the ldflags." }
  18. , {nil, "ndk", "kv", nil, "Set the android NDK directory." }
  19. , {nil, "sdk", "kv", nil, "Set the SDK directory of cross toolchain." }
  20. , {nil, "vs_sdkver", "kv", nil, "Set the Windows SDK version." }
  21. , {nil, "vs_runtime", "kv", nil, "Set the VS Runtime library." }
  22. , {nil, "mingw", "kv", nil, "Set the MingW directory." }
  23. , {nil, "toolchain", "kv", nil, "Set the toolchain name." }
  24. , {nil, "packages", "vs", nil, "The package list." }
  25. }
  26. -- require packages
  27. function _require_packages(argv, packages)
  28. local config_argv = {"f", "-c"}
  29. if argv.verbose then
  30. table.insert(config_argv, "-v")
  31. end
  32. if argv.diagnosis then
  33. table.insert(config_argv, "-D")
  34. end
  35. if argv.plat then
  36. table.insert(config_argv, "--plat=" .. argv.plat)
  37. end
  38. if argv.arch then
  39. table.insert(config_argv, "--arch=" .. argv.arch)
  40. end
  41. if argv.mode then
  42. table.insert(config_argv, "--mode=" .. argv.mode)
  43. end
  44. if argv.ndk then
  45. table.insert(config_argv, "--ndk=" .. argv.ndk)
  46. end
  47. if argv.sdk then
  48. table.insert(config_argv, "--sdk=" .. argv.sdk)
  49. end
  50. if argv.vs_sdkver then
  51. table.insert(config_argv, "--vs_sdkver=" .. argv.vs_sdkver)
  52. end
  53. if argv.vs_runtime then
  54. table.insert(config_argv, "--vs_runtime=" .. argv.vs_runtime)
  55. end
  56. if argv.mingw then
  57. table.insert(config_argv, "--mingw=" .. argv.mingw)
  58. end
  59. if argv.toolchain then
  60. table.insert(config_argv, "--toolchain=" .. argv.toolchain)
  61. end
  62. if argv.cflags then
  63. table.insert(config_argv, "--cflags=" .. argv.cflags)
  64. end
  65. if argv.cxxflags then
  66. table.insert(config_argv, "--cxxflags=" .. argv.cxxflags)
  67. end
  68. if argv.ldflags then
  69. table.insert(config_argv, "--ldflags=" .. argv.ldflags)
  70. end
  71. os.vexecv("xmake", config_argv)
  72. local require_argv = {"require", "-f", "-y"}
  73. if argv.verbose then
  74. table.insert(require_argv, "-v")
  75. end
  76. if argv.diagnosis then
  77. table.insert(require_argv, "-D")
  78. end
  79. if argv.shallow then
  80. table.insert(require_argv, "--shallow")
  81. end
  82. if argv.mode == "debug" and argv.kind == "shared" then
  83. table.insert(require_argv, "--extra={debug=true,configs={shared=true}}")
  84. elseif argv.mode == "debug" then
  85. table.insert(require_argv, "--extra={debug=true}")
  86. elseif argv.kind == "shared" then
  87. table.insert(require_argv, "--extra={configs={shared=true}}")
  88. end
  89. table.join2(require_argv, packages)
  90. os.vexecv("xmake", require_argv)
  91. end
  92. -- the given package is supported?
  93. function _package_is_supported(argv, packagename)
  94. local packages = get_packages()
  95. if packages then
  96. local plat = argv.plat or os.subhost()
  97. local packages_plat = packages[plat]
  98. for _, package in ipairs(packages_plat) do
  99. if package and packagename:split("%s+")[1] == package.name then
  100. local arch = argv.arch or platform.archs(plat)[1] or os.arch()
  101. for _, package_arch in ipairs(package.archs) do
  102. if arch == package_arch then
  103. return true
  104. end
  105. end
  106. end
  107. end
  108. end
  109. end
  110. -- the main entry
  111. function main(...)
  112. -- parse arguments
  113. local argv = option.parse({...}, options, "Test all the given or changed packages.")
  114. -- get packages
  115. math.randomseed(os.time())
  116. local packages = argv.packages or {}
  117. if #packages == 0 then
  118. local files = os.files(path.join(os.scriptdir(), "..", "packages", "*", "*", "xmake.lua"))
  119. local limit = is_host("bsd") and 1 or 10
  120. while #packages < limit do
  121. local file = files[math.random(#files)]
  122. if file:find("packages", 1, true) and path.filename(file) == "xmake.lua" then
  123. assert(file == file:lower(), "%s must be lower case!", file)
  124. local package = path.filename(path.directory(file))
  125. table.insert(packages, package)
  126. end
  127. end
  128. end
  129. if #packages == 0 then
  130. table.insert(packages, "tbox dev")
  131. end
  132. -- remove unsupported packages
  133. for idx, package in irpairs(packages) do
  134. assert(package == package:lower(), "package(%s) must be lower case!", package)
  135. if not _package_is_supported(argv, package) then
  136. table.remove(packages, idx)
  137. end
  138. end
  139. if #packages == 0 then
  140. print("no testable packages on %s!", argv.plat or os.subhost())
  141. return
  142. end
  143. -- prepare test project
  144. local repodir = os.curdir()
  145. local workdir = path.join(os.tmpdir(), "xmake-repo")
  146. print(packages)
  147. os.setenv("XMAKE_STATS", "false")
  148. os.tryrm(workdir)
  149. os.mkdir(workdir)
  150. os.cd(workdir)
  151. os.exec("xmake create test")
  152. os.cd("test")
  153. print(os.curdir())
  154. os.exec("xmake repo --add local-repo %s", repodir)
  155. os.exec("xmake repo -l")
  156. -- require packages
  157. for _, package in ipairs(packages) do
  158. _require_packages(argv, package)
  159. end
  160. end