Skip to content

Commit 1d82d68

Browse files
yukawahiroyuki-komatsu
authored andcommitted
Stop requiring vcvarsall.bat before build_mozc.py
With this commit 'vcvarsall.bat' (and its variant) are no longer requires to be executed before running 'build_mozc.py', like 'build_qt.py' has never required 'vcvarsall.bat' (and its variant) [1]. '--vcvarsall_path' option, which is available in 'build_qt.py' [2], is also available to explicitly specify a custom path of vcvarsall.bat as follows. build_mozc.py --vcvarsall_path=C:\VS\VC\Auxiliary\Build\vcvarsall.bat Overall this commit should make our build instructions simpler and easier to keep maintaining. Closes #923. #codehealth [1]: baf4188 [2]: c777896 PiperOrigin-RevId: 629293616
1 parent fcbd2d3 commit 1d82d68

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

.github/workflows/windows.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ jobs:
5959
shell: cmd
6060
working-directory: .\src
6161
run: |
62-
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
6362
python build_mozc.py gyp
6463
6564
- name: build package
6665
shell: cmd
6766
working-directory: .\src
6867
run: |
69-
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
7068
python build_mozc.py build -c Release package
7169
7270
- name: upload Mozc64.msi
@@ -110,14 +108,12 @@ jobs:
110108
shell: cmd
111109
working-directory: .\src
112110
run: |
113-
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
114111
python build_mozc.py gyp --noqt --msvs_version=2022
115112
116113
- name: runtests
117114
shell: cmd
118115
working-directory: .\src
119116
run: |
120-
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
121117
python build_mozc.py runtests -c Debug
122118
123119
# actions/cache works without this job, but having this would increase the likelihood of cache hit

docs/build_mozc_in_windows.md

-12
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ git clone https://github.com/google/mozc.git
1414
cd mozc\src
1515
1616
python build_tools/update_deps.py
17-
18-
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
19-
2017
python build_tools/build_qt.py --release --confirm_license
2118
python build_mozc.py gyp
2219
python build_mozc.py build -c Release package
@@ -76,15 +73,6 @@ You can skip this step if you would like to manually download these libraries.
7673

7774
## Build
7875

79-
### Setup Build system
80-
81-
If you have not set up the build system in your command prompt, you might need
82-
to execute the setup command like this.
83-
84-
```
85-
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
86-
```
87-
8876
### Build Qt
8977

9078
```

src/build_mozc.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from build_tools.util import RemoveFile
6363
from build_tools.util import RunOrDie
6464
from build_tools.util import RunOrDieError
65+
from build_tools.vs_util import get_vs_env_vars
6566

6667
SRC_DIR = '.'
6768
OSS_SRC_DIR = '.'
@@ -252,6 +253,8 @@ def ParseGypOptions(args):
252253
parser.add_option('--msvs_version', dest='msvs_version',
253254
default='2022',
254255
help='Version of the Visual Studio.')
256+
parser.add_option('--vcvarsall_path', help='Path of vcvarsall.bat',
257+
default=None)
255258

256259
if IsWindows() or IsMac():
257260
parser.add_option('--qtdir', dest='qtdir',
@@ -373,6 +376,15 @@ def UpdateEnvironmentFilesForWindows(out_dir):
373376

374377
def GypMain(options, unused_args):
375378
"""The main function for the 'gyp' command."""
379+
if IsWindows():
380+
# GYP captures environment variables while running so setting them up as if
381+
# the developer manually executed 'vcvarsall.bat' command. Otherwise we end
382+
# up having to explain how to do that for both cmd.exe and PowerShell.
383+
# See https://github.com/google/mozc/pull/923
384+
env_vars = get_vs_env_vars('x64', options.vcvarsall_path)
385+
for (key, value) in env_vars.items():
386+
os.environ[key] = value
387+
376388
# Generate a version definition file.
377389
logging.info('Generating version definition file...')
378390
template_path = '%s/%s' % (OSS_SRC_DIR, options.version_file)
@@ -863,11 +875,6 @@ def main():
863875
command = sys.argv[1]
864876
args = sys.argv[2:]
865877

866-
if IsWindows() and (not os.environ.get('VCToolsRedistDir', '')):
867-
print('VCToolsRedistDir is not defined.')
868-
print('Please use Developer Command Prompt or run vcvarsamd64_x86.bat')
869-
return 1
870-
871878
if command == 'gyp':
872879
(cmd_opts, cmd_args) = ParseGypOptions(args)
873880
GypMain(cmd_opts, cmd_args)

0 commit comments

Comments
 (0)