Пример #1
0
def _FormatSourceHeader(root, output_dir, include_gzipped):
    '''Create the header of the C++ source file for the resource mapping.'''
    rc_header_file = None
    map_header_file = None
    for output in root.GetOutputFiles():
        type = output.GetType()
        if 'rc_header' == type:
            rc_header_file = util.MakeRelativePath(output_dir,
                                                   output.GetOutputFilename())
        elif 'resource_map_header' == type or 'gzipped_resource_map_header' == type:
            map_header_file = util.MakeRelativePath(output_dir,
                                                    output.GetOutputFilename())
    if not rc_header_file or not map_header_file:
        raise Exception('resource_map_source output type requires '
                        'a *resource_map_header and rc_header outputs')
    return '''\
// This file is automatically generated by GRIT.  Do not edit.

#include "%(map_header_file)s"

#include <stddef.h>

#include "base/macros.h"

#include "%(rc_header_file)s"

const %(struct_prefix)sGritResourceMap %(map_name)s[] = {
''' % {
        'map_header_file': map_header_file,
        'rc_header_file': rc_header_file,
        'map_name': GetMapName(root),
        'struct_prefix': 'Gzipped' if include_gzipped else '',
    }
Пример #2
0
def _FormatSourceHeader(root, output_dir):
    '''Create the header of the C++ source file for the resource mapping.'''
    rc_header_file = None
    map_header_file = None
    for output in root.GetOutputFiles():
        type = output.GetType()
        if 'rc_header' == type:
            rc_header_file = util.MakeRelativePath(output_dir,
                                                   output.GetOutputFilename())
        elif 'resource_map_header' == type:
            map_header_file = util.MakeRelativePath(output_dir,
                                                    output.GetOutputFilename())
    if not rc_header_file or not map_header_file:
        raise Exception('resource_map_source output type requires '
                        'a resource_map_header and rc_header outputs')
    return '''\
// This file is automatically generated by GRIT.  Do not edit.

#include "%(map_header_file)s"

#include <stddef.h>

#include <iterator>

#include "%(rc_header_file)s"

const webui::ResourcePath %(map_name)s[] = {
''' % {
        'map_header_file': map_header_file,
        'rc_header_file': rc_header_file,
        'map_name': GetMapName(root),
    }
Пример #3
0
  def Format(self, item, lang='en', output_dir='.'):
    assert isinstance(lang, types.StringTypes)
    from grit.node import structure
    from grit.node import include
    assert isinstance(item, (structure.StructureNode, include.IncludeNode))
    assert (isinstance(item, include.IncludeNode) or
            item.attrs['type'] in ['tr_html', 'admin_template', 'txt', 'muppet'])

    # By default, we use relative pathnames to included resources so that
    # sharing the resulting .rc files is possible.
    #
    # The FileForLanguage() Function has the side effect of generating the file
    # if needed (e.g. if it is an HTML file include).
    filename = os.path.abspath(item.FileForLanguage(lang, output_dir))
    if self.flatten_html:
      filename = item.Flatten(output_dir)
    elif self.filenameWithoutPath:
      filename = os.path.basename(filename)
    elif self.relative_path_:
      filename = util.MakeRelativePath(output_dir, filename)

    filename = filename.replace('\\', '\\\\')  # escape for the RC format

    if isinstance(item, structure.StructureNode) and item.IsExcludedFromRc():
      return ''
    else:
      return '%-18s %-18s "%s"\n' % (item.attrs['name'], self.type_, filename)
Пример #4
0
   def TestRelativePathCombinations(base_path, other_path,
                                    expected_result):
       """ Verify that the relative path function works for
 the given paths regardless of whether or not they end with
 a trailing slash."""
       for path1 in [base_path, base_path + os.path.sep]:
           for path2 in [other_path, other_path + os.path.sep]:
               result = util.MakeRelativePath(path1, path2)
               self.failUnless(result == expected_result)
Пример #5
0
def FormatInclude(item, lang, output_dir, type=None, process_html=False):
    '''Formats an item that is included in an .rc file (e.g. an ICON).

  Args:
    item: an IncludeNode or StructureNode
    lang, output_dir: standard formatter parameters
    type: .rc file resource type, e.g. 'ICON' (ignored unless item is a
          StructureNode)
    process_html: False/True (ignored unless item is a StructureNode)
  '''
    assert isinstance(lang, types.StringTypes)
    from grit.node import structure
    from grit.node import include
    assert isinstance(item, (structure.StructureNode, include.IncludeNode))

    if isinstance(item, include.IncludeNode):
        type = item.attrs['type'].upper()
        process_html = item.attrs['flattenhtml'] == 'true'
        filename_only = item.attrs['filenameonly'] == 'true'
        relative_path = item.attrs['relativepath'] == 'true'
    else:
        assert (isinstance(item, structure.StructureNode)
                and item.attrs['type'] in [
                    'admin_template', 'chrome_html', 'chrome_scaled_image',
                    'igoogle', 'muppet', 'tr_html', 'txt'
                ])
        filename_only = False
        relative_path = False

    # By default, we use relative pathnames to included resources so that
    # sharing the resulting .rc files is possible.
    #
    # The FileForLanguage() Function has the side effect of generating the file
    # if needed (e.g. if it is an HTML file include).
    file_for_lang = item.FileForLanguage(lang, output_dir)
    if file_for_lang is None:
        return ''

    filename = os.path.abspath(file_for_lang)
    if process_html:
        filename = item.Process(output_dir)
    elif filename_only:
        filename = os.path.basename(filename)
    elif relative_path:
        filename = util.MakeRelativePath(output_dir, filename)

    filename = filename.replace('\\', '\\\\')  # escape for the RC format

    if isinstance(item, structure.StructureNode) and item.IsExcludedFromRc():
        return ''

    name = item.attrs['name']
    item_id = rc_header.GetIds(item.GetRoot())[name]
    return '// ID: %d\n%-18s %-18s "%s"\n' % (item_id, name, type, filename)
Пример #6
0
def _FormatHeader(root, output_dir):
  """Returns the required preamble for C files."""
  # Find the location of the resource header file, so that we can include
  # it.
  resource_header = 'resource.h'  # fall back to this
  for output in root.GetOutputFiles():
    if output.attrs['type'] == 'rc_header':
      resource_header = os.path.abspath(output.GetOutputFilename())
      resource_header = util.MakeRelativePath(output_dir, resource_header)
  return """// This file is automatically generated by GRIT.  Do not edit.

#include "%s"

// All strings are UTF-8
""" % (resource_header)
Пример #7
0
    def Format(self, item, lang='en', output_dir='.'):
        """Format the C file header."""
        assert isinstance(lang, types.StringTypes)
        # Find the location of the resource header file, so that we can include
        # it.
        resource_header = 'resource.h'  # fall back to this
        for output in item.GetRoot().GetOutputFiles():
            if output.attrs['type'] == 'rc_header':
                resource_header = os.path.abspath(output.GetOutputFilename())
                resource_header = util.MakeRelativePath(
                    output_dir, resource_header)
        return """//  Copyright %d Google Inc. All Rights Reserved.
// This file is automatically generated by GRIT.  Do not edit.

#include "%s"

// All strings are UTF-8
""" % (util.GetCurrentYear(), resource_header)
Пример #8
0
def _FormatHeader(root, lang, output_dir):
    '''Returns the required preamble for RC files.'''
    assert isinstance(lang, types.StringTypes)
    assert isinstance(root, misc.GritNode)
    # Find the location of the resource header file, so that we can include
    # it.
    resource_header = 'resource.h'  # fall back to this
    language_directive = ''
    for output in root.GetOutputFiles():
        if output.attrs['type'] == 'rc_header':
            resource_header = os.path.abspath(output.GetOutputFilename())
            resource_header = util.MakeRelativePath(output_dir,
                                                    resource_header)
        if output.attrs['lang'] != lang:
            continue
        if output.attrs['language_section'] == '':
            # If no language_section is requested, no directive is added
            # (Used when the generated rc will be included from another rc
            # file that will have the appropriate language directive)
            language_directive = ''
        elif output.attrs['language_section'] == 'neutral':
            # If a neutral language section is requested (default), add a
            # neutral language directive
            language_directive = 'LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL'
        elif output.attrs['language_section'] == 'lang':
            language_directive = 'LANGUAGE %s' % GetLangDirectivePair(lang)
    resource_header = resource_header.replace('\\', '\\\\')
    return '''// This file is automatically generated by GRIT.  Do not edit.

#include "%s"
#include <winresrc.h>
#ifdef IDC_STATIC
#undef IDC_STATIC
#endif
#define IDC_STATIC (-1)

%s


''' % (resource_header, language_directive)
Пример #9
0
  def Format(self, item, lang='en', output_dir='.'):
    assert isinstance(lang, types.StringTypes)
    assert isinstance(item, misc.GritNode)
    # Find the location of the resource header file, so that we can include
    # it.
    resource_header = 'resource.h'  # fall back to this
    language_directive = ''
    for output in item.GetRoot().GetOutputFiles():
      if output.attrs['type'] == 'rc_header':
        resource_header = os.path.abspath(output.GetOutputFilename())
        resource_header = util.MakeRelativePath(output_dir, resource_header)
      if output.attrs['lang'] != lang:
        continue
      if output.attrs['language_section'] == '':
        # If no language_section is requested, no directive is added
        # (Used when the generated rc will be included from another rc
        # file that will have the appropriate language directive)
        language_directive = ''
      elif output.attrs['language_section'] == 'neutral':
        # If a neutral language section is requested (default), add a
        # neutral language directive
        language_directive = 'LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL'
      elif output.attrs['language_section'] == 'lang':
        language_directive = 'LANGUAGE %s' % GetLangDirectivePair(lang)
    resource_header = resource_header.replace('\\', '\\\\')
    return '''// Copyright (c) Google Inc. %d
// All rights reserved.
// This file is automatically generated by GRIT.  Do not edit.

#include "%s"
#include <winresrc.h>
#ifdef IDC_STATIC
#undef IDC_STATIC
#endif
#define IDC_STATIC (-1)

%s


''' % (util.GetCurrentYear(), resource_header, language_directive)