diff options
| author | ruki <[email protected]> | 2017-03-10 09:55:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-03-10 09:55:42 +0800 |
| commit | f99ff317a4b67d7508b40842f83aaea74ab7e20e (patch) | |
| tree | cec35f7c9938f78ad06731a41300e097b6d4b894 | |
| parent | 952b7eb1d18223a664c0c9b20094201cad9a53c8 (diff) | |
fix compile error for rust android
| -rwxr-xr-x | core/src/xmake/os/argv.c | 83 | ||||
| -rw-r--r-- | xmake/platforms/android/load.lua | 4 | ||||
| -rwxr-xr-x | xmake/tools/rustc.lua | 4 |
3 files changed, 33 insertions, 58 deletions
diff --git a/core/src/xmake/os/argv.c b/core/src/xmake/os/argv.c index 233b55d0b..359c94331 100755 --- a/core/src/xmake/os/argv.c +++ b/core/src/xmake/os/argv.c @@ -47,48 +47,21 @@ tb_int_t xm_os_argv(lua_State* lua) tb_check_return_val(args, 0); // done - tb_char_t* buffer = tb_null; + tb_string_t arg; do { - // make buffer - tb_size_t maxn = TB_PATH_MAXN; - buffer = (tb_char_t*)tb_malloc(maxn); - tb_assert_and_check_break(buffer); - - // copy and translate command - tb_char_t ch; - tb_size_t i = 0; - tb_size_t j = 0; - for (i = 0; j <= maxn && (ch = args[i]); i++) - { - // not enough? grow it - if (j == maxn) - { - // grow it - maxn += TB_PATH_MAXN; - buffer = (tb_char_t*)tb_ralloc(buffer, maxn); - tb_assert_and_check_break(buffer); - } - - // translate "\"", "\'", "\\" - tb_char_t next = args[i + 1]; - if (ch == '\\' && (next == '\"' || next == '\'' || next == '\\')) /* skip it */ ; - // copy it - else buffer[j++] = ch; - } - tb_assert_and_check_break(j < maxn); - buffer[j] = '\0'; - - // reset index - i = 1; - // init table lua_newtable(lua); + // init arg + if (!tb_string_init(&arg)) break; + // parse command to the arguments - tb_bool_t s = 0; - tb_char_t* p = buffer; - tb_char_t* b = tb_null; + tb_int_t i = 1; + tb_int_t s = 0; + tb_int_t escape = 0; + tb_char_t ch = 0; + tb_char_t const* p = args; while ((ch = *p)) { // enter double quote? @@ -97,47 +70,49 @@ tb_int_t xm_os_argv(lua_State* lua) else if (!s && ch == '\'') s = 1; // leave quote? else if ((s == 2 && ch == '\"') || (s == 1 && ch == '\'')) s = 0; + // escape charactor? + else if (!escape && ch == '\\') escape = 1; // is argument end with ' '? else if (!s && tb_isspace(ch)) { - // fill zero - *p = '\0'; - // save this argument - if (b) + tb_string_ltrim(&arg); + if (tb_string_size(&arg)) { // save argument - lua_pushstring(lua, b); + lua_pushstring(lua, tb_string_cstr(&arg)); lua_rawseti(lua, -2, i++); - - // clear it - b = tb_null; } + + // clear arg + tb_string_clear(&arg); } - // get the argument pointer - if ((s || !tb_isspace(ch)) && !b) b = p; + // save this charactor to arg if not escape charactor: '\\' + if (escape == 2 || (!escape && ch != '\"' && ch != '\'')) + tb_string_chrcat(&arg, ch); + + // step and cancel escape + if (escape == 1) escape++; + else if (escape == 2) escape = 0; // next p++; } // save this argument - if (b) + tb_string_ltrim(&arg); + if (tb_string_size(&arg)) { // save argument - lua_pushstring(lua, b); + lua_pushstring(lua, tb_string_cstr(&arg)); lua_rawseti(lua, -2, i++); - - // clear it - b = tb_null; } } while (0); - // exit buffer - if (buffer) tb_free(buffer); - buffer = tb_null; + // exit arg + tb_string_exit(&arg); // ok return 1; diff --git a/xmake/platforms/android/load.lua b/xmake/platforms/android/load.lua index ff04b8168..a0349500a 100644 --- a/xmake/platforms/android/load.lua +++ b/xmake/platforms/android/load.lua @@ -113,8 +113,8 @@ function main() -- init flags for rust _g.rcflags = { "--target=" .. targets[arch] } - _g["rc-shflags"] = { } - _g["rc-ldflags"] = { } + _g["rc-shflags"] = { "-C linker=" .. config.get("sh"), "-C link-args=\"" .. (table.concat(_g.shflags, " "):gsub("%-march=.-%s", "")) .. "\"" } + _g["rc-ldflags"] = { "-C linker=" .. config.get("ld"), "-C link-args=\"" .. (table.concat(_g.ldflags, " "):gsub("%-march=.-%s", "")) .. "\"" } -- ok return _g diff --git a/xmake/tools/rustc.lua b/xmake/tools/rustc.lua index 5d008d7a3..6456e7a3a 100755 --- a/xmake/tools/rustc.lua +++ b/xmake/tools/rustc.lua @@ -114,13 +114,13 @@ function buildcmd(sourcefiles, targetkind, targetfile, flags) end -- build the target file -function build(objectfiles, targetkind, targetfile, flags) +function build(sourcefiles, targetkind, targetfile, flags) -- ensure the target directory os.mkdir(path.directory(targetfile)) -- build it - os.run(buildcmd(objectfiles, targetkind, targetfile, flags)) + os.run(buildcmd(sourcefiles, targetkind, targetfile, flags)) end -- make the complie command |
