diff options
| author | ruki <[email protected]> | 2018-12-15 00:41:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-12-14 22:09:54 +0800 |
| commit | 95f46b973794b37ccd62edbcc3bfb010b0f23dcc (patch) | |
| tree | abbd878e0e78c0511c7da072ad43b70f03eeea47 | |
| parent | 107f81a48da61d37ecbffac4e2f816b9cfedb21c (diff) | |
improve interpreter
| -rw-r--r-- | xmake/core/base/interpreter.lua | 17 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 10 | ||||
| -rw-r--r-- | xmake/core/language/language.lua | 11 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 13 | ||||
| -rw-r--r-- | xmake/core/package/repository.lua | 13 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 11 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 8 | ||||
| -rw-r--r-- | xmake/core/project/rule.lua | 8 | ||||
| -rw-r--r-- | xmake/core/project/template.lua | 8 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_package.lua | 6 |
10 files changed, 85 insertions, 20 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 9c2d35450..d45640064 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -662,8 +662,8 @@ function interpreter.new() return instance end --- load results -function interpreter:load(file, scope_kind, remove_repeat, enable_filter) +-- load script file, e.g. xmake.lua +function interpreter:load(file) -- check assert(self and self._PUBLIC and self._PRIVATE and file) @@ -691,18 +691,17 @@ function interpreter:load(file, scope_kind, remove_repeat, enable_filter) setfenv(script, self._PUBLIC) -- do interpreter - local ok, errors = xpcall(script, interpreter._traceback) - if not ok then - return nil, errors - end + return xpcall(script, interpreter._traceback) +end - -- make results +-- make results +function interpreter:make(scope_kind, remove_repeat, enable_filter) + + -- get the results with the given scope local ok, results = xpcall(interpreter._make, interpreter._traceback, self, scope_kind, remove_repeat, enable_filter) if not ok then return nil, results end - - -- ok return results end diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index b2b5b25a0..d42609756 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -317,9 +317,15 @@ function task._load(filepath) local interp = task._interpreter() assert(interp) + -- load script + local ok, errors = interp:load(filepath) + if not ok and os.isfile(filepath) then + return nil, errors + end + -- load tasks - local tasks, errors = interp:load(filepath, "task", true, true) - if not tasks and os.isfile(filepath) then + local tasks, errors = interp:make("task", true, true) + if not tasks then return nil, errors end diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index b1f8fcc24..f06bc94bd 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -293,8 +293,17 @@ function language.load(name) return nil, string.format("the language %s not found!", name) end + -- get interpreter + local interp = language._interpreter() + + -- load script + local ok, errors = interp:load(scriptpath) + if not ok then + return nil, errors + end + -- load language - local results, errors = language._interpreter():load(scriptpath, "language", true, false) + local results, errors = interp:make("language", true, false) if not results and os.isfile(scriptpath) then return nil, errors end diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index e5e36ce4f..e3a9e95dd 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -873,9 +873,18 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile return nil, string.format("the package %s not found!", packagename) end + -- get interpreter + local interp = package._interpreter() + + -- load script + local ok, errors = interp:load(scriptpath) + if not ok then + return nil, errors + end + -- load package and disable filter, we will process filter after a while - local results, errors = package._interpreter():load(scriptpath, "package", true, false) - if not results and os.isfile(scriptpath) then + local results, errors = interp:make("package", true, false) + if not results then return nil, errors end diff --git a/xmake/core/package/repository.lua b/xmake/core/package/repository.lua index 34bb1adec..57145c3b4 100644 --- a/xmake/core/package/repository.lua +++ b/xmake/core/package/repository.lua @@ -99,9 +99,18 @@ function _instance:load() local scriptpath = path.join(self:directory(), "xmake.lua") if os.isfile(scriptpath) then + -- get interpreter + local interp = repository._interpreter() + + -- load script + local ok, errors = interp:load(scriptpath) + if not ok then + os.raise("load repo(%s) failed, " .. errors, self:name()) + end + -- load repository and disable filter - local results, errors = repository._interpreter():load(scriptpath, nil, true, false) - if not results and os.isfile(scriptpath) then + local results, errors = interp:make(nil, true, false) + if not results then os.raise("load repo(%s) failed, " .. errors, self:name()) end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 88770c1ce..fbb4dd299 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -209,8 +209,17 @@ function platform.load(plat) return nil, string.format("the platform %s not found!", plat) end + -- get interpreter + local interp = platform._interpreter() + + -- load script + local ok, errors = interp:load(scriptpath) + if not ok then + return nil, errors + end + -- load platform - local results, errors = platform._interpreter():load(scriptpath, "platform", true, false) + local results, errors = interp:make("platform", true, false) if not results and os.isfile(scriptpath) then return nil, errors end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 5c9eeb9dc..9dcc39426 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -357,8 +357,14 @@ function project._load_scope(scope_kind, remove_repeat, enable_filter) return nil, errors end + -- load script + local ok, errors = interp:load(project.file()) + if not ok then + return nil, errors + end + -- load targets - local results, errors = interp:load(project.file(), scope_kind, remove_repeat, enable_filter) + local results, errors = interp:make(scope_kind, remove_repeat, enable_filter) if not results then return nil, (errors or "load project file failed!") end diff --git a/xmake/core/project/rule.lua b/xmake/core/project/rule.lua index 5945d91ca..ac86639a0 100644 --- a/xmake/core/project/rule.lua +++ b/xmake/core/project/rule.lua @@ -109,8 +109,14 @@ function rule._load(filepath) local interp = rule._interpreter() assert(interp) + -- load script + local ok, errors = interp:load(filepath) + if not ok then + return nil, errors + end + -- load rules - local results, errors = interp:load(filepath, "rule", true, true) + local results, errors = interp:make("rule", true, true) if not results then return nil, errors end diff --git a/xmake/core/project/template.lua b/xmake/core/project/template.lua index c21e5c869..bd140a024 100644 --- a/xmake/core/project/template.lua +++ b/xmake/core/project/template.lua @@ -144,8 +144,14 @@ function template.templates(language) -- load template for _, templatefile in ipairs(templatefiles) do + -- load script + local ok, errors = interp:load(templatefile) + if not ok then + os.raise(errors) + end + -- load templates - local results, errors = interp:load(templatefile, nil, true, true) + local results, errors = interp:make(nil, true, true) if not results then -- trace os.raise(errors) diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua index 9af33f322..54593f1be 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -81,6 +81,12 @@ function sandbox_lib_detect_find_package._find_from_packagedirs(name, opt) return maps[variable] end) + -- load script + local ok, errors = interp:load(packagefile) + if not ok then + raise(errors) + end + -- load the package from the the package file local packageinfos, errors = interp:load(packagefile, "option", true, true) if not packageinfos then |
