Add android_library template and build_configs
This is the GN equivalent of build/java.gypi. It is a template for creating an Android library including java code and Android resources. It currently only compiles java files (including files in srcjars from srcjar targets like java_cpp_template) and zips them together in a .jar and creates the corresponding .jar.TOC. Some of the things still to do: proguard_preprocess, android_lint, emma coverage, dex, everything resources. Adds android_java_library rule for base_java, guava, and jsr-305. This add the --java-srcjars argument to javac.py. This will accept a .zip of .java files and include those files in the compilation. This approach is preferred over using the --src-gendirs option. Many of the parts of building Android stuff (libraries, resources, apks) require knowledge of the dependents of that thing. Examples: javac classpath, for resources aapt needs to know about all dependents, dexing for an apk needs to know about all java code going into that apk. For gyp, this is done primarily with all_dependent_settings. There is then some of this logic in two particular steps (dexing and proguard). These steps, when building an instrumentation apk, need to exclude the things in the tested apk and this is done by having the tested apk essentially write a file saying what it did in those steps and the test apk reading that file and excluding stuff. In GN, all_dependent_settings doesn't really work. This change introduces a new way of calculating and using this information. Specifically .build_config files and build_utils.ExpandFileArgs(). The build_config file for a target contains the information that depends on dependents. The logic in write_build_config and the logic in the template specification are very much tied together (in some sense, write_build_config is just the part of the template specification that can actually inspect the dependency graph). With build_utils.ExpandFileArgs() all the other build scripts are essentially unaware of the .build_config files and can just be written in a (mostly) straightforward way. A large part of the information calculated by the build_config is finding input files to later actions. This requires that those later actions writes a depfile that contains any inputs that are specified by the build_config (in the case of this change, javac and the classpath files). Since a action's script shouldn't really know about the build_config file and what information it got from that, it is safest for the action to write *all* of its inputs into the depfile (but to be correct it only has to write those that aren't explicitly specified in the build files). Depends on: https://codereview.chromium.org/341823003/ BUG=359249 Review URL: https://codereview.chromium.org/269943005 git-svn-id: http://src.chromium.org/svn/trunk/src/build@280995 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
2de75c3040
Коммит
9f9e39c561
|
@ -18,6 +18,7 @@ rebuild, will have a corresponding change in the TOC file.
|
|||
"""
|
||||
|
||||
import optparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import zipfile
|
||||
|
@ -86,8 +87,9 @@ def DoJarToc(options):
|
|||
lambda: UpdateToc(jar_path, toc_path),
|
||||
record_path=record_path,
|
||||
input_paths=[jar_path],
|
||||
force=not os.path.exists(toc_path),
|
||||
)
|
||||
build_utils.Touch(toc_path)
|
||||
build_utils.Touch(toc_path, fail_if_missing=True)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
@ -52,23 +52,22 @@ def ColorJavacOutput(output):
|
|||
|
||||
return '\n'.join(map(ApplyColor, output.split('\n')))
|
||||
|
||||
|
||||
def DoJavac(
|
||||
classpath, javac_includes, classes_dir, chromium_code, java_files):
|
||||
if javac_includes:
|
||||
javac_includes = build_utils.ParseGypList(javac_includes)
|
||||
filtered_java_files = []
|
||||
for f in java_files:
|
||||
for include in javac_includes:
|
||||
if fnmatch.fnmatch(f, include):
|
||||
filtered_java_files.append(f)
|
||||
break
|
||||
java_files = filtered_java_files
|
||||
classpath, classes_dir, chromium_code, java_files):
|
||||
"""Runs javac.
|
||||
|
||||
Builds |java_files| with the provided |classpath| and puts the generated
|
||||
.class files into |classes_dir|. If |chromium_code| is true, extra lint
|
||||
checking will be enabled.
|
||||
"""
|
||||
|
||||
# Compiling guava with certain orderings of input files causes a compiler
|
||||
# crash... Sorted order works, so use that.
|
||||
# See https://code.google.com/p/guava-libraries/issues/detail?id=950
|
||||
# TODO(cjhopman): Remove this when we have update guava or the compiler to a
|
||||
# version without this problem.
|
||||
java_files.sort()
|
||||
classpath = build_utils.ParseGypList(classpath)
|
||||
|
||||
jar_inputs = []
|
||||
for path in classpath:
|
||||
|
@ -107,22 +106,32 @@ def DoJavac(
|
|||
input_strings=javac_cmd)
|
||||
|
||||
|
||||
def main():
|
||||
def main(argv):
|
||||
colorama.init()
|
||||
|
||||
argv = build_utils.ExpandFileArgs(argv)
|
||||
|
||||
parser = optparse.OptionParser()
|
||||
build_utils.AddDepfileOption(parser)
|
||||
|
||||
parser.add_option(
|
||||
'--src-gendirs',
|
||||
help='Directories containing generated java files.')
|
||||
parser.add_option('--classpath', help='Classpath for javac.')
|
||||
parser.add_option(
|
||||
'--java-srcjars',
|
||||
help='List of srcjars to include in compilation.')
|
||||
parser.add_option(
|
||||
'--classpath',
|
||||
action='append',
|
||||
help='Classpath for javac. If this is specified multiple times, they '
|
||||
'will all be appended to construct the classpath.')
|
||||
parser.add_option(
|
||||
'--javac-includes',
|
||||
help='A list of file patterns. If provided, only java files that match' +
|
||||
help='A list of file patterns. If provided, only java files that match'
|
||||
'one of the patterns will be compiled.')
|
||||
parser.add_option(
|
||||
'--jar-excluded-classes',
|
||||
default='',
|
||||
help='List of .class file patterns to exclude from the jar.')
|
||||
|
||||
parser.add_option(
|
||||
|
@ -138,17 +147,39 @@ def main():
|
|||
|
||||
parser.add_option('--stamp', help='Path to touch on success.')
|
||||
|
||||
options, args = parser.parse_args()
|
||||
options, args = parser.parse_args(argv)
|
||||
|
||||
classpath = []
|
||||
for arg in options.classpath:
|
||||
classpath += build_utils.ParseGypList(arg)
|
||||
|
||||
java_files = args
|
||||
if options.src_gendirs:
|
||||
src_gendirs = build_utils.ParseGypList(options.src_gendirs)
|
||||
java_files += build_utils.FindInDirectories(src_gendirs, '*.java')
|
||||
|
||||
with build_utils.TempDir() as classes_dir:
|
||||
with build_utils.TempDir() as temp_dir:
|
||||
classes_dir = os.path.join(temp_dir, 'classes')
|
||||
os.makedirs(classes_dir)
|
||||
if options.java_srcjars:
|
||||
java_dir = os.path.join(temp_dir, 'java')
|
||||
os.makedirs(java_dir)
|
||||
for srcjar in build_utils.ParseGypList(options.java_srcjars):
|
||||
build_utils.ExtractAll(srcjar, path=java_dir)
|
||||
java_files += build_utils.FindInDirectory(java_dir, '*.java')
|
||||
|
||||
if options.javac_includes:
|
||||
javac_includes = build_utils.ParseGypList(options.javac_includes)
|
||||
filtered_java_files = []
|
||||
for f in java_files:
|
||||
for include in javac_includes:
|
||||
if fnmatch.fnmatch(f, include):
|
||||
filtered_java_files.append(f)
|
||||
break
|
||||
java_files = filtered_java_files
|
||||
|
||||
DoJavac(
|
||||
options.classpath,
|
||||
options.javac_includes,
|
||||
classpath,
|
||||
classes_dir,
|
||||
options.chromium_code,
|
||||
java_files)
|
||||
|
@ -170,13 +201,13 @@ def main():
|
|||
if options.depfile:
|
||||
build_utils.WriteDepfile(
|
||||
options.depfile,
|
||||
build_utils.GetPythonDependencies())
|
||||
classpath + build_utils.GetPythonDependencies())
|
||||
|
||||
if options.stamp:
|
||||
build_utils.Touch(options.stamp)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import ast
|
||||
import contextlib
|
||||
import fnmatch
|
||||
import json
|
||||
|
@ -14,6 +15,7 @@ import sys
|
|||
import tempfile
|
||||
import zipfile
|
||||
|
||||
|
||||
CHROMIUM_SRC = os.path.normpath(
|
||||
os.path.join(os.path.dirname(__file__),
|
||||
os.pardir, os.pardir, os.pardir, os.pardir))
|
||||
|
@ -66,6 +68,10 @@ def FindInDirectories(directories, filename_filter):
|
|||
return all_files
|
||||
|
||||
|
||||
def ParseGnList(gn_string):
|
||||
return ast.literal_eval(gn_string)
|
||||
|
||||
|
||||
def ParseGypList(gyp_string):
|
||||
# The ninja generator doesn't support $ in strings, so use ## to
|
||||
# represent $.
|
||||
|
@ -73,6 +79,9 @@ def ParseGypList(gyp_string):
|
|||
# https://code.google.com/p/gyp/issues/detail?id=327
|
||||
# is addressed.
|
||||
gyp_string = gyp_string.replace('##', '$')
|
||||
|
||||
if gyp_string.startswith('['):
|
||||
return ParseGnList(gyp_string)
|
||||
return shlex.split(gyp_string)
|
||||
|
||||
|
||||
|
@ -252,3 +261,45 @@ def WriteDepfile(path, dependencies):
|
|||
depfile.write(': ')
|
||||
depfile.write(' '.join(dependencies))
|
||||
depfile.write('\n')
|
||||
|
||||
|
||||
def ExpandFileArgs(args):
|
||||
"""Replaces file-arg placeholders in args.
|
||||
|
||||
These placeholders have the form:
|
||||
@(filename:key1:key2:...:keyn)
|
||||
|
||||
The value of such a placeholder is calculated by reading 'filename' as json.
|
||||
And then extracting the value at [key1][key2]...[keyn].
|
||||
|
||||
Note: This intentionally does not return the list of files that appear in such
|
||||
placeholders. An action that uses file-args *must* know the paths of those
|
||||
files prior to the parsing of the arguments (typically by explicitly listing
|
||||
them in the action's inputs in build files).
|
||||
"""
|
||||
new_args = list(args)
|
||||
file_jsons = dict()
|
||||
for i, arg in enumerate(args):
|
||||
start = arg.find('@(')
|
||||
if start < 0:
|
||||
continue
|
||||
end = arg[start:].find(')')
|
||||
if end < 0:
|
||||
continue
|
||||
end += start
|
||||
|
||||
if '@(' in arg[end:]:
|
||||
raise Exception('Only one file-lookup-expansion is allowed in each arg.')
|
||||
|
||||
lookup_path = arg[start + 2:end].split(':')
|
||||
file_path = lookup_path[0]
|
||||
if not file_path in file_jsons:
|
||||
file_jsons[file_path] = ReadJson(file_path)
|
||||
|
||||
expansion = file_jsons[file_path]
|
||||
for k in lookup_path[1:]:
|
||||
expansion = expansion[k]
|
||||
|
||||
new_args[i] = arg[:start] + str(expansion) + arg[end + 1:]
|
||||
return new_args
|
||||
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2014 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.
|
||||
|
||||
"""Writes a build_config file.
|
||||
|
||||
The build_config file for a target is a json file containing information about
|
||||
how to build that target based on the target's dependencies. This includes
|
||||
things like: the javac classpath, the list of android resources dependencies,
|
||||
etc. It also includes the information needed to create the build_config for
|
||||
other target's that depend on that one.
|
||||
|
||||
There are several different types of build_configs:
|
||||
android_library: An android library containing java code.
|
||||
|
||||
Android build scripts should not refer to the build_config directly, and the
|
||||
build specification should instead pass information in using the special
|
||||
file-arg syntax (see build_utils.py:ExpandFileArgs). That syntax allows passing
|
||||
of values in a json dict in a file and looks like this:
|
||||
--python-arg=@(build_config_path):javac:classpath
|
||||
|
||||
Note: If paths to input files are passed in this way, it is important that:
|
||||
1. inputs/deps of the action ensure that the files are available the first
|
||||
time the action runs.
|
||||
2. Either (a) or (b)
|
||||
a. inputs/deps ensure that the action runs whenever one of the files changes
|
||||
b. the files are added to the action's depfile
|
||||
"""
|
||||
|
||||
import optparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from util import build_utils
|
||||
|
||||
def main(argv):
|
||||
parser = optparse.OptionParser()
|
||||
build_utils.AddDepfileOption(parser)
|
||||
parser.add_option('--build-config', help='Path to build_config output.')
|
||||
parser.add_option('--type', help='Type of this target.')
|
||||
parser.add_option(
|
||||
'--possible-deps-configs',
|
||||
help='List of paths for dependency\'s build_config files. Some '
|
||||
'dependencies may not write build_config files. Missing build_config '
|
||||
'files are handled differently based on the type of this target.')
|
||||
|
||||
# android_library options
|
||||
parser.add_option('--jar-path', help='Path to target\'s jar output.')
|
||||
|
||||
options, args = parser.parse_args(argv)
|
||||
|
||||
if args:
|
||||
parser.error('No positional arguments should be given.')
|
||||
|
||||
required_options = ('build_config', 'type')
|
||||
build_utils.CheckOptions(options, parser, required_options)
|
||||
|
||||
if options.type == 'android_library':
|
||||
required_options = ('jar_path',)
|
||||
build_utils.CheckOptions(options, parser, required_options)
|
||||
|
||||
deps_configs = build_utils.ParseGypList(options.possible_deps_configs)
|
||||
for c in 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)
|
||||
|
||||
deps_configs = [build_utils.ReadJson(c) for c in deps_configs]
|
||||
|
||||
if options.type == 'android_library':
|
||||
javac_classpath = [c['outputs']['jar_path'] for c in deps_configs]
|
||||
config = {
|
||||
'outputs': {
|
||||
'jar_path': options.jar_path
|
||||
},
|
||||
'javac': {
|
||||
'classpath': javac_classpath
|
||||
}
|
||||
}
|
||||
else:
|
||||
raise Exception('Unknown type: ' + options.type)
|
||||
|
||||
build_utils.WriteJson(config, options.build_config)
|
||||
|
||||
if options.depfile:
|
||||
build_utils.WriteDepfile(
|
||||
options.depfile,
|
||||
build_utils.GetPythonDependencies())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv[1:]))
|
|
@ -9,6 +9,9 @@ if (is_android) {
|
|||
# Absolute directory containing the Android source code.
|
||||
android_src = ""
|
||||
|
||||
android_sdk_root = "//third_party/android_tools/sdk"
|
||||
android_sdk_version = "19"
|
||||
|
||||
# This is set when building the Android WebView inside the Android build
|
||||
# system, using the 'android' gyp backend. The WebView code is still built
|
||||
# when this is unset, but builds using the normal chromium build system.
|
||||
|
@ -46,9 +49,10 @@ if (is_android) {
|
|||
# than just the current one) since these are needed by the Android toolchain
|
||||
# file to define toolchains for all possible targets in one pass.
|
||||
|
||||
android_sdk = "${android_sdk_root}/platforms/android-${android_sdk_version}"
|
||||
|
||||
# Path to the Android NDK and SDK.
|
||||
android_ndk_root = "//third_party/android_tools/ndk"
|
||||
android_sdk_root = "//third_party/android_tools/sdk"
|
||||
|
||||
# Path to the SDK's android.jar
|
||||
android_sdk_jar = "$android_sdk_root/platforms/android-19/android.jar"
|
||||
|
|
|
@ -1,3 +1,65 @@
|
|||
# Copyright 2014 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.
|
||||
|
||||
import("//build/config/android/config.gni")
|
||||
|
||||
|
||||
# Write the target's .build_config file. This is a json file that contains a
|
||||
# dictionary of information about how to build this target (things that
|
||||
# require knowledge about this target's dependencies and cannot be calculated
|
||||
# at gn-time). There is a special syntax to add a value in that dictionary to
|
||||
# an action/action_foreachs args:
|
||||
# --python-arg=@($rebased_build_config_path:key0:key1)
|
||||
# At runtime, such an arg will be replaced by the value in the build_config.
|
||||
# See build/android/gyp/write_build_config.py and
|
||||
# build/android/gyp/util/build_utils.py:ExpandFileArgs
|
||||
template("write_build_config") {
|
||||
assert(defined(invoker.type))
|
||||
assert(defined(invoker.base_path))
|
||||
|
||||
base_path = invoker.base_path
|
||||
type = invoker.type
|
||||
build_config = base_path + ".build_config"
|
||||
|
||||
assert(type == "android_library" || type == "android_binary")
|
||||
|
||||
action(target_name) {
|
||||
script = "//build/android/gyp/write_build_config.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
|
||||
deps = []
|
||||
if (defined(invoker.deps)) {
|
||||
deps += invoker.deps
|
||||
}
|
||||
|
||||
outputs = [
|
||||
depfile,
|
||||
build_config
|
||||
]
|
||||
|
||||
possible_deps_configs = []
|
||||
foreach(d, deps) {
|
||||
dep_gen_dir = get_label_info(d, "target_gen_dir")
|
||||
dep_name = get_label_info(d, "name")
|
||||
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),
|
||||
"--possible-deps-configs=$rebase_possible_deps_configs",
|
||||
"--build-config", rebase_path(build_config, root_build_dir),
|
||||
]
|
||||
|
||||
if (type == "android_library") {
|
||||
jar_path = base_path + ".jar"
|
||||
args += [
|
||||
"--jar-path", rebase_path(jar_path, root_build_dir),
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Creates a zip archive of the inputs.
|
||||
# If base_dir is provided, the archive paths will be relative to it.
|
||||
|
@ -5,13 +67,16 @@ template("zip") {
|
|||
assert(defined(invoker.inputs))
|
||||
assert(defined(invoker.output))
|
||||
|
||||
rebase_inputs = rebase_path(invoker.inputs)
|
||||
rebase_output = rebase_path(invoker.output)
|
||||
rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
|
||||
rebase_output = rebase_path(invoker.output, root_build_dir)
|
||||
action(target_name) {
|
||||
script = "//build/android/gn/zip.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
source_prereqs = invoker.inputs
|
||||
outputs = [depfile, invoker.output]
|
||||
outputs = [
|
||||
depfile,
|
||||
invoker.output
|
||||
]
|
||||
args = [
|
||||
"--depfile", rebase_path(depfile, root_build_dir),
|
||||
"--inputs=$rebase_inputs",
|
||||
|
@ -19,9 +84,151 @@ template("zip") {
|
|||
]
|
||||
if (defined(invoker.base_dir)) {
|
||||
args += [
|
||||
"--base-dir", rebase_path(invoker.base_dir)
|
||||
"--base-dir", rebase_path(invoker.base_dir, root_build_dir)
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Compiles and jars a set of java_files.
|
||||
#
|
||||
# Outputs:
|
||||
# $jar_path.jar
|
||||
# $jar_path.jar.TOC
|
||||
#
|
||||
# Variables
|
||||
# java_files: List of .java files to compile.
|
||||
# java_deps: List of java dependencies. These should all have a .jar output
|
||||
# at "${target_gen_dir}/${target_name}.jar.
|
||||
# chromium_code: If 1, enable extra warnings.
|
||||
# srcjar_deps: List of srcjar dependencies. The .java files contained in the
|
||||
# dependencies srcjar outputs will be compiled and added to the output jar.
|
||||
# jar_path: Use this to explicitly set the output jar path. Defaults to
|
||||
# "${target_gen_dir}/${target_name}.jar.
|
||||
template("java_library") {
|
||||
assert(defined(invoker.java_files))
|
||||
assert(defined(invoker.build_config))
|
||||
assert(defined(invoker.jar_path))
|
||||
|
||||
java_files = invoker.java_files
|
||||
jar_path = invoker.jar_path
|
||||
jar_toc_path = jar_path + ".TOC"
|
||||
|
||||
build_config = invoker.build_config
|
||||
|
||||
jar_excluded_patterns = []
|
||||
if (defined(invoker.jar_excluded_patterns)) {
|
||||
jar_excluded_patterns += invoker.jar_excluded_patterns
|
||||
}
|
||||
|
||||
chromium_code = false
|
||||
if (defined(invoker.chromium_code)) {
|
||||
chromium_code = chromium_code || invoker.chromium_code
|
||||
}
|
||||
|
||||
srcjar_deps = []
|
||||
if (defined(invoker.srcjar_deps)) {
|
||||
srcjar_deps += invoker.srcjar_deps
|
||||
}
|
||||
|
||||
java_srcjars = []
|
||||
foreach(dep, srcjar_deps) {
|
||||
dep_gen_dir = get_label_info(dep, "target_gen_dir")
|
||||
dep_name = get_label_info(dep, "name")
|
||||
java_srcjars += [ "$dep_gen_dir/$dep_name.srcjar" ]
|
||||
}
|
||||
# Mark srcjar_deps as used.
|
||||
assert(srcjar_deps == [] || srcjar_deps != [])
|
||||
|
||||
rebase_jar_path = rebase_path(jar_path, root_build_dir)
|
||||
|
||||
system_jars = [ "${android_sdk}/android.jar" ]
|
||||
action("${target_name}__javac") {
|
||||
script = "//build/android/gyp/javac.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
outputs = [
|
||||
depfile,
|
||||
jar_path,
|
||||
jar_path + ".md5.stamp"
|
||||
]
|
||||
sources = java_files + java_srcjars
|
||||
source_prereqs = system_jars + [ build_config ]
|
||||
|
||||
rebase_system_jars = rebase_path(system_jars, root_build_dir)
|
||||
rebase_java_srcjars = rebase_path(java_srcjars, root_build_dir)
|
||||
rebase_build_config = rebase_path(build_config, root_build_dir)
|
||||
rebase_depfile = rebase_path(depfile, root_build_dir)
|
||||
args = [
|
||||
"--depfile=$rebase_depfile",
|
||||
"--classpath=$rebase_system_jars",
|
||||
"--classpath=@($rebase_build_config:javac:classpath)",
|
||||
"--jar-path=$rebase_jar_path",
|
||||
"--java-srcjars=$rebase_java_srcjars",
|
||||
"--jar-excluded-classes=$jar_excluded_patterns",
|
||||
]
|
||||
if (chromium_code) {
|
||||
args += [ "--chromium-code" ]
|
||||
}
|
||||
|
||||
args += rebase_path(java_files, root_build_dir)
|
||||
}
|
||||
|
||||
# TODO(cjhopman): proguard
|
||||
|
||||
rebase_jar_toc_path = rebase_path(jar_toc_path, root_build_dir)
|
||||
action("${target_name}__jar_toc") {
|
||||
script = "//build/android/gyp/jar_toc.py"
|
||||
depfile = "$target_gen_dir/$target_name.d"
|
||||
outputs = [
|
||||
depfile,
|
||||
jar_toc_path,
|
||||
jar_toc_path + ".md5.stamp"
|
||||
]
|
||||
source_prereqs = [ jar_path ]
|
||||
args = [
|
||||
"--depfile", rebase_path(depfile, root_build_dir),
|
||||
"--jar-path=${rebase_jar_path}",
|
||||
"--toc-path=${rebase_jar_toc_path}",
|
||||
]
|
||||
}
|
||||
|
||||
group(target_name) {
|
||||
deps = [
|
||||
":${target_name}__javac",
|
||||
":${target_name}__jar_toc",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
# This adds Android-specific parts to the java_library template.
|
||||
#
|
||||
# Runs Android lint against the compiled java files.
|
||||
# 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))
|
||||
|
||||
java_library("${target_name}__java_library") {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
# TODO(cjhopman): lint
|
||||
# TODO(cjhopman): dex
|
||||
|
||||
group(target_name) {
|
||||
deps = [
|
||||
":${target_name}__java_library"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("config.gni")
|
||||
import("internal_rules.gni")
|
||||
import("//build/config/android/config.gni")
|
||||
import("//build/config/android/internal_rules.gni")
|
||||
|
||||
# Declare a jni target
|
||||
#
|
||||
|
@ -91,6 +91,8 @@ template("generate_jni") {
|
|||
# jar_file: the path to the .jar. If not provided, will default to the sdk's
|
||||
# android.jar
|
||||
#
|
||||
# deps, forward_dependent_configs_from: As normal
|
||||
#
|
||||
# Example
|
||||
# generate_jar_jni("foo_jni") {
|
||||
# classes = [
|
||||
|
@ -171,9 +173,9 @@ template("generate_jar_jni") {
|
|||
# sources will be compiled using the C pre-processor. If include_path is
|
||||
# specified, it will be passed (with --I) to the pre-processor.
|
||||
#
|
||||
# This target will create a single .srcjar. Adding this target to a library
|
||||
# target's srcjar_deps will make the generated java files be included in that
|
||||
# library's final outputs.
|
||||
# This target will create a single .srcjar. Adding this target to an
|
||||
# android_library target's srcjar_deps will make the generated java files be
|
||||
# included in that library's final outputs.
|
||||
#
|
||||
# Variables
|
||||
# sources: list of files to be processed by the C pre-processor. For each
|
||||
|
@ -247,3 +249,69 @@ template("java_cpp_template") {
|
|||
]
|
||||
}
|
||||
}
|
||||
|
||||
# Declare an Android library target
|
||||
#
|
||||
# This target creates an Android library containing java code and Android
|
||||
# resources.
|
||||
#
|
||||
# Variables
|
||||
# deps: Specifies the dependencies of this target. Java targets in this list
|
||||
# will be added to the javac classpath.
|
||||
# java_files: List of .java files included in this library.
|
||||
# srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
|
||||
# will be added to java_files and be included in this library.
|
||||
#
|
||||
# jar_excluded_patterns: List of patterns of .class files to exclude from the final jar.
|
||||
#
|
||||
# Example
|
||||
# android_library("foo_java") {
|
||||
# java_files = [
|
||||
# "android/org/chromium/foo/Foo.java",
|
||||
# "android/org/chromium/foo/FooInterface.java",
|
||||
# "android/org/chromium/foo/FooService.java",
|
||||
# ]
|
||||
# deps = [
|
||||
# ":bar_java"
|
||||
# ]
|
||||
# srcjar_deps = [
|
||||
# ":foo_generated_enum"
|
||||
# ]
|
||||
# jar_excluded_patterns = [
|
||||
# "*/FooService.class", "*/FooService##*.class"
|
||||
# ]
|
||||
# }
|
||||
template("android_library") {
|
||||
#TODO(cjhopman): resources
|
||||
|
||||
assert(defined(invoker.java_files))
|
||||
dep = ":${target_name}"
|
||||
base_path = get_label_info(dep, "target_gen_dir") + "/" + target_name
|
||||
build_config = base_path + ".build_config"
|
||||
|
||||
write_build_config("${target_name}__build_config") {
|
||||
type = "android_library"
|
||||
|
||||
deps = []
|
||||
if (defined(invoker.deps)) {
|
||||
deps += invoker.deps
|
||||
}
|
||||
|
||||
# base_path
|
||||
}
|
||||
|
||||
jar_path = base_path + ".jar"
|
||||
android_java_library(target_name) {
|
||||
java_files = invoker.java_files
|
||||
build_config = build_config
|
||||
|
||||
if (defined(invoker.jar_excluded_patterns)) {
|
||||
jar_excluded_patterns = invoker.jar_excluded_patterns
|
||||
}
|
||||
|
||||
if (defined(invoker.srcjar_deps)) {
|
||||
srcjar_deps = invoker.srcjar_deps
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче