summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptomulik <ptomulik@meil.pw.edu.pl>2012-06-07 01:03:25 +0200
committerptomulik <ptomulik@meil.pw.edu.pl>2012-06-07 01:03:25 +0200
commit1fdfab3d2ac66b65963f80075632a726cf85ec18 (patch)
treeec2f4f6468a3babaa52d7ed995516ff9c5452e47
parent668afb7816e89899171dfe216b4c42152c77f4bd (diff)
downloadscons-1fdfab3d2ac66b65963f80075632a726cf85ec18.tar.gz
Fixed FindSourceFiles to find leaf nodes.
-rw-r--r--doc/user/gettext.in51
-rw-r--r--doc/user/gettext.xml50
-rw-r--r--doc/user/main.in2
-rw-r--r--doc/user/main.xml6
-rw-r--r--doc/user/troubleshoot.xml4
-rw-r--r--src/CHANGES.txt3
-rw-r--r--src/engine/SCons/Environment.py15
-rw-r--r--src/engine/SCons/Tool/gettext.xml4
-rw-r--r--src/engine/SCons/Tool/xgettext.py18
-rw-r--r--test/FindSourceFiles.py76
10 files changed, 165 insertions, 64 deletions
diff --git a/doc/user/gettext.in b/doc/user/gettext.in
index 22545d30..3370ea91 100644
--- a/doc/user/gettext.in
+++ b/doc/user/gettext.in
@@ -25,18 +25,18 @@
<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>
@@ -46,7 +46,7 @@
</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>
@@ -54,7 +54,7 @@
<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">
@@ -68,8 +68,8 @@
</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
@@ -83,10 +83,11 @@
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>.
@@ -116,7 +117,7 @@
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.
@@ -159,7 +160,7 @@
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 ...
@@ -180,7 +181,7 @@
<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>
@@ -206,7 +207,7 @@
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 ...
@@ -227,15 +228,15 @@
<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>
@@ -245,7 +246,7 @@
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 ...
@@ -280,7 +281,7 @@
<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 ...
@@ -306,7 +307,7 @@
</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
@@ -332,7 +333,7 @@
</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 ...
diff --git a/doc/user/gettext.xml b/doc/user/gettext.xml
index 9fc00767..f5806a4e 100644
--- a/doc/user/gettext.xml
+++ b/doc/user/gettext.xml
@@ -25,18 +25,18 @@
<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>
@@ -45,14 +45,14 @@
</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 */
@@ -64,8 +64,8 @@
}
</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()
@@ -76,10 +76,10 @@
<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>.
@@ -106,7 +106,7 @@
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.
@@ -147,7 +147,7 @@
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 ...
@@ -168,7 +168,7 @@
<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>
@@ -194,7 +194,7 @@
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 ...
@@ -215,15 +215,15 @@
<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>
@@ -233,7 +233,7 @@
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 ...
@@ -266,7 +266,7 @@
<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 ...
@@ -292,7 +292,7 @@
</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
@@ -316,7 +316,7 @@
</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 ...
diff --git a/doc/user/main.in b/doc/user/main.in
index 0f8e3053..61b544ff 100644
--- a/doc/user/main.in
+++ b/doc/user/main.in
@@ -255,7 +255,7 @@
</chapter>
<chapter id="chap-gettext">
- <title>Internaionalization and Localization with Gettext</title>
+ <title>Internationalization and localization with gettext</title>
&gettext;
</chapter>
diff --git a/doc/user/main.xml b/doc/user/main.xml
index 4b0807da..61b544ff 100644
--- a/doc/user/main.xml
+++ b/doc/user/main.xml
@@ -65,6 +65,7 @@
<!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">
@@ -253,6 +254,11 @@
&variants;
</chapter>
+ <chapter id="chap-gettext">
+ <title>Internationalization and localization with gettext</title>
+ &gettext;
+ </chapter>
+
<!--
<chapter id="chap-builders-built-in">
diff --git a/doc/user/troubleshoot.xml b/doc/user/troubleshoot.xml
index 427d5153..093574c4 100644
--- a/doc/user/troubleshoot.xml
+++ b/doc/user/troubleshoot.xml
@@ -375,7 +375,7 @@
'.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'],
@@ -417,7 +417,7 @@
'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': '',
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index f7596223..d1aa963f 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -5,6 +5,9 @@
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).
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 529e3a38..d7b40227 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -2238,7 +2238,20 @@ class Base(SubstitutionEnvironment):
# 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))
diff --git a/src/engine/SCons/Tool/gettext.xml b/src/engine/SCons/Tool/gettext.xml
index 7537882a..54ed1d6e 100644
--- a/src/engine/SCons/Tool/gettext.xml
+++ b/src/engine/SCons/Tool/gettext.xml
@@ -33,8 +33,8 @@ so you're encouraged to see their individual documentation.
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:
diff --git a/src/engine/SCons/Tool/xgettext.py b/src/engine/SCons/Tool/xgettext.py
index 860e51b4..f2f542b6 100644
--- a/src/engine/SCons/Tool/xgettext.py
+++ b/src/engine/SCons/Tool/xgettext.py
@@ -182,19 +182,20 @@ def _scan_xgettext_from_files(target, source, env, files = None, path = None):
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]+$')
@@ -228,16 +229,17 @@ def _pot_update_emitter(target, source, env):
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)
diff --git a/test/FindSourceFiles.py b/test/FindSourceFiles.py
new file mode 100644
index 00000000..b6177e44
--- /dev/null
+++ b/test/FindSourceFiles.py
@@ -0,0 +1,76 @@
+#!/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: