summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-08-23 22:52:16 +0800
committerruki <[email protected]>2018-08-23 11:13:41 +0800
commit791fbecaf73ebf0023b3f958c1527057ba6d5136 (patch)
tree3f27cf00075d440100dd1a75dba0bac9dad6529d
parentc4200870deee0e73c9aaedf2b8a82e709a355920 (diff)
try building project
-rwxr-xr-xtests/projects/c/package/src/main.c (renamed from tests/projects/other/requires/src/main.c)0
-rw-r--r--tests/projects/c/package/test.lua (renamed from tests/projects/other/requires/test.lua)0
-rw-r--r--tests/projects/c/package/xmake.lua (renamed from tests/projects/other/requires/xmake.lua)15
-rw-r--r--xmake/actions/build/build.lua (renamed from xmake/actions/build/builder.lua)7
-rw-r--r--xmake/actions/build/main.lua10
-rw-r--r--xmake/actions/build/trybuild.lua134
-rw-r--r--xmake/actions/build/xmake.lua1
-rw-r--r--xmake/actions/config/main.lua4
-rw-r--r--xmake/actions/config/scangen.lua (renamed from xmake/actions/config/scanner.lua)4
9 files changed, 156 insertions, 19 deletions
diff --git a/tests/projects/other/requires/src/main.c b/tests/projects/c/package/src/main.c
index 9ae580511..9ae580511 100755
--- a/tests/projects/other/requires/src/main.c
+++ b/tests/projects/c/package/src/main.c
diff --git a/tests/projects/other/requires/test.lua b/tests/projects/c/package/test.lua
index 2db93991f..2db93991f 100644
--- a/tests/projects/other/requires/test.lua
+++ b/tests/projects/c/package/test.lua
diff --git a/tests/projects/other/requires/xmake.lua b/tests/projects/c/package/xmake.lua
index b34a691d1..3a787f313 100644
--- a/tests/projects/other/requires/xmake.lua
+++ b/tests/projects/c/package/xmake.lua
@@ -1,17 +1,12 @@
--- define package
-package("mbedtls")
- set_urls("https://github.com/ARMmbed/mbedtls.git")
- add_deps("https://github.com/glennrp/libpng.git@libpng >=1.6.28")
-package_end()
--- group packages
-package("zlib-mbedtls")
+-- define package
+package("zlib-pcre2")
add_deps("zlib >=1.2.11", {system = false})
- add_deps("mbedtls", {optional = true})
+ add_deps("pcre2", {optional = true})
package_end()
-- requires
-add_requires("zlib-mbedtls")
+add_requires("zlib-pcre2")
add_requires("[email protected] ~1.6.0", {alias = "tbox"})
add_requires("unknown", {optional = true})
@@ -19,7 +14,7 @@ add_requires("unknown", {optional = true})
add_rules("mode.debug", "mode.release")
-- add target
-target("console_c")
+target("console")
-- set kind
set_kind("binary")
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/build.lua
index d179ec256..e440a544a 100644
--- a/xmake/actions/build/builder.lua
+++ b/xmake/actions/build/build.lua
@@ -19,7 +19,7 @@
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
--- @file builder.lua
+-- @file build.lua
--
-- imports
@@ -183,8 +183,8 @@ function _stat_target_count(targetname)
end
end
--- build
-function build(targetname)
+-- the main entry
+function main(targetname)
-- enter toolchains environment
environment.enter("toolchains")
@@ -215,3 +215,4 @@ function build(targetname)
environment.leave("toolchains")
end
+
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 6add5aa7b..b0d530ef3 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -28,12 +28,18 @@ import("core.base.task")
import("core.project.config")
import("core.project.project")
import("core.platform.platform")
-import("builder")
+import("build")
+import("trybuild")
import("statistics")
-- main
function main()
+ -- try building it using third-party buildsystem if xmake.lua not exists
+ if not os.isfile(project.file()) and option.get("try") then
+ return trybuild()
+ end
+
-- get the target name
local targetname = option.get("target")
@@ -50,7 +56,7 @@ function main()
try
{
function ()
- builder.build(targetname)
+ build(targetname)
end,
catch
diff --git a/xmake/actions/build/trybuild.lua b/xmake/actions/build/trybuild.lua
new file mode 100644
index 000000000..15fd3e0fa
--- /dev/null
+++ b/xmake/actions/build/trybuild.lua
@@ -0,0 +1,134 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file trybuild.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.platform.environment")
+
+-- try building for makefile
+function _build_for_makefile(buildfile)
+ os.vrun("make")
+end
+
+-- try building for configure
+function _build_for_configure(buildfile)
+ os.vrun("./configure")
+ os.vrun("make")
+end
+
+-- try building for cmakelist
+function _build_for_cmakelists(buildfile)
+ os.vrun("cmake .")
+ os.vrun("make")
+end
+
+-- build for *.sln
+function _build_for_sln(buildfile)
+ os.vrun("msbuild %s -nologo -t:Rebuild -p:Configuration=Release", buildfile)
+end
+
+-- build for *.xcworkspace or *.xcodeproj
+function _build_for_xcode(buildfile)
+ os.vrun("xcodebuild clean build CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO")
+end
+
+-- the main entry
+function main(targetname)
+
+ -- trace
+ cprint("${yellow}xmake.lua not found, try building ..")
+
+ -- enter toolchains environment
+ environment.enter("toolchains")
+
+ -- TODO *.vcproj, premake.lua, scons, autogen.sh, Makefile.am, ...
+ -- init build scripts
+ local buildscripts = {}
+ if is_host("windows") then
+ table.insert(buildscripts, {"*.sln", _build_for_sln})
+ elseif is_host("macosx") then
+ table.insert(buildscripts, {"*.xcworkspace", _build_for_xcode})
+ table.insert(buildscripts, {"*.xcodeproj", _build_for_xcode})
+ end
+ table.insert(buildscripts, {"CMakeLists.txt", _build_for_cmakelists})
+ table.insert(buildscripts, {"configure", _build_for_configure})
+ table.insert(buildscripts, {"[mM]akefile", _build_for_makefile})
+
+
+ -- attempt to build it
+ local ok = false
+ for _, buildscript in pairs(buildscripts) do
+
+ -- save the current directory
+ local oldir = os.curdir()
+
+ -- try building
+ ok = try
+ {
+ function ()
+
+ -- attempt to build it if file exists
+ local files = os.filedirs(buildscript[1])
+ if #files > 0 then
+
+ -- trace
+ print("%s found", path.filename(files[1]))
+
+ -- build it
+ buildscript[2](files[1])
+ return true
+ end
+ end,
+
+ catch
+ {
+ function (errors)
+
+ -- trace verbose info
+ if errors then
+ vprint(errors)
+ end
+ end
+ }
+ }
+
+ -- restore directory
+ os.cd(oldir)
+
+ -- ok?
+ if ok then break end
+ end
+
+ -- leave toolchains environment
+ environment.leave("toolchains")
+
+ -- trace
+ if ok then
+ cprint("${bright}build ok!${clear}${ok_hand}")
+ else
+ raise("build failed!")
+ end
+end
+
+
diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua
index 2344f456f..8618c46e8 100644
--- a/xmake/actions/build/xmake.lua
+++ b/xmake/actions/build/xmake.lua
@@ -49,6 +49,7 @@ task("build")
, {}
, {'j', "jobs", "kv", "4", "Specifies the number of jobs to build simultaneously." }
, {'w', "warning", "k", false, "Enable the warnings output." }
+ , {'t', "try", "k", false, "Try building project using third-party buildsystem." }
, {}
, {nil, "target", "v", nil, "Build the given target." }
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index aa13b767a..fb3ddd1bd 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -30,7 +30,7 @@ import("core.project.project")
import("core.platform.platform")
import("core.project.cache", {nocache = true})
import("lib.detect.cache", {alias = "detectcache"})
-import("scanner")
+import("scangen")
import("menuconf", {alias = "menuconf_show"})
import("configheader", {alias = "generate_configheader"})
import("actions.require.install", {alias = "install_requires", rootdir = os.programdir()})
@@ -176,7 +176,7 @@ function main()
end
-- scan and generate it automatically
- scanner.make()
+ scangen()
end
-- the target name
diff --git a/xmake/actions/config/scanner.lua b/xmake/actions/config/scangen.lua
index 52841feb1..edcaa3e40 100644
--- a/xmake/actions/config/scanner.lua
+++ b/xmake/actions/config/scangen.lua
@@ -19,7 +19,7 @@
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
--- @file scanner.lua
+-- @file scangen.lua
--
-- imports
@@ -29,7 +29,7 @@ import("core.project.template")
import("core.language.language")
-- scan project and generate xmake.lua automaticlly if the project codes exist
-function make()
+function main()
-- trace
cprint("${yellow}xmake.lua not found, scanning files ..")