summaryrefslogtreecommitdiff
path: root/xmake/actions
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-18 22:35:50 +0800
committerruki <[email protected]>2020-02-18 09:35:01 +0800
commit753309f3eca9445904c2e70d99fcdc49a67e5add (patch)
tree141d7d83ff6cbe8782c9ab85f981d993f573cfb8 /xmake/actions
parent0835cadcfe5f48870790cce20d6a3968d7b1ccf7 (diff)
move trybuild config
Diffstat (limited to 'xmake/actions')
-rw-r--r--xmake/actions/build/main.lua17
-rw-r--r--xmake/actions/build/trybuild/autotools.lua47
-rw-r--r--xmake/actions/build/trybuild/cmake.lua54
-rw-r--r--xmake/actions/build/trybuild/make.lua37
-rw-r--r--xmake/actions/build/trybuild/msbuild.lua38
-rw-r--r--xmake/actions/build/trybuild/xcodebuild.lua38
-rw-r--r--xmake/actions/build/xmake.lua3
-rw-r--r--xmake/actions/config/main.lua33
-rw-r--r--xmake/actions/config/xmake.lua5
9 files changed, 34 insertions, 238 deletions
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."