Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1898)

Unified Diff: build/android/gyp/process_resources.py

Issue 106173002: Mirror images for RTL languages at build time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/gyp/mirror_images.py ('k') | build/install-build-deps-android.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/process_resources.py
diff --git a/build/android/gyp/process_resources.py b/build/android/gyp/process_resources.py
index bf1317554e798209838650852bce3a8e90fcbea6..48e4b49dfd71a6539e64b406cf6de0ad16b55b7f 100755
--- a/build/android/gyp/process_resources.py
+++ b/build/android/gyp/process_resources.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Copyright 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -10,8 +10,10 @@ import optparse
import os
import shlex
import shutil
+import tempfile
from util import build_utils
+import mirror_images
def ParseArgs():
"""Parses command line options.
@@ -26,10 +28,15 @@ def ParseArgs():
parser.add_option('--R-dir', help='directory to hold generated R.java')
parser.add_option('--res-dirs',
help='directories containing resources to be packaged')
- parser.add_option('--crunch-input-dir',
- help='directory containing images to be crunched')
+ parser.add_option('--image-input-dir', help='directory containing images to '
+ 'be crunched and possibly mirrored.')
parser.add_option('--crunch-output-dir',
help='directory to hold crunched resources')
+ parser.add_option('--mirror-config', help='config file specifying which '
+ 'images should be mirrored. Images will be mirrored only '
+ 'if this is provided.')
+ parser.add_option('--mirror-output-dir',
+ help='directory where mirrored images should be saved')
parser.add_option('--non-constant-id', action='store_true')
parser.add_option('--custom-package', help='Java package for R.java')
parser.add_option('--android-manifest', help='AndroidManifest.xml path')
@@ -43,9 +50,13 @@ def ParseArgs():
if args:
parser.error('No positional arguments should be given.')
+ if (options.mirror_config is None) != (options.mirror_output_dir is None):
+ parser.error('--mirror-config and --mirror-output-dir must both be present '
+ 'or neither present.')
+
# Check that required options have been provided.
required_options = ('android_sdk', 'android_sdk_tools', 'R_dir',
- 'res_dirs', 'crunch_input_dir', 'crunch_output_dir')
+ 'res_dirs', 'image_input_dir', 'crunch_output_dir')
build_utils.CheckOptions(options, parser, required=required_options)
return options
@@ -77,6 +88,15 @@ def MoveImagesToNonMdpiFolders(res_root):
shutil.move(src_file, dst_file)
+def CrunchImages(aapt, input_res_dir, output_res_dir):
+ build_utils.MakeDirectory(output_res_dir)
+ aapt_cmd = [aapt,
+ 'crunch',
+ '-S', input_res_dir,
+ '-C', output_res_dir]
+ build_utils.CheckOutput(aapt_cmd, fail_if_stderr=True)
+
+
def main():
options = ParseArgs()
android_jar = os.path.join(options.android_sdk, 'android.jar')
@@ -106,16 +126,22 @@ def main():
package_command += ['--custom-package', options.custom_package]
build_utils.CheckOutput(package_command)
+ # Mirror images if requested.
+ if options.mirror_config:
+ # Mirrored images are generated into a temp dir. Once these images are
+ # crunched, they'll go in the desired mirror output dir.
+ mirrored_uncrunched_dir = tempfile.mkdtemp()
+ try:
+ mirror_images.main(['--config', options.mirror_config,
+ '--input-res-dir', options.image_input_dir,
+ '--output-res-dir', mirrored_uncrunched_dir])
+ CrunchImages(aapt, mirrored_uncrunched_dir, options.mirror_output_dir)
+ finally:
+ shutil.rmtree(mirrored_uncrunched_dir)
+
# Crunch image resources. This shrinks png files and is necessary for 9-patch
# images to display correctly.
- build_utils.MakeDirectory(options.crunch_output_dir)
- aapt_cmd = [aapt,
- 'crunch',
- '-S', options.crunch_input_dir,
- '-C', options.crunch_output_dir]
- build_utils.CheckOutput(aapt_cmd, fail_if_stderr=True)
-
- MoveImagesToNonMdpiFolders(options.crunch_output_dir)
+ CrunchImages(aapt, options.image_input_dir, options.crunch_output_dir)
if options.stamp:
build_utils.Touch(options.stamp)
« no previous file with comments | « build/android/gyp/mirror_images.py ('k') | build/install-build-deps-android.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698