Skip to content

Commit 95177a1

Browse files
committed
Support for both MSYS and CYGWIN environment variable
This is a prepare for merge msys2 into cygwin
1 parent 9aea120 commit 95177a1

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

winsup/cygwin/environ.cc

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ strbrk(char *&buf)
180180
/* Parse a string of the form "something=stuff somethingelse=more-stuff",
181181
silently ignoring unknown "somethings". */
182182
static void
183-
parse_options (const char *inbuf)
183+
parse_options (const char *inbuf, bool is_msys2)
184184
{
185185
int istrue;
186186
parse_thing *k;
@@ -201,7 +201,10 @@ parse_options (const char *inbuf)
201201
if (export_settings)
202202
{
203203
debug_printf ("%s", newbuf + 1);
204-
setenv ("CYGWIN", newbuf + 1, 1);
204+
if (is_msys2)
205+
setenv ("MSYS", newbuf + 1, 1);
206+
else
207+
setenv ("CYGWIN", newbuf + 1, 1);
205208
}
206209
return;
207210
}
@@ -674,8 +677,10 @@ _addenv (const char *name, const char *value, int overwrite)
674677
win_env *spenv;
675678
if ((spenv = getwinenv (envhere)))
676679
spenv->add_cache (value);
680+
if (strcmp (name, "MSYS") == 0)
681+
parse_options (value, true);
677682
if (strcmp (name, "CYGWIN") == 0)
678-
parse_options (value);
683+
parse_options (value, false);
679684

680685
return 0;
681686
}
@@ -873,9 +878,12 @@ environ_init (char **envp, int envc)
873878
dumper_init ();
874879
if (envp_passed_in)
875880
{
881+
p = getenv ("MSYS");
882+
if (p)
883+
parse_options (p, true);
876884
p = getenv ("CYGWIN");
877885
if (p)
878-
parse_options (p);
886+
parse_options (p, false);
879887
}
880888
}
881889
__except (NO_ERROR)
@@ -929,8 +937,10 @@ win32env_to_cygenv (PWCHAR rawenv, bool posify)
929937
}
930938
sawTERM = 1;
931939
}
940+
else if (*newp == 'M' && strncmp (newp, "MSYS=", 5) == 0)
941+
parse_options (newp + 5, true);
932942
else if (*newp == 'C' && strncmp (newp, "CYGWIN=", 7) == 0)
933-
parse_options (newp + 7);
943+
parse_options (newp + 7, false);
934944
if (*eq && posify)
935945
posify_maybe (envp + i, *++eq ? eq : --eq, tmpbuf);
936946
debug_printf ("%p: %s", envp[i], envp[i]);
@@ -1193,8 +1203,12 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
11931203
#ifdef __MSYS__
11941204
if (ascii_strncasematch(*srcp, "MSYS=", 5))
11951205
{
1196-
parse_options (*srcp + 5);
1197-
}
1206+
parse_options (*srcp + 5, true);
1207+
}
1208+
else if (ascii_strncasematch(*srcp, "CYGWIN=", 7))
1209+
{
1210+
parse_options (*srcp + 7, false);
1211+
}
11981212
else if (!keep_posix)
11991213
{
12001214
/* Don't pass timezone environment to non-msys applications */

winsup/cygwin/exceptions.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,17 @@ int exec_prepared_command (PWCHAR command)
540540
}
541541
break;
542542
}
543+
if (wcsncmp (p, L"MSYS=", wcslen (L"MSYS=")) == 0)
544+
{
545+
PWCHAR q = wcsstr (p, L"error_start") ;
546+
/* replace 'error_start=...' with '_rror_start=...' */
547+
if (q)
548+
{
549+
*q = L'_' ;
550+
SetEnvironmentVariableW (L"MSYS", p + wcslen (L"MSYS=")) ;
551+
}
552+
break;
553+
}
543554
}
544555
FreeEnvironmentStringsW (rawenv);
545556

winsup/utils/mingw/cygcheck.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static const char *known_env_vars[] = {
108108
"lpath",
109109
"make_mode",
110110
"makeflags",
111+
"msys",
111112
"path",
112113
"pwd",
113114
"strace",

0 commit comments

Comments
 (0)