summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTitanSnow <[email protected]>2017-05-25 11:17:46 +0800
committerTitanSnow <[email protected]>2017-05-25 11:17:46 +0800
commitabb1d5705ecd01d906f63c7d838b73b7c2d1ede6 (patch)
tree6873180d5756c809117dc5c9f8f594aba56af435
parentbbed6a5a8a80437afbb57540d77418084aabd950 (diff)
parent3768a8200a7699e1531c07ee5ab490e7d4f27b11 (diff)
Merge branch 'dev' into installtest
-rw-r--r--CHANGELOG.md2
-rw-r--r--tests/build.lua4
-rw-r--r--xmake/core/base/filter.lua83
-rw-r--r--xmake/core/base/interpreter.lua53
-rw-r--r--xmake/core/project/project.lua5
-rw-r--r--xmake/core/project/task.lua5
-rw-r--r--xmake/core/project/template.lua5
-rw-r--r--xmake/modules/privilege/sudo.lua16
8 files changed, 107 insertions, 66 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 02e4999ba..ebb9d07ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@
### Bugs fixed
* Fix `try-catch-finally`
+* Fix interpreter bug when parsing multi-level subdirs
## v2.1.4
@@ -313,6 +314,7 @@
### Bugs修复
* 修复`try-catch-finally`
+* 修复解释器bug,解决当加载多级子目录时,根域属性设置不对
## v2.1.4
diff --git a/tests/build.lua b/tests/build.lua
index 667b29e99..763ebc3a9 100644
--- a/tests/build.lua
+++ b/tests/build.lua
@@ -23,13 +23,13 @@ function main(argv)
os.exec("xmake m -l")
os.exec("xmake f --cc=gcc --cxx=g++")
os.exec("xmake m buildtest")
- if os.host() ~= "windows" then
+ if sudo.has() then
sudo.exec("xmake install")
sudo.exec("xmake uninstall")
end
os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace")
os.exec("xmake m buildtest")
- if os.host() ~= "windows" then
+ if sudo.has() then
sudo.exec("xmake install --all -v --backtrace")
sudo.exec("xmake uninstall -v --backtrace")
end
diff --git a/xmake/core/base/filter.lua b/xmake/core/base/filter.lua
index 19f502ffd..bd998cfb4 100644
--- a/xmake/core/base/filter.lua
+++ b/xmake/core/base/filter.lua
@@ -32,13 +32,13 @@ local utils = require("base/utils")
local string = require("base/string")
-- new filter instance
-function filter.new(handler)
+function filter.new()
-- init an filter instance
local self = table.inherit(filter)
- -- save handler
- self._HANDLER = handler
+ -- init handler
+ self._HANDLERS = {}
-- ok
return self
@@ -73,6 +73,13 @@ function filter.shell(cmd)
return outdata or ""
end
+-- register handler
+function filter:register(name, handler)
+
+ -- set handler
+ self._HANDLERS[name] = handler
+end
+
-- filter the builtin variables: "hello $(variable)" for string
--
-- .e.g
@@ -84,48 +91,50 @@ function filter:handle(value)
-- check
assert(type(value) == "string")
- -- return it directly if no handler
- local handler = self._HANDLER
- if handler == nil then
- return value
- end
+ -- filter value for all handlers
+ local count = 0
+ for name, handler in pairs(self._HANDLERS) do
- -- filter the builtin variables
- return (value:gsub("%$%((.-)%)", function (variable)
+ -- filter the builtin variables
+ value, count = value:gsub("%$%((.-)%)", function (variable)
- -- check
- assert(variable)
+ -- check
+ assert(variable)
- -- is shell?
- if variable:startswith("shell ") then
- return filter.shell(variable:sub(7, -1))
- end
+ -- is shell?
+ if variable:startswith("shell ") then
+ return filter.shell(variable:sub(7, -1))
+ end
- -- parse variable:mode
- local varmode = variable:split(':')
- local mode = varmode[2]
- variable = varmode[1]
-
- -- handler it
- local result = handler(variable)
+ -- parse variable:mode
+ local varmode = variable:split(':')
+ local mode = varmode[2]
+ variable = varmode[1]
+
+ -- handler it
+ local result = handler(variable)
- -- invalid builtin variable?
- if result == nil then
- os.raise("invalid variable: $(%s)", variable)
- end
-
- -- handle mode
- if mode then
- if mode == "upper" then
- result = result:upper()
- elseif mode == "lower" then
- result = result:lower()
+ -- handle mode
+ if mode then
+ if mode == "upper" then
+ result = result:upper()
+ elseif mode == "lower" then
+ result = result:lower()
+ end
end
+
+ -- ok?
+ return result
+ end)
+
+ -- end?
+ if count == 0 then
+ break
end
+ end
- -- ok?
- return result
- end))
+ -- return old value
+ return value
end
-- return module: filter
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index fdb8fbaa0..48af94dd7 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -96,7 +96,7 @@ function interpreter._merge_root_scope(root, root_prev, override)
local scope_kind = scope_kind_and_name[1]
local scope_name = scope_kind_and_name[2]
local scope_values = root_prev[scope_kind .. "." .. scope_name] or {}
- local scope_root = root[scope_kind] or {}
+ local scope_root = root[scope_kind .. "." .. scope_name] or {}
for name, values in pairs(scope_root) do
if not name:startswith("__") then
if scope_root["__override_" .. name] then
@@ -116,6 +116,36 @@ function interpreter._merge_root_scope(root, root_prev, override)
return root_prev
end
+-- fetch the root values to the child values in root scope
+-- and we will only use the child values if be override mode
+function interpreter._fetch_root_scope(root)
+
+ -- fetch it
+ for scope_kind_and_name, _ in pairs(root or {}) do
+
+ -- is scope_kind.scope_name?
+ scope_kind_and_name = scope_kind_and_name:split('%.')
+ if #scope_kind_and_name == 2 then
+ local scope_kind = scope_kind_and_name[1]
+ local scope_name = scope_kind_and_name[2]
+ local scope_values = root[scope_kind .. "." .. scope_name] or {}
+ local scope_root = root[scope_kind] or {}
+ for name, values in pairs(scope_root) do
+ if not name:startswith("__") then
+ if scope_root["__override_" .. name] then
+ if scope_values[name] == nil then
+ scope_values[name] = values
+ end
+ else
+ scope_values[name] = table.join(values, scope_values[name] or {})
+ end
+ end
+ end
+ root[scope_kind .. "." .. scope_name] = scope_values
+ end
+ end
+end
+
-- register scope end: scopename_end()
function interpreter:_api_register_scope_end(...)
@@ -342,6 +372,9 @@ function interpreter:_api_builtin_add_subdirfiles(isdirs, ...)
-- restore the previous scope
scopes._CURRENT = scope_prev
+ -- fetch the root values in root scopes first
+ interpreter._fetch_root_scope(scopes._ROOT)
+
-- restore the previous root scope and merge current root scope
-- it will override the previous values if the current values are override mode
-- so we priority use the values in subdirs scope
@@ -503,9 +536,8 @@ function interpreter:_make(scope_kind, remove_repeat, enable_filter)
return {}
end
- -- merge root scope first and do not override the root values if be override mode
- -- so we priority use the values in subdirs scope
- scopes._ROOT = interpreter._merge_root_scope(scopes._ROOT, scopes._ROOT, false)
+ -- fetch the root values in root scope first
+ interpreter._fetch_root_scope(scopes._ROOT)
-- merge results
for scope_name, scope in pairs(scope_for_kind) do
@@ -547,7 +579,8 @@ function interpreter.new()
-- init an interpreter instance
local instance = { _PUBLIC = {}
, _PRIVATE = { _SCOPES = {}
- , _MTIMES = {}}}
+ , _MTIMES = {}
+ , _FILTER = require("base/filter").new()}}
-- inherit the interfaces of interpreter
table.inherit2(instance, interpreter)
@@ -673,16 +706,6 @@ function interpreter:filter()
return self._PRIVATE._FILTER
end
--- set filter
-function interpreter:filter_set(filter)
-
- -- check
- assert(self and self._PRIVATE)
-
- -- set it
- self._PRIVATE._FILTER = filter
-end
-
-- get root directory
function interpreter:rootdir()
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 191e53871..76f70db40 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -31,7 +31,6 @@ local io = require("base/io")
local path = require("base/path")
local utils = require("base/utils")
local table = require("base/table")
-local filter = require("base/filter")
local deprecated = require("base/deprecated")
local interpreter = require("base/interpreter")
local target = require("project/target")
@@ -292,7 +291,7 @@ function project._interpreter()
deprecated_project.api_register(interp)
-- set filter
- interp:filter_set(filter.new(function (variable)
+ interp:filter():register("project", function (variable)
-- check
assert(variable)
@@ -338,7 +337,7 @@ function project._interpreter()
-- ok?
return result
- end))
+ end)
-- save interpreter
project._INTERPRETER = interp
diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua
index a162d84e4..08097ded6 100644
--- a/xmake/core/project/task.lua
+++ b/xmake/core/project/task.lua
@@ -29,7 +29,6 @@ local task = task or {}
local os = require("base/os")
local table = require("base/table")
local utils = require("base/utils")
-local filter = require("base/filter")
local string = require("base/string")
local interpreter = require("base/interpreter")
local sandbox = require("sandbox/sandbox")
@@ -183,7 +182,7 @@ function task._interpreter()
}
-- set filter
- interp:filter_set(filter.new(function (variable)
+ interp:filter():register("task", function (variable)
-- check
assert(variable)
@@ -212,7 +211,7 @@ function task._interpreter()
-- ok?
return result
- end))
+ end)
-- save interpreter
task._INTERPRETER = interp
diff --git a/xmake/core/project/template.lua b/xmake/core/project/template.lua
index 91ce420bc..6c61931f9 100644
--- a/xmake/core/project/template.lua
+++ b/xmake/core/project/template.lua
@@ -32,7 +32,6 @@ local path = require("base/path")
local table = require("base/table")
local utils = require("base/utils")
local string = require("base/string")
-local filter = require("base/filter")
local option = require("base/option")
local sandbox = require("sandbox/sandbox")
local project = require("project/project")
@@ -192,7 +191,7 @@ function template.create(language, templateid, targetname)
local projectdir = path.absolute(option.get("project") or path.join(os.curdir(), targetname))
-- set filter
- interp:filter_set(filter.new(function (variable)
+ interp:filter():register("template", function (variable)
-- init maps
local maps =
@@ -210,7 +209,7 @@ function template.create(language, templateid, targetname)
-- ok?
return variable
- end))
+ end)
-- load all templates for the given language
local templates = template.templates(language)
diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua
index d2e2de2cf..4eb5f6538 100644
--- a/xmake/modules/privilege/sudo.lua
+++ b/xmake/modules/privilege/sudo.lua
@@ -37,9 +37,19 @@ function _sudo(runner, cmd, ...)
local program = find_sudo()
assert(program, "sudo not found!")
- -- FIXME: deal with quotes in `os.getenv("PATH")`
- -- run it with administrator permission and preserve parent environment
- runner(program .. " env PATH=\"" .. os.getenv("PATH") .. "\" " .. cmd, ...)
+ -- get current path environment
+ local pathenv = os.getenv("PATH")
+ if pathenv and #pathenv > 0 then
+
+ -- handle double quote
+ pathenv = pathenv:gsub("\"", "\\\"")
+
+ -- run it with administrator permission and preserve parent environment
+ runner(program .. " env PATH=\"" .. pathenv .. "\" " .. cmd, ...)
+ else
+ -- run it with administrator permission
+ runner(program .. " " .. cmd, ...)
+ end
end
-- sudo run shell with administrator permission and arguments list