From 4394e286fca1f9c60a1f8030d96f9fc68675b07f Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 18 Feb 2020 21:04:44 +0800 Subject: improve trybuild --- xmake/actions/build/main.lua | 60 +++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index 51813413b..4b14639a2 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -29,39 +29,43 @@ import("build_files") import("cleaner") import("statistics") +-- try to build +function _trybuild() + + -- get the buildsystem tool + local configfile = nil + local tool = nil + local try_tool = option.get("try-tool") + if try_tool then + tool = import("trybuild." .. try_tool, {try = true, anonymous = true}) + if tool then + configfile = tool.detect() + else + raise("unknown build tool: %s", try_tool) + end + else + for _, name in ipairs({"msbuild", "xcodebuild", "cmake", "autotools", "make"}) do + tool = import("trybuild." .. name, {anonymous = true}) + configfile = tool.detect() + if configfile then + try_tool = name + break + end + end + end + + -- try building it + if configfile and tool and utils.confirm({default = true, description = "${bright}" .. path.filename(configfile) .. "${clear} found, try building it"}) then + tool.build() + end +end + -- main function main() -- try building it using third-party buildsystem if xmake.lua not exists if not os.isfile(project.file()) then - - -- get the buildsystem tool - local configfile = nil - local tool = nil - local try_tool = option.get("try-tool") - if try_tool then - tool = import("trybuild." .. try_tool, {try = true, anonymous = true}) - if tool then - configfile = tool.detect() - else - raise("unknown build tool: %s", try_tool) - end - else - for _, name in ipairs({"msbuild", "xcodebuild", "cmake", "autotools", "make"}) do - tool = import("trybuild." .. name, {anonymous = true}) - configfile = tool.detect() - if configfile then - try_tool = name - break - end - end - end - - -- try building it - if configfile and tool and utils.confirm({default = true, description = "${bright}" .. path.filename(configfile) .. "${clear} found, try building it"}) then - tool.build() - end - return + return _trybuild() end -- post statistics before locking project -- cgit v1.3.1