Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve tab complete #673

Merged
merged 20 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions scripts/get.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -14,6 +14,7 @@ if [ 0 -ne "$(id -u)" ]; then
sudoprefix=
fi
else
export XMAKE_ROOT=y
sudoprefix=
fi

Expand Down Expand Up @@ -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
Expand All @@ -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
OpportunityLiu marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/modules/string/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
105 changes: 74 additions & 31 deletions xmake/actions/config/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,25 +39,29 @@ 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 ()
, {'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."

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
Expand All @@ -74,41 +78,80 @@ 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")

-- make description
local arches = hashset.new()

if opt.plat then
local archs = platform.archs(opt.plat)
if archs then
for _, arch in ipairs(archs) do
arches:insert(arch)
end
end
else
for _, plat in ipairs(platform.plats()) do
local archs = platform.archs(plat)
if archs then
for _, arch in ipairs(archs) do
arches:insert(arch)
end
end
end
end

-- get it
return arches: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")
Expand All @@ -118,7 +161,7 @@ task("config")
end

-- show platform menu options
, function ()
, function ()

-- import platform menu
import("core.platform.menu")
Expand Down
Loading