mirror of
https://github.com/mii443/mozc.git
synced 2025-08-23 00:25:34 +00:00
Simplify ninja env file logic in build_mozc.py
(#1134)
As a preparation to build Mozc for ARM64 in Windows (#1130), this commit aims to simplify UpdateEnvironmentFilesForWindows in build_mozc.py so that we can tweak environment file for ARM64 build configurations in a subsequent commit easily. This is still a mechanical code clean up. There must be no difference in the final artifacts. PiperOrigin-RevId: 703739072
This commit is contained in:
@ -349,6 +349,27 @@ def ParseCleanOptions(args):
|
|||||||
return parser.parse_args(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):
|
def UpdateEnvironmentFilesForWindows(out_dir):
|
||||||
"""Add required environment variables for Ninja build."""
|
"""Add required environment variables for Ninja build."""
|
||||||
python_path_root = MOZC_ROOT
|
python_path_root = MOZC_ROOT
|
||||||
@ -356,22 +377,14 @@ def UpdateEnvironmentFilesForWindows(out_dir):
|
|||||||
original_python_paths = os.environ.get('PYTHONPATH', '')
|
original_python_paths = os.environ.get('PYTHONPATH', '')
|
||||||
if original_python_paths:
|
if original_python_paths:
|
||||||
python_path = os.pathsep.join([original_python_paths, python_path])
|
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):
|
for d in os.listdir(out_dir):
|
||||||
abs_dir = os.path.abspath(os.path.join(out_dir, d))
|
abs_dir = os.path.abspath(os.path.join(out_dir, d))
|
||||||
with open(os.path.join(abs_dir, 'environment.x86'), 'rb') as x86_file:
|
for arch in ['x86', 'x64']:
|
||||||
x86_content = x86_file.read()[:-1] + additional_content
|
env_file = os.path.join(abs_dir, f'environment.{arch}')
|
||||||
with open(os.path.join(abs_dir, 'environment.x86'), 'wb') as x86_file:
|
env = ReadEnvironmentFile(env_file)
|
||||||
x86_file.write(x86_content)
|
env['PYTHONPATH'] = python_path
|
||||||
with open(os.path.join(abs_dir, 'environment.x64'), 'rb') as x64_file:
|
env['VSLANG'] = '1033' # == MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
|
||||||
x64_content = x64_file.read()[:-1] + additional_content
|
WriteEnvironmentFile(env_file, env)
|
||||||
with open(os.path.join(abs_dir, 'environment.x64'), 'wb') as x64_file:
|
|
||||||
x64_file.write(x64_content)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def GypMain(options, unused_args):
|
def GypMain(options, unused_args):
|
||||||
|
Reference in New Issue
Block a user