2016-12-06 21:03:52 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2016 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
# Generate Android.bp for Skia from GN configuration.
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import pprint
|
|
|
|
import string
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
|
2017-01-26 22:21:27 +00:00
|
|
|
tool_cflags = [
|
|
|
|
'-Wno-unused-parameter',
|
|
|
|
]
|
|
|
|
|
|
|
|
# It's easier to maintain one list instead of separate lists.
|
|
|
|
tool_shared_libs = [
|
|
|
|
'liblog',
|
|
|
|
'libGLESv2',
|
|
|
|
'libEGL',
|
|
|
|
'libvulkan',
|
|
|
|
'libz',
|
|
|
|
'libjpeg',
|
|
|
|
'libpng',
|
|
|
|
'libicuuc',
|
|
|
|
'libicui18n',
|
|
|
|
'libexpat',
|
|
|
|
'libft2',
|
2017-08-17 19:13:20 +00:00
|
|
|
'libheif',
|
2017-01-26 22:21:27 +00:00
|
|
|
'libdng_sdk',
|
|
|
|
'libpiex',
|
2017-03-03 20:48:33 +00:00
|
|
|
'libcutils',
|
2017-06-02 14:29:21 +00:00
|
|
|
'libnativewindow',
|
2017-01-26 22:21:27 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# The ordering here is important: libsfntly needs to come after libskia.
|
|
|
|
tool_static_libs = [
|
2017-02-20 15:41:39 +00:00
|
|
|
'libarect',
|
2017-01-26 22:21:27 +00:00
|
|
|
'libjsoncpp',
|
|
|
|
'libskia',
|
|
|
|
'libsfntly',
|
|
|
|
'libwebp-decode',
|
|
|
|
'libwebp-encode',
|
|
|
|
]
|
|
|
|
|
2016-12-06 21:03:52 +00:00
|
|
|
# First we start off with a template for Android.bp,
|
|
|
|
# with holes for source lists and include directories.
|
|
|
|
bp = string.Template('''// This file is autogenerated by gn_to_bp.py.
|
|
|
|
|
|
|
|
cc_library {
|
2016-12-12 19:09:38 +00:00
|
|
|
name: "libskia",
|
|
|
|
cflags: [
|
|
|
|
"-fexceptions",
|
|
|
|
"-Wno-unused-parameter",
|
|
|
|
"-U_FORTIFY_SOURCE",
|
|
|
|
"-D_FORTIFY_SOURCE=1",
|
|
|
|
"-DSKIA_IMPLEMENTATION=1",
|
2017-03-03 20:48:33 +00:00
|
|
|
"-DATRACE_TAG=ATRACE_TAG_VIEW",
|
2016-12-12 19:09:38 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
export_include_dirs: [
|
|
|
|
$export_includes
|
|
|
|
],
|
|
|
|
|
|
|
|
local_include_dirs: [
|
|
|
|
$local_includes
|
|
|
|
],
|
|
|
|
|
|
|
|
srcs: [
|
|
|
|
$srcs
|
|
|
|
],
|
|
|
|
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: [
|
|
|
|
$arm_srcs
|
|
|
|
],
|
|
|
|
|
2017-08-10 13:09:54 +00:00
|
|
|
neon: {
|
2016-12-12 19:09:38 +00:00
|
|
|
srcs: [
|
|
|
|
$arm_neon_srcs
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
arm64: {
|
|
|
|
srcs: [
|
|
|
|
$arm64_srcs
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
mips: {
|
|
|
|
srcs: [
|
2016-12-20 22:34:29 +00:00
|
|
|
$none_srcs
|
2016-12-12 19:09:38 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
mips64: {
|
|
|
|
srcs: [
|
2016-12-20 22:34:29 +00:00
|
|
|
$none_srcs
|
2016-12-12 19:09:38 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
x86: {
|
|
|
|
srcs: [
|
|
|
|
$x86_srcs
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
x86_64: {
|
|
|
|
srcs: [
|
|
|
|
$x86_srcs
|
|
|
|
],
|
|
|
|
},
|
2016-12-06 21:03:52 +00:00
|
|
|
},
|
|
|
|
|
2016-12-12 19:09:38 +00:00
|
|
|
shared_libs: [
|
|
|
|
"libEGL",
|
|
|
|
"libGLESv2",
|
|
|
|
"libdng_sdk",
|
|
|
|
"libexpat",
|
|
|
|
"libft2",
|
2017-08-17 19:13:20 +00:00
|
|
|
"libheif",
|
2016-12-12 19:09:38 +00:00
|
|
|
"libicui18n",
|
|
|
|
"libicuuc",
|
|
|
|
"libjpeg",
|
|
|
|
"liblog",
|
|
|
|
"libpiex",
|
|
|
|
"libpng",
|
|
|
|
"libvulkan",
|
|
|
|
"libz",
|
2017-03-03 20:48:33 +00:00
|
|
|
"libcutils",
|
2017-06-02 14:29:21 +00:00
|
|
|
"libnativewindow",
|
2016-12-12 19:09:38 +00:00
|
|
|
],
|
|
|
|
static_libs: [
|
2017-02-20 17:50:52 +00:00
|
|
|
"libarect",
|
2016-12-12 19:09:38 +00:00
|
|
|
"libsfntly",
|
|
|
|
"libwebp-decode",
|
|
|
|
"libwebp-encode",
|
|
|
|
],
|
2017-01-26 22:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_test {
|
|
|
|
name: "skia_dm",
|
|
|
|
|
|
|
|
cflags: [
|
|
|
|
$tool_cflags
|
|
|
|
],
|
|
|
|
|
|
|
|
local_include_dirs: [
|
|
|
|
$dm_includes
|
|
|
|
],
|
|
|
|
|
|
|
|
srcs: [
|
|
|
|
$dm_srcs
|
|
|
|
],
|
|
|
|
|
|
|
|
shared_libs: [
|
|
|
|
$tool_shared_libs
|
|
|
|
],
|
|
|
|
|
|
|
|
static_libs: [
|
|
|
|
$tool_static_libs
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_test {
|
|
|
|
name: "skia_nanobench",
|
|
|
|
|
|
|
|
cflags: [
|
|
|
|
$tool_cflags
|
|
|
|
],
|
|
|
|
|
|
|
|
local_include_dirs: [
|
|
|
|
$nanobench_includes
|
|
|
|
],
|
|
|
|
|
|
|
|
srcs: [
|
|
|
|
$nanobench_srcs
|
|
|
|
],
|
|
|
|
|
|
|
|
shared_libs: [
|
|
|
|
$tool_shared_libs
|
|
|
|
],
|
|
|
|
|
|
|
|
static_libs: [
|
|
|
|
$tool_static_libs
|
|
|
|
],
|
2016-12-12 19:09:38 +00:00
|
|
|
}''')
|
2016-12-06 21:03:52 +00:00
|
|
|
|
|
|
|
# We'll run GN to get the main source lists and include directories for Skia.
|
|
|
|
gn_args = {
|
2017-03-03 14:21:30 +00:00
|
|
|
'is_official_build': 'true',
|
|
|
|
'skia_enable_tools': 'true',
|
2017-08-17 19:13:20 +00:00
|
|
|
'skia_use_libheif': 'true',
|
2017-03-03 14:21:30 +00:00
|
|
|
'skia_use_vulkan': 'true',
|
|
|
|
'target_cpu': '"none"',
|
|
|
|
'target_os': '"android"',
|
2016-12-06 21:03:52 +00:00
|
|
|
}
|
|
|
|
gn_args = ' '.join(sorted('%s=%s' % (k,v) for (k,v) in gn_args.iteritems()))
|
|
|
|
|
|
|
|
tmp = tempfile.mkdtemp()
|
|
|
|
subprocess.check_call(['gn', 'gen', tmp, '--args=%s' % gn_args, '--ide=json'])
|
|
|
|
|
|
|
|
js = json.load(open(os.path.join(tmp, 'project.json')))
|
|
|
|
|
|
|
|
def strip_slashes(lst):
|
2017-02-23 23:00:06 +00:00
|
|
|
return {str(p.lstrip('/')) for p in lst}
|
2016-12-07 17:27:56 +00:00
|
|
|
|
2016-12-06 21:03:52 +00:00
|
|
|
srcs = strip_slashes(js['targets']['//:skia']['sources'])
|
|
|
|
local_includes = strip_slashes(js['targets']['//:skia']['include_dirs'])
|
|
|
|
export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
|
|
|
|
|
2017-01-26 22:21:27 +00:00
|
|
|
dm_srcs = strip_slashes(js['targets']['//:dm']['sources'])
|
|
|
|
dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs'])
|
|
|
|
|
|
|
|
nanobench_target = js['targets']['//:nanobench']
|
|
|
|
nanobench_srcs = strip_slashes(nanobench_target['sources'])
|
|
|
|
nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
|
|
|
|
|
|
|
|
def GrabDependentSrcs(name, srcs_to_extend, exclude):
|
|
|
|
# Grab the sources from other targets that $name depends on (e.g. optional
|
|
|
|
# Skia components, gms, tests, etc).
|
|
|
|
for dep in js['targets'][name]['deps']:
|
|
|
|
if 'third_party' in dep:
|
|
|
|
continue # We've handled all third-party DEPS as static or shared_libs.
|
|
|
|
if 'none' in dep:
|
|
|
|
continue # We'll handle all cpu-specific sources manually later.
|
|
|
|
if exclude and exclude in dep:
|
|
|
|
continue
|
2017-02-23 23:00:06 +00:00
|
|
|
srcs_to_extend.update(strip_slashes(js['targets'][dep].get('sources', [])))
|
|
|
|
GrabDependentSrcs(dep, srcs_to_extend, exclude)
|
2017-01-26 22:21:27 +00:00
|
|
|
|
|
|
|
GrabDependentSrcs('//:skia', srcs, None)
|
|
|
|
GrabDependentSrcs('//:dm', dm_srcs, 'skia')
|
|
|
|
GrabDependentSrcs('//:nanobench', nanobench_srcs, 'skia')
|
2016-12-07 17:27:56 +00:00
|
|
|
|
|
|
|
# No need to list headers.
|
2017-02-23 23:00:06 +00:00
|
|
|
srcs = {s for s in srcs if not s.endswith('.h')}
|
|
|
|
dm_srcs = {s for s in dm_srcs if not s.endswith('.h')}
|
|
|
|
nanobench_srcs = {s for s in nanobench_srcs if not s.endswith('.h')}
|
2016-12-07 17:27:56 +00:00
|
|
|
|
2016-12-06 21:03:52 +00:00
|
|
|
# Most defines go into SkUserConfig.h, where they're seen by Skia and its users.
|
|
|
|
defines = [str(d) for d in js['targets']['//:skia']['defines']]
|
2017-03-03 14:21:30 +00:00
|
|
|
defines.remove('NDEBUG') # Let the Android build control this.
|
2016-12-06 21:03:52 +00:00
|
|
|
defines.remove('SKIA_IMPLEMENTATION=1') # Only libskia should have this define.
|
|
|
|
|
|
|
|
# For architecture specific files, it's easier to just read the same source
|
|
|
|
# that GN does (opts.gni) rather than re-run GN once for each architecture.
|
|
|
|
|
|
|
|
# This .gni file we want to read is close enough to Python syntax
|
|
|
|
# that we can use execfile() if we supply definitions for GN builtins.
|
|
|
|
|
|
|
|
def get_path_info(path, kind):
|
|
|
|
assert kind == "abspath"
|
|
|
|
# While we want absolute paths in GN, relative paths work best here.
|
|
|
|
return path
|
|
|
|
|
|
|
|
builtins = { 'get_path_info': get_path_info }
|
|
|
|
defs = {}
|
2016-12-19 14:32:21 +00:00
|
|
|
here = os.path.dirname(__file__)
|
2016-12-06 21:03:52 +00:00
|
|
|
execfile(os.path.join(here, 'opts.gni'), builtins, defs)
|
|
|
|
|
2016-12-07 17:27:56 +00:00
|
|
|
# Turn paths from opts.gni into paths relative to external/skia.
|
2016-12-06 21:03:52 +00:00
|
|
|
def scrub(lst):
|
|
|
|
# Perform any string substitutions.
|
|
|
|
for var in defs:
|
|
|
|
if type(defs[var]) is str:
|
|
|
|
lst = [ p.replace('$'+var, defs[var]) for p in lst ]
|
|
|
|
# Relativize paths to top-level skia/ directory.
|
|
|
|
return [os.path.relpath(p, '..') for p in lst]
|
|
|
|
|
2016-12-12 19:09:38 +00:00
|
|
|
# Turn a list of strings into the style bpfmt outputs.
|
2017-01-26 22:21:27 +00:00
|
|
|
def bpfmt(indent, lst, sort=True):
|
|
|
|
if sort:
|
|
|
|
lst = sorted(lst)
|
|
|
|
return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
|
2016-12-06 21:03:52 +00:00
|
|
|
|
|
|
|
# OK! We have everything to fill in Android.bp...
|
|
|
|
with open('Android.bp', 'w') as f:
|
|
|
|
print >>f, bp.substitute({
|
2016-12-12 19:09:38 +00:00
|
|
|
'export_includes': bpfmt(8, export_includes),
|
|
|
|
'local_includes': bpfmt(8, local_includes),
|
|
|
|
'srcs': bpfmt(8, srcs),
|
|
|
|
|
|
|
|
'arm_srcs': bpfmt(16, scrub(defs['armv7'])),
|
|
|
|
'arm_neon_srcs': bpfmt(20, scrub(defs['neon'])),
|
|
|
|
'arm64_srcs': bpfmt(16, scrub(defs['arm64'] +
|
|
|
|
defs['crc32'])),
|
2016-12-20 22:34:29 +00:00
|
|
|
'none_srcs': bpfmt(16, scrub(defs['none'])),
|
2016-12-12 19:09:38 +00:00
|
|
|
'x86_srcs': bpfmt(16, scrub(defs['sse2'] +
|
|
|
|
defs['ssse3'] +
|
|
|
|
defs['sse41'] +
|
|
|
|
defs['sse42'] +
|
2017-07-19 21:20:37 +00:00
|
|
|
defs['avx' ])),
|
2017-01-26 22:21:27 +00:00
|
|
|
|
|
|
|
'tool_cflags' : bpfmt(8, tool_cflags),
|
|
|
|
'tool_shared_libs' : bpfmt(8, tool_shared_libs),
|
|
|
|
'tool_static_libs' : bpfmt(8, tool_static_libs, False),
|
|
|
|
|
|
|
|
'dm_includes' : bpfmt(8, dm_includes),
|
|
|
|
'dm_srcs' : bpfmt(8, dm_srcs),
|
|
|
|
|
|
|
|
'nanobench_includes' : bpfmt(8, nanobench_includes),
|
|
|
|
'nanobench_srcs' : bpfmt(8, nanobench_srcs),
|
2016-12-06 21:03:52 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
#... and all the #defines we want to put in SkUserConfig.h.
|
2016-12-12 14:03:56 +00:00
|
|
|
with open('include/config/SkUserConfig.h', 'w') as f:
|
Stop adding Android-specific defines to SkUserConfig
Remove #defines that lived in gn_to_bp.py and
android_framework_defines.gni. These have been moved into a new file
in Android, SkUserConfigManual.h, in https://googleplex-android-review.git.corp.google.com/#/c/2519600/
Update gn_to_bp.py to include SkUserConfigManual.h, so it will still
result in using the same #defines.
Lately, we've found it difficult to guard changes behind a flag. e.g.
a change to drawing causes a CTS failure in Android, so we have to do
the following:
- put the change behind a flag, and add it to gn_to_bp.py or
android_framework_defines.gni
- generate new images on Android (by running CTS with external/skia
modified to not define the flag)
- create a CL in CTS that uses the new images
- land a CL in Skia that stops defining the flag
- when the Skia change lands, wait for the auto-roller to create a CL
that includes the change, stop the auto-roller, add the topic to the CTS
CL so the two can land at the same time
- land both Android changes (with TreeHugger)
- restart the Android auto-roller
With SkUserConfigManual.h (which lives in Android), the process will
be similar to Chromium:
- land a CL in Android's external/skia that defines a flag e.g.
SK_SUPPORT_LEGACY_FEATURE. Land without TreeHugger because it isn't used
in Skia and does not do anything
- land a change in Skia that changes behavior unless
SK_SUPPORT_LEGACY_FEATURE is defined. This will safely go through the
Android roll and not change any behavior for Android
- create two Android CLs - one in CTS to use the new images, and one in
external/skia to delete SK_SUPPORT_LEGACY_FEATURE. Set them to the same
topic and land them with TreeHugger
In the new process, there is no need to mess with the Android roll.
A downside to the new process is that we cannot test the android
framework defines without checking in to Android. But given how much
we've progressed in automating Android testing, this is fine.
Bug: b/63429612
Change-Id: Idfbaef2f4cae641a75fb6e7bf70428733a441336
Reviewed-on: https://skia-review.googlesource.com/22072
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
2017-07-11 19:53:41 +00:00
|
|
|
print >>f, '// DO NOT MODIFY! This file is autogenerated by gn_to_bp.py.'
|
|
|
|
print >>f, '// If need to change a define, modify SkUserConfigManual.h'
|
2016-12-06 21:03:52 +00:00
|
|
|
print >>f, '#ifndef SkUserConfig_DEFINED'
|
|
|
|
print >>f, '#define SkUserConfig_DEFINED'
|
Stop adding Android-specific defines to SkUserConfig
Remove #defines that lived in gn_to_bp.py and
android_framework_defines.gni. These have been moved into a new file
in Android, SkUserConfigManual.h, in https://googleplex-android-review.git.corp.google.com/#/c/2519600/
Update gn_to_bp.py to include SkUserConfigManual.h, so it will still
result in using the same #defines.
Lately, we've found it difficult to guard changes behind a flag. e.g.
a change to drawing causes a CTS failure in Android, so we have to do
the following:
- put the change behind a flag, and add it to gn_to_bp.py or
android_framework_defines.gni
- generate new images on Android (by running CTS with external/skia
modified to not define the flag)
- create a CL in CTS that uses the new images
- land a CL in Skia that stops defining the flag
- when the Skia change lands, wait for the auto-roller to create a CL
that includes the change, stop the auto-roller, add the topic to the CTS
CL so the two can land at the same time
- land both Android changes (with TreeHugger)
- restart the Android auto-roller
With SkUserConfigManual.h (which lives in Android), the process will
be similar to Chromium:
- land a CL in Android's external/skia that defines a flag e.g.
SK_SUPPORT_LEGACY_FEATURE. Land without TreeHugger because it isn't used
in Skia and does not do anything
- land a change in Skia that changes behavior unless
SK_SUPPORT_LEGACY_FEATURE is defined. This will safely go through the
Android roll and not change any behavior for Android
- create two Android CLs - one in CTS to use the new images, and one in
external/skia to delete SK_SUPPORT_LEGACY_FEATURE. Set them to the same
topic and land them with TreeHugger
In the new process, there is no need to mess with the Android roll.
A downside to the new process is that we cannot test the android
framework defines without checking in to Android. But given how much
we've progressed in automating Android testing, this is fine.
Bug: b/63429612
Change-Id: Idfbaef2f4cae641a75fb6e7bf70428733a441336
Reviewed-on: https://skia-review.googlesource.com/22072
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
2017-07-11 19:53:41 +00:00
|
|
|
print >>f, '#include "SkUserConfigManual.h"'
|
2016-12-07 17:27:56 +00:00
|
|
|
for define in sorted(defines):
|
2016-12-12 14:03:56 +00:00
|
|
|
print >>f, ' #define', define.replace('=', ' ')
|
2016-12-06 21:03:52 +00:00
|
|
|
print >>f, '#endif//SkUserConfig_DEFINED'
|