Skip to content

Commit ed8b5a2

Browse files
mingwandroiddscho
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 cce666e commit ed8b5a2

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
@@ -1131,6 +1131,10 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11311131

11321132
int tl = 0;
11331133
char **pass_dstp;
1134+
#ifdef __MSYS__
1135+
char *msys2_env_conv_excl_env = NULL;
1136+
size_t msys2_env_conv_excl_count = 0;
1137+
#endif
11341138
char **pass_env = (char **) alloca (sizeof (char *)
11351139
* (n + winnum + SPENVS_SIZE + 1));
11361140
/* Iterate over input list, generating a new environment list and refreshing
@@ -1139,9 +1143,18 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11391143
{
11401144
bool calc_tl = !no_envblock;
11411145
#ifdef __MSYS__
1142-
/* Don't pass timezone environment to non-msys applications */
1143-
if (!keep_posix && ascii_strncasematch(*srcp, "TZ=", 3))
1144-
goto next1;
1146+
if (!keep_posix)
1147+
{
1148+
/* Don't pass timezone environment to non-msys applications */
1149+
if (ascii_strncasematch(*srcp, "TZ=", 3))
1150+
goto next1;
1151+
else if (ascii_strncasematch(*srcp, "MSYS2_ENV_CONV_EXCL=", 20))
1152+
{
1153+
msys2_env_conv_excl_env = (char*)alloca (strlen(&(*srcp)[20])+1);
1154+
strcpy (msys2_env_conv_excl_env, &(*srcp)[20]);
1155+
msys2_env_conv_excl_count = string_split_delimited (msys2_env_conv_excl_env, ';');
1156+
}
1157+
}
11451158
#endif
11461159
/* Look for entries that require special attention */
11471160
for (unsigned i = 0; i < SPENVS_SIZE; i++)
@@ -1265,7 +1278,8 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
12651278
}
12661279
#ifdef __MSYS__
12671280
else if (!keep_posix) {
1268-
char *win_arg = arg_heuristic(*srcp);
1281+
char *win_arg = arg_heuristic_with_exclusions
1282+
(*srcp, msys2_env_conv_excl_env, msys2_env_conv_excl_count);
12691283
debug_printf("WIN32_PATH is %s", win_arg);
12701284
p = cstrdup1(win_arg);
12711285
if (win_arg != *srcp)

winsup/cygwin/miscfuncs.cc

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

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

winsup/cygwin/miscfuncs.h

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

85+
size_t string_split_delimited (char * string, char delimiter);
86+
8587
extern void transform_chars (PWCHAR, PWCHAR);
8688
extern inline void
8789
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
@@ -3448,7 +3448,6 @@ arg_heuristic_with_exclusions (char const * const arg, char const * exclusions,
34483448
return arg_result;
34493449
}
34503450

3451-
debug_printf("Input value: (%s)", arg);
34523451
for (size_t excl = 0; excl < exclusions_count; ++excl)
34533452
{
34543453
/* 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)