Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fcitx
Browse files Browse the repository at this point in the history
  • Loading branch information
Fcitx Bot committed Dec 7, 2024
2 parents 11254a5 + e983ab8 commit d2b55bc
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/build_mozc.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,29 +351,42 @@ def ParseCleanOptions(args):
return parser.parse_args(args)


def ReadEnvironmentFile(path):
nul = chr(0)
with open(path, 'rb') as f:
content = f.read()
entries = content.decode('utf-8').split(nul)
env = dict()
for e in entries:
if '=' in e:
key, value = e.split('=', 1)
env[key] = value
return env


def WriteEnvironmentFile(path, env):
nul = chr(0)
entries = [f'{key}={value}' for (key, value) in env.items()]
entries.extend(['', ''])
with open(path, 'wb') as f:
f.write(nul.join(entries).encode('utf-8'))


def UpdateEnvironmentFilesForWindows(out_dir):
"""Add required environment variables for Ninja build."""
python_path_root = MOZC_ROOT
python_path = os.path.abspath(python_path_root)
original_python_paths = os.environ.get('PYTHONPATH', '')
if original_python_paths:
python_path = os.pathsep.join([original_python_paths, python_path])
nul = chr(0)
additional_content = nul.join([
'PYTHONPATH=' + python_path,
'VSLANG=1033', # 1033 == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
nul]).encode('utf-8')
for d in os.listdir(out_dir):
abs_dir = os.path.abspath(os.path.join(out_dir, d))
with open(os.path.join(abs_dir, 'environment.x86'), 'rb') as x86_file:
x86_content = x86_file.read()[:-1] + additional_content
with open(os.path.join(abs_dir, 'environment.x86'), 'wb') as x86_file:
x86_file.write(x86_content)
with open(os.path.join(abs_dir, 'environment.x64'), 'rb') as x64_file:
x64_content = x64_file.read()[:-1] + additional_content
with open(os.path.join(abs_dir, 'environment.x64'), 'wb') as x64_file:
x64_file.write(x64_content)

for arch in ['x86', 'x64']:
env_file = os.path.join(abs_dir, f'environment.{arch}')
env = ReadEnvironmentFile(env_file)
env['PYTHONPATH'] = python_path
env['VSLANG'] = '1033' # == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
WriteEnvironmentFile(env_file, env)


def GypMain(options, unused_args):
Expand Down

0 comments on commit d2b55bc

Please sign in to comment.