Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(960)

Unified Diff: build/android/gyp/write_build_config.py

Issue 361633002: [Android][gn] Add android resources templates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-java
Patch Set: Fix bad rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/gyp/util/build_utils.py ('k') | build/android/gyp/write_ordered_libraries.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/write_build_config.py
diff --git a/build/android/gyp/write_build_config.py b/build/android/gyp/write_build_config.py
index ff12a1ed7ca4641141787987ec4611fcb4b9d9f9..794e6a321018d0bbc82977fe7b73439222f3cef0 100755
--- a/build/android/gyp/write_build_config.py
+++ b/build/android/gyp/write_build_config.py
@@ -10,16 +10,17 @@ 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.
+other targets that depend on that one.
There are several different types of build_configs:
android_library: An android library containing java code.
+ android_resources: A target containing android resources.
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
+ --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
@@ -35,17 +36,40 @@ import sys
from util import build_utils
+dep_config_cache = {}
+def GetDepConfig(path):
+ if not path in dep_config_cache:
+ dep_config_cache[path] = build_utils.ReadJson(path)['deps_info']
+ return dep_config_cache[path]
+
+
+def DepsOfType(wanted_type, configs):
+ return [c for c in configs if c['type'] == wanted_type]
+
+
+def GetAllDepsConfigsInOrder(deps_config_paths):
+ def Deps(path):
+ return set(GetDepConfig(path)['deps_configs'])
+ return build_utils.GetSortedTransitiveDependencies(deps_config_paths, Deps)
+
+
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(
+ '--type',
+ help='Type of this target (e.g. android_library).')
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_resources 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
parser.add_option('--jar-path', help='Path to target\'s jar output.')
@@ -57,37 +81,67 @@ def main(argv):
required_options = ('build_config', 'type')
build_utils.CheckOptions(options, parser, required_options)
+ if not options.type in [
+ 'android_library', 'android_resources']:
+ raise Exception('Unknown type: <%s>' % options.type)
+
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:
+ possible_deps_configs = 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)
- deps_configs = [build_utils.ReadJson(c) for c in deps_configs]
+ direct_deps_config_paths = possible_deps_configs
+ all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)
- 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
- }
+ direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths]
+ all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths]
+
+ direct_library_deps = DepsOfType('android_library', direct_deps_configs)
+ all_resources_deps = DepsOfType('android_resources', all_deps_configs)
+
+ # Initialize some common config.
+ config = {
+ 'deps_info': {
+ 'path': options.build_config,
+ 'type': options.type,
+ 'deps_configs': direct_deps_config_paths,
}
- else:
- raise Exception('Unknown type: ' + options.type)
+ }
+ deps_info = config['deps_info']
- build_utils.WriteJson(config, options.build_config)
+ if options.type == 'android_library':
+ javac_classpath = [c['jar_path'] for c in direct_library_deps]
+ deps_info['jar_path'] = options.jar_path
+ config['javac'] = {
+ 'classpath': javac_classpath,
+ }
+ # Only resources might have srcjars (normal srcjar targets are listed in
+ # srcjar_deps). A resource's srcjar contains the R.java file for those
+ # resources, and (like Android's default build system) we allow a library to
+ # refer to the resources in any of its dependents.
+ config['javac']['srcjars'] = [
+ c['srcjar'] for c in all_resources_deps if 'srcjar' in c]
+
+ if options.type == 'android_resources':
+ 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]
+
+ build_utils.WriteJson(config, options.build_config, only_if_changed=True)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
- build_utils.GetPythonDependencies())
+ all_deps_config_paths + build_utils.GetPythonDependencies())
if __name__ == '__main__':
« no previous file with comments | « build/android/gyp/util/build_utils.py ('k') | build/android/gyp/write_ordered_libraries.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698