summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-01-21 23:07:51 +0800
committerGitHub <[email protected]>2020-01-21 23:07:51 +0800
commit99cafe9b2ab168b89e7e1516cdb3746d9e349a04 (patch)
treee691aedf3a7b7c6a9567b539bc544c7bc37f2fae
parent3321cc86d2676241d32b9e13e59f28ca0810b4a2 (diff)
parent97b0e9c8e673325545d2e55288d66a2dd99d1cc0 (diff)
Merge pull request #673 from OpportunityLiu/dev
improve tab complete
-rw-r--r--.travis.yml2
-rwxr-xr-x[-rw-r--r--]scripts/PKGBUILD0
-rwxr-xr-xscripts/archive-all (renamed from scripts/archive-all.sh)4
-rwxr-xr-x[-rw-r--r--]scripts/get.ps10
-rwxr-xr-xscripts/get.sh60
-rwxr-xr-xscripts/makeself/build-runfile.sh2
-rw-r--r--scripts/register-completions.bash16
-rwxr-xr-x[-rw-r--r--]scripts/register-completions.ps10
-rwxr-xr-xscripts/register-completions.sh26
-rw-r--r--scripts/register-completions.zsh10
-rwxr-xr-x[-rw-r--r--]scripts/srcenv.bat0
-rwxr-xr-x[-rw-r--r--]scripts/srcenv.profile0
-rw-r--r--tests/modules/string/test.lua9
-rw-r--r--xmake/actions/config/xmake.lua127
-rw-r--r--xmake/actions/create/xmake.lua44
-rw-r--r--xmake/actions/global/xmake.lua13
-rw-r--r--xmake/actions/update/main.lua43
-rw-r--r--xmake/actions/update/xmake.lua56
-rw-r--r--xmake/core/base/io.lua2
-rw-r--r--xmake/core/base/path.lua2
-rw-r--r--xmake/core/base/string.lua6
-rw-r--r--xmake/core/base/task.lua79
-rw-r--r--xmake/core/main.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/theme/theme.lua5
-rw-r--r--xmake/core/theme/theme.lua24
-rw-r--r--xmake/modules/private/utils/complete.lua180
-rw-r--r--xmake/platforms/windows/xmake.lua25
-rw-r--r--xmake/plugins/lua/main.lua134
-rw-r--r--xmake/plugins/lua/xmake.lua103
-rw-r--r--xmake/plugins/macro/main.lua30
-rw-r--r--xmake/plugins/macro/xmake.lua20
-rwxr-xr-xxmake/plugins/project/main.lua14
-rw-r--r--xmake/plugins/project/xmake.lua39
33 files changed, 684 insertions, 393 deletions
diff --git a/.travis.yml b/.travis.yml
index 2e2d1e71b..ffa88b418 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -32,6 +32,6 @@ script:
- xmake l private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake
- xmake --version
- travis_wait 60 xmake lua -v -D tests/run.lua
- - scripts/archive-all.sh
+ - scripts/archive-all
- scripts/makeself/build-runfile.sh
- scripts/makeself/xmake.gz.run --info
diff --git a/scripts/PKGBUILD b/scripts/PKGBUILD
index 5163bb1b3..5163bb1b3 100644..100755
--- a/scripts/PKGBUILD
+++ b/scripts/PKGBUILD
diff --git a/scripts/archive-all.sh b/scripts/archive-all
index 5026ae4e8..bd9be43a7 100755
--- a/scripts/archive-all.sh
+++ b/scripts/archive-all
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-# ./scripts/archive-all.sh
+# ./scripts/archive-all
tmpdir=/tmp/.xmake_archive
xmakeroot=`pwd`
if [ -d $tmpdir ]; then
@@ -21,7 +21,7 @@ cd $tmpdir/repo || exit
xmake l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake || exit
cp -r ./core $tmpdir/xmake
cp -r ./xmake $tmpdir/xmake/xmake
-cp ./scripts/get.sh $tmpdir/xmake/scripts
+cp ./scripts/*.sh $tmpdir/xmake/scripts
cp ./*.md $tmpdir/xmake
cp makefile $tmpdir/xmake
cp install $tmpdir/xmake
diff --git a/scripts/get.ps1 b/scripts/get.ps1
index 4ec3df140..4ec3df140 100644..100755
--- a/scripts/get.ps1
+++ b/scripts/get.ps1
diff --git a/scripts/get.sh b/scripts/get.sh
index fce123a23..7be3e63fd 100755
--- a/scripts/get.sh
+++ b/scripts/get.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# xmake getter
-# usage: bash <(curl -s <my location>) [[mirror:]branch] [commit/__install_only__]
+# usage: bash <(curl -s <my location>) [[mirror:]branch|__local__|__run__] [commit/__install_only__]
set -o pipefail
@@ -14,6 +14,7 @@ if [ 0 -ne "$(id -u)" ]; then
sudoprefix=
fi
else
+ export XMAKE_ROOT=y
sudoprefix=
fi
@@ -97,7 +98,7 @@ install_tools()
{ apk --version >/dev/null 2>&1 && $sudoprefix apk add gcc g++ make readline-dev ncurses-dev libc-dev linux-headers; }
}
test_tools || { install_tools && test_tools; } || my_exit "$(echo -e 'Dependencies Installation Fail\nThe getter currently only support these package managers\n\t* apt\n\t* yum\n\t* zypper\n\t* pacman\nPlease install following dependencies manually:\n\t* git\n\t* build essential like `make`, `gcc`, etc\n\t* libreadline-dev (readline-devel)\n\t* ccache (optional)')" 1
-branch=master
+branch=__run__
mirror=xmake-io
IFS=':'
if [ x != "x$1" ]; then
@@ -114,21 +115,32 @@ if [ x != "x$1" ]; then
echo "Branch: $branch"
fi
projectdir=$tmpdir
-if [ 'x__local__' != "x$branch" ]; then
+if [ 'x__local__' = "x$branch" ]; then
+ if [ -d '.git' ]; then
+ git submodule update --init --recursive
+ fi
+ cp -r . $projectdir
+ cd $projectdir || my_exit 'Chdir Error'
+elif [ 'x__run__' = "x$branch" ]; then
+ version=$(git ls-remote --tags "https://github.com/$mirror/xmake" | tail -c 7)
+ if xz --version >/dev/null 2>&1
+ then
+ pack=xz
+ else
+ pack=gz
+ fi
+ mkdir -p $projectdir
+ remote_get_content "https://github.com/$mirror/xmake/releases/download/$version/xmake-$version.$pack.run" > $projectdir/xmake.run
+ sh $projectdir/xmake.run --noexec --target $projectdir
+else
if [ x != "x$2" ]; then
git clone --depth=50 -b "$branch" "https://github.com/$mirror/xmake.git" --recurse-submodules $projectdir || my_exit "$(echo -e 'Clone Fail\nCheck your network or branch name')"
cd $projectdir || my_exit 'Chdir Error'
git checkout -qf "$2"
cd - || my_exit 'Chdir Error'
else
- git clone --depth=1 -b "$branch" "https://github.com/$mirror/xmake.git" --recurse-submodules --shallow-submodules $projectdir || my_exit "$(echo -e 'Clone Fail\nCheck your network or branch name')"
+ git clone --depth=1 -b "$branch" "https://github.com/$mirror/xmake.git" --recurse-submodules $projectdir || my_exit "$(echo -e 'Clone Fail\nCheck your network or branch name')"
fi
-else
- if [ -d '.git' ]; then
- git submodule update --init --recursive
- fi
- cp -r . $projectdir
- cd $projectdir || my_exit 'Chdir Error'
fi
# do build
@@ -144,7 +156,6 @@ fi
# make bytecodes
XMAKE_PROGRAM_DIR="$projectdir/xmake" \
-XMAKE_ROOT=y \
$projectdir/core/src/demo/demo.b l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' $projectdir/xmake || my_exit 'generate bytecode failed!'
# do install
@@ -164,30 +175,11 @@ install_profile()
{
if [ ! -d ~/.xmake ]; then mkdir ~/.xmake; fi
echo "export PATH=$prefix/bin:\$PATH" > ~/.xmake/profile
- echo '
-if [[ "$SHELL" = */zsh ]]; then
- # zsh parameter completion for xmake
- _xmake_zsh_complete()
- {
- local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete 0 nospace "$words")")
- reply=( "${(ps:\n:)completions}" )
- }
- compctl -f -S "" -K _xmake_zsh_complete xmake
-elif [[ "$SHELL" = */bash ]]; then
- # bash parameter completion for xmake
- _xmake_bash_complete()
- {
- local word=${COMP_WORDS[COMP_CWORD]}
- local completions
- completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "conf" "${COMP_LINE}" 2>/dev/null)"
- if [ $? -ne 0 ]; then
- completions=""
+ if [ -f "$projectdir/scripts/register-completions.sh" ]; then
+ cat "$projectdir/scripts/register-completions.sh" >> ~/.xmake/profile
+ else
+ remote_get_content "https://github.com/$mirror/xmake/raw/master/scripts/register-completions.sh" >> ~/.xmake/profile
fi
- COMPREPLY=( $(compgen -W "$completions" -- "$word") )
- }
- complete -o default -o nospace -F _xmake_bash_complete xmake
-fi
-' >> ~/.xmake/profile
if [[ "$SHELL" = */zsh ]]; then
write_profile ~/.zshrc
diff --git a/scripts/makeself/build-runfile.sh b/scripts/makeself/build-runfile.sh
index afc7a1b3c..f46d1d1bf 100755
--- a/scripts/makeself/build-runfile.sh
+++ b/scripts/makeself/build-runfile.sh
@@ -22,7 +22,7 @@ mkdir -p $tmpdir/xmake/scripts
cd $tmpdir/repo || exit
cp -r ./xmake $tmpdir/xmake/xmake
cp -r ./core $tmpdir/xmake
-cp ./scripts/get.sh $tmpdir/xmake/scripts
+cp ./scripts/*.sh $tmpdir/xmake/scripts
cp ./*.md $tmpdir/xmake
cp makefile $tmpdir/xmake
cd $tmpdir/xmake || exit
diff --git a/scripts/register-completions.bash b/scripts/register-completions.bash
deleted file mode 100644
index 18df8a3b7..000000000
--- a/scripts/register-completions.bash
+++ /dev/null
@@ -1,16 +0,0 @@
-# bash parameter completion for xmake
-
-_xmake_bash_complete()
-{
- local word=${COMP_WORDS[COMP_CWORD]}
-
- local completions
- completions="$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete "${COMP_POINT}" "conf" "${COMP_LINE}" 2>/dev/null)"
- if [ $? -ne 0 ]; then
- completions=""
- fi
-
- COMPREPLY=( $(compgen -W "$completions" -- "$word") )
-}
-
-complete -o default -o nospace -F _xmake_bash_complete xmake
diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1
index a9ecd7877..a9ecd7877 100644..100755
--- a/scripts/register-completions.ps1
+++ b/scripts/register-completions.ps1
diff --git a/scripts/register-completions.sh b/scripts/register-completions.sh
new file mode 100755
index 000000000..e274605b2
--- /dev/null
+++ b/scripts/register-completions.sh
@@ -0,0 +1,26 @@
+
+# parameter completions for *nix shell
+
+if [[ "$SHELL" = */zsh ]]; then
+ # zsh parameter completion for xmake
+ _xmake_zsh_complete()
+ {
+ local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")")
+ reply=( "${(ps:\n:)completions}" )
+ }
+ compctl -f -S "" -K _xmake_zsh_complete xmake
+elif [[ "$SHELL" = */bash ]]; then
+ # bash parameter completion for xmake
+ _xmake_bash_complete()
+ {
+ local word=${COMP_WORDS[COMP_CWORD]}
+ local completions
+ completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")"
+ if [ $? -ne 0 ]; then
+ completions=""
+ fi
+ COMPREPLY=( $(compgen -W "$completions") )
+ }
+ complete -o default -o nospace -F _xmake_bash_complete xmake
+fi
+
diff --git a/scripts/register-completions.zsh b/scripts/register-completions.zsh
deleted file mode 100644
index 5c16cf334..000000000
--- a/scripts/register-completions.zsh
+++ /dev/null
@@ -1,10 +0,0 @@
-# zsh parameter completion for xmake
-
-_xmake_zsh_complete()
-{
- local completions=("$(XMAKE_SKIP_HISTORY=1 xmake lua --root private.utils.complete 0 nospace "$words")")
-
- reply=( "${(ps:\n:)completions}" )
-}
-
-compctl -f -S "" -K _xmake_zsh_complete xmake
diff --git a/scripts/srcenv.bat b/scripts/srcenv.bat
index 974c640b9..974c640b9 100644..100755
--- a/scripts/srcenv.bat
+++ b/scripts/srcenv.bat
diff --git a/scripts/srcenv.profile b/scripts/srcenv.profile
index 5e69b5540..5e69b5540 100644..100755
--- a/scripts/srcenv.profile
+++ b/scripts/srcenv.profile
diff --git a/tests/modules/string/test.lua b/tests/modules/string/test.lua
index 538dfd893..57e00dd7e 100644
--- a/tests/modules/string/test.lua
+++ b/tests/modules/string/test.lua
@@ -66,14 +66,23 @@ function test_split(t)
t:are_equal(("1\n\n2\n3"):split('\n', {strict = true}), {"1", "", "2", "3"})
t:are_equal(("abc123123xyz123abc"):split('123', {strict = true}), {"abc", "", "xyz", "abc"})
t:are_equal(("abc123123xyz123abc"):split('[123]+', {strict = true}), {"abc", "xyz", "abc"})
+ t:are_equal(("123abc123123xyz123abc123"):split('[123]+', {strict = true}), {"", "abc", "xyz", "abc", ""})
+ t:are_equal(("123123"):split('[123]+', {strict = true}), {"", ""})
+ t:are_equal((""):split('[123]+', {strict = true}), {""})
-- plain match and contains empty string
t:are_equal(("1\n\n2\n3"):split('\n', {plain = true, strict = true}), {"1", "", "2", "3"})
t:are_equal(("abc123123xyz123abc"):split('123', {plain = true, strict = true}), {"abc", "", "xyz", "abc"})
+ t:are_equal(("123abc123123xyz123abc123"):split('123', {plain = true, strict = true}), {"", "abc", "", "xyz", "abc", ""})
+ t:are_equal(("123"):split('123', {plain = true, strict = true}), {"", ""})
+ t:are_equal((""):split('123', {plain = true, strict = true}), {""})
-- limit split count
t:are_equal(("1\n\n2\n3"):split('\n', {limit = 2}), {"1", "2\n3"})
t:are_equal(("1\n\n2\n3"):split('\n', {limit = 2, strict = true}), {"1", "\n2\n3"})
+ t:are_equal(("\n1\n\n2\n3"):split('\n', {limit = 2, strict = true}), {"", "1\n\n2\n3"})
t:are_equal(("1.2.3.4.5"):split('%.', {limit = 3}), {"1", "2", "3.4.5"})
t:are_equal(("123.45"):split('%.', {limit = 3}), {"123", "45"})
+ t:are_equal((""):split('123', {plain = true, limit = 2, strict = true}), {""})
+ t:are_equal(("123123"):split('123', {plain = true, limit = 2, strict = true}), {"", "123"})
end
diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua
index 6cb5b2247..a4d9604ea 100644
--- a/xmake/actions/config/xmake.lua
+++ b/xmake/actions/config/xmake.lua
@@ -11,7 +11,7 @@
-- 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 ruki
@@ -39,25 +39,46 @@ task("config")
, shortname = 'f'
-- options
- , options =
+ , options =
{
- {'c', "clean", "k", nil, "Clean the cached configure and configure all again." }
- , {nil, "menu", "k", nil, "Configure project with a menu-driven user interface." }
- , {nil, "require", "kv", nil, "Require all dependent packages?",
- " - y: force to enable",
- " - n: disable" }
+ {'c', "clean", "k", nil , "Clean the cached configure and configure all again." }
+ , {nil, "menu", "k", nil , "Configure project with a menu-driven user interface." }
+ , {nil, "require", "kv", nil , "Require all dependent packages?"
+ , values = function (complete)
+ if complete then
+ return {"yes", "no"}
+ else
+ return {"y: force to enable", "n: disable" }
+ end
+ end }
, {category = "."}
- , {'p', "plat", "kv", "$(host)", "Compile for the given platform."
- , values = function ()
- return import("core.platform.platform").plats()
- end }
- , {'a', "arch", "kv", "auto", "Compile for the given architecture."
+ , {'p', "plat", "kv", "$(host)" , "Compile for the given platform."
+ , values = function (complete, opt)
+
+ -- import
+ import("core.platform.platform")
+ import("core.base.hashset")
+
+ if not complete or not opt.arch then
+ return platform.plats()
+ end
+ -- arch has given, find all supported platforms
+ local plats = {}
+ for _, plat in ipairs(platform.plats()) do
+ local archs = hashset.from(platform.archs(plat))
+ if archs:has(opt.arch) then
+ table.insert(plats, plat)
+ end
+ end
+ return plats
+ end }
+ , {'a', "arch", "kv", "auto" , "Compile for the given architecture.",
-- show the description of all architectures
- , function ()
+ function ()
- -- import platform
+ -- import platform
import("core.platform.platform")
-- make description
@@ -74,41 +95,71 @@ task("config")
-- get it
return description
- end }
- , {'m', "mode", "kv", "release", "Compile for the given mode."
- , " - debug"
- , " - release"
- , " - ... (custom)" }
- , {'k', "kind", "kv", "static", "Compile for the given target kind."
- , values = {"static", "shared", "binary"} }
- , {nil, "host", "kv", "$(host)", "The Current Host Environment." }
+ end
+ , values = function (complete, opt)
+ if not complete then return end
+
+ -- import
+ import("core.platform.platform")
+ import("core.base.hashset")
+
+ -- get archs
+ local archset = hashset.new()
+
+ for _, plat in ipairs(opt.plat and { opt.plat } or platform.plats()) do
+ local archs = platform.archs(plat)
+ if archs then
+ for _, arch in ipairs(archs) do
+ archset:insert(arch)
+ end
+ end
+ end
+
+ -- get it
+ return archset:to_array()
+ end }
+ , {'m', "mode", "kv", "release" , "Compile for the given mode."
+ , values = function (complete)
+
+ local modes = (try { function()
+ return import("core.project.project").modes()
+ end }) or {"debug", "release"}
+ table.sort(modes)
+ if not complete then
+ table.insert(modes, "... (custom)")
+ end
+ return modes
+ end }
+ , {'k', "kind", "kv", "static" , "Compile for the given target kind."
+ , values = {"static", "shared", "binary"} }
+ , {nil, "host", "kv", "$(host)" , "The Current Host Environment." }
-- show project menu options
- , function ()
+ , function ()
- -- import project menu
+ -- import project menu
import("core.project.menu")
- -- get project menu options
- return menu.options()
+ -- get project menu options
+ return menu.options()
end
, {category = "Cross Complation Configuration"}
- , {nil, "cross", "kv", nil, "The Cross Toolchains Prefix"
+ , {nil, "cross", "kv", nil, "The Cross Toolchains Prefix"
, "e.g."
, " - i386-mingw32-"
, " - arm-linux-androideabi-" }
- , {nil, "bin", "kv", nil, "The Cross Toolchains Bin Directory"
+ , {nil, "bin", "kv", nil, "The Cross Toolchains Bin Directory"
, "e.g."
, " - sdk/bin (/arm-linux-gcc ..)" }
- , {nil, "sdk", "kv", nil, "The Cross SDK Directory"
+ , {nil, "sdk", "kv", nil, "The Cross SDK Directory"
, "e.g."
, " - sdk/bin"
, " - sdk/lib"
, " - sdk/include" }
-- show language menu options
- , function ()
+ , function ()
-- import language menu
import("core.language.menu")
@@ -118,7 +169,7 @@ task("config")
end
-- show platform menu options
- , function ()
+ , function ()
-- import platform menu
import("core.platform.menu")
@@ -128,13 +179,17 @@ task("config")
end
, {category = "Other Configuration"}
- , {nil, "debugger", "kv", "auto" , "The Debugger" }
- , {nil, "ccache", "kv", true , "Enable or disable the c/c++ compiler cache." }
- , {'o', "buildir", "kv", "build" , "Set the build directory." }
+ , {nil, "debugger", "kv", "auto" , "The Debugger" }
+ , {nil, "ccache", "kv", true , "Enable or disable the c/c++ compiler cache." }
+ , {'o', "buildir", "kv", "build" , "Set the build directory." }
, {}
- , {nil, "target", "v", nil , "Configure for the given target."
- , values = function () return try{ function () return table.keys(import("core.project.project").targets()) end } end }
+ , {nil, "target", "v" , nil , "Configure for the given target."
+ , values = function ()
+ return try { function ()
+ return table.keys(import("core.project.project").targets())
+ end }
+ end }
}
}
diff --git a/xmake/actions/create/xmake.lua b/xmake/actions/create/xmake.lua
index ed5fd6444..5e650f409 100644
--- a/xmake/actions/create/xmake.lua
+++ b/xmake/actions/create/xmake.lua
@@ -41,24 +41,32 @@ task("create")
{'l', "language", "kv", "c++", "The project language"
-- show the description of all languages
- , function ()
+ , values = function (complete, opt)
-- import template
import("core.project.template")
- -- make description
- local description = {}
- for _, language in ipairs(template.languages()) do
- table.insert(description, " - " .. language)
- end
+ -- get languages
+ local languages = template.languages()
- -- get it
- return description
+ if not complete or not opt.template then return languages end
+
+ local accepted_lang = {}
+ for _, l in ipairs(languages) do
+ for _, t in ipairs(template.templates(l)) do
+ if t:name() == opt.template then
+ table.insert(accepted_lang, l)
+ break
+ end
+ end
+ end
+
+ return accepted_lang
end }
- , {'t', "template", "kv", "console", "Select the project template id or name of the given language."
+ , {'t', "template", "kv", "console", "Select the project template id or name of the given language.",
-- show the description of all templates
- , function ()
+ function ()
-- import template
import("core.project.template")
@@ -85,6 +93,22 @@ task("create")
table.insert(description, " - " .. t.name .. ": " .. table.concat(t.languages, ", "))
end
return description
+ end
+ , values = function (complete, opt)
+ if not complete then return end
+
+ -- import template
+ import("core.project.template")
+
+ -- get templates
+ local templates = {}
+ for _, l in ipairs(opt.language and {opt.language} or template.languages()) do
+ for _, t in ipairs(template.templates(l)) do
+ table.insert(templates, t:name())
+ end
+ end
+
+ return templates
end }
, {}
diff --git a/xmake/actions/global/xmake.lua b/xmake/actions/global/xmake.lua
index ca062c608..f294d2804 100644
--- a/xmake/actions/global/xmake.lua
+++ b/xmake/actions/global/xmake.lua
@@ -41,16 +41,19 @@ task("global")
-- options
, options =
{
- {'c', "clean", "k", nil, "Clean the cached configure and configure all again." }
- , {nil, "menu", "k", nil, "Configure with a menu-driven user interface." }
+ {'c', "clean", "k" , nil , "Clean the cached configure and configure all again." }
+ , {nil, "menu", "k" , nil , "Configure with a menu-driven user interface." }
, {category = "."}
- , {nil, "theme", "kv", "default","The theme name." }
- , {nil, "debugger", "kv", "auto", "The Debugger Program Path." }
+ , {nil, "theme", "kv", "default" , "The theme name."
+ , values = function ()
+ return import("core.theme.theme.names")()
+ end }
+ , {nil, "debugger", "kv", "auto" , "The Debugger Program Path." }
-- show platform menu options
, {category = "Platform Configuration"}
- , function ()
+ , function ()
-- import platform menu
import("core.platform.menu")
diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua
index c8e95f5c3..037ea7e5d 100644
--- a/xmake/actions/update/main.lua
+++ b/xmake/actions/update/main.lua
@@ -248,6 +248,33 @@ function _install_script(sourcedir)
end
end
+function _check_repo(sourcedir)
+ -- this file will exists for long time
+ if not os.isfile(path.join(sourcedir, "xmake/core/_xmake_main.lua")) then
+ raise("invalid xmake repo, please check your input!")
+ end
+end
+
+function _check_win_installer(sourcedir)
+ local file = path.join(sourcedir, win_installer_name)
+ if not os.isfile(file) then
+ raise("installer not found at " .. sourcedir)
+ end
+
+ local fp = io.open(file, "rb")
+ local header = fp:read(math.min(1000, fp:size()))
+ fp:close()
+ if header:startswith("MZ") then
+ return
+ end
+ if header:find('\0', 1, true) or not option.get("verbose") then
+ raise("installer is broken")
+ else
+ -- may be a text file, print content for debug
+ raise("installer is broken: " .. header)
+ end
+end
+
-- main
function main()
@@ -308,6 +335,9 @@ function main()
local sourcedir = path.join(os.tmpdir(), "xmakesrc", version)
vprint("prepared to download to temp dir %s ..", sourcedir)
+ -- all user provided urls are considered as git url since check has been performed in fetch_version
+ local install_from_git = not is_official or git.checkurl(mainurls[1])
+
local download_task = function ()
for idx, url in ipairs(mainurls) do
cprintf("\r${yellow} => ${clear}downloading %s .. ", url)
@@ -315,16 +345,15 @@ function main()
{
function ()
os.tryrm(sourcedir)
- -- all user provided urls are considered as git url since check has been performed in fetch_version
- if is_official and not git.checkurl(url) then
+ if not install_from_git then
os.mkdir(sourcedir)
http.download(url, path.join(sourcedir, win_installer_name))
else
- git.clone(url, {depth = 1, recursive = not script_only, branch = version, outputdir = sourcedir})
+ git.clone(url, {depth = 1, recurse_submodules = not script_only, branch = version, outputdir = sourcedir})
end
return true
end,
- catch
+ catch
{
function (errors)
vprint(errors)
@@ -353,6 +382,12 @@ function main()
-- leave environment
environment.leave()
+ if install_from_git then
+ _check_repo(sourcedir)
+ else
+ _check_win_installer(sourcedir)
+ end
+
-- do install
if script_only then
_install_script(sourcedir)
diff --git a/xmake/actions/update/xmake.lua b/xmake/actions/update/xmake.lua
index 8ea268765..74dcd0ba9 100644
--- a/xmake/actions/update/xmake.lua
+++ b/xmake/actions/update/xmake.lua
@@ -38,17 +38,51 @@ task("update")
-- options
, options =
{
- {nil, "uninstall", "k", nil, "Uninstall the current xmake program." }
- , { }
- , {'s', "scriptonly", "k", nil, "Update script only" }
- , {nil, "xmakever", "v", nil, "The given xmake version, or a git source (and branch). ",
- "e.g.",
- " from official source: ",
- " latest, ~2.2.3, dev, master",
- " from custom source:",
- " https://github.com/xmake-io/xmake",
- " github:xmake-io/xmake#~2.2.3",
- " git://github.com/xmake-io/xmake.git#master" }
+ {nil, "uninstall", "k", nil, "Uninstall the current xmake program." }
+ , { }
+ , {'s', "scriptonly", "k", nil, "Update script only" }
+ , {nil, "xmakever", "v", nil, "The given xmake version, or a git source (and branch). ",
+ "e.g.",
+ " from official source: ",
+ " latest, ~2.2.3, dev, master",
+ " from custom source:",
+ " https://github.com/xmake-io/xmake",
+ " github:xmake-io/xmake#~2.2.3",
+ " git://github.com/xmake-io/xmake.git#master",
+ values = function (complete)
+ if not complete then
+ return
+ end
+ return try{ function ()
+ import("private.action.update.fetch_version")
+
+ local seg = complete:split('#', { plain = true, limit = 2, strict = true })
+ if #seg == 1 then
+ if seg[1]:find(':', 1, true) then
+ -- incomplete custom source
+ return
+ else
+ seg[1] = ""
+ end
+ end
+
+ local versions = fetch_version(seg[1])
+ for i,v in ipairs(versions.tags) do
+ if v:startswith("v") and #v > 5 then
+ versions.tags[i] = v:sub(2)
+ end
+ end
+ local candidates = table.join("latest", versions.branches, table.reverse(versions.tags))
+ if versions.is_official then
+ return candidates
+ else
+ for i, v in ipairs(candidates) do
+ candidates[i] = seg[1] .. "#" .. v
+ end
+ return candidates
+ end
+ end }
+ end}
}
}
diff --git a/xmake/core/base/io.lua b/xmake/core/base/io.lua
index 103288288..0770436eb 100644
--- a/xmake/core/base/io.lua
+++ b/xmake/core/base/io.lua
@@ -673,7 +673,7 @@ function io.cat(filepath, linecount, opt)
for line in file:lines(opt) do
-- show line
- io.print(line)
+ io.write(line, "\n")
-- end?
if linecount and count >= linecount then
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index aff61d01b..8332925d5 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -104,7 +104,7 @@ function path.split(p)
-- check
assert(p)
- return p:split("/\\")
+ return p:split("[/\\]")
end
-- get the path seperator
diff --git a/xmake/core/base/string.lua b/xmake/core/base/string.lua
index e1b96fb75..8cdca335f 100644
--- a/xmake/core/base/string.lua
+++ b/xmake/core/base/string.lua
@@ -74,7 +74,7 @@ end
function string:split(delimiter, opt)
local result = {}
local start = 1
- local pos, epos = self:find(delimiter, start, opt and opt.plain)
+ local pos, epos = self:find(delimiter, start, opt and opt.plain)
while pos do
local substr = self:sub(start, pos - 1)
if (#substr > 0) or (opt and opt.strict) then
@@ -88,6 +88,10 @@ function string:split(delimiter, opt)
end
if start <= #self then
table.insert(result, self:sub(start))
+ elseif opt and opt.strict and (not opt.limit or #result < opt.limit) then
+ if start == #self + 1 then
+ table.insert(result, "")
+ end
end
return result
end
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index a3aadb7b0..7ffcdfcc4 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -11,7 +11,7 @@
-- 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 ruki
@@ -24,7 +24,6 @@ local task = task or {}
-- load modules
local os = require("base/os")
local table = require("base/table")
-local utils = require("base/utils")
local string = require("base/string")
local global = require("base/global")
local interpreter = require("base/interpreter")
@@ -36,27 +35,27 @@ function task.common_options()
if not task._COMMON_OPTIONS then
task._COMMON_OPTIONS =
{
- {'q', "quiet", "k", nil, "Quiet operation." }
- , {'y', "yes", "k", nil, "Input yes by default if need user confirm." }
- , {nil, "confirm", "kv", nil, "Input the given result if need user confirm.",
- " - y|yes",
- " - n|no",
- " - d|def"}
- , {'v', "verbose", "k", nil, "Print lots of verbose information for users." }
- , {nil, "root", "k", nil, "Allow to run xmake as root." }
- , {'D', "diagnosis", "k", nil, "Print lots of diagnosis information (backtrace, check info ..) only for developers."
- , "And we can append -v to get more whole information."
- , " e.g. $ xmake -vD"}
- , {nil, "profile", "k", nil, "Print performance data only for developers." }
- , {nil, "version", "k", nil, "Print the version number and exit." }
- , {'h', "help", "k", nil, "Print this help message and exit." }
+ {'q', "quiet", "k", nil, "Quiet operation." }
+ , {'y', "yes", "k", nil, "Input yes by default if need user confirm." }
+ , {nil, "confirm", "kv", nil, "Input the given result if need user confirm."
+ , values = function ()
+ return {"yes", "no", "def"}
+ end }
+ , {'v', "verbose", "k", nil, "Print lots of verbose information for users." }
+ , {nil, "root", "k", nil, "Allow to run xmake as root." }
+ , {'D', "diagnosis", "k", nil, "Print lots of diagnosis information (backtrace, check info ..) only for developers."
+ , "And we can append -v to get more whole information."
+ , " e.g. $ xmake -vD" }
+ , {nil, "profile", "k", nil, "Print performance data only for developers." }
+ , {nil, "version", "k", nil, "Print the version number and exit." }
+ , {'h', "help", "k", nil, "Print this help message and exit." }
, {}
- , {'F', "file", "kv", nil, "Read a given xmake.lua file." }
- , {'P', "project", "kv", nil, "Change to the given project directory."
- , "Search priority:"
- , " 1. The Given Command Argument"
- , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
- , " 3. The Current Directory" }
+ , {'F', "file", "kv", nil, "Read a given xmake.lua file." }
+ , {'P', "project", "kv", nil, "Change to the given project directory."
+ , "Search priority:"
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
, {category = "action"}
}
end
@@ -85,14 +84,14 @@ function task._translate_menu(menu)
-- translate options
local options = menu.options
if options then
-
- -- make full options
+
+ -- make full options
local options_full = {}
for _, opt in ipairs(options) do
-- this option is function? translate it
if type(opt) == "function" then
-
+
-- call menu script in the sandbox
local ok, results = sandbox.load(opt)
if ok then
@@ -180,7 +179,7 @@ function task._interpreter()
-- init interpreter
local interp = interpreter.new()
assert(interp)
-
+
-- define apis
interp:api_define(task.apis())
@@ -192,10 +191,10 @@ function task._interpreter()
-- attempt to get it directly from the configure
local result = config.get(variable)
- if not result or type(result) ~= "string" then
+ if not result or type(result) ~= "string" then
-- init maps
- local maps =
+ local maps =
{
host = os.host()
, tmpdir = function () return os.tmpdir() end
@@ -212,7 +211,7 @@ function task._interpreter()
if type(result) == "function" then
result = result()
end
- end
+ end
-- ok?
return result
@@ -249,7 +248,7 @@ function task._bind(tasks, interp)
-- get interpreter
interp = interp or task._interpreter()
- assert(interp)
+ assert(interp)
-- bind sandbox for menus
for _, taskinst in pairs(tasks) do
@@ -261,8 +260,8 @@ function task._bind(tasks, interp)
-- translate options
local options = taskmenu.options
if options then
-
- -- make full options
+
+ -- make full options
local errors = nil
local options_full = {}
for _, opt in ipairs(options) do
@@ -283,7 +282,7 @@ function task._bind(tasks, interp)
options = options_full
taskmenu.options = options_full
- -- bind sandbox for scripts in option
+ -- bind sandbox for scripts in option
for _, opt in ipairs(options) do
-- bind description and values
@@ -352,18 +351,18 @@ function task._load(filepath)
-- ok?
return tasks
end
-
+
-- get task apis
function task.apis()
- return
+ return
{
values =
{
-- task.set_xxx
"task.set_category" -- main, action, plugin, task (default)
}
- , dictionary =
+ , dictionary =
{
-- task.set_xxx
"task.set_menu"
@@ -386,10 +385,10 @@ end
-- get global tasks
function task.tasks()
-
+
-- return it directly if exists
if task._TASKS then
- return task._TASKS
+ return task._TASKS
end
-- load tasks
@@ -465,7 +464,7 @@ function task.menu(tasks)
if m then
-- add task
- mainmenu.tasks[name] =
+ mainmenu.tasks[name] =
{
category = inst:get("category")
, shortname = m.shortname
@@ -504,7 +503,7 @@ function task:name()
return self._NAME
end
--- run given task
+-- run given task
function task:run(...)
-- check
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index bc8bc04b5..4a8c05b7a 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -217,7 +217,7 @@ function main.entry()
end
-- check run command as root
- if not option.get("root") and (not os.getenv("XMAKE_ROOT") or os.getenv("XMAKE_ROOT") ~= 'y') then
+ if not option.get("root") and os.getenv("XMAKE_ROOT") ~= 'y' then
if os.isroot() then
if not privilege.store() or os.isroot() then
utils.error([[Running xmake as root is extremely dangerous and no longer supported.
diff --git a/xmake/core/sandbox/modules/import/core/theme/theme.lua b/xmake/core/sandbox/modules/import/core/theme/theme.lua
index 68fc423ba..40dd293f3 100644
--- a/xmake/core/sandbox/modules/import/core/theme/theme.lua
+++ b/xmake/core/sandbox/modules/import/core/theme/theme.lua
@@ -55,5 +55,10 @@ function sandbox_core_theme.get(name)
end
end
+-- find all themes
+function sandbox_core_theme.names()
+ return theme.names()
+end
+
-- return module
return sandbox_core_theme
diff --git a/xmake/core/theme/theme.lua b/xmake/core/theme/theme.lua
index 6244edd5f..f8070c44b 100644
--- a/xmake/core/theme/theme.lua
+++ b/xmake/core/theme/theme.lua
@@ -11,7 +11,7 @@
-- 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 ruki
@@ -59,7 +59,7 @@ function theme._interpreter()
-- init interpreter
local interp = interpreter.new()
assert(interp)
-
+
-- define apis
interp:api_define(theme._apis())
@@ -72,7 +72,7 @@ end
-- get theme apis
function theme._apis()
- return
+ return
{
keyvalues =
{
@@ -90,13 +90,27 @@ function theme.directories()
local dirs = theme._DIRS or { path.join(global.directory(), "themes")
, path.join(os.programdir(), "themes")
}
-
+
-- save directories to cache
theme._DIRS = dirs
return dirs
end
--- load the given theme
+-- find all themes
+function theme.names()
+
+ local paths = {}
+ for _, dir in ipairs(theme.directories()) do
+ table.join2(paths, (os.files(path.join(dir, "*", "xmake.lua"))))
+ end
+ for i, v in ipairs(paths) do
+ local value = path.split(v)
+ paths[i] = value[#value - 1]
+ end
+ return paths
+end
+
+-- load the given theme
function theme.load(name)
-- find the theme script path
diff --git a/xmake/modules/private/utils/complete.lua b/xmake/modules/private/utils/complete.lua
index 71c7e9fa3..10c9e7d66 100644
--- a/xmake/modules/private/utils/complete.lua
+++ b/xmake/modules/private/utils/complete.lua
@@ -24,8 +24,10 @@ import("core.base.task")
import("core.base.cli")
local raw_words = {}
+local raw_config
local position = 0
local use_spaces = true
+local no_key = false
local reenter = false
function _print_candidate(is_complate, ...)
@@ -40,29 +42,99 @@ function _print_candidate(is_complate, ...)
end
end
-function _complete_task(tasks, name)
+function _find_candidates(candidates, find)
local has_candidate = false
- for k, _ in pairs(tasks) do
- if k:startswith(name) then
- _print_candidate(true, "%s", k)
+ local results = table.new(#candidates, 0)
+
+ -- find candidate starts with find str
+ for _, v in ipairs(candidates) do
+ if tostring(v):startswith(find) then
+ table.insert(results, v)
has_candidate = true
end
end
- if name == "" then
- return has_candidate
+ -- stop searching if found any
+ if has_candidate then
+ return results
end
- for k, _ in pairs(tasks) do
- -- not startswith
- if k:find(name, 2, true) then
- _print_candidate(true, "%s", k)
- has_candidate = true
+ -- find candidate contains find str
+ for _, v in ipairs(candidates) do
+ if tostring(v):find(find, 1, true) then
+ table.insert(results, v)
end
end
+
+ return results
+end
+
+function _complete_task(tasks, name)
+ local has_candidate = false
+ for _, v in ipairs(_find_candidates((table.keys(tasks)), name)) do
+ _print_candidate(true, "%s", v)
+ has_candidate = true
+ end
return has_candidate
end
+-- complete values of kv
+function _complete_option_kv_v(options, current, completing, name, value)
+
+ -- find completion option
+ local opt
+ for _, v in ipairs(options) do
+ if v[3] == "kv" and (v[1] == name or v[2] == name) then
+ opt = v
+ break
+ end
+ end
+ if not opt then
+ return false
+ end
+
+ -- show candidates of values
+ local values = opt.values
+ if type(values) == "function" then
+ values = values(value, current)
+ end
+ if values == nil and type(opt[4]) == "boolean" then
+ values = { "yes", "no" }
+ -- ignore existing input
+ value = ""
+ end
+
+ -- match values starts with value first
+ for _, v in ipairs(_find_candidates(values, value)) do
+ if no_key then
+ _print_candidate(true, "%s", v)
+ else
+ _print_candidate(true, "--%s=%s", name, v)
+ end
+ end
+
+ -- whether any candidates has been found, finish complete since we don't have more info
+ return true
+end
+
+-- complete keys of kv
+function _complete_option_kv_k(options, current, completing, name)
+
+ local opcandi = table.new(0, 10)
+ for _, opt in ipairs(options) do
+ if opt[2] and current[opt[2]] == nil and (opt[3] == "kv" or opt[3] == "k") then
+ opcandi[opt[2]] = opt
+ end
+ end
+
+ for _, k in ipairs(_find_candidates((table.keys(opcandi)), name)) do
+ local opt = opcandi[k]
+ _print_candidate((opt[3] == "k"), (opt[3] == "k") and "--%s" or "--%s=", opt[2])
+ end
+
+ return true
+end
+
function _complete_option_kv(options, current, completing)
local name, value
@@ -82,65 +154,14 @@ function _complete_option_kv(options, current, completing)
if value then
-- complete values
-
- -- find completion option
- local opt
- for _, v in ipairs(options) do
- if v[3] == "kv" and (v[1] == name or v[2] == name) then
- opt = v
- break
- end
- end
- if not opt then
- return false
- end
-
- -- show candidates of values
- local values = opt.values
- if type(values) == "function" then
- values = values(value)
- end
- if values == nil and type(opt[4]) == "boolean" then
- values = { "y", "n" }
- -- ignore existing input
- value = ""
- end
- for _, v in ipairs(values) do
- if tostring(v):startswith(value) then
- _print_candidate(true, "--%s=%s", name, v)
- end
- end
- return true
- end
-
- local opcandi = table.new(10, 0)
- for _, v in ipairs(options) do
- if current[v[2]] == nil then
- if v[3] == "kv" or v[3] == "k" then table.insert(opcandi, v) end
- end
- end
-
- for _, v in ipairs(opcandi) do
- -- startswith
- if v[2]:startswith(name) then
- _print_candidate((v[3] == "k"), (v[3] == "k") and "--%s" or "--%s=", v[2])
- end
- end
-
- if name == "" then
- return true
- end
-
- for _, v in ipairs(opcandi) do
- -- not startswith
- if v[2]:find(name, 2, true) then
- _print_candidate((v[3] == "k"), (v[3] == "k") and "--%s" or "--%s=", v[2])
- end
+ return _complete_option_kv_v(options, current, completing, name, value)
+ else
+ -- complete keys
+ return _complete_option_kv_k(options, current, completing, name)
end
-
- return true
end
+-- complete options v and vs
function _complete_option_v(options, current, completing)
-- find completion option
local opt
@@ -158,7 +179,7 @@ function _complete_option_v(options, current, completing)
-- show candidates of values
local values = opt.values
if type(values) == "function" then
- values = values(completing)
+ values = values(completing, current)
end
for _, v in ipairs(values) do
if tostring(v):startswith(completing) then
@@ -198,12 +219,12 @@ function _complete_option(options, segs, completing)
-- current context is wrong
if not reenter and (current_options.file or current_options.project) then
- local args = {"lua", "--root", "private.utils.complete", tostring(position), use_spaces and "reenter" or "nospace-reenter", table.unpack(raw_words) }
+ local args = {"lua", "private.utils.complete", tostring(position), raw_config .. "-reenter", table.unpack(raw_words) }
if current_options.file then
- table.insert(args, 3, "--file=" .. current_options.file)
+ table.insert(args, 2, "--file=" .. current_options.file)
end
if current_options.project then
- table.insert(args, 3, "--project=" .. current_options.project)
+ table.insert(args, 2, "--project=" .. current_options.project)
end
os.execv("xmake", args)
return true
@@ -253,22 +274,23 @@ function main(pos, config, ...)
raw_words = {...}
- local is_config = false
- if config:find("nospace", 1, true) then
+ raw_config = (config or ""):trim()
+ if raw_config:find("nospace", 1, true) then
use_spaces = false
- is_config = true
end
- if config:find("reenter", 1, true) then
+ if raw_config:find("reenter", 1, true) then
reenter = true
- is_config = true
end
-
- if not is_config then
- table.insert(raw_words, 1, config)
+ if raw_config:find("nokey", 1, true) then
+ no_key = true
+ end
+ if raw_config:find("debug", 1, true) then
+ debug = true
end
local word = table.concat(raw_words, " ") or ""
position = tonumber(pos) or 0
+
local has_space = word:endswith(" ") or position > #word
word = word:trim()
diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua
index 0dc7b91f8..43c7acccb 100644
--- a/xmake/platforms/windows/xmake.lua
+++ b/xmake/platforms/windows/xmake.lua
@@ -11,7 +11,7 @@
-- 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 ruki
@@ -50,10 +50,10 @@ platform("windows")
-- set menu
set_menu {
- config =
- {
+ config =
+ {
{category = "Visual Studio SDK Configuration" }
- , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio"
+ , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio"
, " e.g. --vs=2017" }
, {nil, "vs_toolset", "kv", nil, "The Microsoft Visual Studio Toolset Version"
, " e.g. --vs_toolset=14.0" }
@@ -67,19 +67,20 @@ platform("windows")
, {category = "WDK Configuration" }
, {nil, "wdk", "kv", "auto", "The WDK Directory" }
, {nil, "wdk_sdkver", "kv", "auto", "The WDK Version" }
- , {nil, "wdk_winver", "kv", "auto", "The WDK Windows Version",
- " - win10_rs3",
- " - win10",
- " - win81",
- " - win8",
- " - win7",
- " - win7_[sp1|sp2|sp3]" }
+ , {nil, "wdk_winver", "kv", "auto", "The WDK Windows Version"
+ , values = function (complete)
+ if complete then
+ return {"win10_rs3", "win10", "win81", "win8", "win7_sp3", "win7_sp2", "win7_sp1", "win7"}
+ else
+ return {"win10[|_rs3]", "win81", "win8", "win7[|_sp1|_sp2|_sp3]"}
+ end
+ end }
, {category = "Vcpkg Configuration" }
, {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" }
}
, global =
- {
+ {
{category = "Visual Studio SDK Configuration" }
, {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" }
, {category = "Cuda SDK Configuration" }
diff --git a/xmake/plugins/lua/main.lua b/xmake/plugins/lua/main.lua
new file mode 100644
index 000000000..c0ed6e3d0
--- /dev/null
+++ b/xmake/plugins/lua/main.lua
@@ -0,0 +1,134 @@
+--!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 ruki
+-- @file main.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.sandbox.module")
+import("core.sandbox.sandbox")
+
+-- get all lua scripts
+function scripts()
+ local names = {}
+ local files = os.files(path.join(os.scriptdir(), "scripts/*.lua"))
+ for _, file in ipairs(files) do
+ table.insert(names, path.basename(file))
+ end
+ return names
+end
+
+-- list all lua scripts
+function _list()
+ print("scripts:")
+ for _, file in ipairs(scripts()) do
+ print(" " .. file)
+ end
+end
+
+function _run_commanad(command, args)
+ local tmpfile = os.tmpfile() .. ".lua"
+ io.writefile(tmpfile, "function main(...)\n" .. command .. "\nend")
+ return _run_script(tmpfile, args)
+end
+
+function _run_script(script, args)
+
+ local func
+ local printresult = false
+
+ -- import and run script
+ if path.extension(script) == ".lua" and os.isfile(script) then
+
+ -- run the given lua script file (xmake lua /tmp/script.lua)
+ vprint("running given lua script file: %s", path.relative(script))
+ func = import(path.basename(script), {rootdir = path.directory(script), anonymous = true})
+
+ elseif os.isfile(path.join(os.scriptdir(), "scripts", script .. ".lua")) then
+
+ -- run builtin lua script (xmake lua echo "hello xmake")
+ vprint("running builtin lua script: %s", script)
+ func = import("scripts." .. script, {anonymous = true})(table.unpack(args, 1, args.n))
+ else
+
+ -- attempt to find the builtin module
+ local object = nil
+ for _, name in ipairs(script:split("%.")) do
+ object = object and object[name] or module.get(name)
+ if not object then
+ break
+ end
+ end
+ if object then
+ -- run builtin modules (xmake lua core.xxx.xxx)
+ vprint("running builtin module: %s", script)
+ func = object
+ else
+ -- run imported modules (xmake lua core.xxx.xxx)
+ vprint("running imported module: %s", script)
+ func = import(script, {anonymous = true})
+ end
+ printresult = true
+ end
+
+ local result = table.pack(func(table.unpack(args, 1, args.n)))
+ if printresult and result and result.n ~= 0 then
+ utils.dump(unpack(result, 1, result.n))
+ end
+end
+
+function _get_args()
+
+ local args = option.get("arguments") or {}
+ args.n = #args
+ for i, value in ipairs(args) do
+ if value:startswith('@') then
+ -- deserialize @ prefixed arg
+ local v, err = string.deserialize(value:sub(2))
+ if err then
+ -- for strings that failed to deserialize, regaed it as a normal string, just show a warning message
+ utils.warning(err)
+ else
+ args[i] = v
+ end
+ end
+ end
+
+ return args
+end
+
+function main()
+
+ if option.get("list") then
+ return _list()
+ end
+
+ -- run command?
+ local script = option.get("script")
+ if option.get("command") and script then
+ return _run_commanad(script, _get_args())
+ end
+
+ -- get script
+ if script then
+ return _run_script(script, _get_args())
+ end
+
+ -- enter interactive mode
+ sandbox.interactive()
+end
diff --git a/xmake/plugins/lua/xmake.lua b/xmake/plugins/lua/xmake.lua
index e264ba14d..23d00b145 100644
--- a/xmake/plugins/lua/xmake.lua
+++ b/xmake/plugins/lua/xmake.lua
@@ -25,87 +25,7 @@ task("lua")
set_category("plugin")
-- on run
- on_run(function ()
-
- -- imports
- import("core.base.option")
- import("core.sandbox.module")
- import("core.sandbox.sandbox")
-
- -- list all lua scripts?
- if option.get("list") then
- print("scripts:")
- local files = os.match(path.join(os.scriptdir(), "scripts/*.lua"))
- for _, file in ipairs(files) do
- print(" " .. path.basename(file))
- end
- return
- end
-
- -- run command?
- local script = option.get("script")
- if option.get("command") and script then
- local tmpfile = os.tmpfile() .. ".lua"
- io.writefile(tmpfile, "function main(...)\n" .. script .. "\nend")
- script = tmpfile
- end
-
- -- get script
- if script then
-
- local args = option.get("arguments") or {}
- args.n = #args
- for i, value in ipairs(args) do
- if value:startswith('@') then
- local v, err = string.deserialize(value:sub(2))
- if err then
- -- for strings that failed to deserialize, regaed it as a normal string, just show a warning message
- utils.warning(err)
- else
- args[i] = v
- end
- end
- end
-
- -- import and run script
- if path.extension(script) == ".lua" and os.isfile(script) then
-
- -- run the given lua script file (xmake lua /tmp/script.lua)
- vprint("running given lua script file: %s", path.relative(script))
- import(path.basename(script), {rootdir = path.directory(script), anonymous = true})(table.unpack(args, 1, args.n))
-
- elseif os.isfile(path.join(os.scriptdir(), "scripts", script .. ".lua")) then
-
- -- run builtin lua script (xmake lua echo "hello xmake")
- vprint("running builtin lua script: %s", script)
- import("scripts." .. script, {anonymous = true})(table.unpack(args, 1, args.n))
- else
-
- -- attempt to find the builtin module
- local object = nil
- for _, name in ipairs(script:split("%.")) do
- object = object and object[name] or module.get(name)
- if not object then
- break
- end
- end
- local result = nil
- if object then
- -- run builtin modules (xmake lua core.xxx.xxx)
- vprint("running builtin module: %s", script)
- result = table.pack(object(table.unpack(args, 1, args.n)))
- else
- -- run imported modules (xmake lua core.xxx.xxx)
- vprint("running imported module: %s", script)
- result = table.pack(import(script, {anonymous = true})(table.unpack(args, 1, args.n)))
- end
- if result and result.n ~= 0 then utils.dump(unpack(result, 1, result.n)) end
- end
- else
- -- enter interactive mode
- sandbox.interactive()
- end
- end)
+ on_run("main")
-- set menu
set_menu {
@@ -119,21 +39,28 @@ task("lua")
, shortname = 'l'
-- options
- , options =
+ , options =
{
- {'l', "list", "k", nil, "List all scripts." }
- , {'c', "command", "k", nil, "Run script as command" }
- , {nil, "script", "v", nil, "Run the given lua script name, file or module and enter interactive mode if no given script.",
+ {'l', "list" , "k" , nil , "List all scripts." }
+ , {'c', "command" , "k" , nil , "Run script as 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",
- " - xmake lua -c 'print(...)' hello xmake!" }
- , {nil, "arguments", "vs", nil, "The script arguments, use '@' to enable deserializing.",
+ " - xmake lua -c 'print(...)' hello xmake!"
+ , values = function (complete, opt)
+ if not complete or opt.command or opt.list then
+ return
+ end
+
+ return import("main.scripts")()
+ end }
+ , {nil, "arguments" , "vs" , nil , "The script arguments, use '@' to enable deserializing.",
"e.g.",
- " - xmake lua lib.detect.find_tool tar @{version=true}" }
+ " - xmake lua lib.detect.find_tool tar @{version=true}" }
}
}
diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua
index 0bbbaa53b..c55b4f680 100644
--- a/xmake/plugins/macro/main.lua
+++ b/xmake/plugins/macro/main.lua
@@ -75,12 +75,10 @@ function _wfile(macroname)
return path.join(path.join(config.directory(), "macros"), macroname .. ".lua")
end
--- list macros
-function _list()
-
- -- trace
- cprint("${bright}macros:")
+-- get all macros
+function macros(anonymousname)
+ local results = {}
-- find all macros
for _, dir in ipairs(_directories()) do
local macrofiles = os.match(path.join(dir, "*.lua"))
@@ -88,14 +86,28 @@ function _list()
-- get macro name
local macroname = path.basename(macrofile)
- if macroname == "anonymous" then
- macroname = ".<anonymous>"
+
+ if macroname == "anonymous" and anonymousname then
+ macroname = anonymousname
end
- -- show it
- print(" " .. macroname)
+ table.insert(results, macroname)
end
end
+ return results
+end
+
+-- list macros
+function _list()
+
+ -- trace
+ cprint("${bright}macros:")
+
+ -- find all macros
+ for _, macroname in ipairs(macros(".<anonymous>")) do
+ -- show it
+ print(" " .. macroname)
+ end
end
-- show macro
diff --git a/xmake/plugins/macro/xmake.lua b/xmake/plugins/macro/xmake.lua
index 24157dfe0..e414ba246 100644
--- a/xmake/plugins/macro/xmake.lua
+++ b/xmake/plugins/macro/xmake.lua
@@ -41,10 +41,10 @@ task("macro")
-- options
, options =
{
- {'b', "begin", "k", nil, "Start to record macro."
+ {'b', "begin", "k", nil, "Start to record macro."
, "e.g."
, "Record macro with name: test"
- , " xmake macro --begin"
+ , " xmake macro --begin"
, " xmake config --plat=macosx"
, " xmake clean"
, " xmake -r"
@@ -68,9 +68,19 @@ task("macro")
, {}
, {nil, "name", "v", ".", "Set the macro name."
, "e.g."
- , " Run the given macro: xmake macro test"
- , " Run the anonymous macro: xmake macro ."
- , " Run the last command: xmake macro .." }
+ , " Run the given macro: xmake macro test"
+ , " Run the anonymous macro: xmake macro ."
+ , " Run the last command: xmake macro .."
+ , values = function (complete, opt)
+ -- hide in help menu
+ if not complete then return end
+ -- don't need name
+ if opt.begin or opt.list or opt.clear then return end
+ -- name should be given by user
+ if opt["end"] or opt.import then return end
+
+ return import("main.macros")(".")
+ end }
, {nil, "arguments", "vs", nil, "Set the macro arguments." }
}
}
diff --git a/xmake/plugins/project/main.lua b/xmake/plugins/project/main.lua
index 147cee3d6..b24a3b47f 100755
--- a/xmake/plugins/project/main.lua
+++ b/xmake/plugins/project/main.lua
@@ -31,13 +31,11 @@ import("vsxmake.vsxmake")
import("clang.compile_flags")
import("clang.compile_commands")
--- make project
-function _make(kind)
+function makers()
-- the maps
- local maps =
- {
- makefile = makefile.make
+ return
+ { makefile = makefile.make
, xmakefile = xmakefile.make
, cmakelists = cmakelists.make
, vs2002 = vs.make(2002)
@@ -61,6 +59,12 @@ function _make(kind)
, compile_flags = compile_flags.make
, compile_commands = compile_commands.make
}
+end
+
+-- make project
+function _make(kind)
+
+ local maps = makers()
assert(maps[kind], "the project kind(%s) is not supported!", kind)
-- make it
diff --git a/xmake/plugins/project/xmake.lua b/xmake/plugins/project/xmake.lua
index 31be1e90b..f5c6c6b30 100644
--- a/xmake/plugins/project/xmake.lua
+++ b/xmake/plugins/project/xmake.lua
@@ -38,22 +38,29 @@ task("project")
-- options
, options =
{
- {'k', "kind", "kv", "makefile", "Set the project kind."
- , " - makefile"
- , " - xmakefile (makefile with xmake)"
- , " - cmakelists"
- , " - compile_flags"
- , " - compile_commands (clang compilation database with json format)"
- , " - vs (auto detect), vs2002, vs2003, vs2005, vs2008"
- , " - vs2010, vs2012, vs2013, vs2015, vs2017, vs2019"
- , " - vsxmake (auto detect), vsxmake2010 ~ vsxmake2019" }
- , {'m', "modes", "kv", nil, "Set the project modes."
- , " e.g. "
- , " - xmake project -k vsxmake -m \"release" .. path.envsep() .. "debug\"" }
- , {'a', "archs", "kv", nil, "Set the project archs."
- , " e.g. "
- , " - xmake project -k vsxmake -a \"x86" .. path.envsep() .. "x64\"" }
- , {nil, "outputdir", "v", ".", "Set the output directory." }
+ {'k', "kind", "kv" , "makefile", "Set the project kind."
+ , " - makefile"
+ , " - xmakefile (makefile with xmake)"
+ , " - cmakelists"
+ , " - compile_flags"
+ , " - compile_commands (clang compilation database with json format)"
+ , " - vs (auto detect), vs2002, vs2003, vs2005, vs2008"
+ , " - vs2010, vs2012, vs2013, vs2015, vs2017, vs2019"
+ , " - vsxmake (auto detect), vsxmake2010 ~ vsxmake2019"
+ , values = function (complete, opt)
+ if not complete then return end
+
+ local values = table.keys(import("main.makers")())
+ table.sort(values, function (a, b) return a > b end)
+ return values
+ end }
+ , {'m', "modes", "kv" , nil , "Set the project modes."
+ , " e.g. "
+ , " - xmake project -k vsxmake -m \"release" .. path.envsep() .. "debug\"" }
+ , {'a', "archs", "kv" , nil , "Set the project archs."
+ , " e.g. "
+ , " - xmake project -k vsxmake -a \"x86" .. path.envsep() .. "x64\"" }
+ , {nil, "outputdir", "v" , "." , "Set the output directory." }
}
}