Skip to content

Commit

Permalink
[Build Chromium] Improve git checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Nov 11, 2020
1 parent 2d3261f commit 58300c9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
47 changes: 29 additions & 18 deletions x-pack/build_chromium/build.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
import subprocess, os, sys, platform, zipfile, hashlib, shutil
from build_util import runcmd, mkdir, md5_file, script_dir, root_dir, configure_environment
from build_util import (
runcmd,
runcmdsilent,
mkdir,
md5_file,
script_dir,
configure_environment,
)

# This file builds Chromium headless on Windows, Mac, and Linux.

# Verify that we have an argument, and if not print instructions
if (len(sys.argv) < 2):
if (len(sys.argv) < 3):
print('Usage:')
print('python build.py {chromium_version}')
print('python build.py {path_to_root} {chromium_version} [arm]')
print('The root path argument should include the "depot_tools" and "chromium" directories. Refer to the Chromium build instructions.')
print('Example:')
print('python build.py 68.0.3440.106')
print('python build.py 4747cc23ae334a57a35ed3c8e6adcdbc8a50d479')
print('python build.py ~/src 68.0.3440.106')
print('python build.py ~/src 4747cc23ae334a57a35ed3c8e6adcdbc8a50d479')
print('python build.py ~/src 4747cc23ae334a57a35ed3c8e6adcdbc8a50d479 arm # build ARM on Linux')
sys.exit(1)

# The version of Chromium we wish to build. This can be any valid git
# commit, tag, or branch, so: 68.0.3440.106 or
# 4747cc23ae334a57a35ed3c8e6adcdbc8a50d479
source_version = sys.argv[1]
source_path = sys.argv[1]
source_version = sys.argv[2]

# Set to "arm" to build for ARM on Linux
arch_name = sys.argv[2] if len(sys.argv) >= 3 else 'x64'
arch_name = sys.argv[3] if len(sys.argv) >= 4 else 'x64'

print('Building Chromium ' + source_version + ' for ' + arch_name)

# Set the environment variables required by the build tools
print('Configuring the build environment')
configure_environment()
configure_environment(script_dir)

# Sync the codebase to the correct version, syncing master first
# to ensure that we actually have all the versions we may refer to
print('Syncing source code')
# Sync the codebase to the correct version
print('Setting local tracking branch')
os.chdir(os.path.join(source_path, 'chromium', 'src'))

os.chdir(os.path.join(root_dir, 'chromium/src'))
checked_out = runcmdsilent('git checkout build-' + source_version)
if checked_out != 0:
print('Syncing remote version')
runcmd('git fetch origin ' + source_version)
print('Creating a new branch for tracking the source version')
runcmd('git checkout -b build-' + source_version + ' ' + source_version)

runcmd('git checkout master')
runcmd('git fetch origin')
runcmd('gclient sync --with_branch_heads --with_tags --jobs 16')
runcmd('git checkout ' + source_version)
runcmd('gclient sync --with_branch_heads --with_tags --jobs 16')
runcmd('gclient runhooks')
print('Updating all modules')
runcmd('gclient sync')

# Copy build args/{Linux | Darwin | Windows}.gn from the root of our directory to out/headless/args.gn,
platform_build_args = os.path.join(script_dir, platform.system().lower(), 'args.gn')
Expand Down
16 changes: 10 additions & 6 deletions x-pack/build_chromium/build_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@

# Compute the root build and script directory as relative to this file
script_dir = os.path.realpath(os.path.join(__file__, '..'))
root_dir = os.path.realpath(os.path.join(script_dir, '..'))

def runcmdsilent(cmd):
"""Executes a string command in the shell"""
print(' > ' + cmd)
return os.system(cmd)

def runcmd(cmd):
"""Executes a string command in the shell"""
print(cmd)
print(' > ' + cmd)
result = os.system(cmd)
if result != 0:
raise Exception(cmd + ' returned ' + str(result))

def mkdir(dir):
"""Makes a directory if it doesn't exist"""
if not os.path.exists(dir):
print('mkdir -p ' + dir)
print(' > mkdir -p ' + dir)
return os.makedirs(dir)

def md5_file(filename):
"""Builds a hex md5 hash of the given file"""
md5 = hashlib.md5()
with open(filename, 'rb') as f:
for chunk in iter(lambda: f.read(128 * md5.block_size), b''):
with open(filename, 'rb') as f:
for chunk in iter(lambda: f.read(128 * md5.block_size), b''):
md5.update(chunk)
return md5.hexdigest()

def configure_environment():
def configure_environment(root_dir):
"""Configures temporary environment variables required by Chromium's build"""
depot_tools_path = os.path.join(root_dir, 'depot_tools')
os.environ['PATH'] = depot_tools_path + os.pathsep + os.environ['PATH']
7 changes: 4 additions & 3 deletions x-pack/build_chromium/linux/args.gn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import("//build/args/headless.gn")
blink_symbol_level = 0
enable_nacl = false
enable_stripping = true
is_component_build = false
is_debug = false
symbol_level = 0
is_component_build = false
remove_webcore_debug_symbols = true
enable_nacl = false
# Please, consult @elastic/kibana-security before changing/removing this option.
use_kerberos = false

0 comments on commit 58300c9

Please sign in to comment.