Skip to content

Commit

Permalink
Add support for Android aidl and support for gyp's java_in_dir
Browse files Browse the repository at this point in the history
Adds the android_aidl template to support Android aidl.

Adds a DEPRECATED_java_in_dir to android_library and android_apk. This
will greatly ease the transition from gyp to gn.

Adds BUILD.gn for third_party/eyesfree (using the two new features
added).

TBR=rsleevi
BUG=359249

Review URL: https://codereview.chromium.org/512923002

Cr-Commit-Position: refs/heads/master@{#293386}
  • Loading branch information
cjhopman authored and Commit bot committed Sep 5, 2014
1 parent 2e86410 commit dad5f42
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 19 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ group("root") {
"//third_party/android_tools:android_support_v13_java",
"//third_party/android_tools:android_support_v7_appcompat_java",
"//third_party/android_tools:android_support_v7_mediarouter_java",
"//third_party/eyesfree:eyesfree_java",
]

deps -= [
Expand Down
54 changes: 54 additions & 0 deletions build/android/gyp/aidl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/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.

"""Invokes Android's aidl
"""

import optparse
import os
import sys

from util import build_utils


def main(argv):
option_parser = optparse.OptionParser()
build_utils.AddDepfileOption(option_parser)
option_parser.add_option('--aidl-path', help='Path to the aidl binary.')
option_parser.add_option('--imports', help='Files to import.')
option_parser.add_option('--includes',
help='Directories to add as import search paths.')
option_parser.add_option('--srcjar', help='Path for srcjar output.')
options, args = option_parser.parse_args(argv[1:])

with build_utils.TempDir() as temp_dir:
for f in args:
classname = os.path.splitext(os.path.basename(f))[0]
output = os.path.join(temp_dir, classname + '.java')
aidl_cmd = [options.aidl_path]
aidl_cmd += [
'-p' + s for s in build_utils.ParseGypList(options.imports)
]
if options.includes is not None:
aidl_cmd += [
'-I' + s for s in build_utils.ParseGypList(options.includes)
]
aidl_cmd += [
f,
output
]
build_utils.CheckOutput(aidl_cmd)

build_utils.ZipDir(options.srcjar, temp_dir)

if options.depfile:
build_utils.WriteDepfile(
options.depfile,
build_utils.GetPythonDependencies())


if __name__ == '__main__':
sys.exit(main(sys.argv))
2 changes: 1 addition & 1 deletion build/android/gyp/write_build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def main(argv):
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)
raise Exception('Unknown deps: ' + str(unknown_deps))

direct_deps_config_paths = [
c for c in possible_deps_config_paths if not c in unknown_deps]
Expand Down
18 changes: 15 additions & 3 deletions build/config/android/internal_rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,23 @@ template("java_library") {
# 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.java_files) || defined(invoker.DEPRECATED_java_in_dir))
assert(defined(invoker.build_config))
assert(defined(invoker.jar_path))
assert(defined(invoker.dex_path))

_java_files = []
if (defined(invoker.java_files)) {
_java_files = invoker.java_files
} else {
_java_files_build_rel = exec_script(
"//build/android/gyp/find.py",
["--pattern", "*.java", rebase_path(invoker.DEPRECATED_java_in_dir, root_build_dir)],
"list lines"
)
_java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
}

_jar_path = invoker.jar_path
_dex_path = invoker.dex_path

Expand All @@ -530,7 +542,7 @@ template("android_java_library") {
jar_excluded_patterns = invoker.jar_excluded_patterns
}
build_config = invoker.build_config
java_files = invoker.java_files
java_files = _java_files

if (defined(invoker.srcjar_deps)) {
srcjar_deps = invoker.srcjar_deps
Expand All @@ -546,7 +558,7 @@ template("android_java_library") {
android_lint("${target_name}__lint") {
android_manifest = _android_manifest
jar_path = _jar_path
java_files = invoker.java_files
java_files = _java_files
}
}

Expand Down
118 changes: 107 additions & 11 deletions build/config/android/rules.gni
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ template("java_cpp_template") {
if (defined(invoker.inputs)) {
inputs = invoker.inputs + []
}
depfile = "${target_gen_dir}/${target_name}.d"
depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"

sources = invoker.sources

Expand Down Expand Up @@ -405,13 +405,17 @@ template("java_strings_grd") {
# 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.
# chromium_code: If true, extra static analysis warning/errors will be enabled.
# chromium_code: If true, extra analysis warning/errors will be enabled.
# jar_excluded_patterns: List of patterns of .class files to exclude from the
# final jar.
# proguard_preprocess: If true, proguard preprocessing will be run. This can
# be used to remove unwanted parts of the library.
# proguard_config: Path to the proguard config for preprocessing.
#
# DEPRECATED_java_in_dir: Directory containing java files. All .java files in
# this directory will be included in the library. This is only supported to
# ease the gyp->gn conversion and will be removed in the future.
#
# Example
# android_library("foo_java") {
# java_files = [
Expand All @@ -430,11 +434,11 @@ 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"
dex_path = base_path + ".dex.jar"
assert(defined(invoker.java_files) || defined(invoker.DEPRECATED_java_in_dir))
_base_path = "$target_gen_dir/$target_name"
_build_config = _base_path + ".build_config"
_jar_path = _base_path + ".jar"
_dex_path = _base_path + ".dex.jar"

write_build_config("${target_name}__build_config") {
type = "android_library"
Expand All @@ -444,7 +448,9 @@ template("android_library") {
deps += invoker.deps
}

# base_path
build_config = _build_config
jar_path = _jar_path
dex_path = _dex_path
}

_chromium_code = true
Expand All @@ -454,8 +460,14 @@ template("android_library") {

android_java_library(target_name) {
chromium_code = _chromium_code
java_files = invoker.java_files
build_config = build_config
if (defined(invoker.java_files)) {
java_files = invoker.java_files
} else {
DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
}
build_config = _build_config
jar_path = _jar_path
dex_path = _dex_path

if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
proguard_preprocess = true
Expand Down Expand Up @@ -546,6 +558,9 @@ template("android_java_prebuilt") {
#
# Variables
# android_manifest: Path to AndroidManifest.xml.
# datadeps: List of dependencies needed at runtime. These will be built but
# won't change the generated .apk in any way (in fact they may be built
# after the .apk is).
# 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
Expand All @@ -561,6 +576,10 @@ template("android_java_prebuilt") {
# libraries depend on other shared_library targets, those dependencies will
# also be included in the apk.
#
# DEPRECATED_java_in_dir: Directory containing java files. All .java files in
# this directory will be included in the library. This is only supported to
# ease the gyp->gn conversion and will be removed in the future.
#
# Example
# android_apk("foo_apk") {
# android_manifest = "AndroidManifest.xml"
Expand Down Expand Up @@ -676,7 +695,11 @@ template("android_apk") {
final_deps += [":${target_name}__java"]
android_java_library("${target_name}__java") {
android_manifest = invoker.android_manifest
java_files = invoker.java_files
if (defined(invoker.java_files)) {
java_files = invoker.java_files
} else {
DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
}
srcjar_deps = _srcjar_deps
dex_path = base_path + ".dex.jar"
}
Expand Down Expand Up @@ -726,6 +749,9 @@ template("android_apk") {

group(target_name) {
deps = final_deps
if (defined(invoker.datadeps)) {
datadeps = invoker.datadeps
}
}
}

Expand Down Expand Up @@ -777,3 +803,73 @@ template("unittest_apk") {
}
}
}

# Generate .java files from .aidl files.
#
# This target will store the .java files in a srcjar and should be included in
# an android_library or android_apk's srcjar_deps.
#
# Variables
# sources: Paths to .aidl files to compile.
# import_include: Path to directory containing .java files imported by the
# .aidl files.
# interface_file: Preprocessed aidl file to import.
#
# Example
# android_aidl("foo_aidl") {
# import_include = "java/src"
# sources = [
# "java/src/com/foo/bar/FooBarService.aidl",
# "java/src/com/foo/bar/FooBarServiceCallback.aidl",
# ]
# }
template("android_aidl") {
srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
aidl_path = "${android_sdk_build_tools}/aidl"
framework_aidl = "$android_sdk/framework.aidl"

action(target_name) {
script = "//build/android/gyp/aidl.py"
sources = invoker.sources

imports = [ framework_aidl ]
if (defined(invoker.interface_file)) {
assert(invoker.interface_file != "")
imports += [ invoker.interface_file ]
}

inputs = [
aidl_path,
] + imports

depfile = "${target_gen_dir}/${target_name}.d"
outputs = [
depfile,
srcjar_path
]
rebased_imports = rebase_path(imports, root_build_dir)
args = [
"--depfile", rebase_path(depfile, root_build_dir),
"--aidl-path", rebase_path(aidl_path, root_build_dir),
"--imports=$rebased_imports",
"--srcjar", rebase_path(srcjar_path, root_build_dir),
]
if (defined(invoker.import_include) && invoker.import_include != "") {
# TODO(cjhopman): aidl supports creating a depfile. We should be able to
# switch to constructing a depfile for the overall action from that
# instead of having all the .java files in the include paths as inputs.
rebased_import_includes = rebase_path(
[invoker.import_include], root_build_dir)
args += [ "--includes=$rebased_import_includes" ]

_java_files_build_rel = exec_script(
"//build/android/gyp/find.py",
rebase_path([invoker.import_include], root_build_dir),
"list lines"
)
_java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
inputs += _java_files
}
args += rebase_path(sources, root_build_dir)
}
}
11 changes: 11 additions & 0 deletions content/public/android/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")

android_aidl("common_aidl") {
interface_file = "java/src/org/chromium/content/common/common.aidl"
import_include = "java/src"
sources = [
"java/src/org/chromium/content/common/IChildProcessCallback.aidl",
"java/src/org/chromium/content/common/IChildProcessService.aidl",
]
}
6 changes: 6 additions & 0 deletions net/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,12 @@ if (is_android) {
]
jni_package = "net"
}
generate_jni("net_test_jni_headers") {
sources = [
"android/javatests/src/org/chromium/net/AndroidKeyStoreTestUtil.java",
]
jni_package = "net"
}
}

if (is_android || is_linux) {
Expand Down
4 changes: 0 additions & 4 deletions net/net.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,10 +1682,6 @@
},
'includes': [ '../build/android/java_cpp_template.gypi' ],
},
],
}],
['OS == "android"', {
'targets': [
{
'target_name': 'net_unittests_apk',
'type': 'none',
Expand Down
18 changes: 18 additions & 0 deletions third_party/eyesfree/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")

android_library("eyesfree_java") {
srcjar_deps = [ ":eyesfree_aidl" ]
DEPRECATED_java_in_dir = "src/android/java/src"
}

android_aidl("eyesfree_aidl") {
import_include = "src/android/java/src"
sources = [
"src/android/java/src/com/googlecode/eyesfree/braille/display/IBrailleService.aidl",
"src/android/java/src/com/googlecode/eyesfree/braille/display/IBrailleServiceCallback.aidl",
"src/android/java/src/com/googlecode/eyesfree/braille/selfbraille/ISelfBrailleService.aidl",
"src/android/java/src/com/googlecode/eyesfree/braille/translate/ITranslatorService.aidl",
"src/android/java/src/com/googlecode/eyesfree/braille/translate/ITranslatorServiceCallback.aidl",
]
}

0 comments on commit dad5f42

Please sign in to comment.