From c5366073e5275dcb8b991d648e21bdf30f955da2 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Tue, 23 May 2017 18:23:32 +0800 Subject: add tests for xmake (un)install --- .travis.yml | 2 +- tests/build.lua | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 63f8ce9bf..544d2eb45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -sudo: false +sudo: required language: C matrix: diff --git a/tests/build.lua b/tests/build.lua index 918b00133..b02062ed4 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -5,12 +5,18 @@ function main(argv) os.exec("xmake m -b") os.exec("xmake f -c") os.exec("xmake") + os.exec("sudo xmake install") + os.exec("sudo xmake uninstall") os.exec("xmake p") os.exec("xmake c") os.exec("xmake f -m release") os.exec("xmake -r -a -v --backtrace") + os.exec("sudo xmake install --all -v --backtrace") + os.exec("sudo xmake uninstall -v --backtrace") os.exec("xmake f --mode=debug --verbose --backtrace") os.exec("xmake --rebuild --all --verbose --backtrace") + os.exec("xmake install -o /tmp -a --verbose --backtrace") + os.exec("xmake uninstall --installdir=/tmp --verbose --backtrace") os.exec("xmake p --verbose --backtrace") os.exec("xmake c --verbose --backtrace") os.exec("xmake m -e buildtest") -- cgit v1.3.1 From 9e014f7b045966f612cdbbde7096ab889d01a0cc Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Tue, 23 May 2017 18:27:49 +0800 Subject: do not test install on windows --- tests/build.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/build.lua b/tests/build.lua index b02062ed4..b607414c0 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -5,18 +5,24 @@ function main(argv) os.exec("xmake m -b") os.exec("xmake f -c") os.exec("xmake") - os.exec("sudo xmake install") - os.exec("sudo xmake uninstall") + if os.host() ~= "windows" then + os.exec("sudo xmake install") + os.exec("sudo xmake uninstall") + end os.exec("xmake p") os.exec("xmake c") os.exec("xmake f -m release") os.exec("xmake -r -a -v --backtrace") - os.exec("sudo xmake install --all -v --backtrace") - os.exec("sudo xmake uninstall -v --backtrace") + if os.host() ~= "windows" then + os.exec("sudo xmake install --all -v --backtrace") + os.exec("sudo xmake uninstall -v --backtrace") + end os.exec("xmake f --mode=debug --verbose --backtrace") os.exec("xmake --rebuild --all --verbose --backtrace") - os.exec("xmake install -o /tmp -a --verbose --backtrace") - os.exec("xmake uninstall --installdir=/tmp --verbose --backtrace") + if os.host() ~= "windows" then + os.exec("xmake install -o /tmp -a --verbose --backtrace") + os.exec("xmake uninstall --installdir=/tmp --verbose --backtrace") + end os.exec("xmake p --verbose --backtrace") os.exec("xmake c --verbose --backtrace") os.exec("xmake m -e buildtest") -- cgit v1.3.1 From f2e0d829b43011cce87568118a5b8b0b469ade1e Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Tue, 23 May 2017 18:56:33 +0800 Subject: use $(xmake) instead of xmake to fix cnf --- tests/build.lua | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/build.lua b/tests/build.lua index b607414c0..1e18dbf1f 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -2,41 +2,41 @@ function main(argv) -- generic? - os.exec("xmake m -b") - os.exec("xmake f -c") - os.exec("xmake") + os.exec("$(xmake) m -b") + os.exec("$(xmake) f -c") + os.exec("$(xmake)") if os.host() ~= "windows" then - os.exec("sudo xmake install") - os.exec("sudo xmake uninstall") + os.exec("sudo $(xmake) install") + os.exec("sudo $(xmake) uninstall") end - os.exec("xmake p") - os.exec("xmake c") - os.exec("xmake f -m release") - os.exec("xmake -r -a -v --backtrace") + os.exec("$(xmake) p") + os.exec("$(xmake) c") + os.exec("$(xmake) f -m release") + os.exec("$(xmake) -r -a -v --backtrace") if os.host() ~= "windows" then - os.exec("sudo xmake install --all -v --backtrace") - os.exec("sudo xmake uninstall -v --backtrace") + os.exec("sudo $(xmake) install --all -v --backtrace") + os.exec("sudo $(xmake) uninstall -v --backtrace") end - os.exec("xmake f --mode=debug --verbose --backtrace") - os.exec("xmake --rebuild --all --verbose --backtrace") + os.exec("$(xmake) f --mode=debug --verbose --backtrace") + os.exec("$(xmake) --rebuild --all --verbose --backtrace") if os.host() ~= "windows" then - os.exec("xmake install -o /tmp -a --verbose --backtrace") - os.exec("xmake uninstall --installdir=/tmp --verbose --backtrace") + os.exec("$(xmake) install -o /tmp -a --verbose --backtrace") + os.exec("$(xmake) uninstall --installdir=/tmp --verbose --backtrace") end - os.exec("xmake p --verbose --backtrace") - os.exec("xmake c --verbose --backtrace") - os.exec("xmake m -e buildtest") - os.exec("xmake m -l") - os.exec("xmake f --cc=gcc --cxx=g++") - os.exec("xmake m buildtest") - os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") - os.exec("xmake m buildtest") - os.exec("xmake m -d buildtest") + os.exec("$(xmake) p --verbose --backtrace") + os.exec("$(xmake) c --verbose --backtrace") + os.exec("$(xmake) m -e buildtest") + os.exec("$(xmake) m -l") + os.exec("$(xmake) f --cc=gcc --cxx=g++") + os.exec("$(xmake) m buildtest") + os.exec("$(xmake) f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") + os.exec("$(xmake) m buildtest") + os.exec("$(xmake) m -d buildtest") -- test iphoneos? if argv and argv.iphoneos then if os.host() == "macosx" then - os.exec("xmake m package -p iphoneos") + os.exec("$(xmake) m package -p iphoneos") end end end -- cgit v1.3.1 From 550e0a96ce87a164d6a74b915d4ffa49ac9455fd Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Tue, 23 May 2017 19:51:30 +0800 Subject: add xmake._EXECUTABLE_PATH to fix $(xmake) $(xmake) is set to join(_PROGRAM_DIR, 'xmake') that is wrong when XMAKE_PROGRAM_DIR is set to another program dir (like developing dir) with no executable so use system-special ways to get absolution path of executable file always --- core/src/xmake/machine.c | 94 ++++++++++++++++++++++++++++-------------- xmake/core/_xmake_main.lua | 1 + xmake/core/project/project.lua | 2 +- xmake/core/project/task.lua | 2 +- 4 files changed, 65 insertions(+), 34 deletions(-) diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index ccfd91254..f6818d3be 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -244,29 +244,39 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl, { // ok ok = tb_true; - break; + // not break // even XMAKE_PROGRAM_DIR is set, exact path is needed } #if defined(TB_CONFIG_OS_WINDOWS) // get the executale file path as program directory - tb_size_t size = (tb_size_t)GetModuleFileName(tb_null, path, (DWORD)maxn); + tb_size_t size = (tb_size_t)GetModuleFileName(tb_null, data, (DWORD)maxn); tb_assert_and_check_break(size < maxn); // end - path[size] = '\0'; + data[size] = '\0'; - // get the directory - while (size-- > 0) + // set _EXECUTABLE_PATH + lua_pushstring(impl -> lua, data); + lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); + + if (!ok) { - if (path[size] == '\\') + // get the directory + while (size-- > 0) { - path[size] = '\0'; - break; + if (data[size] == '\\') + { + data[size] = '\0'; + break; + } } - } - // ok - ok = tb_true; + // copy to path + tb_strcpy(path, data); + + // ok + ok = tb_true; + } #elif defined(TB_CONFIG_OS_MACOSX) /* * _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter @@ -279,44 +289,64 @@ static tb_bool_t xm_machine_main_get_program_directory(xm_machine_impl_t* impl, * needed could be more than MAXPATHLEN. */ tb_uint32_t size = (tb_uint32_t)maxn; - if (!_NSGetExecutablePath(path, &size)) + if (!_NSGetExecutablePath(data, &size)) { - // get path size - size = tb_strlen(path); + // set _EXECUTABLE_PATH + lua_pushstring(impl -> lua, data); + lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); - // get the directory - while (size-- > 0) + if (!ok) { - if (path[size] == '/') + // get path size + size = tb_strlen(data); + + // get the directory + while (size-- > 0) { - path[size] = '\0'; - break; + if (data[size] == '/') + { + data[size] = '\0'; + break; + } } - } - // ok - ok = tb_true; + // copy to path + tb_strcpy(path, data); + + // ok + ok = tb_true; + } } #elif defined(TB_CONFIG_OS_LINUX) // get the executale file path as program directory - ssize_t size = readlink("/proc/self/exe", path, (size_t)maxn); + ssize_t size = readlink("/proc/self/exe", data, (size_t)maxn); if (size > 0 && size < maxn) { // end - path[size] = '\0'; + data[size] = '\0'; - // get the directory - while (size-- > 0) + // set _EXECUTABLE_PATH + lua_pushstring(impl -> lua, data); + lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); + + if (!ok) { - if (path[size] == '/') + // get the directory + while (size-- > 0) { - path[size] = '\0'; - break; + if (data[size] == '/') + { + data[size] = '\0'; + break; + } } - } - // ok - ok = tb_true; + // copy to path + tb_strcpy(path, data); + + // ok + ok = tb_true; + } } #endif diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 1f169e4af..c454406c0 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -36,6 +36,7 @@ xmake._CORE_DIR = _PROGRAM_DIR .. "/core" xmake._TOOLS_DIR = _PROGRAM_DIR .. "/tools" xmake._TEMPLATES_DIR = _PROGRAM_DIR .. "/templates" xmake._PROJECT_FILE = "xmake.lua" +xmake._EXECUTABLE_PATH = _EXECUTABLE_PATH -- init package path package.path = xmake._CORE_DIR .. "/?.lua;" .. package.path diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 6dff6d1a4..e68f399ca 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -320,7 +320,7 @@ function project._interpreter() , projectdir = project.directory() , packagedir = package.directory() , programdir = xmake._PROGRAM_DIR - , xmake = path.join(xmake._PROGRAM_DIR, "xmake") + , xmake = xmake._EXECUTABLE_PATH or path.join(xmake._PROGRAM_DIR, "xmake") } -- map it diff --git a/xmake/core/project/task.lua b/xmake/core/project/task.lua index 0111dd6e9..732a33b34 100644 --- a/xmake/core/project/task.lua +++ b/xmake/core/project/task.lua @@ -204,7 +204,7 @@ function task._interpreter() , projectdir = xmake._PROJECT_DIR , packagedir = package.directory() , programdir = xmake._PROGRAM_DIR - , xmake = path.join(xmake._PROGRAM_DIR, "xmake") + , xmake = xmake._EXECUTABLE_PATH or path.join(xmake._PROGRAM_DIR, "xmake") } -- map it -- cgit v1.3.1 From 36a48f283a68c3f95cab2e4250fb09155a64d406 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Tue, 23 May 2017 20:04:56 +0800 Subject: fix tests --- tests/build.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/build.lua b/tests/build.lua index 1e18dbf1f..12c23b7c5 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -6,31 +6,31 @@ function main(argv) os.exec("$(xmake) f -c") os.exec("$(xmake)") if os.host() ~= "windows" then - os.exec("sudo $(xmake) install") - os.exec("sudo $(xmake) uninstall") + os.exec("$(xmake) install -o /tmp -a --verbose --backtrace") + os.exec("$(xmake) uninstall --installdir=/tmp --verbose --backtrace") end os.exec("$(xmake) p") os.exec("$(xmake) c") os.exec("$(xmake) f -m release") os.exec("$(xmake) -r -a -v --backtrace") - if os.host() ~= "windows" then - os.exec("sudo $(xmake) install --all -v --backtrace") - os.exec("sudo $(xmake) uninstall -v --backtrace") - end os.exec("$(xmake) f --mode=debug --verbose --backtrace") os.exec("$(xmake) --rebuild --all --verbose --backtrace") - if os.host() ~= "windows" then - os.exec("$(xmake) install -o /tmp -a --verbose --backtrace") - os.exec("$(xmake) uninstall --installdir=/tmp --verbose --backtrace") - end os.exec("$(xmake) p --verbose --backtrace") os.exec("$(xmake) c --verbose --backtrace") os.exec("$(xmake) m -e buildtest") os.exec("$(xmake) m -l") os.exec("$(xmake) f --cc=gcc --cxx=g++") os.exec("$(xmake) m buildtest") + if os.host() ~= "windows" then + os.exec("sudo $(xmake) install") + os.exec("sudo $(xmake) uninstall") + end os.exec("$(xmake) f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") os.exec("$(xmake) m buildtest") + if os.host() ~= "windows" then + os.exec("sudo $(xmake) install --all -v --backtrace") + os.exec("sudo $(xmake) uninstall -v --backtrace") + end os.exec("$(xmake) m -d buildtest") -- test iphoneos? -- cgit v1.3.1 From eca531fec122d175b16d4afbbd06d023ef250da6 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Tue, 23 May 2017 20:57:37 +0800 Subject: fix build on macos --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 544d2eb45..7126a6975 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,8 +36,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) + - $(cat $(which xmake)|grep XMAKE_PROGRAM_DIR) + - 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 -- cgit v1.3.1 From 3ddda439ed32acac8dc4028036c4bd81b4a6af89 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 24 May 2017 06:54:38 +0800 Subject: sudo luarocks install to fix build on macos `sudo luarocks install` will install to global package tree that running as all users could find --- .travis.yml | 9 +-- scripts/.travis/copyright | 1 - scripts/.travis/platform.sh | 15 ----- scripts/.travis/setenv_lua.sh | 3 - scripts/.travis/setup_lua.sh | 124 ------------------------------------------ 5 files changed, 3 insertions(+), 149 deletions(-) delete mode 100644 scripts/.travis/copyright delete mode 100644 scripts/.travis/platform.sh delete mode 100644 scripts/.travis/setenv_lua.sh delete mode 100644 scripts/.travis/setup_lua.sh diff --git a/.travis.yml b/.travis.yml index 7126a6975..17390102e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,19 +13,16 @@ matrix: - ubuntu-toolchain-r-test packages: - gcc-5 + - luarocks env: global: - LUAROCKS=2.2.2 - LUA=lua5.1 -before_install: - - rm install - - source scripts/.travis/setenv_lua.sh - - luarocks install luacov - install: - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust; fi + - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust lua; fi + - sudo luarocks install luacov script: - scripts/get.sh __local__ 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 -- cgit v1.3.1 From 7e750ae50b5693d39f9118b7a0490c80185deba2 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 24 May 2017 06:59:13 +0800 Subject: Revert "use $(xmake) instead of xmake to fix cnf" This reverts commit f2e0d829b43011cce87568118a5b8b0b469ade1e. --- tests/build.lua | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/build.lua b/tests/build.lua index 12c23b7c5..6a2ccb339 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -2,41 +2,41 @@ function main(argv) -- generic? - os.exec("$(xmake) m -b") - os.exec("$(xmake) f -c") - os.exec("$(xmake)") + os.exec("xmake m -b") + os.exec("xmake f -c") + os.exec("xmake") if os.host() ~= "windows" then - os.exec("$(xmake) install -o /tmp -a --verbose --backtrace") - os.exec("$(xmake) uninstall --installdir=/tmp --verbose --backtrace") + os.exec("xmake install -o /tmp -a --verbose --backtrace") + os.exec("xmake uninstall --installdir=/tmp --verbose --backtrace") end - os.exec("$(xmake) p") - os.exec("$(xmake) c") - os.exec("$(xmake) f -m release") - os.exec("$(xmake) -r -a -v --backtrace") - os.exec("$(xmake) f --mode=debug --verbose --backtrace") - os.exec("$(xmake) --rebuild --all --verbose --backtrace") - os.exec("$(xmake) p --verbose --backtrace") - os.exec("$(xmake) c --verbose --backtrace") - os.exec("$(xmake) m -e buildtest") - os.exec("$(xmake) m -l") - os.exec("$(xmake) f --cc=gcc --cxx=g++") - os.exec("$(xmake) m buildtest") + os.exec("xmake p") + os.exec("xmake c") + os.exec("xmake f -m release") + os.exec("xmake -r -a -v --backtrace") + os.exec("xmake f --mode=debug --verbose --backtrace") + os.exec("xmake --rebuild --all --verbose --backtrace") + os.exec("xmake p --verbose --backtrace") + os.exec("xmake c --verbose --backtrace") + os.exec("xmake m -e buildtest") + os.exec("xmake m -l") + os.exec("xmake f --cc=gcc --cxx=g++") + os.exec("xmake m buildtest") if os.host() ~= "windows" then - os.exec("sudo $(xmake) install") - os.exec("sudo $(xmake) uninstall") + os.exec("sudo xmake install") + os.exec("sudo xmake uninstall") end - os.exec("$(xmake) f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") - os.exec("$(xmake) m buildtest") + os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") + os.exec("xmake m buildtest") if os.host() ~= "windows" then - os.exec("sudo $(xmake) install --all -v --backtrace") - os.exec("sudo $(xmake) uninstall -v --backtrace") + os.exec("sudo xmake install --all -v --backtrace") + os.exec("sudo xmake uninstall -v --backtrace") end - os.exec("$(xmake) m -d buildtest") + os.exec("xmake m -d buildtest") -- test iphoneos? if argv and argv.iphoneos then if os.host() == "macosx" then - os.exec("$(xmake) m package -p iphoneos") + os.exec("xmake m package -p iphoneos") end end end -- cgit v1.3.1 From 31a7bbec4241981688d5e6ae02259c0930073470 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 23 May 2017 22:12:06 +0800 Subject: add os.addenv and improve os.setenv --- xmake/core/base/os.lua | 22 ++++++++++++++++++++++ xmake/core/sandbox/modules/os.lua | 18 ++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 5a496b414..95ebfa79f 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -38,6 +38,7 @@ os._gid = os._gid or os.gid os._mkdir = os._mkdir or os.mkdir os._rmdir = os._rmdir or os.rmdir os._tmpdir = os._tmpdir or os.tmpdir +os._setenv = os._setenv or os.setenv os._versioninfo = os._versioninfo or os.versioninfo -- copy single file or directory @@ -658,6 +659,27 @@ function os.isroot() return os.uid().euid == 0 end +-- set values to environment variable +function os.setenv(name, ...) + + -- get separator + local seperator = utils.ifelse(os.host() == "windows", ';', ':') + + -- append values + return os._setenv(name, table.concat({...}, seperator)) +end + +-- add values to environment variable +function os.addenv(name, ...) + + -- get separator + local seperator = utils.ifelse(os.host() == "windows", ';', ':') + + -- append values + return os.setenv(name, table.concat({...}, seperator) .. seperator .. (os.getenv(name) or "")) + +end + -- get version info function os.versioninfo() diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 03943072d..083181c00 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -423,7 +423,7 @@ function sandbox_os.raise(msg, ...) os.raise(msg, ...) end --- get the envirnoment variables +-- get values of the envirnoment variable function sandbox_os.getenv(name) -- check @@ -433,14 +433,24 @@ function sandbox_os.getenv(name) return os.getenv(name) end --- set the envirnoment variables -function sandbox_os.setenv(name, values) +-- set values to the envirnoment variable +function sandbox_os.setenv(name, ...) -- check assert(name) -- set it - os.setenv(name, values) + os.setenv(name, ...) +end + +-- add values to the envirnoment variable +function sandbox_os.addenv(name, ...) + + -- check + assert(name) + + -- add it + os.addenv(name, ...) end -- make a new uuid -- cgit v1.3.1 From 89e2cc76f4e4cfd45a089b4967e02756ca8f52cb Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 24 May 2017 07:24:12 +0800 Subject: add xmake to path --- xmake/core/main.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xmake/core/main.lua b/xmake/core/main.lua index cda338294..6788b004e 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -155,6 +155,11 @@ Or you can add `--root` option to allow run as root temporarily. end end + -- add xmake to path + if xmake._EXECUTABLE_PATH then + os.addenv("PATH", path.directory(xmake._EXECUTABLE_PATH)) + end + -- start profiling if option.get("profile") then profiler:start() -- cgit v1.3.1 From 962b99cb4161b98928152d0abd12df0fb1745283 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 24 May 2017 07:41:55 +0800 Subject: fix build by using sudo $(xmake) --- tests/build.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/build.lua b/tests/build.lua index 6a2ccb339..4f4fad93c 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -22,14 +22,14 @@ function main(argv) os.exec("xmake f --cc=gcc --cxx=g++") os.exec("xmake m buildtest") if os.host() ~= "windows" then - os.exec("sudo xmake install") - os.exec("sudo xmake uninstall") + os.exec("sudo \"$(xmake)\" install") + os.exec("sudo \"$(xmake)\" uninstall") end os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") os.exec("xmake m buildtest") if os.host() ~= "windows" then - os.exec("sudo xmake install --all -v --backtrace") - os.exec("sudo xmake uninstall -v --backtrace") + os.exec("sudo \"$(xmake)\" install --all -v --backtrace") + os.exec("sudo \"$(xmake)\" uninstall -v --backtrace") end os.exec("xmake m -d buildtest") -- cgit v1.3.1 From f1e3e370136bcea36ae97e58680ab9d6aa4cba6f Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 07:01:46 +0800 Subject: Revert "fix build by using sudo $(xmake)" This reverts commit 962b99cb4161b98928152d0abd12df0fb1745283. --- tests/build.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/build.lua b/tests/build.lua index 4f4fad93c..6a2ccb339 100644 --- a/tests/build.lua +++ b/tests/build.lua @@ -22,14 +22,14 @@ function main(argv) os.exec("xmake f --cc=gcc --cxx=g++") os.exec("xmake m buildtest") if os.host() ~= "windows" then - os.exec("sudo \"$(xmake)\" install") - os.exec("sudo \"$(xmake)\" uninstall") + os.exec("sudo xmake install") + os.exec("sudo xmake uninstall") end os.exec("xmake f --cc=clang --cxx=clang++ --ld=clang++ --verbose --backtrace") os.exec("xmake m buildtest") if os.host() ~= "windows" then - os.exec("sudo \"$(xmake)\" install --all -v --backtrace") - os.exec("sudo \"$(xmake)\" uninstall -v --backtrace") + os.exec("sudo xmake install --all -v --backtrace") + os.exec("sudo xmake uninstall -v --backtrace") end os.exec("xmake m -d buildtest") -- cgit v1.3.1 From a00ed183e738749f8c5068a3fe56dab54b4fb961 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 07:01:48 +0800 Subject: Revert "add xmake to path" This reverts commit 89e2cc76f4e4cfd45a089b4967e02756ca8f52cb. --- xmake/core/main.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 6788b004e..cda338294 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -155,11 +155,6 @@ Or you can add `--root` option to allow run as root temporarily. end end - -- add xmake to path - if xmake._EXECUTABLE_PATH then - os.addenv("PATH", path.directory(xmake._EXECUTABLE_PATH)) - end - -- start profiling if option.get("profile") then profiler:start() -- cgit v1.3.1 From 7ee82c2b09ee0af9289c2aad852707bd7d2e637b Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 07:44:04 +0800 Subject: fix chaos installation --- makefile | 2 -- scripts/get.sh | 53 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/makefile b/makefile index 4edf55d86..723fe67f7 100644 --- a/makefile +++ b/makefile @@ -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/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!" +} -- cgit v1.3.1 From 4fafe79dd79efe67c3ed92362152a8aa883788c7 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 07:58:21 +0800 Subject: use link on supported os in installation --- makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/makefile b/makefile index 723fe67f7..312decc7c 100644 --- a/makefile +++ b/makefile @@ -61,9 +61,13 @@ install: @# install the xmake directory @cp -r xmake/* $(xmake_dir_install) @# make the xmake loader +ifeq (,$(filter $(PLAT),linux macosx)) @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) -- cgit v1.3.1 From a647f87c9324f735b26cb2f08e32afd1d82357fd Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 24 May 2017 18:25:01 +0800 Subject: use luaL_optstring instead of luaL_checkstring in readline.readline for optal arg --- core/src/xmake/readline/readline.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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); -- cgit v1.3.1 From 0744b67c8e4cbf92ec9fd8bbaedbe35d213b864b Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Wed, 24 May 2017 18:28:32 +0800 Subject: directly inherit os.versioninfo --- xmake/core/sandbox/modules/os.lua | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 -- cgit v1.3.1 From 578211e93c1f49f1b97772425a9724d3e3d5680e Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 08:29:34 +0800 Subject: fix sudo PATH passing --- xmake/modules/privilege/sudo.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xmake/modules/privilege/sudo.lua b/xmake/modules/privilege/sudo.lua index ae35ee23a..099939fc9 100644 --- a/xmake/modules/privilege/sudo.lua +++ b/xmake/modules/privilege/sudo.lua @@ -37,8 +37,9 @@ function _sudo(runner, cmd, ...) local program = find_sudo() assert(program, "sudo not found!") + -- FIXME: deal with spaces in `os.getenv("PATH")` -- run it with administrator permission and preserve parent environment - runner(program .. " PATH=" .. os.getenv("PATH") .. " " .. cmd, ...) + runner(program .. " env PATH=" .. os.getenv("PATH") .. " " .. cmd, ...) end -- sudo run shell with administrator permission and arguments list @@ -53,7 +54,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 -- cgit v1.3.1 From 1f937057f3f7c29bbb074dec7047e55a44131f51 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 09:17:32 +0800 Subject: fix XMAKE_PROGRAM_DIR finding --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 17390102e..b08001b32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ 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 - - $(cat $(which xmake)|grep XMAKE_PROGRAM_DIR) + - 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 -- cgit v1.3.1 From 6f37771660ca4ca340278b2b8e1703e2c1b607d3 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 09:53:28 +0800 Subject: fix lua version on macos --- .travis.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index b08001b32..091ce0618 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,14 +15,9 @@ matrix: - gcc-5 - luarocks -env: - global: - - LUAROCKS=2.2.2 - - LUA=lua5.1 - install: - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install dmd rust lua; fi - - sudo luarocks install luacov + - 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__ -- cgit v1.3.1 From 33826d1116e768e0ed262e22c026eb9dea23652c Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 10:23:25 +0800 Subject: reload bash profile --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 091ce0618..3ceb81d09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ install: script: - scripts/get.sh __local__ + - source ~/.bash_profile - xmake lua versioninfo - xmake f -m coverage -P core - xmake -P core -- cgit v1.3.1 From 64e1e79a26f997e2f6f56360038507a33f6e8b0f Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 10:23:49 +0800 Subject: do not directly install on macos --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index 312decc7c..ac1b466c9 100644 --- a/makefile +++ b/makefile @@ -61,7 +61,7 @@ install: @# install the xmake directory @cp -r xmake/* $(xmake_dir_install) @# make the xmake loader -ifeq (,$(filter $(PLAT),linux macosx)) +ifneq ($(PLAT),linux) @echo '#!/bin/bash' > $(xmake_loader) @echo 'export XMAKE_PROGRAM_DIR=$(xmake_dir_install)' >> $(xmake_loader) @echo '$(xmake_core_install) $(verbose) "$$@"' >> $(xmake_loader) -- cgit v1.3.1 From bbed6a5a8a80437afbb57540d77418084aabd950 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 10:56:24 +0800 Subject: use implement in dev --- core/src/xmake/machine.c | 142 ++++++++++++++++++--------------------------- xmake/core/_xmake_main.lua | 3 +- 2 files changed, 59 insertions(+), 86 deletions(-) diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 5bea2d01e..0281f0a2c 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -238,48 +238,17 @@ static tb_size_t xm_machine_get_program_file(xm_machine_impl_t* impl, tb_char_t* tb_bool_t ok = tb_false; do { - // get it from the environment variable first - tb_char_t data[TB_PATH_MAXN] = {0}; - if (tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data)) && tb_path_absolute(data, path, maxn)) - { - // ok - ok = tb_true; - // not break // even XMAKE_PROGRAM_DIR is set, exact path is needed - } - #if defined(TB_CONFIG_OS_WINDOWS) // get the executale file path as program directory - tb_size_t size = (tb_size_t)GetModuleFileName(tb_null, data, (DWORD)maxn); + tb_size_t size = (tb_size_t)GetModuleFileName(tb_null, path, (DWORD)maxn); tb_assert_and_check_break(size < maxn); // end - data[size] = '\0'; - - // trace - tb_trace_d("programfile: %s", data); + path[size] = '\0'; - // set _EXECUTABLE_PATH - lua_pushstring(impl -> lua, data); - lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); - - if (!ok) - { - // get the directory - while (size-- > 0) - { - if (data[size] == '\\') - { - data[size] = '\0'; - break; - } - } - - // copy to path - tb_strcpy(path, data); + // ok + ok = tb_true; - // ok - ok = tb_true; - } #elif defined(TB_CONFIG_OS_MACOSX) /* * _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter @@ -291,73 +260,75 @@ static tb_size_t xm_machine_get_program_file(xm_machine_impl_t* impl, tb_char_t* * That is the path may be a symbolic link and not the real file. With deep directories the total bufsize * needed could be more than MAXPATHLEN. */ - tb_uint32_t size = (tb_uint32_t)maxn; - if (!_NSGetExecutablePath(data, &size)) - { - // trace - tb_trace_d("programfile: %s", data); - - // set _EXECUTABLE_PATH - lua_pushstring(impl -> lua, data); - lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); - - if (!ok) - { - // get path size - size = tb_strlen(data); - - // get the directory - while (size-- > 0) - { - if (data[size] == '/') - { - data[size] = '\0'; - break; - } - } - - // copy to path - tb_strcpy(path, data); - - // ok - ok = tb_true; - } - } + tb_uint32_t bufsize = (tb_uint32_t)maxn; + if (!_NSGetExecutablePath(path, &bufsize)) + ok = tb_true; #elif defined(TB_CONFIG_OS_LINUX) // get the executale file path as program directory - ssize_t size = readlink("/proc/self/exe", data, (size_t)maxn); + ssize_t size = readlink("/proc/self/exe", path, (size_t)maxn); if (size > 0 && size < maxn) { // end - data[size] = '\0'; + path[size] = '\0'; + + // ok + ok = tb_true; + } +#endif + + } while (0); - // trace - tb_trace_d("programfile: %s", data); + // ok? + if (ok) + { + // trace + tb_trace_d("programfile: %s", path); + + // save the directory to the global variable: _PROGRAM_FILE + lua_pushstring(impl->lua, path); + lua_setglobal(impl->lua, "_PROGRAM_FILE"); + } + + // ok? + return ok; +} +static tb_bool_t xm_machine_get_program_directory(xm_machine_impl_t* impl, tb_char_t* path, tb_size_t maxn, tb_char_t const* programfile) +{ + // check + tb_assert_and_check_return_val(impl && path && maxn, tb_false); - // set _EXECUTABLE_PATH - lua_pushstring(impl -> lua, data); - lua_setglobal(impl -> lua, "_EXECUTABLE_PATH"); + // done + tb_bool_t ok = tb_false; + do + { + // get it from the environment variable first + tb_char_t data[TB_PATH_MAXN] = {0}; + if (tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data)) && tb_path_absolute(data, path, maxn)) + { + // ok + ok = tb_true; + break; + } - if (!ok) + // get it from program file path + if (programfile) + { + tb_size_t size = tb_strlcpy(data, programfile, sizeof(data)); + if (size < sizeof(data)) { // get the directory while (size-- > 0) { - if (data[size] == '/') + if (data[size] == '\\' || data[size] == '/') { data[size] = '\0'; + tb_strlcpy(path, data, maxn); + ok = tb_true; break; } } - - // copy to path - tb_strcpy(path, data); - - // ok - ok = tb_true; } } -#endif } while (0); @@ -549,9 +520,12 @@ tb_int_t xm_machine_main(xm_machine_ref_t machine, tb_int_t argc, tb_char_t** ar tb_char_t path[TB_PATH_MAXN] = {0}; if (!xm_machine_get_project_directory(impl, path, sizeof(path))) return -1; - // get the program file & directory + // get the program file if (!xm_machine_get_program_file(impl, path, sizeof(path))) return -1; + // get the program directory + if (!xm_machine_get_program_directory(impl, path, sizeof(path), path)) return -1; + // append the main script path tb_strcat(path, "/core/_xmake_main.lua"); diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 9ce5fdb42..39bb5f225 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -31,13 +31,12 @@ xmake._NULDEV = _NULDEV xmake._VERSION = _VERSION xmake._VERSION_SHORT = _VERSION_SHORT xmake._PROGRAM_DIR = _PROGRAM_DIR -xmake._PROGRAM_FILE = _EXECUTABLE_PATH +xmake._PROGRAM_FILE = _PROGRAM_FILE xmake._PROJECT_DIR = _PROJECT_DIR xmake._CORE_DIR = _PROGRAM_DIR .. "/core" xmake._TOOLS_DIR = _PROGRAM_DIR .. "/tools" xmake._TEMPLATES_DIR = _PROGRAM_DIR .. "/templates" xmake._PROJECT_FILE = "xmake.lua" -xmake._EXECUTABLE_PATH = _EXECUTABLE_PATH -- init package path package.path = xmake._CORE_DIR .. "/?.lua;" .. package.path -- cgit v1.3.1 From ff1ba702befdf84ba0e872079305565dc62b6ca1 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 13:09:35 +0800 Subject: Revert "do not directly install on macos" This reverts commit 64e1e79a26f997e2f6f56360038507a33f6e8b0f. --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index ac1b466c9..312decc7c 100644 --- a/makefile +++ b/makefile @@ -61,7 +61,7 @@ install: @# install the xmake directory @cp -r xmake/* $(xmake_dir_install) @# make the xmake loader -ifneq ($(PLAT),linux) +ifeq (,$(filter $(PLAT),linux macosx)) @echo '#!/bin/bash' > $(xmake_loader) @echo 'export XMAKE_PROGRAM_DIR=$(xmake_dir_install)' >> $(xmake_loader) @echo '$(xmake_core_install) $(verbose) "$$@"' >> $(xmake_loader) -- cgit v1.3.1 From 67a5ad78de9453d14b562cd7c3f2a4364e370d24 Mon Sep 17 00:00:00 2001 From: TitanSnow Date: Thu, 25 May 2017 13:09:38 +0800 Subject: Revert "use link on supported os in installation" This reverts commit 4fafe79dd79efe67c3ed92362152a8aa883788c7. --- makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/makefile b/makefile index 312decc7c..723fe67f7 100644 --- a/makefile +++ b/makefile @@ -61,13 +61,9 @@ install: @# install the xmake directory @cp -r xmake/* $(xmake_dir_install) @# make the xmake loader -ifeq (,$(filter $(PLAT),linux macosx)) @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) -- cgit v1.3.1