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

Side by Side Diff: chrome/app/nibs/generate_localizer.py

Issue 2387723002: Test CL to demonstrate GN + hermetic toolchain
Patch Set: more fixes. 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
« no previous file with comments | « chrome/app/nibs/BUILD.gn ('k') | chrome/tools/build/mac/run_verify_order.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Usage: generate_localizer [xib_path] [output_dot_h_path] [output_dot_mm_path] 7 # Usage: generate_localizer [xib_path] [output_dot_h_path] [output_dot_mm_path]
8 # 8 #
9 # Extracts all the localizable strings that start with "^IDS" from the given 9 # Extracts all the localizable strings that start with "^IDS" from the given
10 # xib file, and then generates a localizer to process those strings. 10 # xib file, and then generates a localizer to process those strings.
11 11
12
13 import argparse
14 import logging
12 import os 15 import os
13 import plistlib 16 import plistlib
14 import subprocess 17 import subprocess
15 import sys 18 import sys
16 19
17 generate_localizer = "me" 20 generate_localizer = "me"
18 21
19 localizer_template_h = \ 22 localizer_template_h = \
20 '''// ---------- WARNING ---------- 23 '''// ---------- WARNING ----------
21 // THIS IS A GENERATED FILE, DO NOT EDIT IT DIRECTLY! 24 // THIS IS A GENERATED FILE, DO NOT EDIT IT DIRECTLY!
22 // 25 //
23 // This header includes the table used by ui_localizer.mm. Nothing else should 26 // This header includes the table used by ui_localizer.mm. Nothing else should
24 // be including this file. 27 // be including this file.
25 // 28 //
26 // Generated by %(generate_localizer)s. 29 // Generated by %(generate_localizer)s.
27 // Generated from: 30 // Generated from:
28 // %(xib_files)s 31 // %(xib_files)s
29 // 32 //
30 33
31 #ifndef CHROME_APP_NIBS_LOCALIZER_TABLE_H_ 34 #ifndef CHROME_APP_NIBS_LOCALIZER_TABLE_H_
32 #define CHROME_APP_NIBS_LOCALIZER_TABLE_H_ 35 #define CHROME_APP_NIBS_LOCALIZER_TABLE_H_
33 36
34 static const UILocalizerResourceMap kUIResources[] = { 37 static const UILocalizerResourceMap kUIResources[] = {
35 %(resource_map_list)s }; 38 %(resource_map_list)s };
36 static const size_t kUIResourcesSize = arraysize(kUIResources); 39 static const size_t kUIResourcesSize = arraysize(kUIResources);
37 40
38 #endif // CHROME_APP_NIBS_LOCALIZER_TABLE_H_ 41 #endif // CHROME_APP_NIBS_LOCALIZER_TABLE_H_
39 ''' 42 '''
40 43
41 def xib_localizable_strings(xib_path): 44 def xib_localizable_strings(xib_path, xcode_path):
42 """Runs ibtool to extract the localizable strings data from the xib.""" 45 """Runs ibtool to extract the localizable strings data from the xib."""
43 # Take SDKROOT out of the environment passed to ibtool. ibtool itself has 46 # Take SDKROOT out of the environment passed to ibtool. ibtool itself has
44 # no need for it, but when ibtool runs via xcrun and Xcode isn't aware of 47 # no need for it, but when ibtool runs via xcrun and Xcode isn't aware of
45 # the SDK in use, its presence causes an error. 48 # the SDK in use, its presence causes an error.
46 if 'SDKROOT' in os.environ: 49 if 'SDKROOT' in os.environ:
47 ibtool_env = os.environ.copy() 50 ibtool_env = os.environ.copy()
48 del ibtool_env['SDKROOT'] 51 del ibtool_env['SDKROOT']
49 else: 52 else:
50 ibtool_env = os.environ 53 ibtool_env = os.environ
51 54
52 ibtool_cmd = subprocess.Popen(['xcrun', 'ibtool', 55 command = ['xcrun', 'ibtool']
53 '--localizable-strings', xib_path], 56 if xcode_path:
57 ibtool_env['DEVELOPER_DIR'] = xcode_path
58 command.extend(['--localizable-strings', xib_path])
59 ibtool_cmd = subprocess.Popen(command,
54 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 60 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
55 env=ibtool_env) 61 env=ibtool_env)
56 (cmd_out, cmd_err) = ibtool_cmd.communicate() 62 (cmd_out, cmd_err) = ibtool_cmd.communicate()
57 if ibtool_cmd.returncode: 63 if ibtool_cmd.returncode:
58 sys.stderr.write('%s:0: error: ibtool on "%s" failed (%d):\n%s\n' % 64 sys.stderr.write('%s:0: error: ibtool on "%s" failed (%d):\n%s\n' %
59 (generate_localizer, xib_path, ibtool_cmd.returncode, 65 (generate_localizer, xib_path, ibtool_cmd.returncode,
60 cmd_err)) 66 cmd_err))
61 return None 67 return None
62 return cmd_out 68 return cmd_out
63 69
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 'xib_files': "\n// ".join(xib_paths), 103 'xib_files': "\n// ".join(xib_paths),
98 } 104 }
99 h_file = localizer_template_h % values_dict 105 h_file = localizer_template_h % values_dict
100 return h_file 106 return h_file
101 107
102 108
103 def Main(argv=None): 109 def Main(argv=None):
104 global generate_localizer 110 global generate_localizer
105 generate_localizer = os.path.basename(argv[0]) 111 generate_localizer = os.path.basename(argv[0])
106 112
107 # Args 113 parser = argparse.ArgumentParser(
108 if len(argv) < 3: 114 description='Generates a header file that localizes libs.')
109 sys.stderr.write('%s:0: error: Expected output file and then xibs\n' % 115 parser.add_argument('--output_path', required=True,
110 generate_localizer); 116 help='Path to output header file.')
111 return 1 117 parser.add_argument('--developer_dir', required=False,
112 output_path = argv[1]; 118 help='Path to xcode.')
113 xib_paths = argv[2:] 119 parser.add_argument('xibs', nargs='+',
120 help='A list of xibs to localize')
121 args = parser.parse_args()
122
123 output_path = args.output_path
124 xib_paths = args.xibs
114 125
115 full_constants_list = [] 126 full_constants_list = []
116 for xib_path in xib_paths: 127 for xib_path in xib_paths:
117 # Run ibtool and convert to something Python can deal with 128 # Run ibtool and convert to something Python can deal with
118 plist_string = xib_localizable_strings(xib_path) 129 plist_string = xib_localizable_strings(xib_path, args.developer_dir)
119 if not plist_string: 130 if not plist_string:
120 return 2 131 return 2
121 plist = plistlib.readPlistFromString(plist_string) 132 plist = plistlib.readPlistFromString(plist_string)
122 133
123 # Extract the resource constant strings 134 # Extract the resource constant strings
124 localizable_strings = plist['com.apple.ibtool.document.localizable-strings'] 135 localizable_strings = plist['com.apple.ibtool.document.localizable-strings']
125 constants_list = extract_resource_constants(localizable_strings, xib_path) 136 constants_list = extract_resource_constants(localizable_strings, xib_path)
126 if not constants_list: 137 if not constants_list:
127 sys.stderr.write("%s:0: warning: %s didn't find any resource strings\n" % 138 sys.stderr.write("%s:0: warning: %s didn't find any resource strings\n" %
128 (xib_path, generate_localizer)); 139 (xib_path, generate_localizer));
129 full_constants_list.extend(constants_list) 140 full_constants_list.extend(constants_list)
130 141
131 # Generate our file contents 142 # Generate our file contents
132 h_file_content = \ 143 h_file_content = \
133 generate_file_contents(full_constants_list, xib_paths) 144 generate_file_contents(full_constants_list, xib_paths)
134 145
135 # Write out the file 146 # Write out the file
136 file_fd = open(output_path, 'w') 147 file_fd = open(output_path, 'w')
137 file_fd.write(h_file_content) 148 file_fd.write(h_file_content)
138 file_fd.close() 149 file_fd.close()
139 150
140 return 0 151 return 0
141 152
142 if __name__ == '__main__': 153 if __name__ == '__main__':
143 sys.exit(Main(sys.argv)) 154 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « chrome/app/nibs/BUILD.gn ('k') | chrome/tools/build/mac/run_verify_order.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698