Flutter Engine
The Flutter Engine
Functions | Variables
setup_toolchain Namespace Reference

Functions

def FindFileInEnvList (env, env_name, separator, file_name, optional=False)
 
def main ()
 

Variables

 SCRIPT_DIR = os.path.dirname(__file__)
 
string SDK_VERSION = '10.0.22621.0'
 

Function Documentation

◆ FindFileInEnvList()

def setup_toolchain.FindFileInEnvList (   env,
  env_name,
  separator,
  file_name,
  optional = False 
)

Definition at line 229 of file setup_toolchain.py.

229def FindFileInEnvList(env, env_name, separator, file_name, optional=False):
230 parts = env[env_name].split(separator)
231 for path in parts:
232 if os.path.exists(os.path.join(path, file_name)):
233 return os.path.realpath(path)
234 assert optional, "%s is not found in %s:\n%s\nCheck if it is installed." % (
235 file_name, env_name, '\n'.join(parts))
236 return ''
237
238
def FindFileInEnvList(env, env_name, separator, file_name, optional=False)
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ main()

def setup_toolchain.main ( )

Definition at line 239 of file setup_toolchain.py.

239def main():
240 if len(sys.argv) != 7:
241 print('Usage setup_toolchain.py '
242 '<visual studio path> <win sdk path> '
243 '<runtime dirs> <target_os> <target_cpu> '
244 '<environment block name|none>')
245 sys.exit(2)
246 # toolchain_root and win_sdk_path are only read if the hermetic Windows
247 # toolchain is set, that is if DEPOT_TOOLS_WIN_TOOLCHAIN is not set to 0.
248 # With the hermetic Windows toolchain, the visual studio path in argv[1]
249 # is the root of the Windows toolchain directory.
250 toolchain_root = sys.argv[1]
251 win_sdk_path = sys.argv[2]
252
253 runtime_dirs = sys.argv[3]
254 target_os = sys.argv[4]
255 target_cpu = sys.argv[5]
256 environment_block_name = sys.argv[6]
257 if (environment_block_name == 'none'):
258 environment_block_name = ''
259
260 if (target_os == 'winuwp'):
261 target_store = True
262 else:
263 target_store = False
264
265 cpus = ('x86', 'x64', 'arm', 'arm64')
266 assert target_cpu in cpus
267 vc_bin_dir = ''
268 include = ''
269 lib = ''
270
271 # TODO(scottmg|goma): Do we need an equivalent of
272 # ninja_use_custom_environment_files?
273
274 def relflag(s): # Make s relative to builddir when cwd and sdk on same drive.
275 try:
276 return os.path.relpath(s).replace('\\', '/')
277 except ValueError:
278 return s
279
280 def q(s): # Quote s if it contains spaces or other weird characters.
281 return s if re.match(r'^[a-zA-Z0-9._/\\:-]*$', s) else '"' + s + '"'
282
283 for cpu in cpus:
284 if cpu == target_cpu:
285 # Extract environment variables for subprocesses.
286 env = _LoadToolchainEnv(cpu, toolchain_root, win_sdk_path, target_store)
287 env['PATH'] = runtime_dirs + os.pathsep + env['PATH']
288
289 vc_bin_dir = FindFileInEnvList(env, 'PATH', os.pathsep, 'cl.exe')
290
291 # The separator for INCLUDE here must match the one used in
292 # _LoadToolchainEnv() above.
293 include = [p.replace('"', r'\"') for p in env['INCLUDE'].split(';') if p]
294 include = list(map(relflag, include))
295
296 lib = [p.replace('"', r'\"') for p in env['LIB'].split(';') if p]
297 lib = list(map(relflag, lib))
298
299 include_I = ['/I' + i for i in include]
300 include_imsvc = ['-imsvc' + i for i in include]
301 libpath_flags = ['-libpath:' + i for i in lib]
302
303 if (environment_block_name != ''):
304 env_block = _FormatAsEnvironmentBlock(env)
305 with open(environment_block_name, 'w', encoding='utf8') as f:
306 f.write(env_block)
307
308 def ListToArgString(x):
309 return gn_helpers.ToGNString(' '.join(q(i) for i in x))
310
311 def ListToArgList(x):
312 return f'[{", ".join(gn_helpers.ToGNString(i) for i in x)}]'
313
314 print('vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir))
315 assert include_I
316 print(f'include_flags_I = {ListToArgString(include_I)}')
317 print(f'include_flags_I_list = {ListToArgList(include_I)}')
318 assert include_imsvc
319 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and win_sdk_path:
320 flags = ['/winsysroot' + relflag(toolchain_root)]
321 print(f'include_flags_imsvc = {ListToArgString(flags)}')
322 print(f'include_flags_imsvc_list = {ListToArgList(flags)}')
323 else:
324 print(f'include_flags_imsvc = {ListToArgString(include_imsvc)}')
325 print(f'include_flags_imsvc_list = {ListToArgList(include_imsvc)}')
326 print('paths = ' + gn_helpers.ToGNString(env['PATH']))
327 assert libpath_flags
328 print(f'libpath_flags = {ListToArgString(libpath_flags)}')
329 print(f'libpath_flags_list = {ListToArgList(libpath_flags)}')
330 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and win_sdk_path:
331 flags = ['/winsysroot:' + relflag(toolchain_root)]
332 print(f'libpath_lldlink_flags = {ListToArgString(flags)}')
333 print(f'libpath_lldlink_flags_list = {ListToArgList(flags)}')
334 else:
335 print(f'libpath_lldlink_flags = {ListToArgString(libpath_flags)}')
336 print(f'libpath_lldlink_flags_list = {ListToArgList(libpath_flags)}')
337
338
def ToGNString(value, allow_dicts=True)
Definition: gn_helpers.py:30
def print(*args, **kwargs)
Definition: run_tests.py:49
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680

Variable Documentation

◆ SCRIPT_DIR

setup_toolchain.SCRIPT_DIR = os.path.dirname(__file__)

Definition at line 24 of file setup_toolchain.py.

◆ SDK_VERSION

string setup_toolchain.SDK_VERSION = '10.0.22621.0'

Definition at line 25 of file setup_toolchain.py.