Skip to content

Commit 5d5403c

Browse files
mingwandroidGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
environ.cc: New facility/environment variable MSYS2_ENV_CONV_EXCL
Works very much like MSYS2_ARG_CONV_EXCL. In fact it uses the same function, arg_heuristic_with_exclusions (). Also refactors parsing the env. variables to use new function, string_split_delimited (). The env. that is searched through is the merged (POSIX + Windows) one. It remains to be seen if this should be made an option or not. This feature was prompted because the R language (Windows exe) calls bash to run configure.win, which then calls back into R to read its config variables (LOCAL_SOFT) and when this happens, msys2-runtime converts R_ARCH from "/x64" to an absolute Windows path and appends it to another absolute path, R_HOME, forming an invalid path.
1 parent 8b222f9 commit 5d5403c

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

winsup/cygwin/environ.cc

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,10 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11761176

11771177
int tl = 0;
11781178
char **pass_dstp;
1179+
#ifdef __MSYS__
1180+
char *msys2_env_conv_excl_env = NULL;
1181+
size_t msys2_env_conv_excl_count = 0;
1182+
#endif
11791183
char **pass_env = (char **) alloca (sizeof (char *)
11801184
* (n + winnum + SPENVS_SIZE + 1));
11811185
/* Iterate over input list, generating a new environment list and refreshing
@@ -1184,9 +1188,18 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11841188
{
11851189
bool calc_tl = !no_envblock;
11861190
#ifdef __MSYS__
1187-
/* Don't pass timezone environment to non-msys applications */
1188-
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
1189-
goto next1;
1191+
if (!keep_posix)
1192+
{
1193+
/* Don't pass timezone environment to non-msys applications */
1194+
if (ascii_strncasematch(*srcp, "TZ=", 3))
1195+
goto next1;
1196+
else if (ascii_strncasematch(*srcp, "MSYS2_ENV_CONV_EXCL=", 20))
1197+
{
1198+
msys2_env_conv_excl_env = (char*)alloca (strlen(&(*srcp)[20])+1);
1199+
strcpy (msys2_env_conv_excl_env, &(*srcp)[20]);
1200+
msys2_env_conv_excl_count = string_split_delimited (msys2_env_conv_excl_env, ';');
1201+
}
1202+
}
11901203
#endif
11911204
/* Look for entries that require special attention */
11921205
for (unsigned i = 0; i < SPENVS_SIZE; i++)
@@ -1310,7 +1323,8 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
13101323
}
13111324
#ifdef __MSYS__
13121325
else if (!keep_posix) {
1313-
char *win_arg = arg_heuristic(*srcp);
1326+
char *win_arg = arg_heuristic_with_exclusions
1327+
(*srcp, msys2_env_conv_excl_env, msys2_env_conv_excl_count);
13141328
debug_printf("WIN32_PATH is %s", win_arg);
13151329
p = cstrdup1(win_arg);
13161330
if (win_arg != *srcp)

winsup/cygwin/miscfuncs.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ NT_readline::gets ()
308308
}
309309
}
310310

311+
/* Searches through string for delimiter replacing each instance with '\0'
312+
and returning the number of such delimited substrings. This function
313+
Will return 0 for the NULL string and at least 1 otherwise. */
314+
315+
size_t
316+
string_split_delimited (char * string, char delimiter)
317+
{
318+
if ( string == NULL )
319+
return 0;
320+
size_t count = 1;
321+
string = strchr ( string, delimiter );
322+
while (string)
323+
{
324+
*string = '\0';
325+
++count;
326+
string = strchr ( string + 1, delimiter );
327+
}
328+
return count;
329+
}
330+
311331
/* Return an address from the import jmp table of main program. */
312332
void * __reg1
313333
__import_address (void *imp)

winsup/cygwin/miscfuncs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ void backslashify (const char *, char *, bool);
8888
void slashify (const char *, char *, bool);
8989
#define isslash(c) ((c) == '/')
9090

91+
size_t string_split_delimited (char * string, char delimiter);
92+
9193
extern void transform_chars (PWCHAR, PWCHAR);
9294
extern inline void
9395
transform_chars (PUNICODE_STRING upath, USHORT start_idx)

winsup/cygwin/path.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3621,7 +3621,6 @@ arg_heuristic_with_exclusions (char const * const arg, char const * exclusions,
36213621
return arg_result;
36223622
}
36233623

3624-
debug_printf("Input value: (%s)", arg);
36253624
for (size_t excl = 0; excl < exclusions_count; ++excl)
36263625
{
36273626
/* Since we've got regex linked we should maybe switch to that, but

winsup/cygwin/spawn.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
261261
int res = -1;
262262

263263
/* Environment variable MSYS2_ARG_CONV_EXCL contains a list
264-
of ';' separated argument prefixes to pass un-modified..
265-
It isn't applied to env. variables; only spawn arguments.
264+
of ';' separated argument prefixes to pass un-modified.
266265
A value of * means don't convert any arguments. */
267266
char* msys2_arg_conv_excl_env = getenv("MSYS2_ARG_CONV_EXCL");
268267
char* msys2_arg_conv_excl = NULL;
@@ -271,14 +270,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
271270
{
272271
msys2_arg_conv_excl = (char*)alloca (strlen(msys2_arg_conv_excl_env)+1);
273272
strcpy (msys2_arg_conv_excl, msys2_arg_conv_excl_env);
274-
msys2_arg_conv_excl_count = 1;
275-
msys2_arg_conv_excl_env = strchr ( msys2_arg_conv_excl, ';' );
276-
while (msys2_arg_conv_excl_env)
277-
{
278-
*msys2_arg_conv_excl_env = '\0';
279-
++msys2_arg_conv_excl_count;
280-
msys2_arg_conv_excl_env = strchr ( msys2_arg_conv_excl_env + 1, ';' );
281-
}
273+
msys2_arg_conv_excl_count = string_split_delimited (msys2_arg_conv_excl, ';');
282274
}
283275

284276
/* Check if we have been called from exec{lv}p or spawn{lv}p and mask

0 commit comments

Comments
 (0)