diff options
| author | ruki <[email protected]> | 2017-05-26 10:00:43 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-26 10:00:43 +0800 |
| commit | 7d0b8226faf9a4dfc67ded97c4d46e774c2d3ad2 (patch) | |
| tree | a8331eabf3db8fca5760c6bb5c67729a0fee92f8 | |
| parent | 27887740f2be1e2381511632a44b16f2dcddbc49 (diff) | |
improve match pattern for xxx_script
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | tests/apis/xxx_script/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 5 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 5 |
4 files changed, 12 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c22c172a..58601a05e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ * Improve `print` interface to dump table * [#111](https://github.com/tboox/xmake/issues/111): Add `--root` common option to allow run xmake command as root * [#113](https://github.com/tboox/xmake/pull/113): Privilege manage when running as root, store the root privilege and degrade. -* Improve `xxx_script` in `xmake.lua` to support pattern match, .e.g `on_build("macosx|.*", function (target) end)` +* Improve `xxx_script` in `xmake.lua` to support pattern match, .e.g `on_build("iphoneos|arm*", function (target) end)` ### Bugs fixed @@ -312,7 +312,7 @@ * 改进`print`接口去更好些显示table数据 * [#111](https://github.com/tboox/xmake/issues/111): 添加`--root`通用选项去临时支持作为root运行 * [#113](https://github.com/tboox/xmake/pull/113): 改进权限管理,现在作为root运行也是非常安全的 -* 改进`xxx_script`工程描述api,支持多平台模式选择, 例如:`on_build("macosx|.*", function (target) end)` +* 改进`xxx_script`工程描述api,支持多平台模式选择, 例如:`on_build("iphoneos|arm*", function (target) end)` ### Bugs修复 diff --git a/tests/apis/xxx_script/xmake.lua b/tests/apis/xxx_script/xmake.lua index d522b11fb..84f41c225 100644 --- a/tests/apis/xxx_script/xmake.lua +++ b/tests/apis/xxx_script/xmake.lua @@ -5,7 +5,7 @@ target("test") assert(vformat("$(arch)") == "arm64") end) - before_build("macosx|.*", function (target) + before_build("macosx", function (target) assert(vformat("$(plat)") == "macosx") end) @@ -21,6 +21,6 @@ target("test") print("after_build") end) - after_build("linux|.*", function (target) + after_build("linux|*", function (target) assert(vformat("$(plat)") == "linux") end) diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 746347f32..a22c35ed6 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -280,6 +280,11 @@ function interpreter:_api_register_xxx_script(scope_kind, action, ...) os.raise("%s_%s(%s, %s): %s", action, name, tostring(arg1), tostring(arg2), errors) end + -- convert pattern to a lua pattern ('*' => '.*') + pattern = pattern:gsub("([%+%.%-%^%$%(%)%%])", "%%%1") + pattern = pattern:gsub("%*", "\001") + pattern = pattern:gsub("\001", ".*") + -- save script local scripts = scope[name] or {} if type(scripts) == "table" then diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 4edf0f6d1..cd794cb90 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -641,9 +641,10 @@ function target:script(name, generic) elseif type(script) == "table" then -- match script for special plat and arch - local pattern = (config.get("plat") or "") .. '|' .. (config.get("arch") or "") + local plat = (config.get("plat") or "") + local pattern = plat .. '|' .. (config.get("arch") or "") for _pattern, _script in pairs(script) do - if not _pattern:startswith("__") and pattern:find('^' .. _pattern .. '$') then + if not _pattern:startswith("__") and (plat == _pattern or pattern:find('^' .. _pattern .. '$')) then return _script end end |
