Commit c1c3ec91 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android Studio: Add resources editing back

Since owned_resources_dirs was removed, using lint_resource_sources
instead.

Android Studio only supports editing resources, so there is no longer a
need to store/unzip generated resource zips.

Also fixes distribution url for latest canary (which is actually beta on
gLinux).

Bug: 620034,1092741
Change-Id: I51ef5b0b36de009ab46f820aaf45772f2f7da94b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2253078
Commit-Queue: Peter Wen <wnwen@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780019}
parent 0930aaed
...@@ -16,7 +16,6 @@ import re ...@@ -16,7 +16,6 @@ import re
import shutil import shutil
import subprocess import subprocess
import sys import sys
import zipfile
_BUILD_ANDROID = os.path.join(os.path.dirname(__file__), os.pardir) _BUILD_ANDROID = os.path.join(os.path.dirname(__file__), os.pardir)
sys.path.append(_BUILD_ANDROID) sys.path.append(_BUILD_ANDROID)
...@@ -28,6 +27,7 @@ from pylib.constants import host_paths ...@@ -28,6 +27,7 @@ from pylib.constants import host_paths
sys.path.append(os.path.join(_BUILD_ANDROID, 'gyp')) sys.path.append(os.path.join(_BUILD_ANDROID, 'gyp'))
import jinja_template import jinja_template
from util import build_utils 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_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'third_party',
'depot_tools') 'depot_tools')
...@@ -38,7 +38,6 @@ _FILE_DIR = os.path.dirname(__file__) ...@@ -38,7 +38,6 @@ _FILE_DIR = os.path.dirname(__file__)
_GENERATED_JAVA_SUBDIR = 'generated_java' _GENERATED_JAVA_SUBDIR = 'generated_java'
_JNI_LIBS_SUBDIR = 'symlinked-libs' _JNI_LIBS_SUBDIR = 'symlinked-libs'
_ARMEABI_SUBDIR = 'armeabi' _ARMEABI_SUBDIR = 'armeabi'
_RES_SUBDIR = 'extracted-res'
_GRADLE_BUILD_FILE = 'build.gradle' _GRADLE_BUILD_FILE = 'build.gradle'
_CMAKE_FILE = 'CMakeLists.txt' _CMAKE_FILE = 'CMakeLists.txt'
# This needs to come first alphabetically among all modules. # This needs to come first alphabetically among all modules.
...@@ -255,11 +254,8 @@ class _ProjectEntry(object): ...@@ -255,11 +254,8 @@ class _ProjectEntry(object):
'junit_binary', 'junit_binary',
) )
def ResZips(self): def ResSources(self):
return self.DepsInfo().get('owned_resources_zips', []) return self.DepsInfo().get('lint_resource_sources', [])
def ResDirs(self):
return self.DepsInfo().get('owned_resources_dirs', [])
def JavaFiles(self): def JavaFiles(self):
if self._java_files is None: if self._java_files is None:
...@@ -360,24 +356,12 @@ class _ProjectContextGenerator(object): ...@@ -360,24 +356,12 @@ class _ProjectContextGenerator(object):
def EntryOutputDir(self, entry): def EntryOutputDir(self, entry):
return os.path.join(self.project_dir, entry.GradleSubdir()) 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): def GeneratedInputs(self, root_entry):
generated_inputs = set() generated_inputs = set()
generated_inputs.update(self.AllResZips(root_entry))
for entry in self._GetEntries(root_entry): for entry in self._GetEntries(root_entry):
generated_inputs.update(entry.PrebuiltJars()) generated_inputs.update(entry.PrebuiltJars())
return generated_inputs 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): def GenerateManifest(self, root_entry):
android_manifest = root_entry.DepsInfo().get('android_manifest') android_manifest = root_entry.DepsInfo().get('android_manifest')
if not android_manifest: if not android_manifest:
...@@ -401,13 +385,15 @@ class _ProjectContextGenerator(object): ...@@ -401,13 +385,15 @@ class _ProjectContextGenerator(object):
p for e in self._GetEntries(root_entry) for p in e.PrebuiltJars()) p for e in self._GetEntries(root_entry) for p in e.PrebuiltJars())
self.processed_prebuilts.update(prebuilts) self.processed_prebuilts.update(prebuilts)
variables['prebuilts'] = self._Relativize(root_entry, prebuilts) variables['prebuilts'] = self._Relativize(root_entry, prebuilts)
res_dirs = set( res_sources_files = _RebasePath(
p for e in self._GetEntries(root_entry) for p in e.ResDirs()) 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 # Do not add generated resources for the all module since it creates many
# duplicates, and currently resources are only used for editing. # duplicates, and currently resources are only used for editing.
self.processed_res_dirs.update(res_dirs) 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) variables['res_dirs'] = self._Relativize(root_entry, res_dirs)
if self.split_projects: if self.split_projects:
deps = [_ProjectEntry.FromBuildConfigPath(p) deps = [_ProjectEntry.FromBuildConfigPath(p)
...@@ -542,7 +528,7 @@ def _GenerateGradleWrapperPropertiesCanary(): ...@@ -542,7 +528,7 @@ def _GenerateGradleWrapperPropertiesCanary():
return '\n'.join([ return '\n'.join([
'# Generated by //build/android/gradle/generate_gradle.py', '# Generated by //build/android/gradle/generate_gradle.py',
('distributionUrl=https\\://services.gradle.org/distributions/' ('distributionUrl=https\\://services.gradle.org/distributions/'
'gradle-6.4-rc-2-all.zip\n'), 'gradle-6.5-rc-1-all.zip\n'),
'', '',
]) ])
...@@ -716,23 +702,6 @@ def _GenerateSettingsGradle(project_entries): ...@@ -716,23 +702,6 @@ def _GenerateSettingsGradle(project_entries):
return '\n'.join(lines) 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): def _FindAllProjectEntries(main_entries):
"""Returns the list of all _ProjectEntry instances given the root project.""" """Returns the list of all _ProjectEntry instances given the root project."""
found = set() found = set()
...@@ -964,7 +933,6 @@ def main(): ...@@ -964,7 +933,6 @@ def main():
if args.canary: if args.canary:
_WriteFile(wrapper_properties, _GenerateGradleWrapperPropertiesCanary()) _WriteFile(wrapper_properties, _GenerateGradleWrapperPropertiesCanary())
zip_tuples = []
generated_inputs = set() generated_inputs = set()
for entry in entries: for entry in entries:
entries_to_gen = [entry] entries_to_gen = [entry]
...@@ -972,13 +940,9 @@ def main(): ...@@ -972,13 +940,9 @@ def main():
for entry_to_gen in entries_to_gen: 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_to_gen)) generated_inputs.update(generator.GeneratedInputs(entry_to_gen))
zip_tuples.extend(generator.GeneratedZips(entry_to_gen))
if generated_inputs: if generated_inputs:
targets = _RebasePath(generated_inputs, output_dir) targets = _RebasePath(generated_inputs, output_dir)
_RunNinja(output_dir, targets) _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 files will only appear once you\'ve built them.')
logging.warning('Generated projects for Android Studio %s', channel) logging.warning('Generated projects for Android Studio %s', channel)
......
...@@ -9,14 +9,14 @@ buildscript { ...@@ -9,14 +9,14 @@ buildscript {
jcenter() jcenter()
{% if channel == 'canary' %} {% if channel == 'canary' %}
// Workaround for http://b/144885480. // Workaround for http://b/144885480.
maven() { //maven() {
url "http://dl.bintray.com/kotlin/kotlin-eap" // url "http://dl.bintray.com/kotlin/kotlin-eap"
} //}
{% endif %} {% endif %}
} }
dependencies { dependencies {
{% if channel == 'canary' %} {% if channel == 'canary' %}
classpath "com.android.tools.build:gradle:4.1.0-alpha09" classpath "com.android.tools.build:gradle:4.1.0-beta01"
{% 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 %}
......
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