diff options
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/process/close.c | 1 | ||||
| -rw-r--r-- | core/src/xmake/process/open.c | 30 | ||||
| -rw-r--r-- | core/src/xmake/process/openv.c | 40 | ||||
| -rw-r--r-- | core/src/xmake/process/prefix.h | 3 |
4 files changed, 59 insertions, 15 deletions
diff --git a/core/src/xmake/process/close.c b/core/src/xmake/process/close.c index 58373c9cf..94de9b33d 100644 --- a/core/src/xmake/process/close.c +++ b/core/src/xmake/process/close.c @@ -64,6 +64,7 @@ tb_int_t xm_process_close(lua_State* lua) subprocess->errfile = tb_null; } + tb_string_exit(&subprocess->vs_unicode_output); tb_free(subprocess); } diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c index 676d0241f..8cd63d966 100644 --- a/core/src/xmake/process/open.c +++ b/core/src/xmake/process/open.c @@ -53,6 +53,7 @@ tb_int_t xm_process_open(lua_State* lua) tb_char_t const* envs[256] = {0}; tb_char_t const* outpath = tb_null; tb_char_t const* errpath = tb_null; + tb_bool_t vs_unicode_output = tb_false; if (lua_istable(lua, 2)) { // get outpath @@ -67,6 +68,12 @@ tb_int_t xm_process_open(lua_State* lua) errpath = lua_tostring(lua, -1); lua_pop(lua, 1); + // enable vs_unicode_output? + lua_pushstring(lua, "vs_unicode_output"); + lua_gettable(lua, 2); + vs_unicode_output = lua_toboolean(lua, -1); + lua_pop(lua, 1); + // get environments lua_pushstring(lua, "envs"); lua_gettable(lua, 2); @@ -110,21 +117,29 @@ tb_int_t xm_process_open(lua_State* lua) lua_pop(lua, 1); } - // set the new environments - if (envn > 0) attr.envp = envs; - - // TODO - if (1) + // enable vs_unicode_output? @see https://github.com/xmake-io/xmake/issues/528 + if (vs_unicode_output) { xm_subprocess_t* subprocess = tb_malloc0_type(xm_subprocess_t); if (subprocess) { + // init vs_unicode_output + tb_string_init(&subprocess->vs_unicode_output); + // redirect stdout? if (outpath) { // redirect stdout to file subprocess->outfile = tb_file_init(outpath, TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT); subprocess->outtype = TB_PROCESS_REDIRECT_TYPE_FILE; + attr.outfile = subprocess->outfile; + attr.outtype = subprocess->outtype; + +#ifdef TB_CONFIG_OS_WINDOWS + // add environment value of vs_unicode_output + if (envn + 1 < tb_arrayn(envs)) + envs[envn++] = tb_string_cstrfcpy(&subprocess->vs_unicode_output, "VS_UNICODE_OUTPUT=%zu", (tb_size_t)subprocess->outfile); +#endif } // redirect stderr? @@ -133,6 +148,8 @@ tb_int_t xm_process_open(lua_State* lua) // redirect stderr to file subprocess->errfile = tb_file_init(errpath, TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT); subprocess->errtype = TB_PROCESS_REDIRECT_TYPE_FILE; + attr.errfile = subprocess->errfile; + attr.errtype = subprocess->errtype; } attr.priv = subprocess; } @@ -158,6 +175,9 @@ tb_int_t xm_process_open(lua_State* lua) } } + // set the new environments + if (envn > 0) attr.envp = envs; + // init process tb_process_ref_t process = (tb_process_ref_t)tb_process_init_cmd(command, &attr); if (process) lua_pushlightuserdata(lua, (tb_pointer_t)process); diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c index 7bf97c358..79d99c917 100644 --- a/core/src/xmake/process/openv.c +++ b/core/src/xmake/process/openv.c @@ -95,6 +95,7 @@ tb_int_t xm_process_openv(lua_State* lua) tb_char_t const* envs[256] = {0}; tb_char_t const* outpath = tb_null; tb_char_t const* errpath = tb_null; + tb_bool_t vs_unicode_output = tb_false; if (lua_istable(lua, 3)) { // get outpath @@ -109,6 +110,12 @@ tb_int_t xm_process_openv(lua_State* lua) errpath = lua_tostring(lua, -1); lua_pop(lua, 1); + // enable vs_unicode_output? + lua_pushstring(lua, "vs_unicode_output"); + lua_gettable(lua, 3); + vs_unicode_output = lua_toboolean(lua, -1); + lua_pop(lua, 1); + // get environments lua_pushstring(lua, "envs"); lua_gettable(lua, 3); @@ -151,22 +158,30 @@ tb_int_t xm_process_openv(lua_State* lua) } lua_pop(lua, 1); } - - // set the new environments - if (envn > 0) attr.envp = envs; - - // TODO - if (1) + + // enable vs_unicode_output? @see https://github.com/xmake-io/xmake/issues/528 + if (vs_unicode_output) { xm_subprocess_t* subprocess = tb_malloc0_type(xm_subprocess_t); if (subprocess) { + // init vs_unicode_output + tb_string_init(&subprocess->vs_unicode_output); + // redirect stdout? if (outpath) { // redirect stdout to file subprocess->outfile = tb_file_init(outpath, TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT); - subprocess->outtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; + subprocess->outtype = TB_PROCESS_REDIRECT_TYPE_FILE; + attr.outfile = subprocess->outfile; + attr.outtype = subprocess->outtype; + +#ifdef TB_CONFIG_OS_WINDOWS + // add environment value of vs_unicode_output + if (envn + 1 < tb_arrayn(envs)) + envs[envn++] = tb_string_cstrfcpy(&subprocess->vs_unicode_output, "VS_UNICODE_OUTPUT=%zu", (tb_size_t)subprocess->outfile); +#endif } // redirect stderr? @@ -174,7 +189,9 @@ tb_int_t xm_process_openv(lua_State* lua) { // redirect stderr to file subprocess->errfile = tb_file_init(errpath, TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT); - subprocess->errtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; + subprocess->errtype = TB_PROCESS_REDIRECT_TYPE_FILE; + attr.errfile = subprocess->errfile; + attr.errtype = subprocess->errtype; } attr.priv = subprocess; } @@ -187,7 +204,7 @@ tb_int_t xm_process_openv(lua_State* lua) // redirect stdout to file attr.outpath = outpath; attr.outmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; - attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILE; + attr.outtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; } // redirect stderr? @@ -196,10 +213,13 @@ tb_int_t xm_process_openv(lua_State* lua) // redirect stderr to file attr.errpath = errpath; attr.errmode = TB_FILE_MODE_RW | TB_FILE_MODE_TRUNC | TB_FILE_MODE_CREAT; - attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILE; + attr.errtype = TB_PROCESS_REDIRECT_TYPE_FILEPATH; } } + // set the new environments + if (envn > 0) attr.envp = envs; + // init process tb_process_ref_t process = (tb_process_ref_t)tb_process_init(shellname, argv, &attr); if (process) lua_pushlightuserdata(lua, (tb_pointer_t)process); diff --git a/core/src/xmake/process/prefix.h b/core/src/xmake/process/prefix.h index c1391fe19..3ec32f792 100644 --- a/core/src/xmake/process/prefix.h +++ b/core/src/xmake/process/prefix.h @@ -57,6 +57,9 @@ typedef struct __xm_subprocess_t tb_file_ref_t errfile; }; + // vs unicode output environment variable + tb_string_t vs_unicode_output; + }xm_subprocess_t; |
