Commit 29ad1982 authored by tapted@chromium.org's avatar tapted@chromium.org

Revert of Remove apk-codegen.xml (https://codereview.chromium.org/295473002/)

Reason for revert:
Suspected for android compile failure on waterfall starting

http://build.chromium.org/p/chromium/builders/Android/builds/24321

Errors are pretty obscure. Things like

BUILD FAILED
/b/build/slave/Android/build/src/build/android/ant/apk-obfuscate.xml:161: /b/build/slave/Android/build/src/out/Release/multiple_proguards_test_apk/proguard.txt (No such file or directory)
	at proguard.ant.ConfigurationTask.addText(ConfigurationTask.java:315)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

FAILED: cd ../../build/android/tests/multiple_proguards; /*snip*/ build/android/ant/apk-obfuscate.xml
Traceback (most recent call last):
  File "../../../../build/android/gyp/ant.py", line 34, in main
    stdout = build_utils.CheckOutput(['ant'] + verbose_args)
  File "/b/build/slave/Android/build/src/build/android/gyp/util/build_utils.py", line 113, in CheckOutput
    raise CalledProcessError(cwd, args, stdout + stderr)

Original issue's description:
> Remove apk-codegen.xml
> 
> process_resources.py already implements almost everything from 
> apk-codegen.xml so just use that instead.
> 
> BUG=359249,375324,375431
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=272783

TBR=yfriedman@chromium.org,cjhopman@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=359249,375324,375431

Review URL: https://codereview.chromium.org/301543002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272795 0039d316-1c4b-4281-b951-d872f2087c98
parent f1103142
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2005-2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project default="-code-gen">
<property name="verbose" value="false" />
<property name="out.dir" location="${OUT_DIR}" />
<property name="out.absolute.dir" location="${out.dir}" />
<property name="out.res.absolute.dir" location="${out.dir}/res" />
<property name="gen.absolute.dir" value="${out.dir}/gen"/>
<!-- tools location -->
<property name="sdk.dir" location="${ANDROID_SDK_ROOT}"/>
<property name="android.sdk.tools.dir" location="${ANDROID_SDK_TOOLS}" />
<property name="aapt" location="${android.sdk.tools.dir}/aapt" />
<property name="project.target.android.jar" location="${ANDROID_SDK_JAR}" />
<!-- jar file from where the tasks are loaded -->
<path id="android.antlibs">
<pathelement path="${sdk.dir}/tools/lib/ant-tasks.jar" />
</path>
<!-- Custom tasks -->
<taskdef resource="anttasks.properties" classpathref="android.antlibs" />
<!--
Include additional resource folders in the apk, e.g. content/.../res. We
list the res folders in project.library.res.folder.path and the
corresponding java packages in project.library.packages, which must be
semicolon-delimited while ADDITIONAL_RES_PACKAGES is space-delimited, hence
the replacestring filterchain task.
-->
<path id="project.library.res.folder.path">
<filelist files="${ADDITIONAL_RES_DIRS}"/>
</path>
<path id="project.library.bin.r.file.path">
<filelist files="${ADDITIONAL_R_TEXT_FILES}"/>
</path>
<loadresource property="project.library.packages">
<propertyresource name="ADDITIONAL_RES_PACKAGES"/>
<filterchain>
<replacestring from=" " to=";"/>
</filterchain>
</loadresource>
<!-- Set to empty if not set by the loadresource above -->
<property name="project.library.packages" value=""/>
<property name="resource.absolute.dir" value="${RESOURCE_DIR}"/>
<property name="manifest.file" value="${ANDROID_MANIFEST}" />
<property name="manifest.abs.file" location="${manifest.file}" />
<!-- Intermediate files -->
<property name="resource.package.file.name" value="${APK_NAME}.ap_" />
<property name="aapt.ignore.assets" value="" />
<!-- Code Generation: compile resources (aapt -> R.java), aidl -->
<target name="-code-gen">
<mkdir dir="${out.absolute.dir}" />
<mkdir dir="${out.res.absolute.dir}" />
<mkdir dir="${gen.absolute.dir}" />
<aapt executable="${aapt}"
command="package"
verbose="${verbose}"
manifest="${manifest.abs.file}"
androidjar="${project.target.android.jar}"
rfolder="${gen.absolute.dir}"
nonConstantId="false"
libraryResFolderPathRefid="project.library.res.folder.path"
libraryPackagesRefid="project.library.packages"
libraryRFileRefid="project.library.bin.r.file.path"
ignoreAssets="${aapt.ignore.assets}"
binFolder="${out.absolute.dir}"
proguardFile="${out.absolute.dir}/proguard.txt">
<res path="${out.res.absolute.dir}" />
<res path="${resource.absolute.dir}" />
</aapt>
<touch file="${STAMP}" />
</target>
</project>
...@@ -51,6 +51,20 @@ ...@@ -51,6 +51,20 @@
<property name="version.code" value="${APP_MANIFEST_VERSION_CODE}"/> <property name="version.code" value="${APP_MANIFEST_VERSION_CODE}"/>
<property name="version.name" value="${APP_MANIFEST_VERSION_NAME}"/> <property name="version.name" value="${APP_MANIFEST_VERSION_NAME}"/>
<property name="aapt.resource.filter" value="" />
<!-- 'aapt.ignore.assets' is the list of file patterns to ignore under /res and /assets.
Default is "!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"
Overall patterns syntax is:
[!][<dir>|<file>][*suffix-match|prefix-match*|full-match]:more:patterns...
- The first character flag ! avoids printing a warning.
- Pattern can have the flag "<dir>" to match only directories
or "<file>" to match only files. Default is to match both.
- Match is not case-sensitive.
-->
<property name="aapt.ignore.assets" value="" />
<!-- <!--
Include additional resource folders in the apk, e.g. content/.../res. We Include additional resource folders in the apk, e.g. content/.../res. We
list the res folders in project.library.res.folder.path and the list the res folders in project.library.res.folder.path and the
...@@ -82,7 +96,19 @@ ...@@ -82,7 +96,19 @@
<!-- Intermediate files --> <!-- Intermediate files -->
<property name="resource.package.file.name" value="${APK_NAME}.ap_" /> <property name="resource.package.file.name" value="${APK_NAME}.ap_" />
<target name="-package-resources"> <target name="-crunch">
<!-- Updates the pre-processed PNG cache -->
<exec executable="${aapt}" taskName="crunch">
<arg value="crunch" />
<arg value="-v" />
<arg value="-S" />
<arg path="${resource.absolute.dir}" />
<arg value="-C" />
<arg path="${out.res.absolute.dir}" />
</exec>
</target>
<target name="-package-resources" depends="-crunch">
<aapt <aapt
executable="${aapt}" executable="${aapt}"
command="package" command="package"
...@@ -95,13 +121,13 @@ ...@@ -95,13 +121,13 @@
apkfolder="${out.absolute.dir}" apkfolder="${out.absolute.dir}"
nocrunch="${build.packaging.nocrunch}" nocrunch="${build.packaging.nocrunch}"
resourcefilename="${resource.package.file.name}" resourcefilename="${resource.package.file.name}"
resourcefilter="" resourcefilter="${aapt.resource.filter}"
libraryResFolderPathRefid="project.library.res.folder.path" libraryResFolderPathRefid="project.library.res.folder.path"
libraryPackagesRefid="project.library.packages" libraryPackagesRefid="project.library.packages"
libraryRFileRefid="project.library.bin.r.file.path" libraryRFileRefid="project.library.bin.r.file.path"
previousBuildType="" previousBuildType=""
buildType="${build.target}" buildType="${build.target}"
ignoreAssets=""> ignoreAssets="${aapt.ignore.assets}">
<res path="${out.res.absolute.dir}" /> <res path="${out.res.absolute.dir}" />
<res path="${resource.absolute.dir}" /> <res path="${resource.absolute.dir}" />
<!-- <nocompress /> forces no compression on any files in assets or res/raw --> <!-- <nocompress /> forces no compression on any files in assets or res/raw -->
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
import optparse import optparse
import os import os
import re
import shlex import shlex
import shutil import shutil
...@@ -25,10 +24,10 @@ def ParseArgs(): ...@@ -25,10 +24,10 @@ def ParseArgs():
parser.add_option('--android-sdk-tools', parser.add_option('--android-sdk-tools',
help='path to the Android SDK build tools folder') help='path to the Android SDK build tools folder')
parser.add_option('--R-dir', help='directory to hold generated R.java') parser.add_option('--R-dir', help='directory to hold generated R.java')
parser.add_option('--dependencies-res-dirs', parser.add_option('--res-dirs',
help='directories containing resources to be packaged') help='directories containing resources to be packaged')
parser.add_option('--resource-dir', parser.add_option('--crunch-input-dir',
help='directory containing this target\'s resources.') help='directory containing images to be crunched')
parser.add_option('--crunch-output-dir', parser.add_option('--crunch-output-dir',
help='directory to hold crunched resources') help='directory to hold crunched resources')
parser.add_option('--non-constant-id', action='store_true') parser.add_option('--non-constant-id', action='store_true')
...@@ -36,60 +35,19 @@ def ParseArgs(): ...@@ -36,60 +35,19 @@ def ParseArgs():
parser.add_option('--android-manifest', help='AndroidManifest.xml path') parser.add_option('--android-manifest', help='AndroidManifest.xml path')
parser.add_option('--stamp', help='File to touch on success') parser.add_option('--stamp', help='File to touch on success')
parser.add_option(
'--extra-res-packages',
help='Additional package names to generate R.java files for')
parser.add_option(
'--extra-r-text-files',
help='For each additional package, the R.txt file should contain a '
'list of resources to be included in the R.java file in the format '
'generated by aapt')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if args: if args:
parser.error('No positional arguments should be given.') parser.error('No positional arguments should be given.')
# Check that required options have been provided. # Check that required options have been provided.
required_options = ( required_options = ('android_sdk', 'android_sdk_tools', 'R_dir',
'android_sdk', 'res_dirs', 'crunch_input_dir', 'crunch_output_dir')
'android_sdk_tools',
'android_manifest',
'dependencies_res_dirs',
'resource_dir',
'crunch_output_dir',
'R_dir',
)
build_utils.CheckOptions(options, parser, required=required_options) build_utils.CheckOptions(options, parser, required=required_options)
return options return options
def CreateExtraRJavaFiles(
r_dir, extra_packages, extra_r_text_files):
if len(extra_packages) != len(extra_r_text_files):
raise Exception('--extra-res-packages and --extra-r-text-files'
'should have the same length')
java_files = build_utils.FindInDirectory(r_dir, "R.java")
if len(java_files) != 1:
return
r_java_file = java_files[0]
r_java_contents = open(r_java_file).read()
for package in extra_packages:
package_r_java_dir = os.path.join(r_dir, *package.split('.'))
build_utils.MakeDirectory(package_r_java_dir)
package_r_java_path = os.path.join(package_r_java_dir, 'R.java')
open(package_r_java_path, 'w').write(
re.sub(r'package [.\w]*;', 'package %s;' % package, r_java_contents))
# TODO(cjhopman): These extra package's R.java files should be filtered to
# only contain the resources listed in their R.txt files. At this point, we
# have already compiled those other libraries, so doing this would only
# affect how the code in this .apk target could refer to the resources.
def MoveImagesToNonMdpiFolders(res_root): def MoveImagesToNonMdpiFolders(res_root):
"""Move images from drawable-*-mdpi-* folders to drawable-* folders. """Move images from drawable-*-mdpi-* folders to drawable-* folders.
...@@ -137,7 +95,6 @@ def main(): ...@@ -137,7 +95,6 @@ def main():
android_jar = os.path.join(options.android_sdk, 'android.jar') android_jar = os.path.join(options.android_sdk, 'android.jar')
aapt = os.path.join(options.android_sdk_tools, 'aapt') aapt = os.path.join(options.android_sdk_tools, 'aapt')
build_utils.DeleteDirectory(options.R_dir)
build_utils.MakeDirectory(options.R_dir) build_utils.MakeDirectory(options.R_dir)
# Generate R.java. This R.java contains non-final constants and is used only # Generate R.java. This R.java contains non-final constants and is used only
...@@ -153,30 +110,21 @@ def main(): ...@@ -153,30 +110,21 @@ def main():
'-I', android_jar, '-I', android_jar,
'--output-text-symbols', options.R_dir, '--output-text-symbols', options.R_dir,
'-J', options.R_dir] '-J', options.R_dir]
all_res_dirs = ([options.resource_dir] res_dirs = shlex.split(options.res_dirs)
+ shlex.split(options.dependencies_res_dirs)) for res_dir in res_dirs:
for res_dir in all_res_dirs:
package_command += ['-S', res_dir] package_command += ['-S', res_dir]
if options.non_constant_id: if options.non_constant_id:
package_command.append('--non-constant-id') package_command.append('--non-constant-id')
if options.custom_package: if options.custom_package:
package_command += ['--custom-package', options.custom_package] package_command += ['--custom-package', options.custom_package]
build_utils.CheckOutput(package_command) build_utils.CheckOutput(package_command)
if options.extra_res_packages:
CreateExtraRJavaFiles(
options.R_dir,
build_utils.ParseGypList(options.extra_res_packages),
build_utils.ParseGypList(options.extra_r_text_files))
# Crunch image resources. This shrinks png files and is necessary for 9-patch # Crunch image resources. This shrinks png files and is necessary for 9-patch
# images to display correctly. # images to display correctly.
build_utils.DeleteDirectory(options.crunch_output_dir)
build_utils.MakeDirectory(options.crunch_output_dir) build_utils.MakeDirectory(options.crunch_output_dir)
aapt_cmd = [aapt, aapt_cmd = [aapt,
'crunch', 'crunch',
'-S', options.resource_dir, '-S', options.crunch_input_dir,
'-C', options.crunch_output_dir] '-C', options.crunch_output_dir]
build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail) build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail)
......
...@@ -59,7 +59,7 @@ def CheckOptions(options, parser, required=None): ...@@ -59,7 +59,7 @@ def CheckOptions(options, parser, required=None):
if not required: if not required:
return return
for option_name in required: for option_name in required:
if getattr(options, option_name) is None: if not getattr(options, option_name):
parser.error('--%s is required' % option_name.replace('_', '-')) parser.error('--%s is required' % option_name.replace('_', '-'))
def WriteJson(obj, path, only_if_changed=False): def WriteJson(obj, path, only_if_changed=False):
......
...@@ -156,8 +156,8 @@ ...@@ -156,8 +156,8 @@
'android_manifest': '<(DEPTH)/build/android/AndroidManifest.xml', 'android_manifest': '<(DEPTH)/build/android/AndroidManifest.xml',
# Include the dependencies' res dirs so that references to # Include the dependencies' res dirs so that references to
# resources in dependencies can be resolved. # resources in dependencies can be resolved.
'dependencies_res_dirs': ['<@(res_extra_dirs)', 'all_res_dirs': ['<@(res_input_dirs)',
'>@(dependencies_res_input_dirs)',], '>@(dependencies_res_input_dirs)',],
# Write the inputs list to a file, so that its mtime is updated when # Write the inputs list to a file, so that its mtime is updated when
# the list of inputs changes. # the list of inputs changes.
'inputs_list_file': '>|(java_resources.<(_target_name).gypcmd >@(resource_input_paths) >@(dependencies_res_files))' 'inputs_list_file': '>|(java_resources.<(_target_name).gypcmd >@(resource_input_paths) >@(dependencies_res_files))'
...@@ -177,8 +177,8 @@ ...@@ -177,8 +177,8 @@
'--android-sdk', '<(android_sdk)', '--android-sdk', '<(android_sdk)',
'--android-sdk-tools', '<(android_sdk_tools)', '--android-sdk-tools', '<(android_sdk_tools)',
'--R-dir', '<(R_dir)', '--R-dir', '<(R_dir)',
'--dependencies-res-dirs', '>(dependencies_res_dirs)', '--res-dirs', '>(all_res_dirs)',
'--resource-dir', '<(res_dir)', '--crunch-input-dir', '>(res_dir)',
'--crunch-output-dir', '<(res_crunched_dir)', '--crunch-output-dir', '<(res_crunched_dir)',
'--android-manifest', '<(android_manifest)', '--android-manifest', '<(android_manifest)',
'--non-constant-id', '--non-constant-id',
......
...@@ -433,13 +433,8 @@ ...@@ -433,13 +433,8 @@
], ],
'actions': [ 'actions': [
{ {
'action_name': 'process_resources', 'action_name': 'ant_codegen_<(_target_name)',
'message': 'processing resources for <(_target_name)', 'message': 'Generating R.java for <(_target_name)',
'variables': {
# Write the inputs list to a file, so that its mtime is updated when
# the list of inputs changes.
'inputs_list_file': '>|(apk_codegen.<(_target_name).gypcmd >@(additional_input_paths) >@(resource_input_paths))',
},
'conditions': [ 'conditions': [
['is_test_apk == 1', { ['is_test_apk == 1', {
'variables': { 'variables': {
...@@ -448,9 +443,15 @@ ...@@ -448,9 +443,15 @@
} }
}], }],
], ],
'variables': {
# Write the inputs list to a file, so that its mtime is updated when
# the list of inputs changes.
'inputs_list_file': '>|(apk_codegen.<(_target_name).gypcmd >@(additional_input_paths) >@(resource_input_paths))'
},
'inputs': [ 'inputs': [
'<(DEPTH)/build/android/ant/apk-codegen.xml',
'<(DEPTH)/build/android/gyp/util/build_utils.py', '<(DEPTH)/build/android/gyp/util/build_utils.py',
'<(DEPTH)/build/android/gyp/process_resources.py', '<(DEPTH)/build/android/gyp/ant.py',
'<(android_manifest_path)', '<(android_manifest_path)',
'>@(additional_input_paths)', '>@(additional_input_paths)',
'>@(resource_input_paths)', '>@(resource_input_paths)',
...@@ -460,22 +461,23 @@ ...@@ -460,22 +461,23 @@
'<(codegen_stamp)', '<(codegen_stamp)',
], ],
'action': [ 'action': [
'python', '<(DEPTH)/build/android/gyp/process_resources.py', 'python', '<(DEPTH)/build/android/gyp/ant.py',
'--android-sdk', '<(android_sdk)', '-quiet',
'--android-sdk-tools', '<(android_sdk_tools)', '-DADDITIONAL_RES_DIRS=>(additional_res_dirs)',
'-DADDITIONAL_RES_PACKAGES=>(additional_res_packages)',
'--android-manifest', '<(android_manifest_path)', '-DADDITIONAL_R_TEXT_FILES=>(additional_R_text_files)',
'--dependencies-res-dirs', '>(additional_res_dirs)', '-DANDROID_MANIFEST=<(android_manifest_path)',
'-DANDROID_SDK_JAR=<(android_sdk_jar)',
'--extra-res-packages', '>(additional_res_packages)', '-DANDROID_SDK_ROOT=<(android_sdk_root)',
'--extra-r-text-files', '>(additional_R_text_files)', '-DANDROID_SDK_VERSION=<(android_sdk_version)',
'-DANDROID_SDK_TOOLS=<(android_sdk_tools)',
'--resource-dir', '<(resource_dir)', '-DOUT_DIR=<(intermediate_dir)',
'--crunch-output-dir', '<(intermediate_dir)/res', '-DRESOURCE_DIR=<(resource_dir)',
'--R-dir', '<(intermediate_dir)/gen',
'--stamp', '<(codegen_stamp)', '-DSTAMP=<(codegen_stamp)',
'-Dbasedir=.',
'-buildfile',
'<(DEPTH)/build/android/ant/apk-codegen.xml',
], ],
}, },
{ {
......
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