Add GN configuration (issue #1403)

This commit is contained in:
Marshall Greenblatt
2016-06-23 13:42:00 -04:00
parent 05ee60b7b4
commit d0a2e217a0
12 changed files with 2974 additions and 124 deletions

View File

@ -169,17 +169,20 @@ def download_and_extract(src, target):
if temporary and os.path.exists(archive_path):
os.remove(archive_path)
def read_config_file(path):
""" Read a configuration file. """
def read_file(path):
""" Read a file. """
if os.path.exists(path):
fp = open(path, 'r')
data = fp.read()
fp.close()
return data
else:
raise Exception("Path does not exist: %s" % (path))
def read_config_file(path):
""" Read a configuration file. """
# Parse the contents.
return eval(data, {'__builtins__': None}, None)
return eval(read_file(path), {'__builtins__': None}, None)
def write_config_file(path, contents):
""" Write a configuration file. """
@ -399,7 +402,7 @@ parser.add_option('--build-log-file',
'directory.')
parser.add_option('--x64-build',
action='store_true', dest='x64build', default=False,
help='Build for 64-bit systems (Windows and Mac OS X only).')
help='Create a 64-bit build.')
# Distribution-related options.
parser.add_option('--force-distrib',
@ -496,14 +499,6 @@ if options.clientdistrib or options.clientdistribonly:
parser.print_help(sys.stderr)
sys.exit()
if options.x64build and platform != 'windows' and platform != 'macosx':
print 'The x64 build option is only used on Windows and Mac OS X.'
sys.exit()
if platform == 'windows' and not 'GYP_MSVS_VERSION' in os.environ.keys():
print 'You must set the GYP_MSVS_VERSION environment variable on Windows.'
sys.exit()
# CEF branch.
if options.branch != 'trunk' and not options.branch.isdigit():
print 'Invalid branch value: %s' % (options.branch)
@ -519,6 +514,29 @@ branch_is_2272_or_newer = (cef_branch == 'trunk' or int(cef_branch) >= 2272)
# True if the requested branch is 2357 or newer.
branch_is_2357_or_newer = (cef_branch == 'trunk' or int(cef_branch) >= 2357)
# True if the requested branch is 2743 or older.
branch_is_2743_or_older = (cef_branch != 'trunk' and int(cef_branch) <= 2743)
# Whether to use GN or GYP. GYP is currently the default.
use_gn = bool(int(os.environ.get('CEF_USE_GN', '0')))
if use_gn:
if branch_is_2743_or_older:
print 'GN is not supported with branch 2743 and older.'
sys.exit()
else:
if options.x64build and platform != 'windows' and platform != 'macosx':
print 'The x64 build option is only used on Windows and Mac OS X.'
sys.exit()
if platform == 'windows' and not 'GYP_MSVS_VERSION' in os.environ.keys():
print 'You must set the GYP_MSVS_VERSION environment variable on Windows.'
sys.exit()
# True if GYP_DEFINES=target_arch=x64 must be set.
gyp_needs_target_arch_x64 = options.x64build and \
(platform == 'windows' or \
(platform == 'macosx' and not branch_is_2272_or_newer))
# Starting with 43.0.2357.126 the DEPS file is now 100% Git and the .DEPS.git
# file is no longer created.
if branch_is_2357_or_newer:
@ -531,11 +549,6 @@ if platform == 'macosx' and not options.x64build and branch_is_2272_or_newer:
'newer. Add --x64-build flag to generate a 64-bit build.'
sys.exit()
# True if GYP_DEFINES=target_arch=x64 must be set.
gyp_needs_target_arch_x64 = options.x64build and \
(platform == 'windows' or \
(platform == 'macosx' and not branch_is_2272_or_newer))
# Options that force the sources to change.
force_change = options.forceclean or options.forceupdate
@ -869,19 +882,21 @@ if not options.nobuild and (chromium_checkout_changed or \
# Building should also force a distribution.
options.forcedistrib = True
# Set GYP environment variables.
os.environ['GYP_GENERATORS'] = 'ninja'
if gyp_needs_target_arch_x64:
if 'GYP_DEFINES' in os.environ.keys():
os.environ['GYP_DEFINES'] = os.environ['GYP_DEFINES'] + ' ' + \
'target_arch=x64'
else:
os.environ['GYP_DEFINES'] = 'target_arch=x64'
if not use_gn:
# Set GYP environment variables.
os.environ['GYP_GENERATORS'] = 'ninja'
if gyp_needs_target_arch_x64:
if 'GYP_DEFINES' in os.environ.keys():
os.environ['GYP_DEFINES'] = os.environ['GYP_DEFINES'] + ' ' + \
'target_arch=x64'
else:
os.environ['GYP_DEFINES'] = 'target_arch=x64'
# Print all build-related environment variables including any that were set
# previously.
for key in os.environ.keys():
if key.startswith('GYP_') or key.startswith('DEPOT_TOOLS_'):
if key.startswith('CEF_') or key.startswith('GN_') or \
key.startswith('GYP_') or key.startswith('DEPOT_TOOLS_'):
msg('%s=%s' % (key, os.environ[key]))
# Run the cef_create_projects script to generate project files.
@ -897,21 +912,42 @@ if not options.nobuild and (chromium_checkout_changed or \
target = target + ' cef_unittests'
if platform == 'linux':
target = target + ' chrome_sandbox'
build_dir_suffix = ''
if platform == 'windows' and options.x64build:
build_dir_suffix = '_x64'
if use_gn:
# CEF uses a consistent directory naming scheme for GN via
# GetAllPlatformConfigs in tools/gn_args.py.
if options.x64build:
build_dir_suffix = '_GN_x64'
else:
build_dir_suffix = '_GN_x86'
else:
# GYP outputs both x86 and x64 builds to the same directory on Linux and
# Mac OS X. On Windows it suffixes the directory name for x64 builds.
if platform == 'windows' and options.x64build:
build_dir_suffix = '_x64'
if not options.nodebugbuild:
build_path = os.path.join('out', 'Debug' + build_dir_suffix)
if use_gn:
args_path = os.path.join(chromium_src_dir, build_path, 'args.gn')
if os.path.exists(args_path):
msg(args_path + ' contents:\n' + read_file(args_path))
# Make a CEF Debug build.
run(command + os.path.join('out', 'Debug' + build_dir_suffix) + target, \
chromium_src_dir, depot_tools_dir,
run(command + build_path + target, chromium_src_dir, depot_tools_dir,
os.path.join(download_dir, 'build-%s-debug.log' % (cef_branch)) \
if options.buildlogfile else None)
if not options.noreleasebuild:
build_path = os.path.join('out', 'Release' + build_dir_suffix)
if use_gn:
args_path = os.path.join(chromium_src_dir, build_path, 'args.gn')
if os.path.exists(args_path):
msg(args_path + ' contents:\n' + read_file(args_path))
# Make a CEF Release build.
run(command + os.path.join('out', 'Release' + build_dir_suffix) + target, \
chromium_src_dir, depot_tools_dir,
run(command + build_path + target, chromium_src_dir, depot_tools_dir,
os.path.join(download_dir, 'build-%s-release.log' % (cef_branch)) \
if options.buildlogfile else None)