diff options
| author | ruki <[email protected]> | 2017-05-25 13:13:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-25 13:13:30 +0800 |
| commit | 0c98817adb9e37ba3ca9e1c276e52f297976ea53 (patch) | |
| tree | 12cf30f239a65e356990f329e98a8bbeb0f16554 | |
| parent | 3768a8200a7699e1531c07ee5ab490e7d4f27b11 (diff) | |
| parent | 67a5ad78de9453d14b562cd7c3f2a4364e370d24 (diff) | |
Merge pull request #115 from TitanSnow/installtest
add tests for install & uninstall
| -rw-r--r-- | .travis.yml | 20 | ||||
| -rw-r--r-- | core/src/xmake/machine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/readline/readline.c | 4 | ||||
| -rw-r--r-- | makefile | 2 | ||||
| -rw-r--r-- | scripts/.travis/copyright | 1 | ||||
| -rw-r--r-- | scripts/.travis/platform.sh | 15 | ||||
| -rw-r--r-- | scripts/.travis/setenv_lua.sh | 3 | ||||
| -rw-r--r-- | scripts/.travis/setup_lua.sh | 124 | ||||
| -rwxr-xr-x | scripts/get.sh | 53 | ||||
| -rw-r--r-- | tests/build.lua | 8 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/privilege/sudo.lua | 4 |
12 files changed, 49 insertions, 193 deletions
diff --git a/.travis.yml b/.travis.yml index 544d2eb45..3ceb81d09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,22 +13,15 @@ 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 @@ -36,8 +29,9 @@ script: - 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 diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 6baf7f214..0281f0a2c 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -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) { - if (data[size] == '\\' || data[size] == '/') + if (data[size] == '\\' || data[size] == '/') { data[size] = '\0'; tb_strlcpy(path, data, maxn); diff --git a/core/src/xmake/readline/readline.c b/core/src/xmake/readline/readline.c index 9684639be..aceae5785 100644 --- a/core/src/xmake/readline/readline.c +++ b/core/src/xmake/readline/readline.c @@ -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); @@ -68,8 +68,6 @@ install: @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 diff --git a/scripts/.travis/copyright b/scripts/.travis/copyright deleted file mode 100644 index 0346e778f..000000000 --- a/scripts/.travis/copyright +++ /dev/null @@ -1 +0,0 @@ -Copyright (c) 2015-2017 codecov diff --git a/scripts/.travis/platform.sh b/scripts/.travis/platform.sh deleted file mode 100644 index 7259a7d63..000000000 --- a/scripts/.travis/platform.sh +++ /dev/null @@ -1,15 +0,0 @@ -if [ -z "${PLATFORM:-}" ]; then - PLATFORM=$TRAVIS_OS_NAME; -fi - -if [ "$PLATFORM" == "osx" ]; then - PLATFORM="macosx"; -fi - -if [ -z "$PLATFORM" ]; then - if [ "$(uname)" == "Linux" ]; then - PLATFORM="linux"; - else - PLATFORM="macosx"; - fi; -fi diff --git a/scripts/.travis/setenv_lua.sh b/scripts/.travis/setenv_lua.sh deleted file mode 100644 index 499949342..000000000 --- a/scripts/.travis/setenv_lua.sh +++ /dev/null @@ -1,3 +0,0 @@ -export PATH=${PATH}:$HOME/.lua:$HOME/.local/bin:${TRAVIS_BUILD_DIR}/install/luarocks/bin -bash scripts/.travis/setup_lua.sh -eval `$HOME/.lua/luarocks path` diff --git a/scripts/.travis/setup_lua.sh b/scripts/.travis/setup_lua.sh deleted file mode 100644 index 153b99d90..000000000 --- a/scripts/.travis/setup_lua.sh +++ /dev/null @@ -1,124 +0,0 @@ -#! /bin/bash - -# A script for setting up environment for travis-ci testing. -# Sets up Lua and Luarocks. -# LUA must be "lua5.1", "lua5.2" or "luajit". -# luajit2.0 - master v2.0 -# luajit2.1 - master v2.1 - -set -eufo pipefail - -LUAJIT_BASE="LuaJIT-2.0.4" - -source scripts/.travis/platform.sh - -LUA_HOME_DIR=$TRAVIS_BUILD_DIR/install/lua - -LR_HOME_DIR=$TRAVIS_BUILD_DIR/install/luarocks - -mkdir $HOME/.lua - -LUAJIT="no" - -if [ "$PLATFORM" == "macosx" ]; then - if [ "$LUA" == "luajit" ]; then - LUAJIT="yes"; - fi - if [ "$LUA" == "luajit2.0" ]; then - LUAJIT="yes"; - fi - if [ "$LUA" == "luajit2.1" ]; then - LUAJIT="yes"; - fi; -elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then - LUAJIT="yes"; -fi - -mkdir -p "$LUA_HOME_DIR" - -if [ "$LUAJIT" == "yes" ]; then - - if [ "$LUA" == "luajit" ]; then - curl http://luajit.org/download/$LUAJIT_BASE.tar.gz | tar xz; - else - git clone http://luajit.org/git/luajit-2.0.git $LUAJIT_BASE; - fi - - cd $LUAJIT_BASE - - if [ "$LUA" == "luajit2.1" ]; then - git checkout v2.1; - fi - - make && make install PREFIX="$LUA_HOME_DIR" - - if [ "$LUA" == "luajit2.1" ]; then - ln -s $LUA_HOME_DIR/bin/luajit-2.1.0-alpha $HOME/.lua/luajit - ln -s $LUA_HOME_DIR/bin/luajit-2.1.0-alpha $HOME/.lua/lua; - else - ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/luajit - ln -s $LUA_HOME_DIR/bin/luajit $HOME/.lua/lua; - fi; - -else - - if [ "$LUA" == "lua5.1" ]; then - curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz - cd lua-5.1.5; - elif [ "$LUA" == "lua5.2" ]; then - curl http://www.lua.org/ftp/lua-5.2.4.tar.gz | tar xz - cd lua-5.2.4; - elif [ "$LUA" == "lua5.3" ]; then - curl http://www.lua.org/ftp/lua-5.3.1.tar.gz | tar xz - cd lua-5.3.1; - fi - - # Build Lua without backwards compatibility for testing - perl -i -pe 's/-DLUA_COMPAT_(ALL|5_2)//' src/Makefile - make $PLATFORM - make INSTALL_TOP="$LUA_HOME_DIR" install; - - ln -s $LUA_HOME_DIR/bin/lua $HOME/.lua/lua - ln -s $LUA_HOME_DIR/bin/luac $HOME/.lua/luac; - -fi - -cd $TRAVIS_BUILD_DIR - -lua -v - -LUAROCKS_BASE=luarocks-$LUAROCKS - -curl --location http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz - -cd $LUAROCKS_BASE - -if [ "$LUA" == "luajit" ]; then - ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR"; -elif [ "$LUA" == "luajit2.0" ]; then - ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.0" --prefix="$LR_HOME_DIR"; -elif [ "$LUA" == "luajit2.1" ]; then - ./configure --lua-suffix=jit --with-lua-include="$LUA_HOME_DIR/include/luajit-2.1" --prefix="$LR_HOME_DIR"; -else - ./configure --with-lua="$LUA_HOME_DIR" --prefix="$LR_HOME_DIR" -fi - -make build && make install - -ln -s $LR_HOME_DIR/bin/luarocks $HOME/.lua/luarocks - -cd $TRAVIS_BUILD_DIR - -luarocks --version - -rm -rf $LUAROCKS_BASE - -if [ "$LUAJIT" == "yes" ]; then - rm -rf $LUAJIT_BASE; -elif [ "$LUA" == "lua5.1" ]; then - rm -rf lua-5.1.5; -elif [ "$LUA" == "lua5.2" ]; then - rm -rf lua-5.2.4; -elif [ "$LUA" == "lua5.3" ]; then - rm -rf lua-5.3.1; -fi diff --git a/scripts/get.sh b/scripts/get.sh index e780b34cf..f4c605bdc 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -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!" +} diff --git a/tests/build.lua b/tests/build.lua index 3a9e5a385..763ebc3a9 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -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") diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 4b31128d2..4fee98405 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -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(...) @@ -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 diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua index b709d0db8..4eb5f6538 100644 --- a/xmake/modules/privilege/sudo.lua +++ b/xmake/modules/privilege/sudo.lua @@ -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, ...) @@ -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 |
