summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-07-19 09:08:50 +0800
committerruki <[email protected]>2016-07-19 09:08:50 +0800
commitfde422332753177ad7e7f17b602f617d222a3864 (patch)
tree6def78efa8e75146388aacd385de659f5658ce81
parent74568d17141a9bedfa2c0db9d40fa6f3bd38c6ee (diff)
add native shell support for xmake.lua
-rw-r--r--CHANGELOG.md8
-rw-r--r--xmake/core/base/filter.lua39
2 files changed, 47 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index abf59a6dc..d4ab9616b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## master (unreleased)
+### New features
+
+* Add native shell support for `xmake.lua`. .e.g `add_ldflags("$(shell pkg-config --libs sqlite3)")`
+
## v2.0.3
### New features
@@ -125,6 +129,10 @@
## master (������)
+### ������
+
+* ��`xmake.lua`������ԭ��shell֧�֣����磺`add_ldflags("$(shell pkg-config --libs sqlite3)")`
+
## v2.0.3
### ������
diff --git a/xmake/core/base/filter.lua b/xmake/core/base/filter.lua
index c367096e4..5fc9cbed4 100644
--- a/xmake/core/base/filter.lua
+++ b/xmake/core/base/filter.lua
@@ -42,7 +42,41 @@ function filter.new(handler)
return self
end
+-- filter the shell command
+--
+-- .e.g
+--
+-- print("$(shell echo hello xmake)")
+-- add_ldflags("$(shell pkg-config --libs sqlite3)")
+--
+function filter.shell(cmd)
+
+ -- empty?
+ if #cmd == 0 then
+ os.raise("empty $(shell)!")
+ end
+
+ -- run shell
+ local ok, outdata, errdata = os.iorun(cmd)
+ if not ok then
+ os.raise("run $(shell %s) failed, errors: %s", cmd, errdata or "")
+ end
+
+ -- trim it
+ if outdata then
+ outdata = outdata:trim()
+ end
+
+ -- return the shell result
+ return outdata or ""
+end
+
-- filter the builtin variables: "hello $(variable)" for string
+--
+-- .e.g
+--
+-- print("$(host)")
+--
function filter:handle(value)
-- check
@@ -59,6 +93,11 @@ function filter:handle(value)
-- check
assert(variable)
+
+ -- is shell?
+ if variable:startswith("shell ") then
+ return filter.shell(variable:sub(7, -1))
+ end
-- is upper?
local isupper = false