summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-09-29 09:33:39 +0800
committerruki <[email protected]>2018-09-29 09:33:39 +0800
commit5ab49e216d230bcced6b2884f19a70260019bfb3 (patch)
tree9b4f3b9e915852f9d6b62cdb7ddbfe91285444ee
parentf90792531c3a86f91b870716288073a6a8d60201 (diff)
improve to find xcode
-rw-r--r--xmake/modules/detect/sdks/find_ndk.lua6
-rw-r--r--xmake/modules/detect/sdks/find_xcode.lua116
-rw-r--r--xmake/modules/detect/sdks/find_xcode_sdkvers.lua90
-rw-r--r--xmake/platforms/android/check.lua3
-rw-r--r--xmake/platforms/checker.lua64
-rw-r--r--xmake/platforms/iphoneos/check.lua1
-rw-r--r--xmake/platforms/macosx/check.lua1
-rw-r--r--xmake/platforms/watchos/check.lua1
8 files changed, 129 insertions, 153 deletions
diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua
index a3df87ba3..9c9f727c3 100644
--- a/xmake/modules/detect/sdks/find_ndk.lua
+++ b/xmake/modules/detect/sdks/find_ndk.lua
@@ -118,12 +118,12 @@ end
-- @param opt the argument options
-- .e.g {arch = "[armv5te|armv6|armv7-a|armv8-a|arm64-v8a]", verbose = true, force = false, sdkver = 19, toolchains_ver = "4.9"}
--
--- @return the ndk toolchains array. .e.g {{bin = .., cross = ..}, .. }
+-- @return the ndk toolchains. .e.g {bindir = .., cross = ..}
--
-- @code
--
--- local toolchains = find_ndk("/xxx/android-ndk-r10e")
--- local toolchains = find_ndk("/xxx/android-ndk-r10e", {arch = "arm64-v8a"})
+-- local toolchain = find_ndk("/xxx/android-ndk-r10e")
+-- local toolchain = find_ndk("/xxx/android-ndk-r10e", {arch = "arm64-v8a"})
--
-- @endcode
--
diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua
index 143161c1a..bf1e4f873 100644
--- a/xmake/modules/detect/sdks/find_xcode.lua
+++ b/xmake/modules/detect/sdks/find_xcode.lua
@@ -23,18 +23,124 @@
--
-- imports
+import("lib.detect.cache")
+import("core.base.option")
+import("core.base.global")
+import("core.project.config")
import("lib.detect.find_directory")
--- find xcode directory
+-- find vscode directory
+function _find_sdkdir(sdkdir)
+ if sdkdir and os.isdir(sdkdir) then
+ return sdkdir
+ end
+ return find_directory("Xcode.app", {"/Applications"}) or find_directory("Xcode*.app", {"/Applications"})
+end
+
+-- find the sdk version of vscode
+function _find_xcode_sdkver(sdkdir, plat, arch)
+
+ -- select platform sdkdir
+ local platsdkdir = nil
+ if plat == "macosx" then
+ platsdkdir = "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX*.*.sdk"
+ elseif plat == "iphoneos" then
+ if arch == "i386" or arch == "x86_64" then
+ platsdkdir = "Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator*.*.sdk"
+ else
+ platsdkdir = "Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.*.sdk"
+ end
+ elseif plat == "watchos" then
+ if arch == "i386" or arch == "x86_64" then
+ platsdkdir = "Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator*.*.sdk"
+ else
+ platsdkdir = "Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS*.*.sdk"
+ end
+ end
+
+ -- attempt to find the platform directory and get sdk version
+ if platsdkdir then
+ local dir = find_directory(platsdkdir, sdkdir)
+ if dir then
+ return dir:match("%d+%.%d+")
+ end
+ end
+end
+
+-- find the vscode toolchain
+function _find_vscode(sdkdir, xcode_sdkver, plat, arch)
+
+ -- find vscode root directory
+ sdkdir = _find_sdkdir(sdkdir)
+ if not sdkdir then
+ return {}
+ end
+
+ -- find the sdk version
+ local sdkver = xcode_sdkver or _find_xcode_sdkver(sdkdir, plat, arch)
+ if not sdkver then
+ return {}
+ end
+
+ -- ok?
+ return {sdkdir = sdkdir, sdkver = sdkver}
+end
+
+-- find xcode toolchain
--
--- @return the xcode directory
+-- @param sdkdir the xcode directory
+-- @param opt the argument options
+-- .e.g {verbose = true, force = false, sdkver = 19, toolchains_ver = "4.9"}
+--
+-- @return the xcode toolchain. .e.g {bindir = .., cross = ..}
--
-- @code
--
--- local xcode_dir = find_xcode()
+-- local toolchain = find_vscode("/Applications/Xcode.app")
--
-- @endcode
--
-function main()
- return find_directory("Xcode.app", {"/Applications"}) or find_directory("Xcode*.app", {"/Applications"})
+function main(sdkdir, opt)
+
+ -- init arguments
+ opt = opt or {}
+
+ -- attempt to load cache first
+ local key = "detect.sdks.find_vscode." .. (sdkdir or "")
+ local cacheinfo = cache.load(key)
+ if not opt.force and cacheinfo.xcode then
+ return cacheinfo.xcode
+ end
+
+ -- get plat and arch
+ local plat = opt.plat or config.get("plat") or "macosx"
+ local arch = opt.arch or config.get("arch") or "x86_64"
+
+ -- find xcode
+ local xcode = _find_vscode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver or config.get("xcode_sdkver"), plat, arch)
+ if xcode then
+
+ -- save to config
+ config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
+ config.set("xcode_sdkver", xcode.sdkver, {force = true, readonly = true})
+
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the Xcode directory ... ${green}%s", xcode.sdkdir)
+ cprint("checking for the SDK version of Xcode ... ${green}%s", xcode.sdkver)
+ end
+ else
+
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the xcode directory ... ${red}no")
+ end
+ end
+
+ -- save to cache
+ cacheinfo.xcode = xcode or false
+ cache.save(key, cacheinfo)
+
+ -- ok?
+ return xcode
end
diff --git a/xmake/modules/detect/sdks/find_xcode_sdkvers.lua b/xmake/modules/detect/sdks/find_xcode_sdkvers.lua
deleted file mode 100644
index adb327b79..000000000
--- a/xmake/modules/detect/sdks/find_xcode_sdkvers.lua
+++ /dev/null
@@ -1,90 +0,0 @@
---!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 find_xcode_sdkvers.lua
---
-
--- imports
-import("core.project.config")
-import("detect.sdks.find_xcode")
-
--- find xcode sdk versions for the given platform
---
--- @param opt the argument options
--- .e.g {xcode_dir = "", plat = "[iphoneos|watchos]", arch = "[armv7|armv7s|arm64|i386|x86_64]"}
---
--- @return the xcode sdk version array
---
--- @code
---
--- local xcode_sdkvers = find_xcode_sdkvers()
--- local xcode_sdkvers = find_xcode_sdkvers({xcode_dir = ""})
--- local xcode_sdkvers = find_xcode_sdkvers({xcode_dir = "", plat = "iphoneos", arch = "arm64"})
---
--- @endcode
---
-function main(opt)
-
- -- init arguments
- opt = opt or {}
-
- -- get xcode directory
- local xcode_sdkvers = {}
- local xcode_dir = opt.xcode_dir or find_xcode()
- if not xcode_dir or not os.isdir(xcode_dir) then
- return xcode_sdkvers
- end
-
- -- get plat and arch
- local plat = opt.plat or config.get("plat") or "macosx"
- local arch = opt.arch or config.get("arch") or "x86_64"
-
- -- select xcode sdkdir
- local xcode_sdkdir = nil
- if plat == "macosx" then
- xcode_sdkdir = "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX*.sdk"
- elseif plat == "iphoneos" then
- if arch == "i386" or arch == "x86_64" then
- xcode_sdkdir = "Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator*.sdk"
- else
- xcode_sdkdir = "Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk"
- end
- elseif plat == "watchos" then
- if arch == "i386" or arch == "x86_64" then
- xcode_sdkdir = "Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator*.sdk"
- else
- xcode_sdkdir = "Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS*.sdk"
- end
- end
-
- -- attempt to match the directory
- if xcode_sdkdir then
- for _, dir in ipairs(os.dirs(path.join(xcode_dir, xcode_sdkdir))) do
- local xcode_sdkver = dir:match("%d+%.%d+")
- if xcode_sdkver then
- table.insert(xcode_sdkvers, xcode_sdkver)
- end
- end
- end
-
- -- ok?
- return xcode_sdkvers
-end
diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua
index fd5bea46f..cb1cc6436 100644
--- a/xmake/platforms/android/check.lua
+++ b/xmake/platforms/android/check.lua
@@ -28,8 +28,9 @@ import("detect.sdks.find_ndk")
-- check the ndk toolchain
function _check_ndk(config)
- local ndk = find_ndk(config.get("ndk"), {verbose = true})
+ local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true})
if ndk then
+ config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global
config.set("bin", ndk.bindir)
config.set("cross", ndk.cross)
else
diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua
index 2d9d790b0..ebfa25e48 100644
--- a/xmake/platforms/checker.lua
+++ b/xmake/platforms/checker.lua
@@ -25,7 +25,6 @@
-- imports
import("core.base.option")
import("detect.sdks.find_xcode")
-import("detect.sdks.find_xcode_sdkvers")
import("detect.sdks.find_cuda")
import("lib.detect.find_tool")
@@ -119,63 +118,26 @@ end
-- check the xcode application directory
function check_xcode(config, optional)
- -- get the xcode directory
- local xcode_dir = config.get("xcode")
- if not xcode_dir then
+ -- find xcode
+ local xcode = find_xcode(config.get("xcode"), {force = true, verbose = true, plat = config.get("plat"), arch = config.get("arch")})
+ if xcode then
- -- check ok? update it
- xcode_dir = find_xcode()
- if xcode_dir then
-
- -- save it
- config.set("xcode", xcode_dir)
-
- -- trace
- cprint("checking for the Xcode application directory ... ${green}%s", xcode_dir)
+ -- save it (maybe to global)
+ config.set("xcode", xcode.sdkdir, {force = true, readonly = true})
- elseif not optional then
+ elseif not optional then
- -- failed
- cprint("checking for the Xcode application directory ... ${red}no")
- cprint("${bright red}please run:")
- cprint("${red} - xmake config --xcode_dir=xxx")
- cprint("${red}or - xmake global --xcode_dir=xxx")
- raise()
- end
+ -- failed
+ cprint("${bright red}please run:")
+ cprint("${red} - xmake config --xcode=xxx")
+ cprint("${red}or - xmake global --xcode=xxx")
+ raise()
end
-end
--- check the xcode sdk version
-function check_xcode_sdkver(config, optional)
-
- -- get the xcode sdk version
+ -- save target minver
local xcode_sdkver = config.get("xcode_sdkver")
- if not xcode_sdkver then
-
- -- check ok? update it
- xcode_sdkver = find_xcode_sdkvers({xcode_dir = config.get("xcode"), plat = config.get("plat"), arch = config.get("arch")})[1]
- if xcode_sdkver then
-
- -- save it
- config.set("xcode_sdkver", xcode_sdkver)
-
- -- trace
- cprint("checking for the Xcode SDK version for %s ... ${green}%s", config.get("plat"), xcode_sdkver)
-
- elseif not optional then
-
- -- failed
- cprint("checking for the Xcode SDK version for %s ... ${red}no", config.get("plat"))
- cprint("${bright red}please run:")
- cprint("${red} - xmake config --xcode_sdkver=xxx")
- cprint("${red}or - xmake global --xcode_sdkver=xxx")
- raise()
- end
- end
-
- -- get target minver
local target_minver = config.get("target_minver")
- if not target_minver then
+ if xcode_sdkver and not target_minver then
config.set("target_minver", xcode_sdkver)
end
end
diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua
index d42e16e4c..4d81689d4 100644
--- a/xmake/platforms/iphoneos/check.lua
+++ b/xmake/platforms/iphoneos/check.lua
@@ -91,7 +91,6 @@ function main(kind, toolkind)
{
{ checker.check_arch, "arm64" }
, checker.check_xcode
- , checker.check_xcode_sdkver
}
-- init the check list of global
diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua
index 959b90c3b..b37519cdb 100644
--- a/xmake/platforms/macosx/check.lua
+++ b/xmake/platforms/macosx/check.lua
@@ -136,7 +136,6 @@ function main(kind, toolkind)
{
checker.check_arch
, { checker.check_xcode, true }
- , { checker.check_xcode_sdkver, true }
, checker.check_cuda
}
diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua
index 07b619dac..d38639f01 100644
--- a/xmake/platforms/watchos/check.lua
+++ b/xmake/platforms/watchos/check.lua
@@ -91,7 +91,6 @@ function main(kind, toolkind)
{
{ checker.check_arch, "armv7k" }
, checker.check_xcode
- , checker.check_xcode_sdkver
}
-- init the check list of global