Skip to content

Commit 7397992

Browse files
committed
Replace os/arch mapping logic using startswith instead of equality checks
Ref: nodejs#2148 (comment)
1 parent 287efc9 commit 7397992

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

configure

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,20 @@ def uname(switch):
131131

132132

133133
def parse_arch(arch, default):
134-
return {
135-
'arm': 'arm',
136-
'x86': 'ia32',
137-
'i386': 'ia32',
138-
'ia32': 'ia32',
139-
'x86_64': 'x64',
140-
'x64': 'x64'
141-
}.get(arch, default)
134+
mapping = {
135+
'arm': {'arm'},
136+
'ia32': {'x86','ia32','i386'},
137+
'x64': {'x64','amd64','x86_64'},
138+
# TODO support MIPS when acceptable
139+
}
140+
141+
if arch is not None:
142+
for (arch_normalised, arch_mapping) in mapping.items():
143+
for arch_optional in arch_mapping:
144+
if arch.startswith(arch_optional):
145+
return arch_normalised
146+
147+
return default
142148

143149
def host_arch():
144150
"""Host architecture. One of arm, ia32 or x64."""
@@ -154,20 +160,22 @@ def target_arch():
154160
return parse_arch(options.dest_cpu, host_arch())
155161

156162
def parse_os(os, default):
157-
# TODO what to do about cygwin/mingw
158-
return {
159-
'linux': 'linux',
160-
'linux2': 'linux',
161-
'win': 'win',
162-
'win32': 'win',
163-
'w64': 'win',
164-
'cygwin': 'linux',
165-
'darwin': 'mac',
166-
'sunos5': 'solaris',
167-
'freebsd7': 'freebsd',
168-
'freebsd7': 'freebsd',
169-
'openbsd': 'openbsd',
170-
}.get(os, default)
163+
mapping = {
164+
'linux': {'linux','cygwin'},
165+
'win': {'w'},
166+
'mac': {'mac','darwin','osx'},
167+
'solaris': {'solaris','sunos'},
168+
'freebsd': {'freebsd'},
169+
'openbsd': {'openbsd'},
170+
}
171+
172+
if os is not None:
173+
for (os_normalised, os_mapping) in mapping.items():
174+
for os_optional in os_mapping:
175+
if os.startswith(os_optional):
176+
return os_normalised
177+
178+
return default
171179

172180
def host_os():
173181
"""Host operating system. One of win, linux, freebsd, openbsd, solaris, mac."""

0 commit comments

Comments
 (0)