diff options
| author | ruki <[email protected]> | 2020-06-30 21:35:01 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-06-30 21:35:01 +0800 |
| commit | 7210ca7ea63dd201cee8d10081fee8f065ec6c44 (patch) | |
| tree | 5037aea812f5fab79a8c2d6c11e351db5ba66143 | |
| parent | 2b80ef232b9a17cde8b144a37eb4f8ea77266900 (diff) | |
| parent | 4c54385b422e3c191b3a2a13d849774132a601a8 (diff) | |
Merge pull request #879 from OpportunityLiu/dev
fix auto complete
| -rw-r--r-- | xmake/actions/build/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/clean/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/config/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/install/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/package/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/run/xmake.lua | 17 | ||||
| -rw-r--r-- | xmake/actions/uninstall/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/config.lua | 35 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 43 | ||||
| -rw-r--r-- | xmake/modules/private/utils/complete_helper.lua | 56 | ||||
| -rw-r--r-- | xmake/plugins/show/main.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/show/xmake.lua | 3 |
12 files changed, 103 insertions, 69 deletions
diff --git a/xmake/actions/build/xmake.lua b/xmake/actions/build/xmake.lua index 8d3b28291..700bb8996 100644 --- a/xmake/actions/build/xmake.lua +++ b/xmake/actions/build/xmake.lua @@ -59,7 +59,7 @@ task("build") , {} , {nil, "target", "v", nil , "The target name. It will build all default targets if this parameter is not specified." - , values = function () return try{ function () return table.keys(import("core.project.project").targets()) end } end } + , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } } } diff --git a/xmake/actions/clean/xmake.lua b/xmake/actions/clean/xmake.lua index 0d9b265c1..2c0213d37 100644 --- a/xmake/actions/clean/xmake.lua +++ b/xmake/actions/clean/xmake.lua @@ -45,7 +45,7 @@ task("clean") , {} , {nil, "target", "v", nil , "The target name. It will clean all default targets if this parameter is not specified." - , values = function () return try{ function () return table.keys(import("core.project.project").targets()) end } end } + , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } } } diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index c53844e5c..2c8bb97c1 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -206,11 +206,7 @@ task("config") , {} , {nil, "target", "v" , nil , "Configure for the given target." - , values = function () - return try { function () - return table.keys(import("core.project.project").targets()) - end } - end } + , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } } } diff --git a/xmake/actions/install/xmake.lua b/xmake/actions/install/xmake.lua index 09ecc883f..3b859238a 100644 --- a/xmake/actions/install/xmake.lua +++ b/xmake/actions/install/xmake.lua @@ -50,7 +50,7 @@ task("install") , { } , {nil, "target", "v", nil , "The target name. It will install all default targets if this parameter is not specified." - , values = function () return try{ function () return table.keys(import("core.project.project").targets()) end } end } + , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } } } diff --git a/xmake/actions/package/xmake.lua b/xmake/actions/package/xmake.lua index 13c3f4b28..d15c3eec1 100644 --- a/xmake/actions/package/xmake.lua +++ b/xmake/actions/package/xmake.lua @@ -45,7 +45,7 @@ task("package") , {'a', "all", "k", nil , "Package all targets." } , {} , {nil, "target", "v", nil , "The target name. It will package all default targets if this parameter is not specified." - , values = function () return try{ function () return table.keys(import("core.project.project").targets()) end } end } + , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } } } diff --git a/xmake/actions/run/xmake.lua b/xmake/actions/run/xmake.lua index bfdce3af1..a44eb1158 100644 --- a/xmake/actions/run/xmake.lua +++ b/xmake/actions/run/xmake.lua @@ -49,21 +49,8 @@ task("run") " --workdir=`pwd`" } , {} , {nil, "target", "v", nil , "The target name. It will run all default targets if this parameter is not specified." - , values = function () - return try{ - function () - import("core.project.project") - local targets = project.targets() - local runable = {} - for k, v in pairs(targets) do - if v:script("run") or v:get("kind") == "binary" then - table.insert(runable, k) - end - end - return runable - end - } - end } + , values = function (complete, opt) return import("private.utils.complete_helper.runable_targets")(complete, opt) end } + , {nil, "arguments", "vs", nil , "The target arguments" } } } diff --git a/xmake/actions/uninstall/xmake.lua b/xmake/actions/uninstall/xmake.lua index 4f70922c2..882499668 100644 --- a/xmake/actions/uninstall/xmake.lua +++ b/xmake/actions/uninstall/xmake.lua @@ -52,7 +52,7 @@ task("uninstall") "or $ PREFIX=local xmake uninstall" } , { } , {nil, "target", "v", nil , "The target name. It will uninstall all default targets if this parameter is not specified." - , values = function () return try{ function () return table.keys(import("core.project.project").targets()) end } end } + , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } } } diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 837e45faf..90e4656a8 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -122,28 +122,27 @@ function config.options() return configs end --- get the buildir +-- get the buildir function config.buildir() - - -- get it - local buildir = config.get("buildir") - if buildir then - -- get the absolute path first - if not path.is_absolute(buildir) then - local rootdir - if os.isdir(path.join(os.workingdir(), ".xmake")) then - -- we switch to independent working directory @see https://github.com/xmake-io/xmake/issues/820 - rootdir = os.workingdir() - else - rootdir = os.projectdir() - end - buildir = path.absolute(buildir, rootdir) - end + -- get it + local buildir = config.get("buildir") or "build" - -- adjust path for the current directory - buildir = path.relative(buildir, os.curdir()) + -- get the absolute path first + if not path.is_absolute(buildir) then + local rootdir + if os.isdir(path.join(os.workingdir(), ".xmake")) then + -- we switch to independent working directory @see https://github.com/xmake-io/xmake/issues/820 + rootdir = os.workingdir() + else + rootdir = os.projectdir() + end + buildir = path.absolute(buildir, rootdir) end + + -- adjust path for the current directory + buildir = path.relative(buildir, os.curdir()) + return buildir end diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 652ae4758..fc73acd25 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -875,37 +875,32 @@ end -- get the target directory function _instance:targetdir() - -- the target directory - local targetdir = self:get("targetdir") - if not targetdir then - - -- get build directory - targetdir = config.buildir() + -- the target directory or build directory + local targetdir = self:get("targetdir") or config.buildir() - -- append plat sub-directory - local plat = self:plat() - if plat then - targetdir = path.join(targetdir, plat) - end + -- append plat sub-directory + local plat = self:plat() + if plat then + targetdir = path.join(targetdir, plat) + end - -- append arch sub-directory - local arch = self:arch() - if arch then - targetdir = path.join(targetdir, arch) - end + -- append arch sub-directory + local arch = self:arch() + if arch then + targetdir = path.join(targetdir, arch) + end - -- append mode sub-directory - local mode = config.get("mode") - if mode then - targetdir = path.join(targetdir, mode) - end + -- append mode sub-directory + local mode = config.get("mode") + if mode then + targetdir = path.join(targetdir, mode) end -- ok? return targetdir end --- get the target file +-- get the target file function _instance:targetfile() -- the target directory @@ -916,7 +911,7 @@ function _instance:targetfile() -- only compile objects? no target file if targetkind == "object" then - return + return end -- make the target file name and attempt to use the format of linker first @@ -931,7 +926,7 @@ end function _instance:symbolfile() -- the target directory - local targetdir = self:targetdir() or config.buildir() + local targetdir = self:targetdir() assert(targetdir and type(targetdir) == "string") -- the symbol file name diff --git a/xmake/modules/private/utils/complete_helper.lua b/xmake/modules/private/utils/complete_helper.lua new file mode 100644 index 000000000..4e8c38e8f --- /dev/null +++ b/xmake/modules/private/utils/complete_helper.lua @@ -0,0 +1,56 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-2020, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file complete_helper.lua +-- + +function targets() + return try + { + function () + import("core.project.project") + import("core.project.config") + + -- load config + config.load() + + return table.keys(project.targets()) + end + } +end + +function runable_targets() + return try + { + function () + import("core.project.project") + import("core.project.config") + + -- load config + config.load() + + local targets = project.targets() + local runable = {} + for k, v in pairs(targets) do + if v:script("run") or v:get("kind") == "binary" then + table.insert(runable, k) + end + end + return runable + end + } +end
\ No newline at end of file diff --git a/xmake/plugins/show/main.lua b/xmake/plugins/show/main.lua index b1c7b3183..9503b1a75 100644 --- a/xmake/plugins/show/main.lua +++ b/xmake/plugins/show/main.lua @@ -23,7 +23,7 @@ import("core.base.option") -- show list function _show_list(name) - assert(import("lists." .. name, {try = true, anonymous = true}), "unknown list name(%s)", name)() + assert(#name > 0 and import("lists." .. name, {try = true, anonymous = true}), "unknown list name(%s)", name)() end -- main entry diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua index 729d2eece..159eec1a6 100644 --- a/xmake/plugins/show/xmake.lua +++ b/xmake/plugins/show/xmake.lua @@ -42,7 +42,8 @@ task("show") , values = function (complete, opt) return import("list").lists() end}, - {'t', "target" , "kv" , nil , "Show the information of the given target."} + {'t', "target" , "kv" , nil , "Show the information of the given target." + , values = function (complete, opt) return import("private.utils.complete_helper.targets")(complete, opt) end } } } |
