Commit 698728ae authored by wnwen's avatar wnwen Committed by Commit bot

Android: Split up build.gradle.jinja

Increase ninja concurrency from 50 to 1000. Load templates from script
directory. No visible changes except some whitespace differences.

BUG=680217

Review-Url: https://codereview.chromium.org/2621413002
Cr-Commit-Position: refs/heads/master@{#443278}
parent b91494e0
...@@ -2,46 +2,6 @@ ...@@ -2,46 +2,6 @@
{# Use of this source code is governed by a BSD-style license that can be #} {# Use of this source code is governed by a BSD-style license that can be #}
{# found in the LICENSE file. #} {# found in the LICENSE file. #}
// Generated by //build/android/generate_gradle.py // Generated by //build/android/generate_gradle.py
{% if template_type == 'root' %}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.2.3"
}
}
{% elif template_type in ('java_library', 'java_binary') %}
apply plugin: "java"
{% if template_type == 'java_binary' %}
apply plugin: "application"
{% endif %}
sourceSets {
main {
java.srcDirs = [
{% for path in java_dirs %}
"{{ path }}",
{% endfor %}
]
}
}
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{% if template_type == 'java_binary' %}
mainClassName = "{{ main_class }}"
applicationName = "{{ target_name }}"
{% endif %}
{% if template_type in ('java_binary', 'java_library') %}
archivesBaseName = "{{ target_name }}"
{% endif %}
{% else %}
{% if template_type in ('android_library', 'android_junit') %} {% if template_type in ('android_library', 'android_junit') %}
apply plugin: "com.android.library" apply plugin: "com.android.library"
...@@ -89,22 +49,8 @@ android { ...@@ -89,22 +49,8 @@ android {
} }
} }
{% endif %} {% include 'dependencies.jinja' %}
{% if template_type != 'root' %}
dependencies {
{% for path in prebuilts %}
{{ depCompileName }} files("{{ path }}")
{% endfor %}
{% for proj in java_project_deps %}
{{ depCompileName }} project(":{{ proj }}")
{% endfor %}
{% for proj in android_project_deps %}
{{ depCompileName }} project(path: ":{{ proj }}", configuration: "debug")
{% endfor %}
}
{% if template_type.startswith('android') %}
android.variantFilter { variant -> android.variantFilter { variant ->
if (variant.buildType.name.equals('release')) { if (variant.buildType.name.equals('release')) {
variant.setIgnore(true); variant.setIgnore(true);
...@@ -129,6 +75,3 @@ afterEvaluate { ...@@ -129,6 +75,3 @@ afterEvaluate {
task.enabled = false task.enabled = false
} }
} }
{% endif %}
{% endif %}
{# Copyright 2016 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. #}
dependencies {
{% for path in prebuilts %}
{{ depCompileName }} files("{{ path }}")
{% endfor %}
{% for proj in java_project_deps %}
{{ depCompileName }} project(":{{ proj }}")
{% endfor %}
{% for proj in android_project_deps %}
{{ depCompileName }} project(path: ":{{ proj }}", configuration: "debug")
{% endfor %}
}
...@@ -29,9 +29,7 @@ from util import build_utils ...@@ -29,9 +29,7 @@ from util import build_utils
_DEFAULT_ANDROID_MANIFEST_PATH = os.path.join( _DEFAULT_ANDROID_MANIFEST_PATH = os.path.join(
host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml') host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml')
_JINJA_TEMPLATE_PATH = os.path.join( _FILE_DIR = os.path.dirname(__file__)
os.path.dirname(__file__), 'build.gradle.jinja')
_JAVA_SUBDIR = 'symlinked-java' _JAVA_SUBDIR = 'symlinked-java'
_SRCJARS_SUBDIR = 'extracted-srcjars' _SRCJARS_SUBDIR = 'extracted-srcjars'
_JNI_LIBS_SUBDIR = 'symlinked-libs' _JNI_LIBS_SUBDIR = 'symlinked-libs'
...@@ -52,6 +50,11 @@ _DEFAULT_TARGETS = [ ...@@ -52,6 +50,11 @@ _DEFAULT_TARGETS = [
'//content/shell/android:content_shell_apk', '//content/shell/android:content_shell_apk',
] ]
def _TemplatePath(name):
return os.path.join(_FILE_DIR, '{}.jinja'.format(name))
def _RebasePath(path_or_list, new_cwd=None, old_cwd=None): def _RebasePath(path_or_list, new_cwd=None, old_cwd=None):
"""Makes the given path(s) relative to new_cwd, or absolute if not specified. """Makes the given path(s) relative to new_cwd, or absolute if not specified.
...@@ -90,7 +93,7 @@ def _ReadBuildVars(output_dir): ...@@ -90,7 +93,7 @@ def _ReadBuildVars(output_dir):
def _RunNinja(output_dir, args): def _RunNinja(output_dir, args):
cmd = ['ninja', '-C', output_dir, '-j50'] cmd = ['ninja', '-C', output_dir, '-j1000']
cmd.extend(args) cmd.extend(args)
logging.info('Running: %r', cmd) logging.info('Running: %r', cmd)
subprocess.check_call(cmd) subprocess.check_call(cmd)
...@@ -329,13 +332,13 @@ def _GenerateGradleFile(build_config, build_vars, java_dirs, jni_libs, ...@@ -329,13 +332,13 @@ def _GenerateGradleFile(build_config, build_vars, java_dirs, jni_libs,
for p in gradle['dependent_java_projects']] for p in gradle['dependent_java_projects']]
variables['java_project_deps'] = [d.ProjectName() for d in deps] variables['java_project_deps'] = [d.ProjectName() for d in deps]
return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables) return jinja_processor.Render(
_TemplatePath(target_type.split('_')[0]), variables)
def _GenerateRootGradle(jinja_processor): def _GenerateRootGradle(jinja_processor):
"""Returns the data for the root project's build.gradle.""" """Returns the data for the root project's build.gradle."""
variables = {'template_type': 'root'} return jinja_processor.Render(_TemplatePath('root'))
return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables)
def _GenerateSettingsGradle(project_entries): def _GenerateSettingsGradle(project_entries):
...@@ -447,7 +450,7 @@ def main(): ...@@ -447,7 +450,7 @@ def main():
logging.info('Found %d dependent build_config targets.', len(all_entries)) logging.info('Found %d dependent build_config targets.', len(all_entries))
logging.warning('Writing .gradle files...') logging.warning('Writing .gradle files...')
jinja_processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
build_vars = _ReadBuildVars(output_dir) build_vars = _ReadBuildVars(output_dir)
project_entries = [] project_entries = []
srcjar_tuples = [] srcjar_tuples = []
......
{# Copyright 2016 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. #}
// Generated by //build/android/generate_gradle.py
apply plugin: "java"
{% if template_type == 'java_binary' %}
apply plugin: "application"
{% endif %}
sourceSets {
main {
java.srcDirs = [
{% for path in java_dirs %}
"{{ path }}",
{% endfor %}
]
}
}
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
{% if template_type == 'java_binary' %}
mainClassName = "{{ main_class }}"
applicationName = "{{ target_name }}"
{% endif %}
{% if template_type in ('java_binary', 'java_library') %}
archivesBaseName = "{{ target_name }}"
{% endif %}
{% include 'dependencies.jinja' %}
{# Copyright 2016 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. #}
// Generated by //build/android/generate_gradle.py
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.2.3"
}
}
...@@ -37,7 +37,7 @@ class JinjaProcessor(object): ...@@ -37,7 +37,7 @@ class JinjaProcessor(object):
"""Allows easy rendering of jinja templates with input file tracking.""" """Allows easy rendering of jinja templates with input file tracking."""
def __init__(self, loader_base_dir, variables=None): def __init__(self, loader_base_dir, variables=None):
self.loader_base_dir = loader_base_dir self.loader_base_dir = loader_base_dir
self.variables = variables self.variables = variables or {}
self.loader = _RecordingFileSystemLoader(loader_base_dir) self.loader = _RecordingFileSystemLoader(loader_base_dir)
self.env = jinja2.Environment(loader=self.loader) self.env = jinja2.Environment(loader=self.loader)
self.env.undefined = jinja2.StrictUndefined self.env.undefined = jinja2.StrictUndefined
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment