summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-18 06:47:34 +0800
committerruki <[email protected]>2019-08-18 06:47:34 +0800
commit2c5d7d443fcda38f50dae1a0050eca5ff6ef531f (patch)
treed24cbca3c17da52fb47fbba168440b8efb30344b
parentadef5373cbd290f0d679c449d06dcb92dbfe3325 (diff)
fix process.open/openv
-rw-r--r--core/src/xmake/process/open.c94
-rw-r--r--core/src/xmake/process/openv.c93
2 files changed, 101 insertions, 86 deletions
diff --git a/core/src/xmake/process/open.c b/core/src/xmake/process/open.c
index 8cd63d966..bc1b35607 100644
--- a/core/src/xmake/process/open.c
+++ b/core/src/xmake/process/open.c
@@ -73,48 +73,6 @@ tb_int_t xm_process_open(lua_State* lua)
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);
- if (lua_istable(lua, -1))
- {
- // get environment variables count
- envn = (tb_size_t)lua_objlen(lua, -1);
-
- // get all passed environment variables
- tb_size_t i;
- for (i = 0; i < envn; i++)
- {
- // get envs[i]
- lua_pushinteger(lua, i + 1);
- lua_gettable(lua, -2);
-
- // is string?
- if (lua_isstring(lua, -1))
- {
- // add this environment value
- if (i + 1 < tb_arrayn(envs))
- envs[i] = lua_tostring(lua, -1);
- else
- {
- // error
- lua_pushfstring(lua, "envs is too large(%lu > %d) for process.openv", envn, tb_arrayn(envs) - 1);
- lua_error(lua);
- }
- }
- else
- {
- // error
- lua_pushfstring(lua, "invalid envs[%ld] type(%s) for process.openv", i, luaL_typename(lua, -1));
- lua_error(lua);
- }
-
- // pop it
- lua_pop(lua, 1);
- }
- }
- lua_pop(lua, 1);
}
// enable vs_unicode_output? @see https://github.com/xmake-io/xmake/issues/528
@@ -136,7 +94,10 @@ tb_int_t xm_process_open(lua_State* lua)
attr.outtype = subprocess->outtype;
#ifdef TB_CONFIG_OS_WINDOWS
- // add environment value of vs_unicode_output
+ /* add environment value of vs_unicode_output
+ *
+ * @note we have to set it at the beginning, because opt.envs might also have this value.
+ */
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
@@ -175,6 +136,53 @@ tb_int_t xm_process_open(lua_State* lua)
}
}
+ // append other environments after setting VS_UNICODE_OUTPUT
+ if (lua_istable(lua, 2))
+ {
+ // get environments
+ lua_pushstring(lua, "envs");
+ lua_gettable(lua, 2);
+ if (lua_istable(lua, -1))
+ {
+ // get environment variables count
+ tb_size_t count = (tb_size_t)lua_objlen(lua, -1);
+
+ // get all passed environment variables
+ tb_size_t i;
+ for (i = 0; i < count; i++)
+ {
+ // get envs[i]
+ lua_pushinteger(lua, i + 1);
+ lua_gettable(lua, -2);
+
+ // is string?
+ if (lua_isstring(lua, -1))
+ {
+ // add this environment value
+ if (envn + 1 < tb_arrayn(envs))
+ envs[envn++] = lua_tostring(lua, -1);
+ else
+ {
+ // error
+ lua_pushfstring(lua, "envs is too large(%lu > %d) for process.openv", envn, tb_arrayn(envs) - 1);
+ lua_error(lua);
+ }
+ }
+ else
+ {
+ // error
+ lua_pushfstring(lua, "invalid envs[%ld] type(%s) for process.openv", i, luaL_typename(lua, -1));
+ lua_error(lua);
+ }
+
+ // pop it
+ lua_pop(lua, 1);
+ }
+ }
+ lua_pop(lua, 1);
+ }
+
+
// set the new environments
if (envn > 0) attr.envp = envs;
diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c
index 79d99c917..e329f9898 100644
--- a/core/src/xmake/process/openv.c
+++ b/core/src/xmake/process/openv.c
@@ -115,48 +115,6 @@ tb_int_t xm_process_openv(lua_State* lua)
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);
- if (lua_istable(lua, -1))
- {
- // get environment variables count
- envn = (tb_size_t)lua_objlen(lua, -1);
-
- // get all passed environment variables
- tb_size_t i;
- for (i = 0; i < envn; i++)
- {
- // get envs[i]
- lua_pushinteger(lua, i + 1);
- lua_gettable(lua, -2);
-
- // is string?
- if (lua_isstring(lua, -1))
- {
- // add this environment value
- if (i + 1 < tb_arrayn(envs))
- envs[i] = lua_tostring(lua, -1);
- else
- {
- // error
- lua_pushfstring(lua, "envs is too large(%lu > %d) for process.openv", envn, tb_arrayn(envs) - 1);
- lua_error(lua);
- }
- }
- else
- {
- // error
- lua_pushfstring(lua, "invalid envs[%ld] type(%s) for process.openv", i, luaL_typename(lua, -1));
- lua_error(lua);
- }
-
- // pop it
- lua_pop(lua, 1);
- }
- }
- lua_pop(lua, 1);
}
// enable vs_unicode_output? @see https://github.com/xmake-io/xmake/issues/528
@@ -178,7 +136,10 @@ tb_int_t xm_process_openv(lua_State* lua)
attr.outtype = subprocess->outtype;
#ifdef TB_CONFIG_OS_WINDOWS
- // add environment value of vs_unicode_output
+ /* add environment value of vs_unicode_output
+ *
+ * @note we have to set it at the beginning, because opt.envs might also have this value.
+ */
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
@@ -217,6 +178,52 @@ tb_int_t xm_process_openv(lua_State* lua)
}
}
+ // append other environments after setting VS_UNICODE_OUTPUT
+ if (lua_istable(lua, 3))
+ {
+ // get environments
+ lua_pushstring(lua, "envs");
+ lua_gettable(lua, 3);
+ if (lua_istable(lua, -1))
+ {
+ // get environment variables count
+ tb_size_t count = (tb_size_t)lua_objlen(lua, -1);
+
+ // get all passed environment variables
+ tb_size_t i;
+ for (i = 0; i < count; i++)
+ {
+ // get envs[i]
+ lua_pushinteger(lua, i + 1);
+ lua_gettable(lua, -2);
+
+ // is string?
+ if (lua_isstring(lua, -1))
+ {
+ // add this environment value
+ if (envn + 1 < tb_arrayn(envs))
+ envs[envn++] = lua_tostring(lua, -1);
+ else
+ {
+ // error
+ lua_pushfstring(lua, "envs is too large(%lu > %d) for process.openv", envn, tb_arrayn(envs) - 1);
+ lua_error(lua);
+ }
+ }
+ else
+ {
+ // error
+ lua_pushfstring(lua, "invalid envs[%ld] type(%s) for process.openv", i, luaL_typename(lua, -1));
+ lua_error(lua);
+ }
+
+ // pop it
+ lua_pop(lua, 1);
+ }
+ }
+ lua_pop(lua, 1);
+ }
+
// set the new environments
if (envn > 0) attr.envp = envs;