Add beginnings of android_apk and unittest_apk templates
This adds two templates, android_apk and unittest_apk. unittest_apk is a simple wrapper of android_apk for packaging gtests into apks. android_apk currently just does the java compilation, processing resources, and build_config stuff for apks. BUG=359249 Review URL: https://codereview.chromium.org/379333003 git-svn-id: http://src.chromium.org/svn/trunk/src/build@286031 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
70872679ea
Коммит
5eb3802f61
|
@ -102,6 +102,11 @@ def main():
|
|||
|
||||
options, _ = parser.parse_args()
|
||||
|
||||
if options.depfile:
|
||||
build_utils.WriteDepfile(
|
||||
options.depfile,
|
||||
build_utils.GetPythonDependencies())
|
||||
|
||||
DoJarToc(options)
|
||||
|
||||
if options.depfile:
|
||||
|
|
|
@ -70,6 +70,11 @@ def ParseArgs(args):
|
|||
'list of resources to be included in the R.java file in the format '
|
||||
'generated by aapt')
|
||||
|
||||
parser.add_option(
|
||||
'--all-resources-zip-out',
|
||||
help='Path for output of all resources. This includes resources in '
|
||||
'dependencies.')
|
||||
|
||||
parser.add_option('--stamp', help='File to touch on success')
|
||||
|
||||
(options, args) = parser.parse_args(args)
|
||||
|
@ -242,6 +247,10 @@ def main():
|
|||
|
||||
ZipResources(zip_resource_dirs, options.resource_zip_out)
|
||||
|
||||
if options.all_resources_zip_out:
|
||||
ZipResources(
|
||||
zip_resource_dirs + dep_subdirs, options.all_resources_zip_out)
|
||||
|
||||
if options.R_dir:
|
||||
build_utils.DeleteDirectory(options.R_dir)
|
||||
shutil.copytree(gen_dir, options.R_dir)
|
||||
|
|
|
@ -66,11 +66,11 @@ def main(argv):
|
|||
'dependencies may not write build_config files. Missing build_config '
|
||||
'files are handled differently based on the type of this target.')
|
||||
|
||||
# android_resources options
|
||||
# android_resources/apk options
|
||||
parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
|
||||
parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
|
||||
|
||||
# android_library options
|
||||
# android_library/apk options
|
||||
parser.add_option('--jar-path', help='Path to target\'s jar output.')
|
||||
|
||||
options, args = parser.parse_args(argv)
|
||||
|
@ -78,25 +78,34 @@ def main(argv):
|
|||
if args:
|
||||
parser.error('No positional arguments should be given.')
|
||||
|
||||
required_options = ('build_config', 'type')
|
||||
build_utils.CheckOptions(options, parser, required_options)
|
||||
|
||||
if not options.type in [
|
||||
'android_library', 'android_resources']:
|
||||
'android_library', 'android_resources', 'android_apk']:
|
||||
raise Exception('Unknown type: <%s>' % options.type)
|
||||
|
||||
if options.type == 'android_library':
|
||||
required_options = ('jar_path',)
|
||||
build_utils.CheckOptions(options, parser, required_options)
|
||||
|
||||
possible_deps_configs = build_utils.ParseGypList(
|
||||
required_options = ['build_config'] + {
|
||||
'android_library': ['jar_path'],
|
||||
'android_resources': ['resources_zip'],
|
||||
'android_apk': ['jar_path', 'resources_zip']
|
||||
}[options.type]
|
||||
|
||||
build_utils.CheckOptions(options, parser, required_options)
|
||||
|
||||
possible_deps_config_paths = build_utils.ParseGypList(
|
||||
options.possible_deps_configs)
|
||||
for c in possible_deps_configs:
|
||||
if not os.path.exists(c):
|
||||
# Currently we only allow deps to things that write build_config files.
|
||||
raise Exception('Unknown dep type: ' + c)
|
||||
|
||||
direct_deps_config_paths = possible_deps_configs
|
||||
|
||||
|
||||
|
||||
allow_unknown_deps = options.type == 'android_apk'
|
||||
unknown_deps = [
|
||||
c for c in possible_deps_config_paths if not os.path.exists(c)]
|
||||
if unknown_deps and not allow_unknown_deps:
|
||||
raise Exception('Unknown deps: ' + unknown_deps)
|
||||
|
||||
direct_deps_config_paths = [
|
||||
c for c in possible_deps_config_paths if not c in unknown_deps]
|
||||
all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)
|
||||
|
||||
direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths]
|
||||
|
@ -115,8 +124,9 @@ def main(argv):
|
|||
}
|
||||
deps_info = config['deps_info']
|
||||
|
||||
if options.type == 'android_library':
|
||||
if options.type in ['android_library', 'android_apk']:
|
||||
javac_classpath = [c['jar_path'] for c in direct_library_deps]
|
||||
deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
|
||||
deps_info['jar_path'] = options.jar_path
|
||||
config['javac'] = {
|
||||
'classpath': javac_classpath,
|
||||
|
@ -128,10 +138,11 @@ def main(argv):
|
|||
config['javac']['srcjars'] = [
|
||||
c['srcjar'] for c in all_resources_deps if 'srcjar' in c]
|
||||
|
||||
if options.type == 'android_resources':
|
||||
if options.type == 'android_resources' or options.type == 'android_apk':
|
||||
deps_info['resources_zip'] = options.resources_zip
|
||||
if options.srcjar:
|
||||
deps_info['srcjar'] = options.srcjar
|
||||
|
||||
config['resources'] = {}
|
||||
config['resources']['dependency_zips'] = [
|
||||
c['resources_zip'] for c in all_resources_deps]
|
||||
|
|
|
@ -23,13 +23,12 @@ rebased_android_sdk_build_tools = rebase_path(android_sdk_build_tools, root_buil
|
|||
# build/android/gyp/util/build_utils.py:ExpandFileArgs
|
||||
template("write_build_config") {
|
||||
assert(defined(invoker.type))
|
||||
assert(defined(invoker.base_path))
|
||||
assert(defined(invoker.build_config))
|
||||
|
||||
base_path = invoker.base_path
|
||||
type = invoker.type
|
||||
build_config = base_path + ".build_config"
|
||||
build_config = invoker.build_config
|
||||
|
||||
assert(type == "android_binary" || type == "android_library" || type == "android_resources")
|
||||
assert(type == "android_apk" || type == "android_library" || type == "android_resources")
|
||||
|
||||
action(target_name) {
|
||||
script = "//build/android/gyp/write_build_config.py"
|
||||
|
@ -52,6 +51,7 @@ template("write_build_config") {
|
|||
possible_deps_configs += [ "$dep_gen_dir/$dep_name.build_config" ]
|
||||
}
|
||||
rebase_possible_deps_configs = rebase_path(possible_deps_configs)
|
||||
|
||||
args = [
|
||||
"--type", type,
|
||||
"--depfile", rebase_path(depfile, root_build_dir),
|
||||
|
@ -59,23 +59,23 @@ template("write_build_config") {
|
|||
"--build-config", rebase_path(build_config, root_build_dir),
|
||||
]
|
||||
|
||||
if (type == "android_library") {
|
||||
jar_path = base_path + ".jar"
|
||||
if (type == "android_library" || type == "android_apk") {
|
||||
args += [
|
||||
"--jar-path", rebase_path(jar_path, root_build_dir),
|
||||
"--jar-path", rebase_path(invoker.jar_path, root_build_dir),
|
||||
]
|
||||
}
|
||||
|
||||
if (type == "android_resources") {
|
||||
if (type == "android_resources" || type == "android_apk") {
|
||||
assert(defined(invoker.resources_zip))
|
||||
args += [
|
||||
"--resources-zip", rebase_path(invoker.resources_zip, root_build_dir),
|
||||
]
|
||||
if (defined(invoker.srcjar)) {
|
||||
args += [
|
||||
"--srcjar", rebase_path(invoker.srcjar, root_build_dir)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (defined(invoker.srcjar)) {
|
||||
args += [
|
||||
"--srcjar", rebase_path(invoker.srcjar, root_build_dir)
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,6 @@ template("zip") {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
# Compiles and jars a set of java files.
|
||||
#
|
||||
# Outputs:
|
||||
|
@ -229,17 +228,18 @@ template("java_library") {
|
|||
# Dexes the output jar for inclusion in an APK.
|
||||
template("android_java_library") {
|
||||
assert(defined(invoker.java_files))
|
||||
|
||||
assert(defined(invoker.build_config))
|
||||
assert(defined(invoker.jar_path))
|
||||
|
||||
_jar_path = invoker.jar_path
|
||||
|
||||
java_library("${target_name}__java_library") {
|
||||
jar_path = _jar_path
|
||||
if (defined(invoker.jar_excluded_patterns)) {
|
||||
jar_excluded_patterns = invoker.jar_excluded_patterns
|
||||
}
|
||||
build_config = invoker.build_config
|
||||
java_files = invoker.java_files
|
||||
jar_path = invoker.jar_path
|
||||
|
||||
if (defined(invoker.srcjar_deps)) {
|
||||
srcjar_deps = invoker.srcjar_deps
|
||||
|
@ -265,6 +265,11 @@ template("process_resources") {
|
|||
resource_dirs = invoker.resource_dirs
|
||||
android_manifest = invoker.android_manifest
|
||||
|
||||
non_constant_id = true
|
||||
if (defined(invoker.generate_constant_ids) && invoker.generate_constant_ids) {
|
||||
non_constant_id = false
|
||||
}
|
||||
|
||||
action(target_name) {
|
||||
script = "//build/android/gyp/process_resources.py"
|
||||
|
||||
|
@ -293,7 +298,6 @@ template("process_resources") {
|
|||
"--depfile", rebase_path(depfile, root_build_dir),
|
||||
"--android-sdk", rebase_path(android_sdk, root_build_dir),
|
||||
"--android-sdk-tools", rebase_path(android_sdk_build_tools, root_build_dir),
|
||||
"--non-constant-id",
|
||||
"--android-manifest", rebase_path(android_manifest, root_build_dir),
|
||||
|
||||
"--resource-dirs=$rebase_resource_dirs",
|
||||
|
@ -303,6 +307,10 @@ template("process_resources") {
|
|||
"--dependencies-res-zips=@FileArg($rebase_build_config:resources:dependency_zips)",
|
||||
]
|
||||
|
||||
if (non_constant_id) {
|
||||
args += [ "--non-constant-id" ]
|
||||
}
|
||||
|
||||
if (defined(invoker.custom_package)) {
|
||||
args += [
|
||||
"--custom-package", invoker.custom_package,
|
||||
|
@ -312,5 +320,17 @@ template("process_resources") {
|
|||
if (defined(invoker.v14_verify_only) && invoker.v14_verify_only) {
|
||||
args += ["--v14-verify-only"]
|
||||
}
|
||||
|
||||
if (defined(invoker.all_resources_zip_path)) {
|
||||
all_resources_zip = invoker.all_resources_zip_path
|
||||
outputs += [ all_resources_zip ]
|
||||
args += [
|
||||
"--all-resources-zip-out", rebase_path(all_resources_zip, root_build_dir)
|
||||
]
|
||||
}
|
||||
|
||||
if (defined(invoker.args)) {
|
||||
args += invoker.args
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -344,6 +344,7 @@ template("android_resources") {
|
|||
template("java_strings_grd") {
|
||||
base_path = "$target_gen_dir/$target_name"
|
||||
resources_zip = base_path + ".resources.zip"
|
||||
build_config = base_path + ".build_config"
|
||||
|
||||
write_build_config("${target_name}__build_config") {
|
||||
type = "android_resources"
|
||||
|
@ -421,9 +422,9 @@ template("java_strings_grd") {
|
|||
# }
|
||||
template("android_library") {
|
||||
assert(defined(invoker.java_files))
|
||||
|
||||
base_path = "$target_gen_dir/$target_name"
|
||||
build_config = base_path + ".build_config"
|
||||
jar_path = base_path + ".jar"
|
||||
|
||||
write_build_config("${target_name}__build_config") {
|
||||
type = "android_library"
|
||||
|
@ -436,7 +437,6 @@ template("android_library") {
|
|||
# base_path
|
||||
}
|
||||
|
||||
jar_path = base_path + ".jar"
|
||||
android_java_library(target_name) {
|
||||
java_files = invoker.java_files
|
||||
build_config = build_config
|
||||
|
@ -450,3 +450,137 @@ template("android_library") {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Declare an Android apk target
|
||||
#
|
||||
# This target creates an Android APK containing java code, resources, assets,
|
||||
# and (possibly) native libraries.
|
||||
#
|
||||
# Variables
|
||||
# android_manifest: Path to AndroidManifest.xml.
|
||||
# deps: List of dependencies. All Android java resources and libraries in the
|
||||
# "transitive closure" of these dependencies will be included in the apk.
|
||||
# Note: this "transitive closure" actually only includes such targets if
|
||||
# they are depended on through android_library or android_resources targets
|
||||
# (and so not through builtin targets like 'action', 'group', etc).
|
||||
# java_files: List of .java files to include in the apk.
|
||||
# srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
|
||||
# will be added to java_files and be included in this apk.
|
||||
# apk_name: Name for final apk.
|
||||
# final_apk_path: Path to final built apk. Default is
|
||||
# $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
|
||||
# native_libs: List paths of native libraries to include in this apk. If these
|
||||
# libraries depend on other shared_library targets, those dependencies will
|
||||
# also be included in the apk.
|
||||
#
|
||||
# Example
|
||||
# android_apk("foo_apk") {
|
||||
# android_manifest = "AndroidManifest.xml"
|
||||
# java_files = [
|
||||
# "android/org/chromium/foo/FooApplication.java",
|
||||
# "android/org/chromium/foo/FooActivity.java",
|
||||
# ]
|
||||
# deps = [
|
||||
# ":foo_support_java"
|
||||
# ":foo_resources"
|
||||
# ]
|
||||
# srcjar_deps = [
|
||||
# ":foo_generated_enum"
|
||||
# ]
|
||||
# native_libs = [
|
||||
# native_lib_path
|
||||
# ]
|
||||
# }
|
||||
template("android_apk") {
|
||||
gen_dir = "$target_gen_dir/$target_name"
|
||||
base_path = "$gen_dir/$target_name"
|
||||
build_config = base_path + ".build_config"
|
||||
resource_zip_path = base_path + ".resources.zip"
|
||||
all_resources_zip_path = base_path + ".resources.all.zip"
|
||||
resource_srcjar_path = base_path + ".resources.srcjar"
|
||||
jar_path = base_path + ".jar"
|
||||
|
||||
# Just mark these as used for now.
|
||||
assert(!defined(invoker.native_libs)
|
||||
|| invoker.native_libs == [] || true)
|
||||
assert(!defined(invoker.final_apk_path)
|
||||
|| invoker.final_apk_path == "" || true)
|
||||
|
||||
final_deps = []
|
||||
|
||||
# TODO(cjhopman): Remove this once we correctly generate the real
|
||||
# NativeLibraries.java
|
||||
srcjar_deps = [ "//base:base_native_libraries_gen" ]
|
||||
if (defined(invoker.srcjar_deps)) {
|
||||
srcjar_deps += invoker.srcjar_deps
|
||||
}
|
||||
|
||||
write_build_config("${target_name}__build_config") {
|
||||
type = "android_apk"
|
||||
srcjar = resource_srcjar_path
|
||||
resources_zip = resource_zip_path
|
||||
|
||||
if (defined(invoker.deps)) {
|
||||
deps = invoker.deps
|
||||
}
|
||||
}
|
||||
|
||||
final_deps += [":${target_name}__process_resources"]
|
||||
process_resources("${target_name}__process_resources") {
|
||||
android_manifest = invoker.android_manifest
|
||||
|
||||
resource_dirs = ["//build/android/ant/empty/res"]
|
||||
zip_path = resource_zip_path
|
||||
srcjar_path = resource_srcjar_path
|
||||
|
||||
generate_constant_ids = true
|
||||
}
|
||||
|
||||
final_deps += [":${target_name}__java"]
|
||||
android_java_library("${target_name}__java") {
|
||||
java_files = invoker.java_files
|
||||
}
|
||||
|
||||
# TODO(cjhopman): dex
|
||||
# TODO(cjhopman): native
|
||||
# TODO(cjhopman): create+finalize apk
|
||||
|
||||
group(target_name) {
|
||||
deps = final_deps
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Declare an Android gtest apk
|
||||
#
|
||||
# This target creates an Android apk for running gtest-based unittests.
|
||||
#
|
||||
# Variables
|
||||
# deps: Specifies the dependencies of this target. These will be passed to
|
||||
# the underlying android_apk invocation and should include the java and
|
||||
# resource dependencies of the apk.
|
||||
# unittests_dep: This should be the label of the gtest native target. This
|
||||
# target must be defined previously in the same file.
|
||||
#
|
||||
# Example
|
||||
# unittest_apk("foo_unittests_apk") {
|
||||
# deps = [ ":foo_java", ":foo_resources" ]
|
||||
# unittests_dep = ":foo_unittests"
|
||||
# }
|
||||
template("unittest_apk") {
|
||||
test_suite_name = get_label_info(invoker.unittests_dep, "name")
|
||||
android_apk(target_name) {
|
||||
apk_name = test_suite_name
|
||||
final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
|
||||
java_files = [
|
||||
"//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java"
|
||||
]
|
||||
android_manifest = "//testing/android/java/AndroidManifest.xml"
|
||||
unittests_outputs = get_target_outputs(invoker.unittests_dep)
|
||||
native_libs = [unittests_outputs[0]]
|
||||
if (defined(invoker.deps)) {
|
||||
deps = invoker.deps
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче