示例#1
0
def _ParseRcFlags(flags):
    """Gets a mapping of defines.

  Args:
    flags: env['RCFLAGS']; the input defines.

  Returns:
    A tuple of (defines, res_file):
      defines: A mapping of {name: val}
      res_file: None, or the specified res file for static file dependencies.
  """
    from grit import util

    defines = {}
    res_file = None
    # Get the CPP defines from the environment.
    res_flag = '--res_file='
    for flag in flags:
        if flag.startswith(res_flag):
            res_file = flag[len(res_flag):]
            continue
        if flag.startswith('/D'):
            flag = flag[2:]
        name, val = util.ParseDefine(flag)
        # Only apply to first instance of a given define
        if name not in defines:
            defines[name] = val
    return (defines, res_file)
示例#2
0
文件: resize.py 项目: sz21/WTL-DUI
  def Run(self, opts, args):
    self.SetOptions(opts)

    own_opts, args = getopt.getopt(args, 'l:f:c:D:')
    for key, val in own_opts:
      if key == '-l':
        self.SetLanguage(val)
      if key == '-f':
        self.base_folder = val
      if key == '-c':
        self.codepage_number = int(val)
        self.codepage_number_specified_explicitly = True
      if key == '-D':
        name, val = util.ParseDefine(val)
        self.defines[name] = val

    res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose)
    res_tree.OnlyTheseTranslations([self.lang])
    res_tree.RunGatherers(True)

    # Dialog IDs are either explicitly listed, or we output all dialogs from the
    # .grd file
    dialog_ids = args
    if not len(dialog_ids):
      for node in res_tree:
        if node.name == 'structure' and node.attrs['type'] == 'dialog':
          dialog_ids.append(node.attrs['name'])

    self.Process(res_tree, dialog_ids)
示例#3
0
def DoMain(argv):
  os.environ['cwd'] = os.getcwd()

  parser = optparse.OptionParser()
  parser.add_option("--inputs", action="store_true", dest="inputs")
  parser.add_option("--outputs", action="store_true", dest="outputs")
  parser.add_option("-D", action="append", dest="defines", default=[])
  # grit build also supports '-E KEY=VALUE', support that to share command
  # line flags.
  parser.add_option("-E", action="append", dest="build_env", default=[])
  parser.add_option("-p", action="store", dest="predetermined_ids_file")
  parser.add_option("-w", action="append", dest="allowlist_files", default=[])
  parser.add_option("-f", dest="ids_file", default="")
  parser.add_option("-t", dest="target_platform", default=None)

  options, args = parser.parse_args(argv)

  defines = {}
  for define in options.defines:
    name, val = util.ParseDefine(define)
    defines[name] = val

  for env_pair in options.build_env:
    (env_name, env_value) = env_pair.split('=', 1)
    os.environ[env_name] = env_value

  if options.inputs:
    if len(args) > 1:
      raise WrongNumberOfArguments("Expected 0 or 1 arguments for --inputs.")

    inputs = []
    if len(args) == 1:
      filename = args[0]
      inputs = Inputs(filename, defines, options.ids_file,
                      options.target_platform)

    # Add in the grit source files.  If one of these change, we want to re-run
    # grit.
    inputs.extend(GritSourceFiles())
    inputs = [f.replace('\\', '/') for f in inputs]

    if len(args) == 1:
      # Include grd file as second input (works around gyp expecting it).
      inputs.insert(1, args[0])
    if options.allowlist_files:
      inputs.extend(options.allowlist_files)
    return '\n'.join(inputs)
  elif options.outputs:
    if len(args) != 2:
      raise WrongNumberOfArguments(
          "Expected exactly 2 arguments for --outputs.")

    prefix, filename = args
    outputs = [posixpath.join(prefix, f)
               for f in Outputs(filename, defines,
                                options.ids_file, options.target_platform)]
    return '\n'.join(outputs)
  else:
    raise WrongNumberOfArguments("Expected --inputs or --outputs.")
示例#4
0
    def Run(self, opts, args):
        self.SetOptions(opts)

        limit_file = None
        limit_is_grd = False
        limit_file_dir = None
        limit_untranslated_lang = False
        own_opts, args = getopt.getopt(args, 'l:D:E:ihL')
        for key, val in own_opts:
            if key == '-l':
                limit_file = open(val, 'r')
                limit_file_dir = util.dirname(val)
                if not len(limit_file_dir):
                    limit_file_dir = '.'
                limit_is_grd = os.path.splitext(val)[1] == '.grd'
            elif key == '-i':
                self.format = self.FORMAT_IDS_ONLY
            elif key == '-L':
                limit_untranslated_lang = args[1:] if len(args) > 1 else False
            elif key == '-D':
                name, val = util.ParseDefine(val)
                self.defines[name] = val
            elif key == '-E':
                (env_name, env_value) = val.split('=', 1)
                os.environ[env_name] = env_value
        if not len(args) == 1 and not limit_untranslated_lang:
            print(
                'grit xmb takes exactly one argument, the path to the XMB file '
                'to output.')
            return 2

        xmb_path = args[0]
        res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose)
        res_tree.SetOutputLanguage('en')
        res_tree.SetDefines(self.defines)
        res_tree.OnlyTheseTranslations(limit_untranslated_lang or [])
        res_tree.RunGatherers()

        lang_jobs = []
        xmb_prefix, ext = os.path.splitext(xmb_path)
        for lang in limit_untranslated_lang or []:
            lang_jobs.append((lang, xmb_prefix + "_" + lang + ext))

        for lang, cur_xmb_path in lang_jobs or [(None, xmb_path)]:
            try:
                os.makedirs(os.path.dirname(cur_xmb_path))
            except:
                pass
            with open(cur_xmb_path, 'wb') as output_file:
                self.Process(res_tree,
                             output_file,
                             limit_file,
                             limit_is_grd,
                             limit_file_dir,
                             missing_translate_for_lang=lang)
        if limit_file:
            limit_file.close()
        print "Wrote %s" % xmb_path
示例#5
0
    def Run(self, opts, args):
        self.output_directory = '.'
        first_ids_file = None
        whitelist_filenames = []
        target_platform = None
        (own_opts, args) = getopt.getopt(args, 'o:D:E:f:w:t:')
        for (key, val) in own_opts:
            if key == '-o':
                self.output_directory = val
            elif key == '-D':
                name, val = util.ParseDefine(val)
                self.defines[name] = val
            elif key == '-E':
                (env_name, env_value) = val.split('=', 1)
                os.environ[env_name] = env_value
            elif key == '-f':
                # TODO([email protected]): Remove this override once change
                # lands in WebKit.grd to specify the first_ids_file in the
                # .grd itself.
                first_ids_file = val
            elif key == '-w':
                whitelist_filenames.append(val)
            elif key == '-t':
                target_platform = val

        if len(args):
            print 'This tool takes no tool-specific arguments.'
            return 2
        self.SetOptions(opts)
        if self.scons_targets:
            self.VerboseOut(
                'Using SCons targets to identify files to output.\n')
        else:
            self.VerboseOut('Output directory: %s (absolute path: %s)\n' %
                            (self.output_directory,
                             os.path.abspath(self.output_directory)))

        if whitelist_filenames:
            self.whitelist_names = set()
            for whitelist_filename in whitelist_filenames:
                self.VerboseOut('Using whitelist: %s\n' % whitelist_filename)
                whitelist_contents = util.ReadFile(whitelist_filename,
                                                   util.RAW_TEXT)
                self.whitelist_names.update(
                    whitelist_contents.strip().split('\n'))

        self.res = grd_reader.Parse(opts.input,
                                    debug=opts.extra_verbose,
                                    first_ids_file=first_ids_file,
                                    defines=self.defines,
                                    target_platform=target_platform)
        # Set an output context so that conditionals can use defines during the
        # gathering stage; we use a dummy language here since we are not outputting
        # a specific language.
        self.res.SetOutputLanguage('en')
        self.res.RunGatherers()
        self.Process()
        return 0
示例#6
0
def DoMain(argv):
    parser = optparse.OptionParser()
    parser.add_option("--inputs", action="store_true", dest="inputs")
    parser.add_option("--outputs", action="store_true", dest="outputs")
    parser.add_option("-D", action="append", dest="defines", default=[])
    # grit build also supports '-E KEY=VALUE', support that to share command
    # line flags.
    parser.add_option("-E", action="append", dest="build_env", default=[])
    parser.add_option("-w",
                      action="append",
                      dest="whitelist_files",
                      default=[])

    options, args = parser.parse_args(argv)

    defines = {}
    for define in options.defines:
        name, val = util.ParseDefine(define)
        defines[name] = val

    if options.inputs:
        if len(args) > 1:
            raise WrongNumberOfArguments(
                "Expected 0 or 1 arguments for --inputs.")

        inputs = []
        if len(args) == 1:
            filename = args[0]
            inputs = Inputs(filename, defines)

        # Add in the grit source files.  If one of these change, we want to re-run
        # grit.
        inputs.extend(GritSourceFiles())
        inputs = [f.replace('\\', '/') for f in inputs]

        if len(args) == 1:
            # Include grd file as second input (works around gyp expecting it).
            inputs = [inputs[0], args[0]] + inputs[1:]
        if options.whitelist_files:
            inputs.extend(options.whitelist_files)
        return '\n'.join(inputs)
    elif options.outputs:
        if len(args) != 2:
            raise WrongNumberOfArguments(
                "Expected exactly 2 arguments for --ouputs.")

        prefix, filename = args
        outputs = [
            posixpath.join(prefix, f) for f in Outputs(filename, defines)
        ]
        return '\n'.join(outputs)
    else:
        raise WrongNumberOfArguments("Expected --inputs or --outputs.")
示例#7
0
    def Run(self, opts, args):
        os.environ['cwd'] = os.getcwd()

        self.SetOptions(opts)

        limit_file = None
        limit_is_grd = False
        limit_file_dir = None
        own_opts, args = getopt.getopt(args, 'l:D:ih', ('help', ))
        for key, val in own_opts:
            if key == '-l':
                limit_file = open(val, 'r')
                limit_file_dir = util.dirname(val)
                if not len(limit_file_dir):
                    limit_file_dir = '.'
                limit_is_grd = os.path.splitext(val)[1] == '.grd'
            elif key == '-i':
                self.format = self.FORMAT_IDS_ONLY
            elif key == '-D':
                name, val = util.ParseDefine(val)
                self.defines[name] = val
            elif key == '-E':
                (env_name, env_value) = val.split('=', 1)
                os.environ[env_name] = env_value
            elif key == '--help':
                self.ShowUsage()
                sys.exit(0)
        if not len(args) == 1:
            print(
                'grit xmb takes exactly one argument, the path to the XMB file '
                'to output.')
            return 2

        xmb_path = args[0]
        res_tree = grd_reader.Parse(opts.input,
                                    debug=opts.extra_verbose,
                                    defines=self.defines)
        res_tree.SetOutputLanguage('en')
        res_tree.SetDefines(self.defines)
        res_tree.OnlyTheseTranslations([])
        res_tree.RunGatherers()

        with open(xmb_path, 'wb') as output_file:
            self.Process(res_tree, output_file, limit_file, limit_is_grd,
                         limit_file_dir)
        if limit_file:
            limit_file.close()
        print("Wrote %s" % xmb_path)
示例#8
0
    def Run(self, opts, args):
        self.SetOptions(opts)

        limit_file = None
        limit_is_grd = False
        limit_file_dir = None
        output_format = 'xtb'
        include_all = False
        output_only_translated = False
        own_opts, args = getopt.getopt(args, 'D:E:tpgAT')
        for key, val in own_opts:
            if key == '-D':
                name, val = util.ParseDefine(val)
                self.defines[name] = val
            elif key == '-E':
                (env_name, env_value) = val.split('=', 1)
                os.environ[env_name] = env_value
            elif key == '-t':
                output_format = 'text'
            elif key == '-p':
                output_format = 'pot'
            elif key == '-g':
                output_format = 'gengo'
            elif key == '-A':
                self.include_all = True
            elif key == '-T':
                self.output_only_translated = True
        if not len(args) == 2:
            print('grit xtb takes exactly two arguments, LANG and OUTPUTPATH')
            return 2

        lang = args[0]
        xmb_path = args[1]
        res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose)
        res_tree.SetOutputLanguage(lang)
        res_tree.SetDefines(self.defines)
        res_tree.OnlyTheseTranslations([lang])
        res_tree.RunGatherers()

        with open(xmb_path, 'wb') as output_file:
            self.Process(lang, res_tree, output_file, output_format)
        if limit_file:
            limit_file.close()
        print "Wrote %s" % xmb_path
示例#9
0
    def Run(self, opts, args):
        self.SetOptions(opts)

        own_opts, args = getopt.getopt(args, 'D:h')
        for key, val in own_opts:
            if key == '-D':
                name, val = util.ParseDefine(val)
                self.defines[name] = val
            elif key == '-E':
                (env_name, env_value) = val.split('=', 1)
                os.environ[env_name] = env_value

        res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose)
        res_tree.SetOutputLanguage('en')
        res_tree.SetDefines(self.defines)
        res_tree.RunGatherers()

        self.Process(res_tree)
        print "done"
示例#10
0
  def Run(self, opts, args):
    os.environ['cwd'] = os.getcwd()
    self.output_directory = '.'
    first_ids_file = None
    predetermined_ids_file = None
    whitelist_filenames = []
    assert_output_files = []
    target_platform = None
    depfile = None
    depdir = None
    whitelist_support = False
    write_only_new = False
    depend_on_stamp = False
    js_minifier = None
    replace_ellipsis = True
    (own_opts, args) = getopt.getopt(args, 'a:p:o:D:E:f:w:t:',
        ('depdir=','depfile=','assert-file-list=',
         'help',
         'output-all-resource-defines',
         'no-output-all-resource-defines',
         'no-replace-ellipsis',
         'depend-on-stamp',
         'js-minifier=',
         'write-only-new=',
         'whitelist-support'))
    for (key, val) in own_opts:
      if key == '-a':
        assert_output_files.append(val)
      elif key == '--assert-file-list':
        with open(val) as f:
          assert_output_files += f.read().splitlines()
      elif key == '-o':
        self.output_directory = val
      elif key == '-D':
        name, val = util.ParseDefine(val)
        self.defines[name] = val
      elif key == '-E':
        (env_name, env_value) = val.split('=', 1)
        os.environ[env_name] = env_value
      elif key == '-f':
        # TODO([email protected]): Remove this override once change
        # lands in WebKit.grd to specify the first_ids_file in the
        # .grd itself.
        first_ids_file = val
      elif key == '-w':
        whitelist_filenames.append(val)
      elif key == '--no-replace-ellipsis':
        replace_ellipsis = False
      elif key == '-p':
        predetermined_ids_file = val
      elif key == '-t':
        target_platform = val
      elif key == '--depdir':
        depdir = val
      elif key == '--depfile':
        depfile = val
      elif key == '--write-only-new':
        write_only_new = val != '0'
      elif key == '--depend-on-stamp':
        depend_on_stamp = True
      elif key == '--js-minifier':
        js_minifier = val
      elif key == '--whitelist-support':
        whitelist_support = True
      elif key == '--help':
        self.ShowUsage()
        sys.exit(0)

    if len(args):
      print 'This tool takes no tool-specific arguments.'
      return 2
    self.SetOptions(opts)
    if self.scons_targets:
      self.VerboseOut('Using SCons targets to identify files to output.\n')
    else:
      self.VerboseOut('Output directory: %s (absolute path: %s)\n' %
                      (self.output_directory,
                       os.path.abspath(self.output_directory)))

    if whitelist_filenames:
      self.whitelist_names = set()
      for whitelist_filename in whitelist_filenames:
        self.VerboseOut('Using whitelist: %s\n' % whitelist_filename);
        whitelist_contents = util.ReadFile(whitelist_filename, util.RAW_TEXT)
        self.whitelist_names.update(whitelist_contents.strip().split('\n'))

    if js_minifier:
      minifier.SetJsMinifier(js_minifier)

    self.write_only_new = write_only_new

    self.res = grd_reader.Parse(opts.input,
                                debug=opts.extra_verbose,
                                first_ids_file=first_ids_file,
                                predetermined_ids_file=predetermined_ids_file,
                                defines=self.defines,
                                target_platform=target_platform)

    # Set an output context so that conditionals can use defines during the
    # gathering stage; we use a dummy language here since we are not outputting
    # a specific language.
    self.res.SetOutputLanguage('en')
    self.res.SetWhitelistSupportEnabled(whitelist_support)
    self.res.RunGatherers()

    # Replace ... with the single-character version. http://crbug.com/621772
    if replace_ellipsis:
      for node in self.res:
        if isinstance(node, message.MessageNode):
          node.SetReplaceEllipsis(True)

    self.Process()

    if assert_output_files:
      if not self.CheckAssertedOutputFiles(assert_output_files):
        return 2

    if depfile and depdir:
      self.GenerateDepfile(depfile, depdir, first_ids_file, depend_on_stamp)

    return 0
示例#11
0
def DoMain(argv):
    argparser = argparse.ArgumentParser()

    action = argparser.add_mutually_exclusive_group(required=True)
    action.add_argument("--build",
                        action="store_const",
                        dest="action",
                        const=WRITE_GRD_FILES)
    action.add_argument("--list-main-sources",
                        action="store_const",
                        dest="action",
                        const=PRINT_MAIN_SOURCES)
    action.add_argument("--list-secondary-sources",
                        action="store_const",
                        dest="action",
                        const=PRINT_SECONDARY_SOURCES)
    action.add_argument("--list-main-resources",
                        action="store_const",
                        dest="action",
                        const=PRINT_MAIN_RESOURCES)
    action.add_argument("--list-secondary-resources",
                        action="store_const",
                        dest="action",
                        const=PRINT_SECONDARY_RESOURCES)
    action.add_argument("--list-sources",
                        action="store_const",
                        dest="action",
                        const=PRINT_TARGET_SOURCES)
    action.add_argument("--list-resources",
                        action="store_const",
                        dest="action",
                        const=PRINT_TARGET_RESOURCES)
    action.add_argument("--list-update-sources",
                        action="store_const",
                        dest="action",
                        const=PRINT_SPECIAL_UPDATE_SOURCES)
    action.add_argument("--list-update-targets",
                        action="store_const",
                        dest="action",
                        const=PRINT_SPECIAL_UPDATE_TARGETS)
    action.add_argument("--list-all",
                        action="store_const",
                        dest="action",
                        const=PRINT_ALL)

    argparser.add_argument("-D", action="append", dest="defines")
    argparser.add_argument("-E", action="append", dest="build_env")
    argparser.add_argument("-t", default=None, dest="target_platform")
    argparser.add_argument("-f",
                           default="GRIT_DIR/../gritsettings/resource_ids",
                           dest="idsfile")
    argparser.add_argument("--root", default=None)
    argparser.add_argument("--updatejson", default=None)
    argparser.add_argument("--translation", default=None)
    argparser.add_argument("--output-file-name", default=None)

    argparser.add_argument("main_resource")
    argparser.add_argument("secondary_resource")
    argparser.add_argument("target_dir")

    options = argparser.parse_args(argv)

    # Copied from chromium
    # Copyright (c) 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.
    defines = {}
    for define in options.defines or []:
        name, val = util.ParseDefine(define)
        defines[name] = val

    for env_pair in options.build_env or []:
        (env_name, env_value) = env_pair.split('=', 1)
        os.environ[env_name] = env_value
    # End copies

    params = dict(
        defines=defines,
        target_platform=options.target_platform,
        first_ids_file=None,  #options.idsfile,
    )

    if options.action in [WRITE_GRD_FILES, PRINT_ALL]:
        output = merge_resource(options.main_resource,
                                options.secondary_resource,
                                options.target_dir,
                                action=options.action,
                                params=params,
                                json_file=options.updatejson,
                                root_dir=options.root,
                                translation_dir=options.translation,
                                output_file_name=options.output_file_name)
    else:
        output = perform_list_actions(
            options.action, options.target_dir,
            os.path.dirname(options.main_resource),
            os.path.dirname(options.secondary_resource))
    return "\n".join(output) if output else ""
示例#12
0
文件: build.py 项目: DrovioHQ/Qt
    def Run(self, opts, args):
        self.output_directory = '.'
        first_ids_file = None
        whitelist_filenames = []
        assert_output_files = []
        target_platform = None
        depfile = None
        depdir = None
        rc_header_format = None
        output_all_resource_defines = None
        write_only_new = False
        depend_on_stamp = False
        (own_opts, args) = getopt.getopt(
            args, 'a:o:D:E:f:w:t:h:',
            ('depdir=', 'depfile=', 'assert-file-list=',
             'output-all-resource-defines', 'no-output-all-resource-defines',
             'depend-on-stamp', 'write-only-new='))
        for (key, val) in own_opts:
            if key == '-a':
                assert_output_files.append(val)
            elif key == '--assert-file-list':
                with open(val) as f:
                    assert_output_files += f.read().splitlines()
            elif key == '-o':
                self.output_directory = val
            elif key == '-D':
                name, val = util.ParseDefine(val)
                self.defines[name] = val
            elif key == '-E':
                (env_name, env_value) = val.split('=', 1)
                os.environ[env_name] = env_value
            elif key == '-f':
                # TODO([email protected]): Remove this override once change
                # lands in WebKit.grd to specify the first_ids_file in the
                # .grd itself.
                first_ids_file = val
            elif key == '-w':
                whitelist_filenames.append(val)
            elif key == '--output-all-resource-defines':
                output_all_resource_defines = True
            elif key == '--no-output-all-resource-defines':
                output_all_resource_defines = False
            elif key == '-t':
                target_platform = val
            elif key == '-h':
                rc_header_format = val
            elif key == '--depdir':
                depdir = val
            elif key == '--depfile':
                depfile = val
            elif key == '--write-only-new':
                write_only_new = val != '0'
            elif key == '--depend-on-stamp':
                depend_on_stamp = True

        if len(args):
            print 'This tool takes no tool-specific arguments.'
            return 2
        self.SetOptions(opts)
        if self.scons_targets:
            self.VerboseOut(
                'Using SCons targets to identify files to output.\n')
        else:
            self.VerboseOut('Output directory: %s (absolute path: %s)\n' %
                            (self.output_directory,
                             os.path.abspath(self.output_directory)))

        if whitelist_filenames:
            self.whitelist_names = set()
            for whitelist_filename in whitelist_filenames:
                self.VerboseOut('Using whitelist: %s\n' % whitelist_filename)
                whitelist_contents = util.ReadFile(whitelist_filename,
                                                   util.RAW_TEXT)
                self.whitelist_names.update(
                    whitelist_contents.strip().split('\n'))

        self.write_only_new = write_only_new

        self.res = grd_reader.Parse(opts.input,
                                    debug=opts.extra_verbose,
                                    first_ids_file=first_ids_file,
                                    defines=self.defines,
                                    target_platform=target_platform)

        # If the output_all_resource_defines option is specified, override the value
        # found in the grd file.
        if output_all_resource_defines is not None:
            self.res.SetShouldOutputAllResourceDefines(
                output_all_resource_defines)

        # Set an output context so that conditionals can use defines during the
        # gathering stage; we use a dummy language here since we are not outputting
        # a specific language.
        self.res.SetOutputLanguage('en')
        if rc_header_format:
            self.res.AssignRcHeaderFormat(rc_header_format)
        self.res.RunGatherers()
        self.Process()

        if assert_output_files:
            if not self.CheckAssertedOutputFiles(assert_output_files):
                return 2

        if depfile and depdir:
            self.GenerateDepfile(depfile, depdir, first_ids_file,
                                 depend_on_stamp)

        return 0
def main():

    argparser = argparse.ArgumentParser()
    argparser.add_argument("--vivaldi-file")
    argparser.add_argument("--locale")
    argparser.add_argument("--messages")
    argparser.add_argument("-D", action="append", dest="defines", default=[])
    # grit build also supports '-E KEY=VALUE', support that to share command
    # line flags. Dummy parameter in this script
    argparser.add_argument("-E", action="append", dest="build_env", default=[])
    # grit adds -t android when cross-compiling. Dummy parameter in this script.
    argparser.add_argument("-t", action="append", dest="build_env", default=[])
    argparser.add_argument("--extra-grd-file")
    argparser.add_argument("grd_file")
    argparser.add_argument("output_file")

    options = argparser.parse_args()

    defines = {}
    for define in options.defines:
        name, val = util.ParseDefine(define)
        defines[name] = val

    node_list = {}
    # Don't need to loop platforms, so using win32 as platform
    resources = grd_reader.Parse(options.grd_file,
                                 defines=defines,
                                 target_platform="win32")
    resources.SetOutputLanguage('en')
    resources.UberClique().keep_additional_translations_ = True
    resources.RunGatherers()

    names = None
    if options.extra_grd_file:
        import vivaldi_resources as vivaldi

        names = vivaldi.update_resources(resources,
                                         options.extra_grd_file,
                                         params=dict(defines=defines,
                                                     target_platform="win32"),
                                         active_only=False)

    for node in resources:
        node.unique_id = None
        if "name" in node.attrs and node.GetCliques():
            node.unique_id = "{}.{}".format(node.attrs["name"],
                                            node.GetCliques()[0].GetId())

    message_list = None
    if options.messages:
        with open(options.messages, "r") as f:
            message_list = [x.strip() for x in f.readlines()]
        message_list.extend(names or [])

    for node in resources:
        if node.unique_id and node.unique_id not in node_list:
            if (not isinstance(node, message.MessageNode)
                    or not node.IsTranslateable() or "name" not in node.attrs):
                continue
            if message_list and node.attrs["name"] not in message_list:
                continue
            node_list[node.unique_id] = node

    with open(options.output_file, "w") as f:
        print('msgid ""', file=f)
        print('msgstr ""', file=f)
        if options.locale:
            print('"Language: %s\\n"' % options.locale, file=f)
        print('"MIME-Version: 1.0\\n"', file=f)
        print('"Content-Type: text/plain; charset=UTF-8\\n"', file=f)
        print('', file=f)

        message_map = {}
        for _, node in node_list.items():
            message_map.setdefault(node.attrs["name"], []).append(node)

        for _, node in sorted(node_list.items()):
            write_message(
                f,
                options,
                node,
                options.locale,
                have_variants=(len(message_map[node.attrs["name"]]) > 1))