| Index: build/android/gradle/generate_gradle.py
|
| diff --git a/build/android/gradle/generate_gradle.py b/build/android/gradle/generate_gradle.py
|
| index c4e86655c1536f5bdc82e097329d4421012ee22c..ec50a247b376407ccba490952bc00b4acc82fa8e 100755
|
| --- a/build/android/gradle/generate_gradle.py
|
| +++ b/build/android/gradle/generate_gradle.py
|
| @@ -7,6 +7,7 @@
|
|
|
| import argparse
|
| import codecs
|
| +import glob
|
| import logging
|
| import os
|
| import re
|
| @@ -258,9 +259,9 @@
|
| java_files = []
|
| for entry in self._GetEntries(root_entry):
|
| java_files += entry.JavaFiles()
|
| - java_dirs, single_files = _ComputeJavaSourceDirsAndFiles(
|
| + java_dirs, excludes = _ComputeJavaSourceDirsAndExcludes(
|
| constants.GetOutDirectory(), java_files)
|
| - return java_dirs, single_files
|
| + return java_dirs, excludes
|
|
|
| def _GenCustomManifest(self, entry):
|
| """Returns the path to the generated AndroidManifest.xml.
|
| @@ -332,11 +333,11 @@
|
| # TODO(agrieve): Add an option to use interface jars and see if that speeds
|
| # things up at all.
|
| variables = {}
|
| - java_dirs, java_files = self._GenJavaDirs(root_entry)
|
| + java_dirs, excludes = self._GenJavaDirs(root_entry)
|
| java_dirs.sort()
|
| variables['java_dirs'] = self._Relativize(root_entry, java_dirs)
|
| variables['java_dirs'].append(_SRCJARS_SUBDIR)
|
| - variables['java_files'] = self._Relativize(root_entry, java_files)
|
| + variables['java_excludes'] = excludes
|
| variables['jni_libs'] = self._Relativize(
|
| root_entry, set(self._GenJniLibs(root_entry)))
|
| variables['prebuilts'] = [
|
| @@ -387,18 +388,42 @@
|
| return found_roots
|
|
|
|
|
| -def _ComputeJavaSourceDirsAndFiles(output_dir, java_files):
|
| - """Computes the list of java source directories and single files.
|
| +def _ComputeExcludeFilters(wanted_files, unwanted_files, parent_dir):
|
| + """Returns exclude patters to exclude unwanted files but keep wanted files.
|
| +
|
| + - Shortens exclude list by globbing if possible.
|
| + - Exclude patterns are relative paths from the parent directory.
|
| + """
|
| + excludes = []
|
| + files_to_include = set(wanted_files)
|
| + files_to_exclude = set(unwanted_files)
|
| + while files_to_exclude:
|
| + unwanted_file = files_to_exclude.pop()
|
| + target_exclude = os.path.join(
|
| + os.path.dirname(unwanted_file), '*.java')
|
| + found_files = set(glob.glob(target_exclude))
|
| + valid_files = found_files & files_to_include
|
| + if valid_files:
|
| + excludes.append(os.path.relpath(unwanted_file, parent_dir))
|
| + else:
|
| + excludes.append(os.path.relpath(target_exclude, parent_dir))
|
| + files_to_exclude -= found_files
|
| + return excludes
|
| +
|
| +
|
| +def _ComputeJavaSourceDirsAndExcludes(output_dir, java_files):
|
| + """Computes the list of java source directories and exclude patterns.
|
|
|
| 1. Computes the root java source directories from the list of files.
|
| - 2. Compute single files that are not included in full directories.
|
| - 3. Returns the list of java source directories and single files.
|
| + 2. Compute exclude patterns that exclude all extra files only.
|
| + 3. Returns the list of java source directories and exclude patterns.
|
| """
|
| java_dirs = []
|
| - single_files = set()
|
| + excludes = []
|
| if java_files:
|
| java_files = _RebasePath(java_files)
|
| computed_dirs = _ComputeJavaSourceDirs(java_files)
|
| + java_dirs = computed_dirs.keys()
|
| all_found_java_files = set()
|
|
|
| for directory, files in computed_dirs.iteritems():
|
| @@ -406,20 +431,19 @@
|
| all_found_java_files.update(found_java_files)
|
| unwanted_java_files = set(found_java_files) - set(files)
|
| if unwanted_java_files:
|
| - logging.debug('Directory requires single files: %s', directory)
|
| - single_files.update(files)
|
| - else:
|
| - java_dirs.append(directory)
|
| + logging.debug('Directory requires excludes: %s', directory)
|
| + excludes.extend(
|
| + _ComputeExcludeFilters(files, unwanted_java_files, directory))
|
|
|
| missing_java_files = set(java_files) - all_found_java_files
|
| # Warn only about non-generated files that are missing.
|
| missing_java_files = [p for p in missing_java_files
|
| if not p.startswith(output_dir)]
|
| if missing_java_files:
|
| - logging.error(
|
| + logging.warning(
|
| 'Some java files were not found: %s', missing_java_files)
|
|
|
| - return java_dirs, list(single_files)
|
| + return java_dirs, excludes
|
|
|
|
|
| def _CreateRelativeSymlink(target_path, link_path):
|
| @@ -495,8 +519,6 @@
|
| _RebasePath(os.path.join(build_vars['android_sdk_build_tools'],
|
| 'source.properties')))
|
| variables['build_tools_version'] = source_properties['Pkg.Revision']
|
| - # TODO(wnwen): Remove this line once http://crbug.com/688263 is fixed.
|
| - variables['build_tools_version'] = '25.0.0'
|
| variables['compile_sdk_version'] = (
|
| 'android-%s' % build_vars['android_sdk_version'])
|
| variables['main'] = generator.Generate(entry)
|
| @@ -716,7 +738,7 @@
|
| _ExtractZips(generator.project_dir, zip_tuples)
|
|
|
| logging.warning('Project created! (%d subprojects)', len(project_entries))
|
| - logging.warning('Generated projects are targeting Android Studio 2.3')
|
| + logging.warning('Generated projects work best with Android Studio 2.2')
|
| logging.warning('For more tips: https://chromium.googlesource.com/chromium'
|
| '/src.git/+/master/docs/android_studio.md')
|
|
|
|
|