summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-04-26 14:41:59 +0800
committerruki <[email protected]>2017-04-26 14:41:59 +0800
commit6346af0f672353eedc5c3a6efe4ed3d5a0a52e5a (patch)
treec533a03262179392ee8d10f9ec83964812a55d71
parent38a85e0cfac525962e347174fb16080fc447664c (diff)
fix os.host and add is_host
-rw-r--r--CHANGELOG.md4
-rw-r--r--docs/manual.md43
-rwxr-xr-xdocs/zh/manual.md30
-rw-r--r--xmake/core/project/project.lua16
-rw-r--r--xmake/core/sandbox/modules/interpreter/os.lua23
-rw-r--r--xmake/core/sandbox/modules/os.lua6
6 files changed, 100 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0365c7c94..9f80d0323 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
### New features
* [#68](https://github.com/tboox/xmake/issues/68): Add `$(programdir)` and `$(xmake)` builtin variables
+* add `is_host` api to get current host operating system
### Changes
@@ -18,6 +19,7 @@
* [#67](https://github.com/tboox/xmake/issues/67): Fix `sudo make install` permission problem
* [#70](https://github.com/tboox/xmake/issues/70): Fix check android compiler error
* Fix temporary file path conflict
+* Fix `os.host` and `os.arch` interfaces
## v2.1.3
@@ -266,6 +268,7 @@
### 新特性
* [#68](https://github.com/tboox/xmake/issues/68): 天剑`$(programdir)`和`$(xmake)`内建变量
+* 添加`is_host`接口去判断当前的主机环境
### 改进
@@ -279,6 +282,7 @@
* [#67](https://github.com/tboox/xmake/issues/67): 修复 `sudo make install` 命令权限问题
* [#70](https://github.com/tboox/xmake/issues/70): 修复检测android编译器错误
* 修复临时文件路径冲突问题
+* 修复`os.host`, `os.arch`等接口
## v2.1.3
diff --git a/docs/manual.md b/docs/manual.md
index 803eb0283..aed9bdfef 100644
--- a/docs/manual.md
+++ b/docs/manual.md
@@ -28,18 +28,19 @@ It's according to the following rules:
Conditions are generally used to handle some special compilation platforms.
-| 接口 | 描述 | 支持版本 |
-| ------------------------- | ---------------------------------------- | -------- |
-| [is_os](#is_os) | Is the current compilation system? | >= 2.0.1 |
-| [is_arch](#is_arch) | Is the current compilation architecture? | >= 2.0.1 |
-| [is_plat](#is_plat) | Is the current compilation platform? | >= 2.0.1 |
-| [is_mode](#is_mode) | Is the current compilation mode? | >= 2.0.1 |
-| [is_kind](#is_kind) | Is the current target kind? | >= 2.0.1 |
-| [is_option](#is_option) | Is the given options enabled? | >= 2.0.1 |
+| 接口 | 描述 | 支持版本 |
+| ------------------------- | ---------------------------------------- | -------- |
+| [is_os](#is_os) | Is the current compilation target system? | >= 2.0.1 |
+| [is_arch](#is_arch) | Is the current compilation architecture? | >= 2.0.1 |
+| [is_plat](#is_plat) | Is the current compilation platform? | >= 2.0.1 |
+| [is_host](#is_host) | Is the current compilation host system? | >= 2.1.4 |
+| [is_mode](#is_mode) | Is the current compilation mode? | >= 2.0.1 |
+| [is_kind](#is_kind) | Is the current target kind? | >= 2.0.1 |
+| [is_option](#is_option) | Is the given options enabled? | >= 2.0.1 |
##### is_os
-###### Is the current compilation system
+###### Is the current compilation target system
```lua
if is_os("ios") then
@@ -110,6 +111,30 @@ Support platforms:
* iphoneos
* watchos
+##### is_host
+
+###### Is the current compilation host system
+
+Some compilation platforms can be built on multiple different operating systems, for example: android ndk (on linux, macOS and windows).
+
+So, we can use this api to determine the current host operating system.
+
+```lua
+if is_host("windows") then
+ add_includes("C:\\includes")
+else
+ add_includes("/usr/includess")
+end
+```
+
+Support hosts:
+
+* windows
+* linux
+* macosx
+
+We can also get it from [$(host)](#var-host) or [os.host](#os-host).
+
##### is_mode
###### Is the current compilation mode
diff --git a/docs/zh/manual.md b/docs/zh/manual.md
index d7a4d9b7d..63c6f7f0d 100755
--- a/docs/zh/manual.md
+++ b/docs/zh/manual.md
@@ -30,16 +30,17 @@ search: zh
| 接口 | 描述 | 支持版本 |
| ------------------------- | ----------------------------- | -------- |
-| [is_os](#is_os) | 判断当前构建的操作系统 | >= 2.0.1 |
+| [is_os](#is_os) | 判断当前构建目标的操作系统 | >= 2.0.1 |
| [is_arch](#is_arch) | 判断当前编译架构 | >= 2.0.1 |
| [is_plat](#is_plat) | 判断当前编译平台 | >= 2.0.1 |
+| [is_host](#is_host) | 判断当前主机环境操作系统 | >= 2.1.4 |
| [is_mode](#is_mode) | 判断当前编译模式 | >= 2.0.1 |
| [is_kind](#is_kind) | 判断当前编译类型 | >= 2.0.1 |
| [is_option](#is_option) | 判断选项是否启用 | >= 2.0.1 |
##### is_os
-###### 判断当前构建的操作系统
+###### 判断当前构建目标的操作系统
```lua
-- 如果当前操作系统是ios
@@ -115,6 +116,31 @@ end
当然你也可以自己扩展添加自己的平台。。。
+##### is_host
+
+###### 判断当前主机环境的操作系统
+
+有些编译平台是可以在多个不同的操作系统进行构建的,例如:android的ndk就支持linux,macOS还有windows环境。
+
+这个时候就可以通过这个接口,区分当前是在哪个系统环境下进行的构建。
+
+```lua
+-- 如果当前主机环境是windows
+if is_host("windows") then
+ add_includes("C:\\includes")
+else
+ add_includes("/usr/includess")
+end
+```
+
+目前支持的主机环境有:
+
+* windows
+* linux
+* macosx
+
+你也可以通过[$(host)](#var-host)内置变量或者[os.host](#os-host)接口,来进行获取
+
##### is_mode
###### 判断当前编译模式
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index e9ac7399e..d0434a3b1 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -120,6 +120,21 @@ function project._api_is_kind(interp, ...)
end
end
+-- the current host is belong to the given hosts?
+function project._api_is_host(interp, ...)
+
+ -- get the current host
+ local host = xmake._HOST
+ if not host then return false end
+
+ -- exists this host? and escape '-'
+ for _, h in ipairs(table.join(...)) do
+ if h and type(h) == "string" and host:find(h:gsub("%-", "%%-")) then
+ return true
+ end
+ end
+end
+
-- enable options?
function project._api_is_option(interp, ...)
@@ -259,6 +274,7 @@ function project._interpreter()
-- is_xxx
{"is_os", project._api_is_os }
, {"is_kind", project._api_is_kind }
+ , {"is_host", project._api_is_host }
, {"is_mode", project._api_is_mode }
, {"is_plat", project._api_is_plat }
, {"is_arch", project._api_is_arch }
diff --git a/xmake/core/sandbox/modules/interpreter/os.lua b/xmake/core/sandbox/modules/interpreter/os.lua
index eebaed102..b11e6bcb4 100644
--- a/xmake/core/sandbox/modules/interpreter/os.lua
+++ b/xmake/core/sandbox/modules/interpreter/os.lua
@@ -35,9 +35,7 @@ sandbox_os.time = os.time
sandbox_os.mtime = os.mtime
sandbox_os.mclock = os.mclock
sandbox_os.getenv = os.getenv
-sandbox_os.dirs = os.dirs
-sandbox_os.host = os.host
-sandbox_os.arch = os.arch
+sandbox_os.isdir = os.isdir
sandbox_os.isfile = os.isfile
sandbox_os.exists = os.exists
sandbox_os.curdir = os.curdir
@@ -46,12 +44,27 @@ sandbox_os.uuid = os.uuid
-- match files
function sandbox_os.files(pattern, ...)
- return os.match(string.format(pattern, ...))
+ return os.files(string.format(pattern, ...))
end
-- match directories
function sandbox_os.dirs(pattern, ...)
- return os.match(string.format(pattern, ...), true)
+ return os.dirs(string.format(pattern, ...))
+end
+
+-- match file and directories
+function sandbox_os.filedirs(pattern, ...)
+ return os.filedirs(string.format(pattern, ...))
+end
+
+-- get the system host
+function sandbox_os.host()
+ return xmake._HOST
+end
+
+-- get the system architecture
+function sandbox_os.arch()
+ return xmake._ARCH
end
-- return module
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index b0c7741b9..4fbc1740b 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -397,22 +397,16 @@ end
-- get the system host
function sandbox_os.host()
-
- -- get it
return xmake._HOST
end
-- get the system architecture
function sandbox_os.arch()
-
- -- get it
return xmake._ARCH
end
-- get the system null device
function sandbox_os.nuldev()
-
- -- get it
return xmake._NULDEV
end