summaryrefslogtreecommitdiff
path: root/chromium/build/android/gradle/generate_gradle.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/build/android/gradle/generate_gradle.py')
-rwxr-xr-xchromium/build/android/gradle/generate_gradle.py91
1 files changed, 44 insertions, 47 deletions
diff --git a/chromium/build/android/gradle/generate_gradle.py b/chromium/build/android/gradle/generate_gradle.py
index 5501aa984d7..85b24410eaa 100755
--- a/chromium/build/android/gradle/generate_gradle.py
+++ b/chromium/build/android/gradle/generate_gradle.py
@@ -16,7 +16,6 @@ import re
import shutil
import subprocess
import sys
-import zipfile
_BUILD_ANDROID = os.path.join(os.path.dirname(__file__), os.pardir)
sys.path.append(_BUILD_ANDROID)
@@ -28,6 +27,7 @@ from pylib.constants import host_paths
sys.path.append(os.path.join(_BUILD_ANDROID, 'gyp'))
import jinja_template
from util import build_utils
+from util import resource_utils
_DEPOT_TOOLS_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party',
'depot_tools')
@@ -38,7 +38,6 @@ _FILE_DIR = os.path.dirname(__file__)
_GENERATED_JAVA_SUBDIR = 'generated_java'
_JNI_LIBS_SUBDIR = 'symlinked-libs'
_ARMEABI_SUBDIR = 'armeabi'
-_RES_SUBDIR = 'extracted-res'
_GRADLE_BUILD_FILE = 'build.gradle'
_CMAKE_FILE = 'CMakeLists.txt'
# This needs to come first alphabetically among all modules.
@@ -255,11 +254,8 @@ class _ProjectEntry(object):
'junit_binary',
)
- def ResZips(self):
- return self.DepsInfo().get('owned_resources_zips', [])
-
- def ResDirs(self):
- return self.DepsInfo().get('owned_resources_dirs', [])
+ def ResSources(self):
+ return self.DepsInfo().get('lint_resource_sources', [])
def JavaFiles(self):
if self._java_files is None:
@@ -360,24 +356,12 @@ class _ProjectContextGenerator(object):
def EntryOutputDir(self, entry):
return os.path.join(self.project_dir, entry.GradleSubdir())
- def AllResZips(self, root_entry):
- res_zips = []
- for entry in self._GetEntries(root_entry):
- res_zips += entry.ResZips()
- return set(_RebasePath(res_zips))
-
def GeneratedInputs(self, root_entry):
generated_inputs = set()
- generated_inputs.update(self.AllResZips(root_entry))
for entry in self._GetEntries(root_entry):
generated_inputs.update(entry.PrebuiltJars())
return generated_inputs
- def GeneratedZips(self, root_entry):
- entry_output_dir = self.EntryOutputDir(root_entry)
- return [(s, os.path.join(entry_output_dir, _RES_SUBDIR))
- for s in self.AllResZips(root_entry)]
-
def GenerateManifest(self, root_entry):
android_manifest = root_entry.DepsInfo().get('android_manifest')
if not android_manifest:
@@ -401,13 +385,15 @@ class _ProjectContextGenerator(object):
p for e in self._GetEntries(root_entry) for p in e.PrebuiltJars())
self.processed_prebuilts.update(prebuilts)
variables['prebuilts'] = self._Relativize(root_entry, prebuilts)
- res_dirs = set(
- p for e in self._GetEntries(root_entry) for p in e.ResDirs())
+ res_sources_files = _RebasePath(
+ set(p for e in self._GetEntries(root_entry) for p in e.ResSources()))
+ res_sources = []
+ for res_sources_file in res_sources_files:
+ res_sources.extend(build_utils.ReadSourcesList(res_sources_file))
+ res_dirs = resource_utils.DeduceResourceDirsFromFileList(res_sources)
# Do not add generated resources for the all module since it creates many
# duplicates, and currently resources are only used for editing.
self.processed_res_dirs.update(res_dirs)
- res_dirs.add(
- os.path.join(self.EntryOutputDir(root_entry), _RES_SUBDIR))
variables['res_dirs'] = self._Relativize(root_entry, res_dirs)
if self.split_projects:
deps = [_ProjectEntry.FromBuildConfigPath(p)
@@ -527,11 +513,35 @@ def _CreateJniLibsDir(output_dir, entry_output_dir, so_files):
def _GenerateLocalProperties(sdk_dir):
- """Returns the data for project.properties as a string."""
+ """Returns the data for local.properties as a string."""
return '\n'.join([
'# Generated by //build/android/gradle/generate_gradle.py',
'sdk.dir=%s' % sdk_dir,
- ''])
+ '',
+ ])
+
+
+def _GenerateGradleWrapperPropertiesCanary():
+ """Returns the data for gradle-wrapper.properties as a string."""
+ # Before May 2020, this wasn't necessary. Might not be necessary at some point
+ # in the future?
+ return '\n'.join([
+ '# Generated by //build/android/gradle/generate_gradle.py',
+ ('distributionUrl=https\\://services.gradle.org/distributions/'
+ 'gradle-6.5-rc-1-all.zip\n'),
+ '',
+ ])
+
+
+def _GenerateGradleProperties():
+ """Returns the data for gradle.properties as a string."""
+ return '\n'.join([
+ '# Generated by //build/android/gradle/generate_gradle.py',
+ '',
+ '# Tells Gradle to show warnings during project sync.',
+ 'org.gradle.warning.mode=all',
+ '',
+ ])
def _GenerateBaseVars(generator, build_vars):
@@ -692,23 +702,6 @@ def _GenerateSettingsGradle(project_entries):
return '\n'.join(lines)
-def _ExtractFile(zip_path, extracted_path):
- logging.debug('Extracting %s to %s', zip_path, extracted_path)
- with zipfile.ZipFile(zip_path) as z:
- z.extractall(extracted_path)
-
-
-def _ExtractZips(entry_output_dir, zip_tuples):
- """Extracts all zips to the directory given in the tuples."""
- extracted_paths = set(s[1] for s in zip_tuples)
- for extracted_path in extracted_paths:
- assert _IsSubpathOf(extracted_path, entry_output_dir)
- shutil.rmtree(extracted_path, True)
-
- for zip_path, extracted_path in zip_tuples:
- _ExtractFile(zip_path, extracted_path)
-
-
def _FindAllProjectEntries(main_entries):
"""Returns the list of all _ProjectEntry instances given the root project."""
found = set()
@@ -930,8 +923,16 @@ def main():
_WriteFile(
os.path.join(generator.project_dir, 'local.properties'),
_GenerateLocalProperties(args.sdk_path))
+ _WriteFile(os.path.join(generator.project_dir, 'gradle.properties'),
+ _GenerateGradleProperties())
+
+ wrapper_properties = os.path.join(generator.project_dir, 'gradle', 'wrapper',
+ 'gradle-wrapper.properties')
+ if os.path.exists(wrapper_properties):
+ os.unlink(wrapper_properties)
+ if args.canary:
+ _WriteFile(wrapper_properties, _GenerateGradleWrapperPropertiesCanary())
- zip_tuples = []
generated_inputs = set()
for entry in entries:
entries_to_gen = [entry]
@@ -939,13 +940,9 @@ def main():
for entry_to_gen in entries_to_gen:
# Build all paths references by .gradle that exist within output_dir.
generated_inputs.update(generator.GeneratedInputs(entry_to_gen))
- zip_tuples.extend(generator.GeneratedZips(entry_to_gen))
if generated_inputs:
targets = _RebasePath(generated_inputs, output_dir)
_RunNinja(output_dir, targets)
- if zip_tuples:
- # This extracts generated xml files (e.g. strings).
- _ExtractZips(generator.project_dir, zip_tuples)
logging.warning('Generated files will only appear once you\'ve built them.')
logging.warning('Generated projects for Android Studio %s', channel)