Skip to content

Commit

Permalink
Fix code page detection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0k-z authored and dvander committed Feb 29, 2024
1 parent 63d8fd8 commit 14aec13
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ambuild2/frontend/cpp/msvc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import subprocess
import sys
import tempfile
import codecs
from ambuild2 import util
from ambuild2.frontend.version import Version
try:
Expand Down Expand Up @@ -253,9 +254,15 @@ def DetectInclusionPattern(text):
raise Exception('Could not find compiler inclusion pattern')

def GetCodePage():
stdout = subprocess.run(
"chcp", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL
).stdout
return re.match(b".+: (\d+)\s*$", stdout).group(1).decode()
try:
stdout = subprocess.run(
"chcp", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
stdin=subprocess.DEVNULL
).stdout
codec = 'cp'+re.match(b".+: (\d+)\s*$", stdout).group(1).decode()
codecs.lookup(codec)
return codec
except LookupError:
print("Warning: Codec lookup failed, falling back to utf-8.")
return 'utf-8'

0 comments on commit 14aec13

Please sign in to comment.