diff options
| author | TitanSnow <[email protected]> | 2017-05-16 12:50:14 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-16 12:50:14 +0800 |
| commit | 37b4a7647163afdd392c7afcc61955244b6117cb (patch) | |
| tree | c81b8cb6f43dd5929e1edc0beb57ab075c965ebc | |
| parent | 3129cd5005814ddd4fba736f127bf7f13809d4b7 (diff) | |
| parent | a7c6ffab557760c2c2adf69e4f646c678f4e3034 (diff) | |
Merge branch 'dev' into command
| -rw-r--r-- | xmake/core/base/interpreter.lua | 6 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import.lua | 39 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_file.lua | 39 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_library.lua | 39 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_path.lua | 39 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_ccache.lua | 39 | ||||
| -rw-r--r-- | xmake/plugins/lua/xmake.lua | 31 |
7 files changed, 210 insertions, 22 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 1f31756a1..fdb8fbaa0 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1084,7 +1084,7 @@ function interpreter:api_register_on_script(scope_kind, ...) script = function (...) -- import it - return import(modulename).main(...) + return import(modulename)(...) end end @@ -1119,7 +1119,7 @@ function interpreter:api_register_before_script(scope_kind, ...) script = function (...) -- import it - return import(modulename).main(...) + return import(modulename)(...) end end @@ -1154,7 +1154,7 @@ function interpreter:api_register_after_script(scope_kind, ...) script = function (...) -- import it - return import(modulename).main(...) + return import(modulename)(...) end end diff --git a/xmake/core/sandbox/modules/import.lua b/xmake/core/sandbox/modules/import.lua index 234e76925..56e517e5b 100644 --- a/xmake/core/sandbox/modules/import.lua +++ b/xmake/core/sandbox/modules/import.lua @@ -31,6 +31,7 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local string = require("base/string") +local global = require("project/global") local sandbox = require("sandbox/sandbox") local raise = require("sandbox/modules/raise") @@ -104,16 +105,11 @@ function sandbox_import._find(dir, name) -- load the single module? local module = nil if os.isfile(path.join(dir, name .. ".lua")) then - - -- ok return true -- load modules elseif os.isdir(path.join(dir, name)) then - - -- ok return true - end -- not found @@ -269,15 +265,31 @@ function sandbox_import.import(name, args) local rootdir = args.rootdir or instance:rootdir() assert(rootdir) + -- the sandbox modules directory + local modules_sandbox_dir = path.join(xmake._CORE_DIR, "sandbox/modules/import") + + -- the extension modules directory + local modules_extension_dir = path.join(xmake._PROGRAM_DIR, "modules") + + -- the global modules directory for users + local modules_global_dir = path.join(global.directory(), "modules") + + -- init module directories + local modules_directories = + { + rootdir -- load module from the given root directory first + , path.join(global.directory(), "modules") -- load module from the user global modules directory + , path.join(xmake._PROGRAM_DIR, "modules") -- load module from the extension modules directory + , path.join(xmake._CORE_DIR, "sandbox/modules/import") -- load module from the sandbox core modules directory + } + -- load module local module = nil local errors = nil - if sandbox_import._find(rootdir, name) then - -- load module from the sandbox root directory - module, errors = sandbox_import._load(rootdir, name, instance) - else - -- load module from the sandbox core directory - module, errors = sandbox_import._load(path.join(xmake._CORE_DIR, "sandbox/modules/import"), name) + for idx, moduledir in ipairs(modules_directories) do + if sandbox_import._find(moduledir, name) then + module, errors = sandbox_import._load(moduledir, name, utils.ifelse(idx < #modules_directories, instance, nil)) -- last modules need not fork sandbox + end end -- check @@ -320,6 +332,11 @@ function sandbox_import.import(name, args) end + -- bind main entry + if module.main then + setmetatable(module, { __call = function (_, ...) return module.main(...) end}) + end + -- import this module into the parent scope scope_parent[imported_name] = module diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua new file mode 100644 index 000000000..ca873ee71 --- /dev/null +++ b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua @@ -0,0 +1,39 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_file.lua +-- + +-- define module +local sandbox_lib_detect_find_file = sandbox_lib_detect_find_file or {} + +-- load modules +local raise = require("sandbox/modules/raise") + +-- find file +function sandbox_lib_detect_find_file.main(...) + + -- TODO + print("find file") +end + +-- return module +return sandbox_lib_detect_find_file diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_library.lua b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua new file mode 100644 index 000000000..e48f75ebe --- /dev/null +++ b/xmake/core/sandbox/modules/import/lib/detect/find_library.lua @@ -0,0 +1,39 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_library.lua +-- + +-- define module +local sandbox_lib_detect_find_library = sandbox_lib_detect_find_library or {} + +-- load modules +local raise = require("sandbox/modules/raise") + +-- find file +function sandbox_lib_detect_find_library.main(...) + + -- TODO + print("find file") +end + +-- return module +return sandbox_lib_detect_find_library diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua new file mode 100644 index 000000000..fe2b4993d --- /dev/null +++ b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua @@ -0,0 +1,39 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_path.lua +-- + +-- define module +local sandbox_lib_detect_find_path = sandbox_lib_detect_find_path or {} + +-- load modules +local raise = require("sandbox/modules/raise") + +-- find file +function sandbox_lib_detect_find_path.main(...) + + -- TODO + print("find path") +end + +-- return module +return sandbox_lib_detect_find_path diff --git a/xmake/modules/lib/detect/find_ccache.lua b/xmake/modules/lib/detect/find_ccache.lua new file mode 100644 index 000000000..66338da2a --- /dev/null +++ b/xmake/modules/lib/detect/find_ccache.lua @@ -0,0 +1,39 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_ccache.lua +-- + +-- imports +import("lib.detect.find_file") + +-- find ccache +-- +-- @param ... detected dirs, files, regs +-- +-- @return {shellname = ... , fullpath = ...} or nil +-- +function main(...) + + -- TODO + print("ccache") + find_file() +end diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua index 3e161cd4c..0b867d966 100644 --- a/xmake/plugins/lua/xmake.lua +++ b/xmake/plugins/lua/xmake.lua @@ -35,7 +35,7 @@ task("lua") import("core.base.option") import("core.sandbox.sandbox") - -- list all scripts? + -- list all lua scripts? if option.get("list") then print("scripts:") local files = os.match(path.join(os.scriptdir(), "scripts/*.lua")) @@ -60,9 +60,18 @@ task("lua") -- import and run script if os.isfile(name) then - import(path.basename(name), {rootdir = path.directory(name)}).main(unpack(option.get("arguments") or {})) + + -- run the given lua script file (xmake lua /tmp/script.lua) + import(path.basename(name), {rootdir = path.directory(name)})(unpack(option.get("arguments") or {})) + + elseif os.isfile(path.join(os.scriptdir(), "scripts", name .. ".lua")) then + + -- run builtin lua script (xmake lua echo "hello xmake") + import("scripts." .. name)(unpack(option.get("arguments") or {})) else - import("scripts." .. name).main(unpack(option.get("arguments") or {})) + + -- run modules (xmake lua core.xxx.xxx) + import(name)(unpack(option.get("arguments") or {})) end else -- enter interactive mode @@ -84,11 +93,17 @@ task("lua") -- options , options = { - {'l', "list", "k", nil, "List all scripts." } - , {nil, "root", "k", nil, "Allow to run script as root." } - , {'c', "command", "kv", nil, "Run command" } - , {nil, "script", "v", nil, "Run the given lua script." } - , {nil, "arguments", "vs", nil, "The script arguments." } + + {'l', "list", "k", nil, "List all scripts." } + , {nil, "root", "k", nil, "Allow to run script as root." } + , {'c', "command", "kv", nil, "Run command" } + , {nil, "script", "v", nil, "Run the given lua script name, file or module and enter interactive mode if no given script.", + ".e.g", + " - xmake lua (enter interactive mode)", + " - xmake lua /tmp/script.lua", + " - xmake lua echo 'hello xmake'", + " - xmake lua core.xxx.xxx" } + , {nil, "arguments", "vs", nil, "The script arguments." } } } |
