summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-12-30 20:21:40 +0800
committerruki <[email protected]>2018-12-30 20:21:40 +0800
commitbeb5d95700face346617903f45bc8ad26c689882 (patch)
tree460baf12cc91de94f3f54c88e37a4b6c1aef5fdd
parentd563d8d01f7f2aa1daa6e177dfe483e52ac786f8 (diff)
add add_platformdirs api
-rw-r--r--xmake/core/platform/platform.lua56
-rw-r--r--xmake/core/project/project.lua6
-rw-r--r--xmake/modules/detect/sdks/find_xcode.lua24
3 files changed, 57 insertions, 29 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua
index fcab41b59..9ce8eddbc 100644
--- a/xmake/core/platform/platform.lua
+++ b/xmake/core/platform/platform.lua
@@ -152,15 +152,6 @@ function _instance:_is_builtin_conf(name)
return builtin_configs[name]
end
--- the directories of platform
-function platform._directories()
-
- -- the directories
- return { path.join(global.directory(), "platforms")
- , path.join(os.programdir(), "platforms")
- }
-end
-
-- the interpreter
function platform._interpreter()
@@ -174,7 +165,19 @@ function platform._interpreter()
assert(interp)
-- define apis
- interp:api_define
+ interp:api_define(platform._apis())
+
+ -- save interpreter
+ platform._INTERPRETER = interp
+
+ -- ok?
+ return interp
+end
+
+-- get platform apis
+function platform._apis()
+
+ return
{
values =
{
@@ -188,7 +191,6 @@ function platform._interpreter()
{
-- platform.on_xxx
"platform.on_load"
- , "platform.on_check" -- TODO removed
, "platform.on_config_check"
, "platform.on_global_check"
, "platform.on_environment_enter"
@@ -201,12 +203,32 @@ function platform._interpreter()
, "platform.set_formats"
}
}
+end
- -- save interpreter
- platform._INTERPRETER = interp
+-- get platform directories
+function platform.directories()
- -- ok?
- return interp
+ -- init directories
+ local dirs = platform._DIRS or { path.join(global.directory(), "platforms")
+ , path.join(os.programdir(), "platforms")
+ }
+
+ -- save directories to cache
+ platform._DIRS = dirs
+ return dirs
+end
+
+-- add platform directories
+function platform.add_directories(...)
+
+ -- add directories
+ local dirs = platform.directories()
+ for _, dir in ipairs({...}) do
+ table.insert(dirs, 1, dir)
+ end
+
+ -- remove unique directories
+ platform._DIRS = table.unique(dirs)
end
-- load the given platform
@@ -226,7 +248,7 @@ function platform.load(plat)
-- find the platform script path
local scriptpath = nil
- for _, dir in ipairs(platform._directories()) do
+ for _, dir in ipairs(platform.directories()) do
-- find this directory
scriptpath = path.join(dir, plat, "xmake.lua")
@@ -346,7 +368,7 @@ function platform.plats()
-- get all platforms
local plats = {}
- local dirs = platform._directories()
+ local dirs = platform.directories()
for _, dir in ipairs(dirs) do
-- get the platform list
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index f830a27e2..1ed4a9f4f 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -161,6 +161,11 @@ function project._api_add_packagedirs(interp, ...)
interp:api_builtin_includes(pkgdirs)
end
+-- add platform directories
+function project._api_add_platformdirs(interp, ...)
+ platform.add_directories(...)
+end
+
-- get interpreter
function project.interpreter()
@@ -233,6 +238,7 @@ function project.interpreter()
, {"add_moduledirs", project._api_add_moduledirs }
, {"add_plugindirs", project._api_add_plugindirs }
, {"add_packagedirs", project._api_add_packagedirs }
+ , {"add_platformdirs", project._api_add_platformdirs }
}
}
diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua
index e9a806c68..ed33f0e57 100644
--- a/xmake/modules/detect/sdks/find_xcode.lua
+++ b/xmake/modules/detect/sdks/find_xcode.lua
@@ -29,7 +29,7 @@ import("core.base.global")
import("core.project.config")
import("lib.detect.find_directory")
--- find vscode directory
+-- find xcode directory
function _find_sdkdir(sdkdir)
if sdkdir and os.isdir(sdkdir) then
return sdkdir
@@ -37,14 +37,12 @@ function _find_sdkdir(sdkdir)
return find_directory("Xcode.app", {"/Applications"}) or find_directory("Xcode*.app", {"/Applications"})
end
--- find the sdk version of vscode
+-- find the sdk version of xcode
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 plat == "iphoneos" then
if arch == "i386" or arch == "x86_64" then
platsdkdir = "Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator*.*.sdk"
else
@@ -56,6 +54,8 @@ function _find_xcode_sdkver(sdkdir, plat, arch)
else
platsdkdir = "Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS*.*.sdk"
end
+ else
+ platsdkdir = "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX*.*.sdk"
end
-- attempt to find the platform directory and get sdk version
@@ -67,10 +67,10 @@ function _find_xcode_sdkver(sdkdir, plat, arch)
end
end
--- find the vscode toolchain
-function _find_vscode(sdkdir, xcode_sdkver, plat, arch)
+-- find the xcode toolchain
+function _find_xcode(sdkdir, xcode_sdkver, plat, arch)
- -- find vscode root directory
+ -- find xcode root directory
sdkdir = _find_sdkdir(sdkdir)
if not sdkdir then
return {}
@@ -96,7 +96,7 @@ end
--
-- @code
--
--- local toolchain = find_vscode("/Applications/Xcode.app")
+-- local toolchain = find_xcode("/Applications/Xcode.app")
--
-- @endcode
--
@@ -106,7 +106,7 @@ function main(sdkdir, opt)
opt = opt or {}
-- attempt to load cache first
- local key = "detect.sdks.find_vscode"
+ local key = "detect.sdks.find_xcode"
local cacheinfo = cache.load(key)
if not opt.force and cacheinfo.xcode and cacheinfo.xcode.sdkdir and os.isdir(cacheinfo.xcode.sdkdir) then
return cacheinfo.xcode
@@ -117,7 +117,7 @@ function main(sdkdir, opt)
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") or config.get("sdk"), opt.sdkver or config.get("xcode_sdkver"), plat, arch)
+ local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode") or config.get("sdk"), opt.sdkver or config.get("xcode_sdkver"), plat, arch)
if xcode and xcode.sdkdir then
-- save to config
@@ -133,7 +133,7 @@ function main(sdkdir, opt)
-- trace
if opt.verbose or option.get("verbose") then
- cprint("checking for the xcode directory ... ${red}no")
+ cprint("checking for the Xcode directory ... ${red}no")
end
end