Commit 7c1077d1 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Fix generate_gradle.py handling tests

- Correctly handle generated files in test entries.
- Fix fast to still output prebuilt jars.
  - Moving towards making `--fast` only generate what is necessary.
  - Still room to improve in avoiding tons of copies of the same mojom
    generated java files in many gn targets.

Bug: 620034
Change-Id: I651cd0684c4388b90181638023e25a027c2d8949
Reviewed-on: https://chromium-review.googlesource.com/1169694Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582690}
parent fe78cf5b
...@@ -169,7 +169,7 @@ class _ProjectEntry(object): ...@@ -169,7 +169,7 @@ class _ProjectEntry(object):
self._build_config = None self._build_config = None
self._java_files = None self._java_files = None
self._all_entries = None self._all_entries = None
self.android_test_entries = None self.android_test_entries = []
@classmethod @classmethod
def FromGnTarget(cls, gn_target): def FromGnTarget(cls, gn_target):
...@@ -373,21 +373,24 @@ class _ProjectContextGenerator(object): ...@@ -373,21 +373,24 @@ class _ProjectContextGenerator(object):
res_zips += entry.ResZips() res_zips += entry.ResZips()
return set(_RebasePath(res_zips)) return set(_RebasePath(res_zips))
def GeneratedInputs(self, root_entry): def GeneratedInputs(self, root_entry, fast=None):
generated_inputs = self.AllResZips(root_entry) generated_inputs = set()
generated_inputs.update(self.AllSrcjars(root_entry)) if not fast:
generated_inputs.update(self.AllResZips(root_entry))
generated_inputs.update(self.AllSrcjars(root_entry))
for entry in self._GetEntries(root_entry): for entry in self._GetEntries(root_entry):
generated_inputs.update(entry.GeneratedJavaFiles()) generated_inputs.update(entry.GeneratedJavaFiles())
generated_inputs.update(entry.PrebuiltJars()) generated_inputs.update(entry.PrebuiltJars())
return generated_inputs return generated_inputs
def GeneratedZips(self, root_entry): def GeneratedZips(self, root_entry, fast=None):
entry_output_dir = self.EntryOutputDir(root_entry) entry_output_dir = self.EntryOutputDir(root_entry)
tuples = [] tuples = []
tuples.extend((s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) if not fast:
for s in self.AllSrcjars(root_entry)) tuples.extend((s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR))
tuples.extend((s, os.path.join(entry_output_dir, _RES_SUBDIR)) for s in self.AllSrcjars(root_entry))
for s in self.AllResZips(root_entry)) tuples.extend((s, os.path.join(entry_output_dir, _RES_SUBDIR))
for s in self.AllResZips(root_entry))
return tuples return tuples
def GenerateManifest(self, root_entry): def GenerateManifest(self, root_entry):
...@@ -972,24 +975,24 @@ def main(): ...@@ -972,24 +975,24 @@ def main():
_WriteFile(os.path.join(generator.project_dir, 'local.properties'), _WriteFile(os.path.join(generator.project_dir, 'local.properties'),
_GenerateLocalProperties(sdk_path)) _GenerateLocalProperties(sdk_path))
if not args.fast: zip_tuples = []
zip_tuples = [] generated_inputs = set()
generated_inputs = set() for entry in entries:
for entry in entries: entries_to_gen = [entry]
entries_to_gen.extend(entry.android_test_entries)
for entry_to_gen in entries_to_gen:
# Build all paths references by .gradle that exist within output_dir. # Build all paths references by .gradle that exist within output_dir.
generated_inputs.update(generator.GeneratedInputs(entry)) generated_inputs.update(
zip_tuples.extend(generator.GeneratedZips(entry)) generator.GeneratedInputs(entry_to_gen, args.fast))
if generated_inputs: zip_tuples.extend(generator.GeneratedZips(entry_to_gen, args.fast))
logging.warning('Building generated source files...') if generated_inputs:
targets = _RebasePath(generated_inputs, output_dir) logging.warning('Building generated source files...')
_RunNinja(output_dir, targets, args.j) targets = _RebasePath(generated_inputs, output_dir)
if zip_tuples: _RunNinja(output_dir, targets, args.j)
_ExtractZips(generator.project_dir, zip_tuples) if zip_tuples:
_ExtractZips(generator.project_dir, zip_tuples)
logging.warning('Generated projects for Android Studio %s', channel) logging.warning('Generated projects for Android Studio %s', channel)
if not args.fast:
logging.warning('Run with --fast flag to skip generating files (faster, '
'but less correct)')
logging.warning('For more tips: https://chromium.googlesource.com/chromium' logging.warning('For more tips: https://chromium.googlesource.com/chromium'
'/src.git/+/master/docs/android_studio.md') '/src.git/+/master/docs/android_studio.md')
......
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