Commits

Paweł Tomulik committed eb3c916

Fixed FindSourceFiles to find leaf nodes.

Comments (0)

Files changed (10)

doc/user/gettext.in

 
   <para>
   The &t-link-gettext; toolset supports internationalization and localization
-  of SCons-based projects. The tools provided within &t-link-gettext; by
-  automatize generation and updates of translation files. You can manage
-  translations and translation templates simillary as it was done with
-  autotools.
+  of SCons-based projects. Builders provided by &t-link-gettext; automatize
+  generation and updates of translation files. You can manage translations and
+  translation templates similarly as it was done with autotools.
   </para>
 
   <section>
   <title>Prerequisites</title>
   <para>
-    Setup your operating system, so you can use several languages. In following
-    examples we use locales <literal>en_US</literal>, <literal>de_DE</literal>,
-    and <literal>pl_PL</literal>.
+    To follow examples provided in this chapter setup your operating system to
+    support two or more languages. In following examples we use locales
+    <literal>en_US</literal>, <literal>de_DE</literal>, and
+    <literal>pl_PL</literal>.
   </para>
 
   <para>
   </para>
 
   <para>
-    To edit translation files, you may install <ulink
+    To edit translation files you may wish to install <ulink
     url="http://www.poedit.net/">poedit</ulink> editor.
   </para>
   </section>
   <section>
   <title>Simple project</title>
     <para>
-    Let's start with some simple project, the "Hello world" program 
+    Let's start with very simple project, the "Hello world" program 
     for example
     <scons_example name="ex1">
     <file name="hello.c" printme="1">
     </file>
     </scons_example>
 
-    Prepare simple <filename>SConstruct</filename> script to compile the
-    program.
+    Prepare <filename>SConstruct</filename> script to compile the program
+    as usual.
     <scons_example name="ex2">
     <file name="SConstruct" printme="1">
     # SConstruct
     Now we'll convert the project to multi-lingual one. I assume, that you
     already have <ulink
     url="http://www.gnu.org/software/gettext/manual/gettext.html">GNU gettext
-    utilities</ulink> installed. If not, install it from repository, or
-    download from <ulink url="http://ftp.gnu.org/gnu/gettext/">
+    utilities</ulink> installed. If not, install them from your preffered
+    package repository, or download from <ulink
+    url="http://ftp.gnu.org/gnu/gettext/">
     http://ftp.gnu.org/gnu/gettext/</ulink>. For the purpose of this example,
-    you should have following three locales installed on your system 
+    you should have following three locales installed on your system
     <literal>en_US</literal>, <literal>de_DE</literal> and
     <literal>pl_PL</literal>. On debian, for example, you may enable certain
     locales through <command>dpkg-reconfigure locales</command>.
     url="http://www.gnu.org/software/gettext/manual/gettext.html#Sources">
     http://www.gnu.org/software/gettext/manual/gettext.html#Sources</ulink>.
     The <function>gettext("...")</function> in above source has two purposes.
-    First is is recognized by the <command>xgettext(1)</command> program, which
+    First, it marks messages for <command>xgettext(1)</command> program, which
     we will use to extract from the sources the messages for localization.
     Second, it calls the <literal>gettext</literal> library internals to
     translate the message at runtime.
     Generate translation files with <command>scons po-update</command>.
     You should see the output from SCons simillar to this:
     <screen>
-    ptomulik@:$ scons po-update
+    user@host:$ scons po-update
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     <para>
     If everything is right, you shall see following new files.
     <screen>
-    ptomulik@:$ ls *.po*
+    user@host:$ ls *.po*
     de.po  en.po  messages.pot  pl.po
     </screen>
     </para>
     Now compile the project by executing <command>scons</command> command. The
     output should be similar to this:
     <screen>
-    ptomulik@:$ scons
+    user@host:$ scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     <para>
     Your program should be now ready. You may try it as follows (linux):
     <screen>
-    ptomulik@:$ LANG=en_US.UTF-8 ./hello
+    user@host:$ LANG=en_US.UTF-8 ./hello
     Welcome to beautiful world
     </screen>
     <screen>
-    ptomulik@:$ LANG=de_DE.UTF-8 ./hello
+    user@host:$ LANG=de_DE.UTF-8 ./hello
     Hallo Welt
     </screen>
     <screen>
-    ptomulik@:$ LANG=pl_PL.UTF-8 ./hello
+    user@host:$ LANG=pl_PL.UTF-8 ./hello
     Witaj swiecie
     </screen>
     </para>
     swiecie\n"</literal>. Run <command>scons</command> to see how scons
     reacts to this
     <screen>
-    ptomulik@:$scons
+    user@host:$scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     <command>msgmerge(1)</command> program is used by SCons to update
     <literal>PO</literal> file. The output from compilation is like:
     <screen>
-    ptomulik@:$scons
+    user@host:$scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     </screen>
     </para>
     <para>
-    The last example demonstrates what happens, if we change the source code
+    The next example demonstrates what happens, if we change the source code
     in such way, that the internationalized messages do not change. The answer
     is, that none of translation files (<literal>POT</literal>,
     <literal>PO</literal>) is touched (i.e. no content changes, no
     </scons_example>
     Compile project. You'll see on your screen
     <screen>
-    ptomulik@:$scons
+    user@host:$scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...

doc/user/gettext.xml

 
   <para>
   The &t-link-gettext; toolset supports internationalization and localization
-  of SCons-based projects. The tools provided within &t-link-gettext; by
-  automatize generation and updates of translation files. You can manage
-  translations and translation templates simillary as it was done with
-  autotools.
+  of SCons-based projects. Builders provided by &t-link-gettext; automatize
+  generation and updates of translation files. You can manage translations and
+  translation templates similarly as it was done with autotools.
   </para>
 
   <section>
   <title>Prerequisites</title>
   <para>
-    Setup your operating system, so you can use several languages. In following
-    examples we use locales <literal>en_US</literal>, <literal>de_DE</literal>,
-    and <literal>pl_PL</literal>.
+    To follow examples provided in this chapter setup your operating system to
+    support two or more languages. In following examples we use locales
+    <literal>en_US</literal>, <literal>de_DE</literal>, and
+    <literal>pl_PL</literal>.
   </para>
 
   <para>
   </para>
 
   <para>
-    To edit translation files, you may install <ulink url="http://www.poedit.net/">poedit</ulink> editor.
+    To edit translation files you may wish to install <ulink url="http://www.poedit.net/">poedit</ulink> editor.
   </para>
   </section>
 
   <section>
   <title>Simple project</title>
     <para>
-    Let's start with some simple project, the "Hello world" program 
+    Let's start with very simple project, the "Hello world" program 
     for example
     <programlisting>
     /* hello.c */
     }
     </programlisting>
 
-    Prepare simple <filename>SConstruct</filename> script to compile the
-    program.
+    Prepare <filename>SConstruct</filename> script to compile the program
+    as usual.
     <programlisting>
     # SConstruct
     env = Environment()
     <para>
     Now we'll convert the project to multi-lingual one. I assume, that you
     already have <ulink url="http://www.gnu.org/software/gettext/manual/gettext.html">GNU gettext
-    utilities</ulink> installed. If not, install it from repository, or
-    download from <ulink url="http://ftp.gnu.org/gnu/gettext/">
+    utilities</ulink> installed. If not, install them from your preffered
+    package repository, or download from <ulink url="http://ftp.gnu.org/gnu/gettext/">
     http://ftp.gnu.org/gnu/gettext/</ulink>. For the purpose of this example,
-    you should have following three locales installed on your system 
+    you should have following three locales installed on your system
     <literal>en_US</literal>, <literal>de_DE</literal> and
     <literal>pl_PL</literal>. On debian, for example, you may enable certain
     locales through <command>dpkg-reconfigure locales</command>.
     be found at <ulink url="http://www.gnu.org/software/gettext/manual/gettext.html#Sources">
     http://www.gnu.org/software/gettext/manual/gettext.html#Sources</ulink>.
     The <function>gettext("...")</function> in above source has two purposes.
-    First is is recognized by the <command>xgettext(1)</command> program, which
+    First, it marks messages for <command>xgettext(1)</command> program, which
     we will use to extract from the sources the messages for localization.
     Second, it calls the <literal>gettext</literal> library internals to
     translate the message at runtime.
     Generate translation files with <command>scons po-update</command>.
     You should see the output from SCons simillar to this:
     <screen>
-    ptomulik@:$ scons po-update
+    user@host:$ scons po-update
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     <para>
     If everything is right, you shall see following new files.
     <screen>
-    ptomulik@:$ ls *.po*
+    user@host:$ ls *.po*
     de.po  en.po  messages.pot  pl.po
     </screen>
     </para>
     Now compile the project by executing <command>scons</command> command. The
     output should be similar to this:
     <screen>
-    ptomulik@:$ scons
+    user@host:$ scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     <para>
     Your program should be now ready. You may try it as follows (linux):
     <screen>
-    ptomulik@:$ LANG=en_US.UTF-8 ./hello
+    user@host:$ LANG=en_US.UTF-8 ./hello
     Welcome to beautiful world
     </screen>
     <screen>
-    ptomulik@:$ LANG=de_DE.UTF-8 ./hello
+    user@host:$ LANG=de_DE.UTF-8 ./hello
     Hallo Welt
     </screen>
     <screen>
-    ptomulik@:$ LANG=pl_PL.UTF-8 ./hello
+    user@host:$ LANG=pl_PL.UTF-8 ./hello
     Witaj swiecie
     </screen>
     </para>
     swiecie\n"</literal>. Run <command>scons</command> to see how scons
     reacts to this
     <screen>
-    ptomulik@:$scons
+    user@host:$scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     <command>msgmerge(1)</command> program is used by SCons to update
     <literal>PO</literal> file. The output from compilation is like:
     <screen>
-    ptomulik@:$scons
+    user@host:$scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
     </screen>
     </para>
     <para>
-    The last example demonstrates what happens, if we change the source code
+    The next example demonstrates what happens, if we change the source code
     in such way, that the internationalized messages do not change. The answer
     is, that none of translation files (<literal>POT</literal>,
     <literal>PO</literal>) is touched (i.e. no content changes, no
     </programlisting>
     Compile project. You'll see on your screen
     <screen>
-    ptomulik@:$scons
+    user@host:$scons
     scons: Reading SConscript files ...
     scons: done reading SConscript files.
     scons: Building targets ...
   </chapter>
 
   <chapter id="chap-gettext">
-    <title>Internaionalization and Localization with Gettext</title>
+    <title>Internationalization and localization with gettext</title>
     &gettext;
   </chapter>
 

doc/user/main.xml

     <!ENTITY factories SYSTEM "factories.xml">
     <!ENTITY file-removal SYSTEM "file-removal.xml">
     <!ENTITY functions SYSTEM "functions.xml">
+    <!ENTITY gettext SYSTEM "gettext.xml">
     <!ENTITY hierarchy SYSTEM "hierarchy.xml">
     <!ENTITY java SYSTEM "java.xml">
     <!ENTITY install SYSTEM "install.xml">
     &variants;
   </chapter>
 
+  <chapter id="chap-gettext">
+    <title>Internationalization and localization with gettext</title>
+    &gettext;
+  </chapter>
+
   <!--
 
   <chapter id="chap-builders-built-in">

doc/user/troubleshoot.xml

                          '.SPP',
                          '.sx'],
         'CXX': '$CC',
-        'CXXCOM': '$CXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $CXXFLAGS $CCFLAGS $_CCCOMCOM',
+        'CXXCOM': '${TEMPFILE("$CXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $CXXFLAGS $CCFLAGS $_CCCOMCOM")}',
         'CXXFILESUFFIX': '.cc',
         'CXXFLAGS': ['$(', '/TP', '$)'],
         'DSUFFIXES': ['.d'],
         'SHCCFLAGS': ['$CCFLAGS'],
         'SHCFLAGS': ['$CFLAGS'],
         'SHCXX': '$CXX',
-        'SHCXXCOM': '$SHCXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $SHCXXFLAGS $SHCCFLAGS $_CCCOMCOM',
+        'SHCXXCOM': '${TEMPFILE("$SHCXX $_MSVC_OUTPUT_FLAG /c $CHANGED_SOURCES $SHCXXFLAGS $SHCCFLAGS $_CCCOMCOM")}',
         'SHCXXFLAGS': ['$CXXFLAGS'],
         'SHELL': None,
         'SHLIBPREFIX': '',
                             Change Log
 
 RELEASE 2.X.X - 
+  From Paweł Tomulik:
+    - Added gettext toolset
+    - Fixed FindSourceFiles to find final sources (leaf nodes).
 
   From Mortoray:
     - Make -s (silent mode) be silent about entering subdirs (#2976).

src/engine/SCons/Environment.py

     #        srcnode = file.srcnode()
     #        while srcnode != file.srcnode():
     #            srcnode = file.srcnode()
-
+    # ------------------------------------------------------------------
+    # Sure!, the above code is like:
+    #
+    #        a = b
+    #        while a != b:
+    #          a = b
+    #        return c
+    #
+    # Let's do the job as below:
+        def final_source(node):
+            while (node != node.srcnode()):
+              node = node.srcnode()
+            return node
+        sources = map( final_source, sources );
         # remove duplicates
         return list(set(sources))
 

src/engine/SCons/Tool/gettext.xml

 
 Each of the above tools provides its own builder(s) which may be used to
 perform particular activities related to software internationalization. You
-may be however interested in <emphasis>top-level</emphasis> builders
-&b-Translate; and &b-InstallMOFiles; described few paragraphs later.
+may be however interested in <emphasis>top-level</emphasis> builder
+&b-Translate; described few paragraphs later.
 
 To use &t-gettext; tools add <literal>'gettext'</literal> tool to your
 environment:

src/engine/SCons/Tool/xgettext.py

   if not SCons.Util.is_List(path):
     path = [ path ]
 
+  path = SCons.Util.flatten(path)
+
   dirs = ()
   for p in path:
     if not isinstance(p, SCons.Node.FS.Base):
       if SCons.Util.is_String(p):
         p = env.subst(p, source = source, target = target)
       p = env.arg2nodes(p, env.fs.Dir)
-    if SCons.Util.is_List(p):
-      dirs = dirs + tuple(p)
-    else:
-      dirs += (p,)
+    dirs += tuple(p)
+  # cwd is the default search path (when no path is defined by user)
   if not dirs:
     dirs = (env.fs.getcwd(),)
 
+  # Parse 'POTFILE.in' files.
   re_comment = re.compile(r'^#[^\n\r]*$\r?\n?', re.M)
   re_emptyln = re.compile(r'^[ \t\r]*$\r?\n?', re.M)
   re_trailws = re.compile(r'[ \t\r]+$')
   if not SCons.Util.is_List(xfrom):
     xfrom = [ xfrom ]
 
+  xfrom = SCons.Util.flatten(xfrom)
+  
+  # Prepare list of 'POTFILE.in' files.
   files = []
   for xf in xfrom:
     if not isinstance(xf, SCons.Node.FS.Base):
       if SCons.Util.is_String(xf):
+        # Interpolate variables in strings 
         xf = env.subst(xf, source = source, target = target)
       xf = env.arg2nodes(xf)
-    if SCons.Util.is_List(xf):
-      files.extend(xf)
-    else:
-      files.append(xf)
+    files.extend(xf)
   if files:
     env.Depends(target, files)
     _scan_xgettext_from_files(target, source, env, files)

test/FindSourceFiles.py

+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test Environment's FindSourceFiles method.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+# Quite complex, but real-life test.
+# 0. Setup VariantDir, "var", without duplication. The "src" is source dir.
+# 1. Generate souce file var/foo.c from src/foo.c.in. Define program foo.
+# 2. Gather all sources necessary to create '.' node and create source
+#    tarball. We expect 'src/foo.c.in' file within tarbal, and no content
+#    under 'var' directory.
+test.subdir('src')
+test.subdir('variant')
+
+test.write('SConstruct', """
+VariantDir(src_dir = 'src', variant_dir = 'var', duplicate = 0)
+env = Environment(tools = ['default','textfile','packaging'])
+SConscript(['var/SConscript'], exports = 'env')
+sources = env.FindSourceFiles('.')
+pkg = env.Package( NAME = 'foo', VERSION = '1.0', PACKAGETYPE = 'src_tarbz2',
+                   source = sources )
+Ignore( '.', pkg )
+""")
+
+test.write('src/SConscript', """
+Import('env')
+foo_c = env.Substfile('foo.c.in', SUBST_DICT = {'__A__' : '0' })
+foo = env.Program(foo_c)
+""")
+
+test.write('src/foo.c.in', """ int main() { return __A__;}
+""")
+
+test.run(arguments = 'package')
+
+test.must_exist('foo-1.0/src/SConscript')
+test.must_exist('foo-1.0/src/foo.c.in')
+test.must_not_exist('foo-1.0/var/SConscript')
+test.must_not_exist('foo-1.0/var/foo.c.in')
+
+test.pass_test()
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.