116def _LoadToolchainEnv(cpu, toolchain_root, sdk_dir, target_store):
117 """Returns a dictionary with environment variables that must be set while
118 running binaries from the toolchain (e.g. INCLUDE and PATH for cl.exe)."""
119
120
121
122 assert cpu in ('x86', 'x64', 'arm', 'arm64')
123 if bool(
int(os.environ.get(
'DEPOT_TOOLS_WIN_TOOLCHAIN', 1)))
and sdk_dir:
124
125 env = os.path.normpath(os.path.join(sdk_dir, 'bin/SetEnv.%s.json' % cpu))
126 env = json.load(open(env))['env']
127 if env['VSINSTALLDIR'] == [["..", "..\\"]]:
128
129 json_relative_dir = os.path.join(sdk_dir, 'bin')
130 else:
131
132 json_relative_dir = toolchain_root
133 for k in env:
134 entries = [os.path.join(*([json_relative_dir] + e)) for e in env[k]]
135
136
137
138 sep = os.pathsep if k == 'PATH' else ';'
139 env[k] = sep.join(entries)
140
141 env['PATH'] = env['PATH'] + os.pathsep + os.environ['PATH']
142
143 for k in os.environ:
144 if k not in env:
145 env[k] = os.environ[k]
146
147 varlines = []
148 for k in sorted(env.keys()):
149 varlines.append('%s=%s' % (str(k), str(env[k])))
150 variables = '\n'.join(varlines)
151
152
153 if sys.platform in ('win32', 'cygwin'):
154 script = os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.cmd'))
155 arg = '/' + cpu
156 json_env = _ExtractImportantEnvironment(variables)
157 cmd_env = _ExtractImportantEnvironment(_LoadEnvFromBat([script, arg]))
158 assert _LowercaseDict(json_env) == _LowercaseDict(cmd_env)
159 else:
160 if 'GYP_MSVS_OVERRIDE_PATH' not in os.environ:
161 os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath()
162
163 script_path = os.path.normpath(os.path.join(
164 os.environ['GYP_MSVS_OVERRIDE_PATH'],
165 'VC/vcvarsall.bat'))
166 if not os.path.exists(script_path):
167
168
169
170
171
172
173
174 if 'VSINSTALLDIR' in os.environ:
175 del os.environ['VSINSTALLDIR']
176 if 'INCLUDE' in os.environ:
177 del os.environ['INCLUDE']
178 if 'LIB' in os.environ:
179 del os.environ['LIB']
180 if 'LIBPATH' in os.environ:
181 del os.environ['LIBPATH']
182 other_path = os.path.normpath(os.path.join(
183 os.environ['GYP_MSVS_OVERRIDE_PATH'],
184 'VC/Auxiliary/Build/vcvarsall.bat'))
185 if not os.path.exists(other_path):
186 raise Exception('%s is missing - make sure VC++ tools are installed.' %
187 script_path)
188 script_path = other_path
189 cpu_arg = "amd64"
190 if (cpu != 'x64'):
191
192 cpu_arg += '_' + cpu
193 args = [script_path, cpu_arg, ]
194
195 if (target_store):
196 args.append('store')
197
198
199
200 args.append(SDK_VERSION)
201 variables = _LoadEnvFromBat(args)
202 return _ExtractImportantEnvironment(variables)
203
204
Type::kYUV Type::kRGBA() int(0.7 *637)