From 753309f3eca9445904c2e70d99fcdc49a67e5add Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 18 Feb 2020 22:35:50 +0800 Subject: move trybuild config --- xmake/actions/build/main.lua | 17 ++++--- xmake/actions/build/trybuild/autotools.lua | 47 ------------------- xmake/actions/build/trybuild/cmake.lua | 54 ---------------------- xmake/actions/build/trybuild/make.lua | 37 --------------- xmake/actions/build/trybuild/msbuild.lua | 38 --------------- xmake/actions/build/trybuild/xcodebuild.lua | 38 --------------- xmake/actions/build/xmake.lua | 3 -- xmake/actions/config/main.lua | 33 +++++++------ xmake/actions/config/xmake.lua | 5 ++ .../modules/private/action/trybuild/autotools.lua | 47 +++++++++++++++++++ xmake/modules/private/action/trybuild/cmake.lua | 54 ++++++++++++++++++++++ xmake/modules/private/action/trybuild/make.lua | 37 +++++++++++++++ xmake/modules/private/action/trybuild/msbuild.lua | 38 +++++++++++++++ .../modules/private/action/trybuild/xcodebuild.lua | 38 +++++++++++++++ 14 files changed, 248 insertions(+), 238 deletions(-) delete mode 100644 xmake/actions/build/trybuild/autotools.lua delete mode 100644 xmake/actions/build/trybuild/cmake.lua delete mode 100644 xmake/actions/build/trybuild/make.lua delete mode 100644 xmake/actions/build/trybuild/msbuild.lua delete mode 100644 xmake/actions/build/trybuild/xcodebuild.lua create mode 100644 xmake/modules/private/action/trybuild/autotools.lua create mode 100644 xmake/modules/private/action/trybuild/cmake.lua create mode 100644 xmake/modules/private/action/trybuild/make.lua create mode 100644 xmake/modules/private/action/trybuild/msbuild.lua create mode 100644 xmake/modules/private/action/trybuild/xcodebuild.lua diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index 4b14639a2..3e2f71aa2 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -32,30 +32,33 @@ import("statistics") -- try to build function _trybuild() + -- load config + config.load() + -- 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}) + local trybuild = config.get("trybuild") + if trybuild then + tool = import("private.action.trybuild." .. trybuild, {try = true, anonymous = true}) if tool then configfile = tool.detect() else - raise("unknown build tool: %s", try_tool) + raise("unknown build tool: %s", trybuild) end else for _, name in ipairs({"msbuild", "xcodebuild", "cmake", "autotools", "make"}) do - tool = import("trybuild." .. name, {anonymous = true}) + tool = import("private.action.trybuild." .. name, {anonymous = true}) configfile = tool.detect() if configfile then - try_tool = name + config.set("trybuild", name, {readonly = true, force = true}) 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 + if configfile and tool and (trybuild or utils.confirm({default = true, description = "${bright}" .. path.filename(configfile) .. "${clear} found, try building it"})) then tool.build() end end diff --git a/xmake/actions/build/trybuild/autotools.lua b/xmake/actions/build/trybuild/autotools.lua deleted file mode 100644 index c2bda369e..000000000 --- a/xmake/actions/build/trybuild/autotools.lua +++ /dev/null @@ -1,47 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file autotools.lua --- - --- imports -import("core.base.option") -import("lib.detect.find_file") - --- detect build-system and configuration file -function detect() - return find_file("configure", os.curdir()) or find_file("configure.ac", os.curdir()) -end - --- do build -function build() - if not os.isfile("configure") then - if os.isfile("autogen.sh") then - os.execv("sh", {"./autogen.sh"}) - elseif os.isfile("configure.ac") then - os.exec("autoreconf --install --symlink") - end - end - os.mkdir("build/install") - os.exec("./configure --prefix=%s", path.absolute("build/install")) - os.exec("make -j4") - os.exec("make install") - cprint("installed to ${bright}%s", path.absolute("build/install")) - cprint("${bright}build ok!") -end - - diff --git a/xmake/actions/build/trybuild/cmake.lua b/xmake/actions/build/trybuild/cmake.lua deleted file mode 100644 index 09ad6750c..000000000 --- a/xmake/actions/build/trybuild/cmake.lua +++ /dev/null @@ -1,54 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file cmake.lua --- - --- imports -import("core.base.option") -import("lib.detect.find_file") - --- detect build-system and configuration file -function detect() - return find_file("CMakeLists.txt", os.curdir()) -end - --- do build -function build() - os.mkdir("build") - os.cd("build") - if is_host("windows") and os.arch() == "x64" then - os.exec("cmake -A x64 -DCMAKE_INSTALL_PREFIX=\"%s\" ..", path.absolute("build/install")) - else - os.exec("cmake -DCMAKE_INSTALL_PREFIX=\"%s\" ..", path.absolute("build/install")) - end - if is_host("windows") then - - local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") - os.exec("msbuild \"%s\" -nologo -t:Rebuild -p:Configuration=Release -p:Platform=%s", slnfile, os.arch() == "x64" and "x64" or "Win32") - - local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj" - os.exec("msbuild \"%s\" /property:configuration=Release", projfile) - else - os.exec("make -j4") - os.exec("make install") - end - cprint("installed to ${bright}%s", path.absolute("build/install")) - cprint("${bright}build ok!") -end - - diff --git a/xmake/actions/build/trybuild/make.lua b/xmake/actions/build/trybuild/make.lua deleted file mode 100644 index 4572e4e73..000000000 --- a/xmake/actions/build/trybuild/make.lua +++ /dev/null @@ -1,37 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file make.lua --- - --- imports -import("core.base.option") -import("lib.detect.find_file") - --- detect build-system and configuration file -function detect() - return find_file("[mM]akefile", os.curdir()) -end - --- do build -function build() - os.exec("make clean") - os.exec("make -j" .. option.get("jobs")) - cprint("${bright}build ok!") -end - - diff --git a/xmake/actions/build/trybuild/msbuild.lua b/xmake/actions/build/trybuild/msbuild.lua deleted file mode 100644 index 18005c70e..000000000 --- a/xmake/actions/build/trybuild/msbuild.lua +++ /dev/null @@ -1,38 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file msbuild.lua --- - --- imports -import("core.base.option") -import("lib.detect.find_file") - --- detect build-system and configuration file -function detect() - if is_host("windows") then - return find_file("*.sln", os.curdir()) - end -end - --- do build -function build() - os.exec("msbuild \"%s\" -nologo -t:Rebuild -p:Configuration=Release -p:Platform=%s", buildfile, os.arch() == "x64" and "x64" or "Win32") - cprint("${bright}build ok!") -end - - diff --git a/xmake/actions/build/trybuild/xcodebuild.lua b/xmake/actions/build/trybuild/xcodebuild.lua deleted file mode 100644 index 81a15018c..000000000 --- a/xmake/actions/build/trybuild/xcodebuild.lua +++ /dev/null @@ -1,38 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file xcodebuild.lua --- - --- imports -import("core.base.option") -import("lib.detect.find_directory") - --- detect build-system and configuration file -function detect() - if is_host("macosx") then - return find_directory("*.xcworkspace", os.curdir()) or find_directory("*.xcodeproj", os.curdir()) - end -end - --- do build -function build() - os.exec("xcodebuild clean build CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO") - cprint("${bright}build ok!") -end - - diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua index 2d57e554a..eab28b41f 100644 --- a/xmake/actions/build/xmake.lua +++ b/xmake/actions/build/xmake.lua @@ -46,9 +46,6 @@ task("build") , {'j', "jobs", "kv", tostring(math.ceil(os.cpuinfo().ncpu * 3 / 2)), "Specifies the number of jobs to build simultaneously." } , {'w', "warning", "k", false , "Enable the warnings output." } - , {nil, "try", "k", false , "Try building project using third-party buildsystem." } - , {nil, "try-tool", "kv", nil , "Set the third-party buildsystem tool when `--try` is enabled." - , values = {"make", "cmake", "autotools", "msbuild", "xcodebuild"}} , {nil, "files", "kv", nil , "Build the given source files.", "e.g. ", " - xmake --files=src/main.c", diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index ecb372abb..90f141968 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -147,7 +147,8 @@ function main() -- scan project and generate it if xmake.lua not exists local autogen = false - if not os.isfile(project.file()) then + local trybuild = option.get("trybuild") + if not os.isfile(project.file()) and not trybuild then autogen = utils.confirm({default = false, description = "xmake.lua not found, try generating it"}) if autogen then scangen() @@ -264,20 +265,24 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) config.set("buildir", path.relative(buildir, project.directory()), {readonly = true, force = true}) end - -- install and update requires and config header - local require_enable = option.boolean(option.get("require")) - if (recheck or require_enable) and require_enable ~= false then - install_requires() - end + -- only config for building project using third-party buildsystem + if not trybuild then - -- check target and ensure to load all targets, @note we must load targets after installing required packages, - -- otherwise has_package() will be invalid. - _check_target(targetname) + -- install and update requires and config header + local require_enable = option.boolean(option.get("require")) + if (recheck or require_enable) and require_enable ~= false then + install_requires() + end - -- update the config header - if recheck then - generate_configfiles() - generate_configheader() + -- check target and ensure to load all targets, @note we must load targets after installing required packages, + -- otherwise has_package() will be invalid. + _check_target(targetname) + + -- update the config header + if recheck then + generate_configfiles() + generate_configheader() + end end -- dump config @@ -290,7 +295,7 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) configcache:set("options_" .. targetname, options) -- save options and configure for each targets if be all - if targetname == "all" then + if not trybuild and targetname == "all" then for _, target in pairs(project.targets()) do config.save(target:name()) configcache:set("options_" .. target:name(), options) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index bf9272c63..571daca36 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -51,6 +51,11 @@ task("config") return {"y: force to enable", "n: disable" } end end } + , {nil, "trybuild", "kv", nil , "Try building and set the third-party buildsystem tool.", + "e.g.", + " - xmake f --trybuild=auto; xmake", + " - xmake f --trybuild=autotools -p android --ndk=xxx; xmake" + , values = {"auto", "make", "cmake", "autotools", "msbuild", "xcodebuild"}} , {category = "."} , {'p', "plat", "kv", "$(subhost)" , "Compile for the given platform." diff --git a/xmake/modules/private/action/trybuild/autotools.lua b/xmake/modules/private/action/trybuild/autotools.lua new file mode 100644 index 000000000..c2bda369e --- /dev/null +++ b/xmake/modules/private/action/trybuild/autotools.lua @@ -0,0 +1,47 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file autotools.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_file") + +-- detect build-system and configuration file +function detect() + return find_file("configure", os.curdir()) or find_file("configure.ac", os.curdir()) +end + +-- do build +function build() + if not os.isfile("configure") then + if os.isfile("autogen.sh") then + os.execv("sh", {"./autogen.sh"}) + elseif os.isfile("configure.ac") then + os.exec("autoreconf --install --symlink") + end + end + os.mkdir("build/install") + os.exec("./configure --prefix=%s", path.absolute("build/install")) + os.exec("make -j4") + os.exec("make install") + cprint("installed to ${bright}%s", path.absolute("build/install")) + cprint("${bright}build ok!") +end + + diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua new file mode 100644 index 000000000..09ad6750c --- /dev/null +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -0,0 +1,54 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file cmake.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_file") + +-- detect build-system and configuration file +function detect() + return find_file("CMakeLists.txt", os.curdir()) +end + +-- do build +function build() + os.mkdir("build") + os.cd("build") + if is_host("windows") and os.arch() == "x64" then + os.exec("cmake -A x64 -DCMAKE_INSTALL_PREFIX=\"%s\" ..", path.absolute("build/install")) + else + os.exec("cmake -DCMAKE_INSTALL_PREFIX=\"%s\" ..", path.absolute("build/install")) + end + if is_host("windows") then + + local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") + os.exec("msbuild \"%s\" -nologo -t:Rebuild -p:Configuration=Release -p:Platform=%s", slnfile, os.arch() == "x64" and "x64" or "Win32") + + local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj" + os.exec("msbuild \"%s\" /property:configuration=Release", projfile) + else + os.exec("make -j4") + os.exec("make install") + end + cprint("installed to ${bright}%s", path.absolute("build/install")) + cprint("${bright}build ok!") +end + + diff --git a/xmake/modules/private/action/trybuild/make.lua b/xmake/modules/private/action/trybuild/make.lua new file mode 100644 index 000000000..4572e4e73 --- /dev/null +++ b/xmake/modules/private/action/trybuild/make.lua @@ -0,0 +1,37 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file make.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_file") + +-- detect build-system and configuration file +function detect() + return find_file("[mM]akefile", os.curdir()) +end + +-- do build +function build() + os.exec("make clean") + os.exec("make -j" .. option.get("jobs")) + cprint("${bright}build ok!") +end + + diff --git a/xmake/modules/private/action/trybuild/msbuild.lua b/xmake/modules/private/action/trybuild/msbuild.lua new file mode 100644 index 000000000..18005c70e --- /dev/null +++ b/xmake/modules/private/action/trybuild/msbuild.lua @@ -0,0 +1,38 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file msbuild.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_file") + +-- detect build-system and configuration file +function detect() + if is_host("windows") then + return find_file("*.sln", os.curdir()) + end +end + +-- do build +function build() + os.exec("msbuild \"%s\" -nologo -t:Rebuild -p:Configuration=Release -p:Platform=%s", buildfile, os.arch() == "x64" and "x64" or "Win32") + cprint("${bright}build ok!") +end + + diff --git a/xmake/modules/private/action/trybuild/xcodebuild.lua b/xmake/modules/private/action/trybuild/xcodebuild.lua new file mode 100644 index 000000000..81a15018c --- /dev/null +++ b/xmake/modules/private/action/trybuild/xcodebuild.lua @@ -0,0 +1,38 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xcodebuild.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_directory") + +-- detect build-system and configuration file +function detect() + if is_host("macosx") then + return find_directory("*.xcworkspace", os.curdir()) or find_directory("*.xcodeproj", os.curdir()) + end +end + +-- do build +function build() + os.exec("xcodebuild clean build CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO") + cprint("${bright}build ok!") +end + + -- cgit v1.3.1