Skip to content

Commit 7a09f8c

Browse files
authored
Add mechanism to override OS (for testing purposes) (#993)
Similar to `EMSDK_ARCH` which I added in #935.
1 parent fd08e9a commit 7a09f8c

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

emsdk.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@
5858
VERBOSE = int(os.getenv('EMSDK_VERBOSE', '0'))
5959
TTY_OUTPUT = not os.getenv('EMSDK_NOTTY', not sys.stdout.isatty())
6060

61-
WINDOWS = False
62-
if os.name == 'nt' or (os.getenv('SYSTEMROOT') is not None and 'windows' in os.getenv('SYSTEMROOT').lower()) or (os.getenv('COMSPEC') is not None and 'windows' in os.getenv('COMSPEC').lower()):
63-
WINDOWS = True
64-
6561

6662
def errlog(msg):
6763
print(msg, file=sys.stderr)
@@ -72,26 +68,42 @@ def exit_with_error(msg):
7268
sys.exit(1)
7369

7470

71+
WINDOWS = False
7572
MINGW = False
7673
MSYS = False
77-
if os.getenv('MSYSTEM'):
78-
MSYS = True
79-
# Some functions like os.path.normpath() exhibit different behavior between
80-
# different versions of Python, so we need to distinguish between the MinGW
81-
# and MSYS versions of Python
82-
if sysconfig.get_platform() == 'mingw':
83-
MINGW = True
84-
if os.getenv('MSYSTEM') != 'MSYS' and os.getenv('MSYSTEM') != 'MINGW64':
85-
# https://stackoverflow.com/questions/37460073/msys-vs-mingw-internal-environment-variables
86-
errlog('Warning: MSYSTEM environment variable is present, and is set to "' + os.getenv('MSYSTEM') + '". This shell has not been tested with emsdk and may not work.')
87-
8874
MACOS = False
89-
if platform.mac_ver()[0] != '':
90-
MACOS = True
91-
9275
LINUX = False
93-
if not MACOS and (platform.system() == 'Linux'):
94-
LINUX = True
76+
77+
if 'EMSDK_OS' in os.environ:
78+
EMSDK_OS = os.environ['EMSDK_OS']
79+
if EMSDK_OS == 'windows':
80+
WINDOWS = True
81+
elif EMSDK_OS == 'linux':
82+
LINUX = True
83+
elif EMSDK_OS == 'macos':
84+
MACOS = True
85+
else:
86+
assert False
87+
else:
88+
if os.name == 'nt' or (os.getenv('SYSTEMROOT') is not None and 'windows' in os.getenv('SYSTEMROOT').lower()) or (os.getenv('COMSPEC') is not None and 'windows' in os.getenv('COMSPEC').lower()):
89+
WINDOWS = True
90+
91+
if os.getenv('MSYSTEM'):
92+
MSYS = True
93+
# Some functions like os.path.normpath() exhibit different behavior between
94+
# different versions of Python, so we need to distinguish between the MinGW
95+
# and MSYS versions of Python
96+
if sysconfig.get_platform() == 'mingw':
97+
MINGW = True
98+
if os.getenv('MSYSTEM') != 'MSYS' and os.getenv('MSYSTEM') != 'MINGW64':
99+
# https://stackoverflow.com/questions/37460073/msys-vs-mingw-internal-environment-variables
100+
errlog('Warning: MSYSTEM environment variable is present, and is set to "' + os.getenv('MSYSTEM') + '". This shell has not been tested with emsdk and may not work.')
101+
102+
if platform.mac_ver()[0] != '':
103+
MACOS = True
104+
105+
if not MACOS and (platform.system() == 'Linux'):
106+
LINUX = True
95107

96108
UNIX = (MACOS or LINUX)
97109

0 commit comments

Comments
 (0)