summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
Diffstat (limited to 'build')
-rwxr-xr-xbuild/android/gn/zip.py39
-rw-r--r--build/config/android/internal_rules.gni25
-rw-r--r--build/config/android/rules.gni82
3 files changed, 146 insertions, 0 deletions
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"
+ ]
+ }
+}