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 24 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
Original file line number Diff line number Diff line change
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
142 changes: 84 additions & 58 deletions core/src/xmake/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,48 @@ 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, 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';

// ok
ok = tb_true;
// trace
tb_trace_d("programfile: %s", data);

// 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;
}
#elif defined(TB_CONFIG_OS_MACOSX)
/*
* _NSGetExecutablePath() copies the path of the main executable into the buffer. The bufsize parameter
Expand All @@ -260,75 +291,73 @@ 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 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", path, (size_t)maxn);
if (size > 0 && size < maxn)
tb_uint32_t size = (tb_uint32_t)maxn;
if (!_NSGetExecutablePath(data, &size))
{
// end
path[size] = '\0';
// trace
tb_trace_d("programfile: %s", data);

// ok
ok = tb_true;
}
#endif

} while (0);
// set _EXECUTABLE_PATH
lua_pushstring(impl -> lua, data);
lua_setglobal(impl -> lua, "_EXECUTABLE_PATH");

// ok?
if (ok)
{
// trace
tb_trace_d("programfile: %s", path);
if (!ok)
{
// get path size
size = tb_strlen(data);

// save the directory to the global variable: _PROGRAM_FILE
lua_pushstring(impl->lua, path);
lua_setglobal(impl->lua, "_PROGRAM_FILE");
}
// get the directory
while (size-- > 0)
{
if (data[size] == '/')
{
data[size] = '\0';
break;
}
}

// 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);
// copy to path
tb_strcpy(path, data);

// 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;
// ok
ok = tb_true;
}
}

// get it from program file path
if (programfile)
#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);
if (size > 0 && size < maxn)
{
tb_size_t size = tb_strlcpy(data, programfile, sizeof(data));
if (size < sizeof(data))
// end
data[size] = '\0';

// trace
tb_trace_d("programfile: %s", data);

// set _EXECUTABLE_PATH
lua_pushstring(impl -> lua, data);
lua_setglobal(impl -> lua, "_EXECUTABLE_PATH");

if (!ok)
{
// 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] = '\0';
tb_strlcpy(path, data, maxn);
ok = tb_true;
break;
}
}

// copy to path
tb_strcpy(path, data);

// ok
ok = tb_true;
}
}
#endif

} while (0);

Expand Down Expand Up @@ -520,12 +549,9 @@ 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
// get the program file & directory
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");

Expand Down
4 changes: 1 addition & 3 deletions core/src/xmake/readline/readline.c
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.