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

add tests for install & uninstall #115

Merged
merged 28 commits into from May 25, 2017
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c536607
add tests for xmake (un)install
ruihe774 May 23, 2017
9e014f7
do not test install on windows
ruihe774 May 23, 2017
f2e0d82
use $(xmake) instead of xmake to fix cnf
ruihe774 May 23, 2017
550e0a9
add xmake._EXECUTABLE_PATH to fix $(xmake)
ruihe774 May 23, 2017
36a48f2
fix tests
ruihe774 May 23, 2017
eca531f
fix build on macos
ruihe774 May 23, 2017
3ddda43
sudo luarocks install
ruihe774 May 23, 2017
7e750ae
Revert "use $(xmake) instead of xmake to fix cnf"
ruihe774 May 23, 2017
31a7bbe
add os.addenv and improve os.setenv
waruqi May 23, 2017
89e2cc7
add xmake to path
ruihe774 May 23, 2017
962b99c
fix build by using sudo $(xmake)
ruihe774 May 23, 2017
f1e3e37
Revert "fix build by using sudo $(xmake)"
ruihe774 May 24, 2017
a00ed18
Revert "add xmake to path"
ruihe774 May 24, 2017
7ee82c2
fix chaos installation
ruihe774 May 24, 2017
4fafe79
use link on supported os in installation
ruihe774 May 24, 2017
b91fc2f
Merge branch 'dev' into installtest
ruihe774 May 25, 2017
a647f87
use luaL_optstring instead of luaL_checkstring in readline.readline f…
ruihe774 May 24, 2017
0744b67
directly inherit os.versioninfo
ruihe774 May 24, 2017
578211e
fix sudo PATH passing
ruihe774 May 25, 2017
1f93705
fix XMAKE_PROGRAM_DIR finding
ruihe774 May 25, 2017
c55e08a
Merge branch 'dev' into installtest
ruihe774 May 25, 2017
6f37771
fix lua version on macos
ruihe774 May 25, 2017
33826d1
reload bash profile
ruihe774 May 25, 2017
64e1e79
do not directly install on macos
ruihe774 May 25, 2017
bbed6a5
use implement in dev
ruihe774 May 25, 2017
abb1d57
Merge branch 'dev' into installtest
ruihe774 May 25, 2017
ff1ba70
Revert "do not directly install on macos"
ruihe774 May 25, 2017
67a5ad7
Revert "use link on supported os in installation"
ruihe774 May 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 7 additions & 13 deletions .travis.yml
Expand Up @@ -13,31 +13,25 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- gcc-5

env:
global:
- LUAROCKS=2.2.2
- LUA=lua5.1

before_install:
- rm install
- source scripts/.travis/setenv_lua.sh
- luarocks install luacov
- luarocks

install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust lua51; fi
- sudo luarocks install luacov || sudo luarocks-5.1 install luacov

script:
- scripts/get.sh __local__
- source ~/.bash_profile
- xmake lua versioninfo
- xmake f -m coverage -P core
- xmake -P core
- export XMAKE_PROGRAM_DIR=$PWD/xmake
- core/build/xmake lua versioninfo
- echo "require('luacov.runner').init({['statsfile']='$PWD/luacov.stats.out',['reportfile']='$PWD/luacov.report.out'})" > tmp
- cat xmake/core/_xmake_main.lua >> tmp
- mv tmp xmake/core/_xmake_main.lua
- cp core/build/xmake $(which xmake) || sudo cp core/build/xmake $(which xmake)
- export XMAKE_PROGRAM_DIR=~/.local/share/xmake
- mv tmp "$XMAKE_PROGRAM_DIR/core/_xmake_main.lua"
- cp core/build/xmake "$XMAKE_PROGRAM_DIR" || sudo cp core/build/xmake "$XMAKE_PROGRAM_DIR"
- xmake lua versioninfo
- xmake lua --backtrace tests/test.lua

Expand Down
2 changes: 1 addition & 1 deletion core/src/xmake/machine.c
Expand Up @@ -319,7 +319,7 @@ static tb_bool_t xm_machine_get_program_directory(xm_machine_impl_t* impl, tb_ch
// get the directory
while (size-- > 0)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to write the following code three times.

                while (size-- > 0)
                {
                    if (data[size] == '/')
                    {
                        data[size] = '\0';
                        break;
                    }
                }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use this implementation in dev to replace it directly. 😸

if (data[size] == '\\' || data[size] == '/')
if (data[size] == '\\' || data[size] == '/')
{
data[size] = '\0';
tb_strlcpy(path, data, maxn);
Expand Down
4 changes: 1 addition & 3 deletions core/src/xmake/readline/readline.c
Expand Up @@ -47,9 +47,7 @@ tb_int_t xm_readline_readline(lua_State* lua)
tb_assert_and_check_return_val(lua, 0);

// get the prompt
tb_char_t const* prompt = tb_null;
if (tb_strcmp("nil", luaL_typename(lua, 1)) != 0)
prompt = luaL_checkstring(lua, 1);
tb_char_t const* prompt = luaL_optstring(lua, 1, tb_null);

// call readline
tb_char_t* line = readline(prompt);
Expand Down
6 changes: 4 additions & 2 deletions makefile
Expand Up @@ -61,15 +61,17 @@ install:
@# install the xmake directory
@cp -r xmake/* $(xmake_dir_install)
@# make the xmake loader
ifneq ($(PLAT),linux)
Copy link
Member

@waruqi waruqi May 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this? Although we can get the executable path on linux, macOS and windows now. But maybe we cannot get it successfully on some linux distributions. So I think we still need export XMAKE_PROGRAM_DIR=/xxx

@echo '#!/bin/bash' > $(xmake_loader)
@echo 'export XMAKE_PROGRAM_DIR=$(xmake_dir_install)' >> $(xmake_loader)
@echo '$(xmake_core_install) $(verbose) "$$@"' >> $(xmake_loader)
else
@ln -s '$(xmake_core_install)' '$(xmake_loader)'
endif
@# install the xmake loader
@if [ ! -d $(prefix)/bin ]; then mkdir -p $(prefix)/bin; fi
@mv $(xmake_loader) $(xmake_loader_install)
@chmod 777 $(xmake_loader_install)
@# tip
@$(if $(findstring $(prefix)/bin,$(PATH)),,echo 'please export PATH=$$PATH:$(prefix)/bin')
@# remove xmake.out
@if [ -f '/tmp/xmake.out' ]; then rm /tmp/xmake.out; fi
@# ok
Expand Down
1 change: 0 additions & 1 deletion scripts/.travis/copyright

This file was deleted.

15 changes: 0 additions & 15 deletions scripts/.travis/platform.sh

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/.travis/setenv_lua.sh

This file was deleted.

124 changes: 0 additions & 124 deletions scripts/.travis/setup_lua.sh

This file was deleted.

53 changes: 33 additions & 20 deletions scripts/get.sh
Expand Up @@ -98,29 +98,42 @@ then
my_exit 'Build Fail' $rv
fi
fi
PATHclone=$PATH
patharr=($PATHclone)
prefix=
for st in "${patharr[@]}"
do
if [[ "$st" = "$HOME"* ]]
then
cwd=$PWD
mkdir -p "$st"
cd "$st" || continue
echo $$ > $$xmake_getter_test 2>/dev/null || continue
rm $$xmake_getter_test 2>/dev/null || continue
cd .. || continue
mkdir -p share 2>/dev/null || continue
prefix=$(pwd)
cd "$cwd" || my_exit 'Chdir Error'
break
fi
done
# PATHclone=$PATH
# patharr=($PATHclone)
if [ "$prefix" = "" ]
then
prefix=~/.local
fi
# for st in "${patharr[@]}"
# do
# if [[ "$st" = "$HOME"* ]]
# then
# cwd=$PWD
# mkdir -p "$st"
# cd "$st" || continue
# echo $$ > $$xmake_getter_test 2>/dev/null || continue
# rm $$xmake_getter_test 2>/dev/null || continue
# cd .. || continue
# mkdir -p share 2>/dev/null || continue
# prefix=$(pwd)
# cd "$cwd" || my_exit 'Chdir Error'
# break
# fi
# done
if [ "x$prefix" != x ]
then
make -C /tmp/$$xmake_getter --no-print-directory install prefix="$prefix"|| my_exit 'Install Fail'
else
$sudoprefix make -C /tmp/$$xmake_getter --no-print-directory install || my_exit 'Install Fail'
fi
xmake --version
shell_profile(){
if [[ "$SHELL" = */zsh ]]; then echo ~/.zshrc
elif [[ "$SHELL" = */ksh ]]; then echo ~/.kshrc
else echo ~/.bash_profile; fi
}
xmake --version >/dev/null 2>&1 && xmake --version || {
echo "export PATH=$prefix/bin:\$PATH" >> $(shell_profile)
export PATH=$prefix/bin:$PATH
xmake --version
echo -e "Reload shell profile by running \x1b[1msource '$(shell_profile)'\x1b[0m now!"
}
8 changes: 4 additions & 4 deletions tests/build.lua
Expand Up @@ -24,14 +24,14 @@ function main(argv)
os.exec("xmake f --cc=gcc --cxx=g++")
os.exec("xmake m buildtest")
if sudo.has() then
-- sudo.exec("xmake install")
-- sudo.exec("xmake uninstall")
sudo.exec("xmake install")
sudo.exec("xmake uninstall")
end
os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace")
os.exec("xmake m buildtest")
if sudo.has() then
-- sudo.exec("xmake install --all -v --backtrace")
-- sudo.exec("xmake uninstall -v --backtrace")
sudo.exec("xmake install --all -v --backtrace")
sudo.exec("xmake uninstall -v --backtrace")
end
os.exec("xmake m -d buildtest")

Expand Down
6 changes: 1 addition & 5 deletions xmake/core/sandbox/modules/os.lua
Expand Up @@ -48,6 +48,7 @@ sandbox_os.nuldev = os.nuldev
sandbox_os.emptydir = os.emptydir
sandbox_os.programdir = os.programdir
sandbox_os.programfile = os.programfile
sandbox_os.versioninfo = os.versioninfo

-- copy file or directory
function sandbox_os.cp(...)
Expand Down Expand Up @@ -459,11 +460,6 @@ function sandbox_os.uuid(name)
return uuid
end

-- get versioninfo
function sandbox_os.versioninfo()
return os.versioninfo()
end

-- return module
return sandbox_os

4 changes: 2 additions & 2 deletions xmake/modules/privilege/sudo.lua
Expand Up @@ -45,7 +45,7 @@ function _sudo(runner, cmd, ...)
pathenv = pathenv:gsub("\"", "\\\"")

-- run it with administrator permission and preserve parent environment
runner(program .. " PATH=\"" .. pathenv .. "\" " .. cmd, ...)
runner(program .. " env PATH=\"" .. pathenv .. "\" " .. cmd, ...)
else
-- run it with administrator permission
runner(program .. " " .. cmd, ...)
Expand All @@ -64,7 +64,7 @@ function _sudov(runner, shellname, argv)
assert(program, "sudo not found!")

-- run it with administrator permission and preserve parent environment
runner(program, table.join("PATH=" .. os.getenv("PATH"), shellname, argv))
runner(program, table.join("env", "PATH=" .. os.getenv("PATH"), shellname, argv))
end

-- sudo run lua script with administrator permission and arguments list
Expand Down