Skip to content

Commit d5d06d5

Browse files
mingwandroidAlexpux
authored andcommitted
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 e62394e commit d5d06d5

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

winsup/cygwin/environ.cc

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

11181118
int tl = 0;
11191119
char **pass_dstp;
1120+
#ifdef __MSYS__
1121+
char *msys2_env_conv_excl_env = NULL;
1122+
size_t msys2_env_conv_excl_count = 0;
1123+
#endif
11201124
char **pass_env = (char **) alloca (sizeof (char *)
11211125
* (n + winnum + SPENVS_SIZE + 1));
11221126
/* Iterate over input list, generating a new environment list and refreshing
@@ -1125,9 +1129,18 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11251129
{
11261130
bool calc_tl = !no_envblock;
11271131
#ifdef __MSYS__
1128-
/* Don't pass timezone environment to non-msys applications */
1129-
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
1130-
goto next1;
1132+
if (!keep_posix)
1133+
{
1134+
/* Don't pass timezone environment to non-msys applications */
1135+
if (ascii_strncasematch(*srcp, "TZ=", 3))
1136+
goto next1;
1137+
else if (ascii_strncasematch(*srcp, "MSYS2_ENV_CONV_EXCL=", 20))
1138+
{
1139+
msys2_env_conv_excl_env = (char*)alloca (strlen(&(*srcp)[20])+1);
1140+
strcpy (msys2_env_conv_excl_env, &(*srcp)[20]);
1141+
msys2_env_conv_excl_count = string_split_delimited (msys2_env_conv_excl_env, ';');
1142+
}
1143+
}
11311144
#endif
11321145
/* Look for entries that require special attention */
11331146
for (unsigned i = 0; i < SPENVS_SIZE; i++)
@@ -1251,7 +1264,8 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
12511264
}
12521265
#ifdef __MSYS__
12531266
else if (!keep_posix) {
1254-
char *win_arg = arg_heuristic(*srcp);
1267+
char *win_arg = arg_heuristic_with_exclusions
1268+
(*srcp, msys2_env_conv_excl_env, msys2_env_conv_excl_count);
12551269
debug_printf("WIN32_PATH is %s", win_arg);
12561270
p = cstrdup1(win_arg);
12571271
if (win_arg != *srcp)

winsup/cygwin/miscfuncs.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,27 @@ slashify (const char *src, char *dst, bool trailing_slash_p)
527527
*dst++ = 0;
528528
}
529529

530+
/* Searches through string for delimiter replacing each instance with '\0'
531+
and returning the number of such delimited substrings. This function
532+
Will return 0 for the NULL string and at least 1 otherwise. */
533+
534+
size_t
535+
string_split_delimited (char * string, char delimiter)
536+
{
537+
if ( string == NULL )
538+
return 0;
539+
size_t count = 1;
540+
string = strchr ( string, delimiter );
541+
while (string)
542+
{
543+
*string = '\0';
544+
++count;
545+
string = strchr ( string + 1, delimiter );
546+
}
547+
return count;
548+
}
549+
550+
530551
/* Return an address from the import jmp table of main program. */
531552
void * __reg1
532553
__import_address (void *imp)

winsup/cygwin/miscfuncs.h

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

61+
size_t string_split_delimited (char * string, char delimiter);
62+
6163
extern void transform_chars (PWCHAR, PWCHAR);
6264
extern inline void
6365
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
@@ -3437,7 +3437,6 @@ arg_heuristic_with_exclusions (char const * const arg, char const * exclusions,
34373437
return arg_result;
34383438
}
34393439

3440-
debug_printf("Input value: (%s)", arg);
34413440
for (size_t excl = 0; excl < exclusions_count; ++excl)
34423441
{
34433442
/* 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
@@ -262,8 +262,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
262262
int res = -1;
263263

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

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

0 commit comments

Comments
 (0)