示例#1
0
def generate(env, **kw):
    """ Generate `xgettext` tool """

    if sys.platform == 'win32':
        xgettext = SCons.Tool.find_program_path(
            env,
            'xgettext',
            default_paths=MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS)
        if xgettext:
            xgettext_bin_dir = os.path.dirname(xgettext)
            env.AppendENVPath('PATH', xgettext_bin_dir)
        else:
            SCons.Warnings.Warning(
                'xgettext tool requested, but binary not found in ENV PATH')
    try:
        env['XGETTEXT'] = _detect_xgettext(env)
    except:
        env['XGETTEXT'] = 'xgettext'
    # NOTE: sources="$SOURCES" would work as well. However, we use following
    # construction to convert absolute paths provided by scons onto paths
    # relative to current working dir. Note, that scons expands $SOURCE(S) to
    # absolute paths for sources $SOURCE(s) outside of current subtree (e.g. in
    # "../"). With source=$SOURCE these absolute paths would be written to the
    # resultant *.pot file (and its derived *.po files) as references to lines in
    # source code (e.g. referring lines in *.c files). Such references would be
    # correct (e.g. in poedit) only on machine on which *.pot was generated and
    # would be of no use on other hosts (having a copy of source code located
    # in different place in filesystem).
    sources = '$( ${_concat( "", SOURCES, "", __env__, XgettextRPaths, TARGET' \
              + ', SOURCES)} $)'

    # NOTE: the output from $XGETTEXTCOM command must go to stdout, not to a file.
    # This is required by the POTUpdate builder's action.
    xgettextcom = '$XGETTEXT $XGETTEXTFLAGS $_XGETTEXTPATHFLAGS' \
                  + ' $_XGETTEXTFROMFLAGS -o - ' + sources

    xgettextpathflags = '$( ${_concat( XGETTEXTPATHPREFIX, XGETTEXTPATH' \
                        + ', XGETTEXTPATHSUFFIX, __env__, RDirs, TARGET, SOURCES)} $)'
    xgettextfromflags = '$( ${_concat( XGETTEXTFROMPREFIX, XGETTEXTFROM' \
                        + ', XGETTEXTFROMSUFFIX, __env__, target=TARGET, source=SOURCES)} $)'

    env.SetDefault(_XGETTEXTDOMAIN='${TARGET.filebase}',
                   XGETTEXTFLAGS=[],
                   XGETTEXTCOM=xgettextcom,
                   XGETTEXTCOMSTR='',
                   XGETTEXTPATH=[],
                   XGETTEXTPATHPREFIX='-D',
                   XGETTEXTPATHSUFFIX='',
                   XGETTEXTFROM=None,
                   XGETTEXTFROMPREFIX='-f',
                   XGETTEXTFROMSUFFIX='',
                   _XGETTEXTPATHFLAGS=xgettextpathflags,
                   _XGETTEXTFROMFLAGS=xgettextfromflags,
                   POTSUFFIX=['.pot'],
                   POTUPDATE_ALIAS='pot-update',
                   XgettextRPaths=RPaths(env))
    env.Append(BUILDERS={'_POTUpdateBuilder': _POTUpdateBuilder(env)})
    env.AddMethod(_POTUpdateBuilderWrapper, 'POTUpdate')
    env.AlwaysBuild(env.Alias('$POTUPDATE_ALIAS'))
示例#2
0
def generate(env,**kw):
  """ Generate `xgettext` tool """
  import SCons.Util
  from SCons.Tool.GettextCommon import RPaths, _detect_xgettext

  try:
    env['XGETTEXT'] = _detect_xgettext(env)
  except:
    env['XGETTEXT'] = 'xgettext' 
  # NOTE: sources="$SOURCES" would work as well. However, we use following
  # construction to convert absolute paths provided by scons onto paths
  # relative to current working dir. Note, that scons expands $SOURCE(S) to
  # absolute paths for sources $SOURCE(s) outside of current subtree (e.g. in
  # "../"). With source=$SOURCE these absolute paths would be written to the
  # resultant *.pot file (and its derived *.po files) as references to lines in
  # source code (e.g. referring lines in *.c files). Such references would be
  # correct (e.g. in poedit) only on machine on which *.pot was generated and
  # would be of no use on other hosts (having a copy of source code located
  # in different place in filesystem).
  sources = '$( ${_concat( "", SOURCES, "", __env__, XgettextRPaths, TARGET' \
    + ', SOURCES)} $)'

  # NOTE: the output from $XGETTEXTCOM command must go to stdout, not to a file.
  # This is required by the POTUpdate builder's action.
  xgettextcom = '$XGETTEXT $XGETTEXTFLAGS $_XGETTEXTPATHFLAGS' \
    + ' $_XGETTEXTFROMFLAGS -o - ' + sources

  xgettextpathflags = '$( ${_concat( XGETTEXTPATHPREFIX, XGETTEXTPATH' \
    + ', XGETTEXTPATHSUFFIX, __env__, RDirs, TARGET, SOURCES)} $)'
  xgettextfromflags = '$( ${_concat( XGETTEXTFROMPREFIX, XGETTEXTFROM' \
    + ', XGETTEXTFROMSUFFIX, __env__, target=TARGET, source=SOURCES)} $)'

  env.SetDefault(
    _XGETTEXTDOMAIN     = '${TARGET.filebase}',
    XGETTEXTFLAGS       = [ ],
    XGETTEXTCOM         = xgettextcom,
    XGETTEXTCOMSTR      = '',
    XGETTEXTPATH        = [ ],
    XGETTEXTPATHPREFIX   = '-D',
    XGETTEXTPATHSUFFIX   = '',
    XGETTEXTFROM        = None,
    XGETTEXTFROMPREFIX   = '-f',
    XGETTEXTFROMSUFFIX   = '',
   _XGETTEXTPATHFLAGS    = xgettextpathflags,
   _XGETTEXTFROMFLAGS   = xgettextfromflags,
    POTSUFFIX           =  ['.pot'],
    POTUPDATE_ALIAS     = 'pot-update',
    XgettextRPaths      = RPaths(env)
  )
  env.Append( BUILDERS = {
    '_POTUpdateBuilder' : _POTUpdateBuilder(env)
  } )
  env.AddMethod(_POTUpdateBuilderWrapper, 'POTUpdate')
  env.AlwaysBuild(env.Alias('$POTUPDATE_ALIAS'))