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:
@@ -15,12 +15,11 @@ include_directories(
|
|||||||
)
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for name, target in native.targets.iteritems() %}
|
# Android studio will index faster when adding all sources into one library.
|
||||||
{% if target.sources is defined %}
|
{% if native.sources is defined %}
|
||||||
add_library("{{ name }}"
|
add_library("chromium"
|
||||||
{% for path in target.sources %}
|
{% for path in native.sources %}
|
||||||
{{ path }}
|
{{ path }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
)
|
)
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
|
||||||
|
@@ -587,29 +587,39 @@ def _IsTestDir(path):
|
|||||||
|
|
||||||
# Example: //chrome/android:monochrome
|
# Example: //chrome/android:monochrome
|
||||||
def _GetNative(relative_func, target_names):
|
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()
|
out_dir = constants.GetOutDirectory()
|
||||||
with open(os.path.join(out_dir, 'project.json'), 'r') as project_file:
|
with open(os.path.join(out_dir, 'project.json'), 'r') as project_file:
|
||||||
projects = json.load(project_file)
|
projects = json.load(project_file)
|
||||||
project_targets = projects['targets']
|
project_targets = projects['targets']
|
||||||
root_dir = projects['build_settings']['root_path']
|
root_dir = projects['build_settings']['root_path']
|
||||||
targets = {}
|
|
||||||
includes = set()
|
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):
|
def process_paths(paths):
|
||||||
# Ignores leading //
|
# Ignores leading //
|
||||||
return relative_func(
|
return relative_func(
|
||||||
sorted(os.path.join(root_dir, path[2:]) for path in paths))
|
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 {
|
return {
|
||||||
'targets': targets,
|
'sources': process_paths(sources),
|
||||||
'includes': process_paths(includes),
|
'includes': process_paths(includes),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ buildscript {
|
|||||||
{% elif channel == 'beta' %}
|
{% elif channel == 'beta' %}
|
||||||
classpath "com.android.tools.build:gradle:4.0.0-rc01"
|
classpath "com.android.tools.build:gradle:4.0.0-rc01"
|
||||||
{% else %}
|
{% else %}
|
||||||
classpath "com.android.tools.build:gradle:3.6.3"
|
classpath "com.android.tools.build:gradle:4.0.1"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -93,7 +93,7 @@ invocation of `generate_gradle.py`.
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
build/android/gradle/generate_gradle.py --native-target //chrome/android:monochrome
|
build/android/gradle/generate_gradle.py --native-target //chrome/android:libchrome
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tips
|
## Tips
|
||||||
|
Reference in New Issue
Block a user