diff options
author | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-26 04:01:47 +0000 |
---|---|---|
committer | cjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-26 04:01:47 +0000 |
commit | 6fad603bfebe6314ecaa4d74a3ffdca430eeb8a6 (patch) | |
tree | 46e88b39046ce753373ac25fafb549b19b57d9d8 | |
parent | 29a5d132d2e499651a741611f5c4504e5298a684 (diff) | |
download | chromium_src-6fad603bfebe6314ecaa4d74a3ffdca430eeb8a6.zip chromium_src-6fad603bfebe6314ecaa4d74a3ffdca430eeb8a6.tar.gz chromium_src-6fad603bfebe6314ecaa4d74a3ffdca430eeb8a6.tar.bz2 |
Add java_cpp_template template
This is the GN version of build/java_cpp_template.gypi.
It defines a template that wraps an action_foreach that generates .java
files using the host C preprocessor.
The major difference in the GN version is that it takes all the
generated java files and zips them together in a single .srcjar. When
such a target is included in the srcjar_deps of a java library, the
.java files in the .srcjar will be treated much like files listed in
that libraries java_sources (particularly they will be compiled and
included in the .jar/.dex).
Depends on https://crrev.com/264773014/
BUG=359249
Review URL: https://codereview.chromium.org/264923007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272775 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/BUILD.gn | 36 | ||||
-rwxr-xr-x | build/android/gn/zip.py | 39 | ||||
-rw-r--r-- | build/config/android/internal_rules.gni | 25 | ||||
-rw-r--r-- | build/config/android/rules.gni | 82 |
4 files changed, 182 insertions, 0 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn index f1c5329..b4faecf 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -1319,4 +1319,40 @@ if (is_android) { ] jni_package = "base" } + + java_cpp_template("base_java_application_state") { + sources = [ + "android/java/src/org/chromium/base/ApplicationState.template", + ] + source_prereqs = [ + "android/application_state_list.h" + ] + + package_name = "org/chromium/base" + } + + java_cpp_template("base_java_memory_pressure_level_list") { + sources = [ + "android/java/src/org/chromium/base/MemoryPressureLevelList.template", + ] + source_prereqs = [ + "memory/memory_pressure_level_list.h" + ] + + package_name = "org/chromium/base" + } + + java_cpp_template("base_native_libraries_gen") { + sources = [ + "android/java/templates/NativeLibraries.template", + ] + source_prereqs = [ + "android/java/templates/native_libraries_array.h", + ] + + package_name = "org/chromium/base/library_loader" + include_path = "android/java/templates" + } + + } diff --git a/build/android/gn/zip.py b/build/android/gn/zip.py new file mode 100755 index 0000000..4bd0adf0 --- /dev/null +++ b/build/android/gn/zip.py @@ -0,0 +1,39 @@ +#!/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. + +"""Archives a set of files. +""" + +import ast +import optparse +import os +import sys +import zipfile + +def DoZip(inputs, output, base_dir): + with zipfile.ZipFile(output, 'w') as outfile: + for f in inputs: + outfile.write(f, os.path.relpath(f, base_dir)) + +def main(): + parser = optparse.OptionParser() + parser.add_option('--inputs', help='List of files to archive.') + parser.add_option('--output', help='Path to output archive.') + parser.add_option('--base-dir', + help='If provided, the paths in the archive will be ' + 'relative to this directory', default='.') + + options, _ = parser.parse_args() + + inputs = ast.literal_eval(options.inputs) + output = options.output + base_dir = options.base_dir + + DoZip(inputs, output, base_dir) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/build/config/android/internal_rules.gni b/build/config/android/internal_rules.gni new file mode 100644 index 0000000..b3114ef --- /dev/null +++ b/build/config/android/internal_rules.gni @@ -0,0 +1,25 @@ + +# Creates a zip archive of the inputs. +# If base_dir is provided, the archive paths will be relative to it. +template("zip") { + assert(defined(invoker.inputs)) + assert(defined(invoker.output)) + + rebase_inputs = rebase_path(invoker.inputs) + rebase_output = rebase_path(invoker.output) + action(target_name) { + script = "//build/android/gn/zip.py" + source_prereqs = invoker.inputs + outputs = [invoker.output] + args = [ + "--inputs=$rebase_inputs", + "--output=$rebase_output", + ] + if (defined(invoker.base_dir)) { + args += [ + "--base-dir", rebase_path(invoker.base_dir) + ] + } + } +} + diff --git a/build/config/android/rules.gni b/build/config/android/rules.gni index 850f13e..abf64a1 100644 --- a/build/config/android/rules.gni +++ b/build/config/android/rules.gni @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("internal_rules.gni") + # Declare a jni target # # This target generates the native jni bindings for a set of .java files. @@ -57,3 +59,83 @@ template("generate_jni") { } } } + +# Declare a target for c-preprocessor-generated java files +# +# This target generates java files using the host C pre-processor. Each file in +# 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. +# +# Variables +# sources: list of files to be processed by the C pre-processor. For each +# file in sources, there will be one .java file in the final .srcjar. For a +# file named FooBar.template, a java file will be created with name +# FooBar.java. +# source_prereqs: additional compile-time dependencies. Any files +# `#include`-ed in the templates should be listed here. +# package_name: this will be the subdirectory for each .java file in the .srcjar. +# +# Example +# java_cpp_template("foo_generated_enum") { +# sources = [ +# "android/java/templates/Foo.template", +# ] +# source_prereqs = [ +# "android/java/templates/native_foo_header.h", +# ] +# +# package_name = "org/chromium/base/library_loader" +# include_path = "android/java/templates" +# } +template("java_cpp_template") { + assert(defined(invoker.sources)) + package_name = invoker.package_name + "" + + if (defined(invoker.include_path)) { + include_path = invoker.include_path + "" + } else { + include_path = "//" + } + + action_foreach("${target_name}__apply_gcc") { + script = "//build/android/gyp/gcc_preprocess.py" + if (defined(invoker.source_prereqs)) { + source_prereqs = invoker.source_prereqs + [] + } + + sources = invoker.sources + + gen_dir = "${target_gen_dir}/${package_name}" + gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java" + + outputs = [ + gcc_template_output_pattern + ] + + args = [ + "--include-path", rebase_path(include_path, root_build_dir), + "--output", rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java", + "--template={{source}}", + ] + } + + apply_gcc_outputs = get_target_outputs(":${target_name}__apply_gcc") + base_gen_dir = get_label_info(":${target_name}__apply_gcc", "target_gen_dir") + + srcjar_path = "${target_gen_dir}/${target_name}.srcjar" + zip("${target_name}__zip_srcjar") { + inputs = apply_gcc_outputs + output = srcjar_path + base_dir = base_gen_dir + } + + group(target_name) { + deps = [ + ":${target_name}__zip_srcjar" + ] + } +} |