1# Copyright (c) 2011 The Chromium Embedded Framework Authors. 2# Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6from __future__ import absolute_import 7from __future__ import print_function 8from file_util import make_dir, write_file 9from gclient_util import * 10from gn_args import GetAllPlatformConfigs, GetConfigFileContents 11import issue_1999 12import os 13import sys 14 15# The CEF directory is the parent directory of _this_ script. 16cef_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) 17# The src directory is the parent directory of the CEF directory. 18src_dir = os.path.abspath(os.path.join(cef_dir, os.pardir)) 19 20# Determine the platform. 21if sys.platform == 'win32': 22 platform = 'windows' 23elif sys.platform == 'darwin': 24 platform = 'mac' 25elif sys.platform.startswith('linux'): 26 platform = 'linux' 27else: 28 print('Unknown operating system platform') 29 sys.exit() 30 31print("\nGenerating CEF version header file...") 32cmd = [sys.executable, 'tools/make_version_header.py', 'include/cef_version.h'] 33RunAction(cef_dir, cmd) 34 35print("\nPatching build configuration and source files for CEF...") 36cmd = [sys.executable, 'tools/patcher.py'] 37RunAction(cef_dir, cmd) 38 39if platform == 'linux' and 'CEF_INSTALL_SYSROOT' in os.environ: 40 for arch in os.environ['CEF_INSTALL_SYSROOT'].split(','): 41 if len(arch) == 0: 42 continue 43 print("\nInstalling %s sysroot environment..." % arch) 44 cmd = [ 45 sys.executable, 'build/linux/sysroot_scripts/install-sysroot.py', 46 '--arch', arch 47 ] 48 RunAction(src_dir, cmd) 49 50print("\nGenerating CEF project files...") 51 52gn_args = {} 53 54if platform == 'windows': 55 # Force use of the locally installed version of Visual Studio. 56 if not 'DEPOT_TOOLS_WIN_TOOLCHAIN' in os.environ: 57 os.environ['DEPOT_TOOLS_WIN_TOOLCHAIN'] = '0' 58 59 # By default GN+Ninja on Windows expects Visual Studio and Windows SDK to be 60 # installed on the local machine. To build when Visual Studio and/or SDK is 61 # extracted to a directory but not installed (e.g. via a custom toolchain) set 62 # the following environment variables: 63 # 64 # o Enable use of a custom toolchain on Windows. 65 # 66 # set WIN_CUSTOM_TOOLCHAIN=1 67 # 68 # o Used by tools/msvs_env.bat to configure the MSVS tools environment. 69 # Should be set to "none" because VC variables for CEF will be set via 70 # INCLUDE/LIB/PATH. 71 # 72 # set CEF_VCVARS=none 73 # 74 # o Used by the following scripts: 75 # (a) build/vs_toolchain.py SetEnvironmentAndGetRuntimeDllDirs when 76 # determining whether to copy VS runtime binaries to the output directory. 77 # If GYP_MSVS_OVERRIDE_PATH exists then binaries will not be copied and 78 # should instead be discoverable via the PATH env variable. 79 # (b) build/toolchain/win/setup_toolchain.py _LoadToolchainEnv when 80 # writing environment.* files that specify INCLUDE/LIB/PATH values. If 81 # vcvarsall.bat [1] exists then environment variables will be derived from 82 # there and the specified INCLUDE/LIB values will be ignored by Chromium 83 # (PATH is retained because it might contain required VS runtime libraries). 84 # If this file does not exist then the INCLUDE/LIB/PATH values are also 85 # required by Chromium. 86 # TODO(cef): Rename to VS_ROOT and VS_VERSION after Chromium cleans up GYP 87 # dependencies. 88 # 89 # set GYP_MSVS_OVERRIDE_PATH=<VS root directory> 90 # set GYP_MSVS_VERSION=<VS version> 91 # 92 # o Used to configure GN arguments in this script. 93 # 94 # set VS_CRT_ROOT=<VS CRT root directory> 95 # set SDK_ROOT=<Platform SDK root directory> 96 # 97 # o Used by various scripts as described above. These values are optional when 98 # vcvarsall.bat [1] exists. 99 # 100 # set INCLUDE=<VS include paths> 101 # set LIB=<VS library paths> 102 # set PATH=<VS executable paths> 103 # 104 # See tools/depot_tools/win_toolchain/package_from_installed.py for an example 105 # packaging script along with required directory contents and INCLUDE/LIB/PATH 106 # values. 107 # 108 # [1] The vcvarsall.bat script must exist in "%GYP_MSVS_OVERRIDE_PATH%\VC\" or 109 # "%GYP_MSVS_OVERRIDE_PATH%\VC\Auxiliary\Build\". If the Windows SDK is not 110 # installed (e.g. not discoverable via the Windows registry) then 111 # "%GYP_MSVS_OVERRIDE_PATH%\Common7\Tools\vsdevcmd\core\winsdk.bat" must be 112 # patched to support discovery via SDK_ROOT as described in 113 # https://bitbucket.org/chromiumembedded/cef/issues/2773#comment-59687474. 114 # 115 if bool(int(os.environ.get('WIN_CUSTOM_TOOLCHAIN', '0'))): 116 required_vars = [ 117 'CEF_VCVARS', 118 'GYP_MSVS_OVERRIDE_PATH', 119 'GYP_MSVS_VERSION', 120 'VS_CRT_ROOT', 121 'SDK_ROOT', 122 ] 123 for var in required_vars: 124 if not var in os.environ.keys(): 125 raise Exception('%s environment variable must be set' % var) 126 127 # Windows custom toolchain requirements. See comments in gn_args.py. 128 gn_args['visual_studio_path'] = os.environ['GYP_MSVS_OVERRIDE_PATH'] 129 gn_args['visual_studio_version'] = os.environ['GYP_MSVS_VERSION'] 130 gn_args['visual_studio_runtime_dirs'] = os.environ['VS_CRT_ROOT'] 131 gn_args['windows_sdk_path'] = os.environ['SDK_ROOT'] 132 133configs = GetAllPlatformConfigs(gn_args) 134for dir, config in configs.items(): 135 # Create out directories and write the args.gn file. 136 out_path = os.path.join(src_dir, 'out', dir) 137 make_dir(out_path, False) 138 args_gn_path = os.path.join(out_path, 'args.gn') 139 args_gn_contents = GetConfigFileContents(config) 140 write_file(args_gn_path, args_gn_contents) 141 142 # Generate the Ninja config. 143 cmd = ['gn', 'gen', os.path.join('out', dir)] 144 if 'GN_ARGUMENTS' in os.environ.keys(): 145 cmd.extend(os.environ['GN_ARGUMENTS'].split(' ')) 146 RunAction(src_dir, cmd) 147 if platform == 'windows': 148 issue_1999.apply(out_path) 149