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

Side by Side Diff: grit/tool/build.py

Issue 9802029: Make first_ids_file an optional attribute of the .grd file. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''The 'grit build' tool along with integration for this tool with the 6 '''The 'grit build' tool along with integration for this tool with the
7 SCons build system. 7 SCons build system.
8 ''' 8 '''
9 9
10 import filecmp 10 import filecmp
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 -o OUTPUTDIR Specify what directory output paths are relative to. 50 -o OUTPUTDIR Specify what directory output paths are relative to.
51 Defaults to the current directory. 51 Defaults to the current directory.
52 52
53 -D NAME[=VAL] Specify a C-preprocessor-like define NAME with optional 53 -D NAME[=VAL] Specify a C-preprocessor-like define NAME with optional
54 value VAL (defaults to 1) which will be used to control 54 value VAL (defaults to 1) which will be used to control
55 conditional inclusion of resources. 55 conditional inclusion of resources.
56 56
57 -E NAME=VALUE Set environment variable NAME to VALUE (within grit). 57 -E NAME=VALUE Set environment variable NAME to VALUE (within grit).
58 58
59 -f FIRSTIDFILE Path to a python file that specifies the first id of 59 -f FIRSTIDSFILE Path to a python file that specifies the first id of
60 value to use for resources. Defaults to the file 60 value to use for resources. A non-empty value here will
61 resources_ids next to grit.py. Set to an empty string 61 override the value specified in the <grit> node's
62 if you don't want to use a first id file. 62 first_ids_file.
63 63
64 -w WHITELISTFILE Path to a file containing the string names of the 64 -w WHITELISTFILE Path to a file containing the string names of the
65 resources to include. Anything not listed is dropped. 65 resources to include. Anything not listed is dropped.
66 66
67 67
68 Conditional inclusion of resources only affects the output of files which 68 Conditional inclusion of resources only affects the output of files which
69 control which resources get linked into a binary, e.g. it affects .rc files 69 control which resources get linked into a binary, e.g. it affects .rc files
70 meant for compilation but it does not affect resource header files (that define 70 meant for compilation but it does not affect resource header files (that define
71 IDs). This helps ensure that values of IDs stay the same, that all messages 71 IDs). This helps ensure that values of IDs stay the same, that all messages
72 are exported to translation interchange files (e.g. XMB files), etc. 72 are exported to translation interchange files (e.g. XMB files), etc.
73 ''' 73 '''
74 74
75 def ShortDescription(self): 75 def ShortDescription(self):
76 return 'A tool that builds RC files for compilation.' 76 return 'A tool that builds RC files for compilation.'
77 77
78 def Run(self, opts, args): 78 def Run(self, opts, args):
79 self.output_directory = '.' 79 self.output_directory = '.'
80 first_id_filename = None 80 first_ids_file = None
81 whitelist_filenames = [] 81 whitelist_filenames = []
82 (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:') 82 (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:')
83 for (key, val) in own_opts: 83 for (key, val) in own_opts:
84 if key == '-o': 84 if key == '-o':
85 self.output_directory = val 85 self.output_directory = val
86 elif key == '-D': 86 elif key == '-D':
87 name, val = ParseDefine(val) 87 name, val = ParseDefine(val)
88 self.defines[name] = val 88 self.defines[name] = val
89 elif key == '-E': 89 elif key == '-E':
90 (env_name, env_value) = val.split('=') 90 (env_name, env_value) = val.split('=')
91 os.environ[env_name] = env_value 91 os.environ[env_name] = env_value
92 elif key == '-f': 92 elif key == '-f':
93 first_id_filename = val 93 # TODO(joi@chromium.org): Remove this override once change
94 # lands in WebKit.grd to specify the first_ids_file in the
95 # .grd itself.
tony 2012/03/28 17:31:56 I like the command line flag. In Chromium, if some
Jói 2012/03/29 11:36:15 I'd prefer to have just one way to do things, but
96 first_ids_file = val
94 elif key == '-w': 97 elif key == '-w':
95 whitelist_filenames.append(val) 98 whitelist_filenames.append(val)
96 99
97 if len(args): 100 if len(args):
98 print "This tool takes no tool-specific arguments." 101 print "This tool takes no tool-specific arguments."
99 return 2 102 return 2
100 self.SetOptions(opts) 103 self.SetOptions(opts)
101 if self.scons_targets: 104 if self.scons_targets:
102 self.VerboseOut('Using SCons targets to identify files to output.\n') 105 self.VerboseOut('Using SCons targets to identify files to output.\n')
103 else: 106 else:
104 self.VerboseOut('Output directory: %s (absolute path: %s)\n' % 107 self.VerboseOut('Output directory: %s (absolute path: %s)\n' %
105 (self.output_directory, 108 (self.output_directory,
106 os.path.abspath(self.output_directory))) 109 os.path.abspath(self.output_directory)))
107 110
108 if whitelist_filenames: 111 if whitelist_filenames:
109 self.whitelist_names = set() 112 self.whitelist_names = set()
110 for whitelist_filename in whitelist_filenames: 113 for whitelist_filename in whitelist_filenames:
111 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); 114 self.VerboseOut('Using whitelist: %s\n' % whitelist_filename);
112 whitelist_file = open(whitelist_filename) 115 whitelist_file = open(whitelist_filename)
113 self.whitelist_names |= set(whitelist_file.read().strip().split('\n')) 116 self.whitelist_names |= set(whitelist_file.read().strip().split('\n'))
114 whitelist_file.close() 117 whitelist_file.close()
115 118
116 self.res = grd_reader.Parse(opts.input, first_id_filename=first_id_filename, 119 self.res = grd_reader.Parse(opts.input,
117 debug=opts.extra_verbose, defines=self.defines) 120 debug=opts.extra_verbose,
121 first_ids_file=first_ids_file,
122 defines=self.defines)
118 self.res.RunGatherers(recursive = True) 123 self.res.RunGatherers(recursive = True)
119 self.Process() 124 self.Process()
120 return 0 125 return 0
121 126
122 def __init__(self): 127 def __init__(self):
123 # Default file-creation function is built-in file(). Only done to allow 128 # Default file-creation function is built-in file(). Only done to allow
124 # overriding by unit test. 129 # overriding by unit test.
125 self.fo_create = file 130 self.fo_create = file
126 131
127 # key/value pairs of C-preprocessor like defines that are used for 132 # key/value pairs of C-preprocessor like defines that are used for
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 296
292 # Print out any fallback warnings, and missing translation errors, and 297 # Print out any fallback warnings, and missing translation errors, and
293 # exit with an error code if there are missing translations in a non-pseudo 298 # exit with an error code if there are missing translations in a non-pseudo
294 # and non-official build. 299 # and non-official build.
295 warnings = (self.res.UberClique().MissingTranslationsReport(). 300 warnings = (self.res.UberClique().MissingTranslationsReport().
296 encode('ascii', 'replace')) 301 encode('ascii', 'replace'))
297 if warnings and self.defines.get('_google_chrome', False): 302 if warnings and self.defines.get('_google_chrome', False):
298 print warnings 303 print warnings
299 if self.res.UberClique().HasMissingTranslations(): 304 if self.res.UberClique().HasMissingTranslations():
300 sys.exit(-1) 305 sys.exit(-1)
OLDNEW
« grit/node/misc.py ('K') | « grit/node/misc.py ('k') | grit_info.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698