Commit f06b5d19 authored by michaeldo's avatar michaeldo Committed by Commit Bot

Add script to generate CronetChromeWebView.framework

By default, the script will build CronetChromeWebView.framework and copy the
results to ./out/CronetChromeWebView/. use_goma=true is also passed to gn unless
specified otherwise with the --no-goma option.

BUG=none

Review-Url: https://codereview.chromium.org/2941683002
Cr-Commit-Position: refs/heads/master@{#481957}
parent ca5afdce
...@@ -99,7 +99,6 @@ ios_web_view_sources = [ ...@@ -99,7 +99,6 @@ ios_web_view_sources = [
ios_web_view_sources += ios_web_view_public_headers ios_web_view_sources += ios_web_view_public_headers
ios_web_view_deps = [ ios_web_view_deps = [
":generate_license",
":packed_resources", ":packed_resources",
"//base", "//base",
"//components/flags_ui", "//components/flags_ui",
...@@ -249,22 +248,81 @@ bundle_data("packed_resources") { ...@@ -249,22 +248,81 @@ bundle_data("packed_resources") {
] ]
} }
action("generate_license") { if (additional_toolchains == [] || current_toolchain == default_toolchain) {
_license_path = "$target_out_dir/LICENSE" _package_dir = "$root_out_dir/cronet_ios_web_view"
script = "//tools/licenses.py" action("cronet_ios_web_view_generate_license") {
inputs = [ _license_path = "$_package_dir/LICENSE"
"//buildtools/$host_os/gn",
] script = "//tools/licenses.py"
outputs = [ inputs = [
_license_path, "//buildtools/$host_os/gn",
] ]
args = [ outputs = [
"license_file", _license_path,
rebase_path(_license_path, root_build_dir), ]
"--gn-target", args = [
"//ios/web_view", "license_file",
"--gn-out-dir", rebase_path(_license_path, root_build_dir),
".", "--gn-target",
] "//ios/web_view",
"--gn-out-dir",
".",
]
}
copy("cronet_ios_web_view_package_copy") {
sources = [
"$root_out_dir/CronetChromeWebView.framework",
"//AUTHORS",
"//chrome/VERSION",
]
outputs = [
"$_package_dir/{{source_file_part}}",
]
deps = [
":cronet_web_view_combined",
]
}
if (enable_dsyms) {
action("cronet_ios_web_view_dsym_archive") {
script = "//chrome/tools/build/mac/archive_symbols.py"
# These are the dSYMs that will be archived. The sources list must be
# the target outputs that correspond to the dSYMs (since a dSYM is a
# directory it cannot be listed as a source file). The targets that
# generate both the dSYM and binary image are listed in deps.
_dsyms = [ "$root_out_dir/CronetChromeWebView.dSYM" ]
sources = [
"$root_out_dir/CronetChromeWebView.framework",
]
_output = "$_package_dir/CronetChromeWebView.dSYM.tar.bz2"
outputs = [
_output,
]
args = [ rebase_path(_output, root_out_dir) ] +
rebase_path(_dsyms, root_out_dir)
deps = [
":cronet_web_view_combined",
]
}
} else {
group("cronet_ios_web_view_dsym_archive") {
}
}
group("cronet_ios_web_view_package") {
deps = [
":cronet_ios_web_view_dsym_archive",
":cronet_ios_web_view_generate_license",
":cronet_ios_web_view_package_copy",
]
}
} }
#!/usr/bin/python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Builds and packages CronetChromeWebView.framework.
"""
import argparse
import os
import shutil
import sys
def target_dir_name(build_config, target_device):
"""Returns a default output directory name string.
Args:
build_config: A string describing the build configuration. Ex: 'Debug'
target_device: A string describing the target device. Ex: 'simulator'
"""
return '%s-iphone%s' % (build_config, target_device)
def build(build_config, target_device, extra_gn_options):
"""Generates and builds CronetChromeWebView.framework.
Args:
build_config: A string describing the build configuration. Ex: 'Debug'
target_device: A string describing the target device. Ex: 'simulator'
extra_gn_options: A string of gn args (space separated key=value items) to
be appended to the gn gen command.
Returns:
The return code of generating ninja if it is non-zero, else the return code
of the ninja build command.
"""
if target_device == 'os':
target_cpu = 'arm'
additional_cpu = 'arm64'
else:
target_cpu = 'x86'
additional_cpu = 'x64'
if build_config == 'Debug':
build_config_gn_args = 'is_debug=true'
else:
build_config_gn_args = ('is_debug=false enable_stripping=true '
'is_official_build=true')
build_dir = os.path.join("out", target_dir_name(build_config, target_device))
gn_args = ('target_os="ios" enable_websockets=false '
'is_component_build=false use_xcode_clang=true '
'disable_file_support=true disable_ftp_support=true '
'disable_brotli_filter=true ios_enable_code_signing=false '
'target_cpu="%s" additional_target_cpus = ["%s"] %s %s' %
(target_cpu, additional_cpu, build_config_gn_args,
extra_gn_options))
gn_command = 'gn gen %s --args=\'%s\'' % (build_dir, gn_args)
print gn_command
gn_result = os.system(gn_command)
if gn_result != 0:
return gn_result
ninja_command = ('ninja -C %s ios/web_view:cronet_ios_web_view_package' %
build_dir)
print ninja_command
return os.system(ninja_command)
def copy_build_products(build_config, target_device, out_dir):
"""Copies the resulting framework and symbols to out_dir.
Args:
build_config: A string describing the build configuration. Ex: 'Debug'
target_device: A string describing the target device. Ex: 'simulator'
out_dir: A string to the path which all build products will be copied.
"""
target_dir = target_dir_name(build_config, target_device)
build_dir = os.path.join("out", target_dir)
# Copy framework.
framework_source = os.path.join(build_dir, 'CronetChromeWebView.framework')
framework_dest = os.path.join(out_dir, target_dir,
'CronetChromeWebView.framework')
print 'Copying %s to %s' % (framework_source, framework_dest)
shutil.copytree(framework_source, framework_dest)
# Copy symbols.
symbols_source = os.path.join(build_dir, 'CronetChromeWebView.dSYM')
symbols_dest = os.path.join(out_dir, target_dir, 'CronetChromeWebView.dSYM')
print 'Copying %s to %s' % (symbols_source, symbols_dest)
shutil.copytree(symbols_source, symbols_dest)
def package_framework(build_config, target_device, out_dir, extra_gn_options):
"""Builds CronetChromeWebView.framework and copies the result to out_dir.
Args:
build_config: A string describing the build configuration. Ex: 'Debug'
target_device: A string describing the target device. Ex: 'simulator'
out_dir: A string to the path which all build products will be copied.
extra_gn_options: A string of gn args (space separated key=value items) to
be appended to the gn gen command.
Returns:
The return code of the build if it fails or 0 if the build was successful.
"""
print '\nBuilding for %s (%s)' % (target_device, build_config)
build_result = build(build_config, target_device, extra_gn_options)
if build_result != 0:
error = 'Building %s/%s failed with code: ' % (build_config, target_device)
print >>sys.stderr, error, build_result
return build_result
copy_build_products(build_config, target_device, out_dir)
return 0
def package_all_frameworks(out_dir, extra_gn_options):
"""Builds CronetChromeWebView.framework.
Builds Release and Debug versions of CronetChromeWebView.framework for both
iOS devices and simulator and copies the resulting frameworks into out_dir.
Args:
out_dir: A string to the path which all build products will be copied.
extra_gn_options: A string of gn args (space separated key=value items) to
be appended to the gn gen command.
Returns:
0 if all builds are successful or 1 if any build fails.
"""
print 'Building CronetChromeWebView.framework...'
# Package all builds in the output directory
os.makedirs(out_dir)
if package_framework('Debug', 'simulator', out_dir, extra_gn_options) != 0:
return 1
if package_framework('Debug', 'os', out_dir, extra_gn_options) != 0:
return 1
if package_framework('Release', 'simulator', out_dir, extra_gn_options) != 0:
return 1
if package_framework('Release', 'os', out_dir, extra_gn_options) != 0:
return 1
# Copy common files from last built package to out_dir.
build_dir = os.path.join("out", target_dir_name('Release', 'os'))
package_dir = os.path.join(build_dir, 'cronet_ios_web_view')
shutil.copy2(os.path.join(package_dir, 'AUTHORS'), out_dir)
shutil.copy2(os.path.join(package_dir, 'LICENSE'), out_dir)
shutil.copy2(os.path.join(package_dir, 'VERSION'), out_dir)
print '\nSuccess! CronetChromeWebView.framework is packaged into %s' % out_dir
return 0
def main():
description = "Build and package CronetChromeWebView.framework"
parser = argparse.ArgumentParser(description=description)
parser.add_argument('out_dir', nargs='?', default='out/CronetChromeWebView',
help='path to output directory')
parser.add_argument('--no_goma', action='store_true',
help='Prevents adding use_goma=true to the gn args.')
options, extra_options = parser.parse_known_args()
print 'Options:', options
if len(extra_options):
print >>sys.stderr, 'Unknown options: ', extra_options
return 1
out_dir = options.out_dir
# Make sure that the output directory does not exist
if os.path.exists(out_dir):
print >>sys.stderr, 'The output directory already exists: ' + out_dir
return 1
gn_options = '' if options.no_goma else 'use_goma=true'
return package_all_frameworks(out_dir, gn_options)
if __name__ == '__main__':
sys.exit(main())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment