Skip to content

Commit 55f0c77

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 5d7492a commit 55f0c77

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

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

winsup/cygwin/miscfuncs.cc

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

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