diff options
| author | ruki <[email protected]> | 2020-02-19 23:16:19 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-19 13:37:57 +0800 |
| commit | 83be106cb6ef6f55dc992f97afa938ffed231087 (patch) | |
| tree | f36f4ad629249fcfbdd03cad3fdbcef0658667b1 | |
| parent | ed49fcb8e77087a12b01cae2bb7841a75a25b0fc (diff) | |
impl trybuild/meson
| -rw-r--r-- | xmake/actions/build/main.lua | 3 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 24 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/autotools.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/cmake.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/make.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/meson.lua | 32 |
6 files changed, 70 insertions, 21 deletions
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index a38ebb7c1..9eff98819 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -66,7 +66,8 @@ function _try_build() end -- try building it - if configfile and tool and (trybuild or utils.confirm({default = true, description = "${bright}" .. path.filename(configfile) .. "${clear} found, try building it"})) then + if configfile and tool and (trybuild or utils.confirm({default = true, + description = "${bright}" .. path.filename(configfile) .. "${clear} found, try building it or you can run `${bright}xmake f --trybuild=${clear}` to set buildsystem"})) then if not trybuild then task.run("config", {target = targetname, trybuild = trybuild_detected}) end diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 038807745..71f77089a 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -424,6 +424,30 @@ function sandbox_os.execv(program, argv, opt) return ok end +-- execute command and echo verbose info if [-v|--verbose] option is enabled +function sandbox_os.vexec(cmd, ...) + + -- echo command + if option.get("verbose") then + print(vformat(cmd, ...)) + end + + -- run it + sandbox_os.exec(cmd, ...) +end + +-- execute command with arguments list and echo verbose info if [-v|--verbose] option is enabled +function sandbox_os.vexecv(program, argv, opt) + + -- echo command + if option.get("verbose") then + print(vformat(program) .. " " .. sandbox_os.args(argv)) + end + + -- run it + sandbox_os.execv(program, argv, opt) +end + -- match files or directories function sandbox_os.match(pattern, mode, callback) return os.match(vformat(pattern), mode, callback) diff --git a/xmake/modules/private/action/trybuild/autotools.lua b/xmake/modules/private/action/trybuild/autotools.lua index cbb36a166..cbedd70e6 100644 --- a/xmake/modules/private/action/trybuild/autotools.lua +++ b/xmake/modules/private/action/trybuild/autotools.lua @@ -152,10 +152,10 @@ end function clean() if find_file("[mM]akefile", os.curdir()) then if option.get("all") then - os.exec("make distclean") + os.vexec("make distclean") os.tryrm(_get_artifacts_dir()) else - os.exec("make clean") + os.vexec("make clean") end end end @@ -172,9 +172,9 @@ function build() -- generate configure if not os.isfile("configure") then if os.isfile("autogen.sh") then - os.execv("sh", {"./autogen.sh"}) + os.vexecv("sh", {"./autogen.sh"}) elseif os.isfile("configure.ac") then - os.exec("autoreconf --install --symlink") + os.vexec("autoreconf --install --symlink") end end @@ -191,12 +191,12 @@ function build() end end end - os.execv("./configure", argv, {envs = _get_buildenvs()}) + os.vexecv("./configure", argv, {envs = _get_buildenvs()}) end -- do build - os.exec("make -j" .. option.get("jobs")) - os.exec("make install") + os.vexec("make -j" .. option.get("jobs")) + os.vexec("make install") cprint("output to ${bright}%s", artifacts_dir) cprint("${bright}build ok!") end diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua index 287b8aefc..7cef45c37 100644 --- a/xmake/modules/private/action/trybuild/cmake.lua +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -47,9 +47,9 @@ function clean() if configfile then local oldir = os.cd(buildir) if is_plat("windows") then - os.exec("msbuild \"%s\" -nologo -t:Clean -p:Configuration=%s -p:Platform=%s", configfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") + os.vexec("msbuild \"%s\" -nologo -t:Clean -p:Configuration=%s -p:Platform=%s", configfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") else - os.exec("make clean") + os.vexec("make clean") end os.cd(oldir) end @@ -76,20 +76,20 @@ function build() table.insert(argv, "x64") end table.insert(argv, '..') - os.execv(cmake.program, argv) + os.vexecv(cmake.program, argv) end -- do build if is_plat("windows") then local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") - os.exec("msbuild \"%s\" -nologo -t:Build -p:Configuration=%s -p:Platform=%s", slnfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") + os.vexec("msbuild \"%s\" -nologo -t:Build -p:Configuration=%s -p:Platform=%s", slnfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj" if os.isfile(projfile) then - os.exec("msbuild \"%s\" /property:configuration=%s", projfile, is_mode("debug") and "Debug" or "Release") + os.vexec("msbuild \"%s\" /property:configuration=%s", projfile, is_mode("debug") and "Debug" or "Release") end else - os.exec("make -j" .. option.get("jobs")) - os.exec("make install") + os.vexec("make -j" .. option.get("jobs")) + os.vexec("make install") end cprint("output to ${bright}%s", artifacts_dir) cprint("${bright}build ok!") diff --git a/xmake/modules/private/action/trybuild/make.lua b/xmake/modules/private/action/trybuild/make.lua index 2258b13b7..34f0ccaaa 100644 --- a/xmake/modules/private/action/trybuild/make.lua +++ b/xmake/modules/private/action/trybuild/make.lua @@ -29,12 +29,12 @@ end -- do clean function clean() - os.exec("make clean") + os.vexec("make clean") end -- do build function build() - os.exec("make -j" .. option.get("jobs")) + os.vexec("make -j" .. option.get("jobs")) cprint("${bright}build ok!") end diff --git a/xmake/modules/private/action/trybuild/meson.lua b/xmake/modules/private/action/trybuild/meson.lua index 17982e190..7268b243a 100644 --- a/xmake/modules/private/action/trybuild/meson.lua +++ b/xmake/modules/private/action/trybuild/meson.lua @@ -43,6 +43,20 @@ end function clean() local buildir = _get_buildir() if os.isdir(buildir) then + local configfile = find_file("build.ninja", buildir) + if configfile then + local ninja = assert(find_tool("ninja"), "ninja not found!") + local ninja_argv = {"-C", buildir} + if option.get("verbose") or option.get("diagnosis") then + table.insert(ninja_argv, "-v") + end + table.insert(ninja_argv, "-t") + table.insert(ninja_argv, "clean") + os.vexecv(ninja.program, ninja_argv) + if option.get("all") then + os.tryrm(buildir) + end + end end end @@ -54,17 +68,27 @@ function build() if not os.isdir(artifacts_dir) then os.mkdir(artifacts_dir) end - os.cd(_get_buildir()) -- generate makefile + local buildir = _get_buildir() local meson = assert(find_tool("meson"), "meson not found!") - local configfile = nil + local configfile = find_file("build.ninja", buildir) if not configfile then local argv = {"--prefix=" .. artifacts_dir} - table.insert(argv, _get_buildir()) - os.execv("meson", argv) + table.insert(argv, buildir) + os.vexecv(meson.program, argv) end + -- do build + local ninja = assert(find_tool("ninja"), "ninja not found!") + local ninja_argv = {"-C", buildir} + if option.get("verbose") or option.get("diagnosis") then + table.insert(ninja_argv, "-v") + end + table.insert(ninja_argv, "-j") + table.insert(ninja_argv, option.get("jobs")) + os.vexecv(ninja.program, ninja_argv) + os.vexecv(ninja.program, table.join("install", ninja_argv)) cprint("output to ${bright}%s", artifacts_dir) cprint("${bright}build ok!") end |
