Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support of utf8 encoding #105

Merged
merged 3 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pylib/gyp/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import sys
import re
import os
import locale
Expand Down Expand Up @@ -121,7 +122,10 @@ def WriteXmlIfChanged(content, path, encoding="utf-8", pretty=False, win32=False

default_encoding = locale.getdefaultlocale()[1]
if default_encoding and default_encoding.upper() != encoding.upper():
xml_string = xml_string.encode(encoding)
if sys.platform == "win32" and sys.version_info < (3, 7):
targos marked this conversation as resolved.
Show resolved Hide resolved
xml_string = xml_string.decode("cp1251").encode(encoding)
else:
xml_string = xml_string.encode(encoding)

# Get the old content
try:
Expand Down
2 changes: 1 addition & 1 deletion pylib/gyp/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def LoadOneBuildFile(build_file_path, data, aux_data, includes, is_target, check
return data[build_file_path]

if os.path.exists(build_file_path):
build_file_contents = open(build_file_path).read()
build_file_contents = open(build_file_path, encoding='utf-8').read()
else:
raise GypError(f"{build_file_path} not found (cwd: {os.getcwd()})")

Expand Down