0

Fix: generate_gradle.py for native targets

1. Generate only one cmake add_library command.
2. Read all deps from project.json.
3. Update gradle build tool to 4.0.1.
4. Update docs.

Change-Id: I88fd4bcc969c158b1522da210bf815e598e55957
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2342540
Commit-Queue: Richard He <linyhe@microsoft.com>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796646}
This commit is contained in:
Richard He
2020-08-11 00:36:26 +00:00
committed by Commit Bot
parent cec1845fbc
commit b08a6943d5
4 changed files with 28 additions and 19 deletions

@ -15,12 +15,11 @@ include_directories(
)
{% endif %}
{% for name, target in native.targets.iteritems() %}
{% if target.sources is defined %}
add_library("{{ name }}"
{% for path in target.sources %}
# Android studio will index faster when adding all sources into one library.
{% if native.sources is defined %}
add_library("chromium"
{% for path in native.sources %}
{{ path }}
{% endfor %}
)
{% endif %}
{% endfor %}

@ -587,29 +587,39 @@ def _IsTestDir(path):
# Example: //chrome/android:monochrome
def _GetNative(relative_func, target_names):
"""Returns an object containing native c++ sources list and its included path
Iterate through all target_names and their deps to get the list of included
paths and sources."""
out_dir = constants.GetOutDirectory()
with open(os.path.join(out_dir, 'project.json'), 'r') as project_file:
projects = json.load(project_file)
project_targets = projects['targets']
root_dir = projects['build_settings']['root_path']
targets = {}
includes = set()
processed_target = set()
targets_stack = list(target_names)
sources = []
while targets_stack:
target_name = targets_stack.pop()
if target_name in processed_target:
continue
processed_target.add(target_name)
target = project_targets[target_name]
includes.update(target.get('include_dirs', []))
targets_stack.extend(target.get('deps', []))
# Ignore generated files
sources.extend(f for f in target.get('sources', [])
if f.endswith('.cc') and not f.startswith('//out'))
def process_paths(paths):
# Ignores leading //
return relative_func(
sorted(os.path.join(root_dir, path[2:]) for path in paths))
for target_name in target_names:
target = project_targets[target_name]
includes.update(target.get('include_dirs', []))
sources = [f for f in target.get('sources', []) if f.endswith('.cc')]
if sources:
# CMake does not like forward slashes or colons for the target name.
filtered_name = target_name.replace('/', '.').replace(':', '-')
targets[filtered_name] = {
'sources': process_paths(sources),
}
return {
'targets': targets,
'sources': process_paths(sources),
'includes': process_paths(includes),
}

@ -20,7 +20,7 @@ buildscript {
{% elif channel == 'beta' %}
classpath "com.android.tools.build:gradle:4.0.0-rc01"
{% else %}
classpath "com.android.tools.build:gradle:3.6.3"
classpath "com.android.tools.build:gradle:4.0.1"
{% endif %}
}
}

@ -93,7 +93,7 @@ invocation of `generate_gradle.py`.
Example:
```shell
build/android/gradle/generate_gradle.py --native-target //chrome/android:monochrome
build/android/gradle/generate_gradle.py --native-target //chrome/android:libchrome
```
## Tips