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

Side by Side Diff: build/android/gyp/locale_pak_assets.py

Issue 2345143002: Move language pak files to assets. (Closed)
Patch Set: Added srcjar_deps for chrome_apk targets Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2016 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6 """Creates a srcjar for locale pak file paths.
7
8 Creates a srcjar with a class containing an array of locale pak files so that
9 these assets can be enumerated and extracted as necessary. This is much
10 more efficient than using AssetManager.list().
11
12 The generated class implements:
13 //base/android/java/src/org/chromium/base/LocalePakFiles.java
14
15 Providing access to pak file paths via:
16 public static String[] getFiles()
17 """
18
19 import argparse
20 import collections
21 import os
22 import string
23 import sys
24 import zipfile
25
26 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
27 from pylib.constants import host_paths
28 from util import build_utils
29
30 _CLASSNAME = 'LocalePakFiles'
31 _PACKAGE_BASE = 'org.chromium.'
32 _THIS_FILE = os.path.abspath(__file__)
33
34
35 def _CreateLocalePakFilesJava(pakfiles, package, classname, target):
36 """Generate the java file contents for the locale pak file class."""
37 file_tmpl = string.Template("""
38 // Copyright 2016 The Chromium Authors. All rights reserved.
39 // Use of this source code is governed by a BSD-style license that can be
40 // found in the LICENSE file.
41
42 // This file is generated by:
43 // ${THIS_FILE}
44 // From target:
45 // ${TARGET}
46
47 package ${PACKAGE};
48
49 public class LocalePakFiles {
50 private static String[] pakFiles = {${PAKFILES}};
51
52 public static String[] getFiles() {
53 return pakFiles;
54 }
55 }
56 """)
57
58 values = {
59 'TARGET': target,
60 'PACKAGE': package,
61 'CLASSNAME': classname,
62 'THIS_FILE': os.path.relpath(_THIS_FILE, host_paths.DIR_SOURCE_ROOT),
63 'PAKFILES': ', '.join('"%s"' % p for p in pakfiles),
64 }
65
66 return file_tmpl.substitute(values)
67
68
69 def _WriteJarOutput(output_path, in_zip_path, data):
70 """Write file data to a srcjar."""
71 path = os.path.dirname(output_path)
72 if path and not os.path.exists(path):
73 os.makedirs(path)
74 with zipfile.ZipFile(output_path, 'w') as srcjar:
75 build_utils.AddToZipHermetic(srcjar, in_zip_path, data=data)
76
77
78 def main():
79 parser = argparse.ArgumentParser()
80 build_utils.AddDepfileOption(parser)
81 parser.add_argument('--locale-paks', required=True,
82 help='List of pak file paths to be added to srcjar')
83 parser.add_argument('--srcjar', required=True, help='Path to output srcjar')
84 parser.add_argument('--target', required=True, help='Target invoking script')
85 parser.add_argument('--package-suffix', required=True,
86 help='Specifies package suffix for generated Java file. The generated '
87 'file will reside in org.chromium.PACKAGE_SUFFIX')
88
89 args = parser.parse_args()
90
91 sources = build_utils.ParseGnList(args.locale_paks)
92
93 if args.depfile:
94 build_utils.WriteDepfile(args.depfile, args.srcjar, sources)
agrieve 2016/09/21 20:34:02 nit: don't pass sources into WriteDepfile. GN alre
estevenson 2016/09/21 22:35:18 Done.
95
96 pakfiles = [os.path.basename(s) for s in sources]
97 package = _PACKAGE_BASE + args.package_suffix
98 srcjar_contents = _CreateLocalePakFilesJava(
99 pakfiles, package, _CLASSNAME, args.target)
100 in_zip_path = os.path.join(
101 package.replace('.', '/'), _CLASSNAME + '.java')
102 _WriteJarOutput(args.srcjar, in_zip_path, srcjar_contents)
103
104
105 if __name__ == '__main__':
106 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698