Commits

dirkbaechle  committed f80d6ab

- added an explicit Gs() Builder to the gs.py Tool
- updated documentation accordingly and added a (very) simple test

  • Participants
  • Parent commits 73a9107

Comments (0)

Files changed (7)

File doc/generated/builders.gen

 </example_commands>
 </listitem>
   </varlistentry>
+  <varlistentry id="b-Gs">
+    <term>
+      <function>Gs()</function>
+    </term>
+    <term>
+      <function>env.Gs()</function>
+    </term>
+    <listitem>
+<para xmlns="http://www.scons.org/dbxsd/v1.0">
+A Builder for explicitly calling the <literal>gs</literal> executable.
+Depending on the underlying OS, the different names <literal>gs</literal>,
+<literal>gsos2</literal> and <literal>gswin32c</literal>
+are tried.
+</para>
+<example_commands xmlns="http://www.scons.org/dbxsd/v1.0">env = Environment(tools=['gs'])
+env.Gs('cover.jpg','scons-scons.pdf',
+       GSFLAGS='-dNOPAUSE -dBATCH -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -q') 
+       )
+</example_commands>
+</listitem>
+  </varlistentry>
   <varlistentry id="b-Install">
     <term>
       <function>Install()</function>

File doc/generated/builders.mod

 <!ENTITY b-DocbookXInclude "<function xmlns='http://www.scons.org/dbxsd/v1.0'>DocbookXInclude</function>">
 <!ENTITY b-DocbookXslt "<function xmlns='http://www.scons.org/dbxsd/v1.0'>DocbookXslt</function>">
 <!ENTITY b-DVI "<function xmlns='http://www.scons.org/dbxsd/v1.0'>DVI</function>">
+<!ENTITY b-Gs "<function xmlns='http://www.scons.org/dbxsd/v1.0'>Gs</function>">
 <!ENTITY b-Install "<function xmlns='http://www.scons.org/dbxsd/v1.0'>Install</function>">
 <!ENTITY b-InstallAs "<function xmlns='http://www.scons.org/dbxsd/v1.0'>InstallAs</function>">
 <!ENTITY b-InstallVersionedLib "<function xmlns='http://www.scons.org/dbxsd/v1.0'>InstallVersionedLib</function>">
 <!ENTITY b-env-DocbookXInclude "<function xmlns='http://www.scons.org/dbxsd/v1.0'>env.DocbookXInclude</function>">
 <!ENTITY b-env-DocbookXslt "<function xmlns='http://www.scons.org/dbxsd/v1.0'>env.DocbookXslt</function>">
 <!ENTITY b-env-DVI "<function xmlns='http://www.scons.org/dbxsd/v1.0'>env.DVI</function>">
+<!ENTITY b-env-Gs "<function xmlns='http://www.scons.org/dbxsd/v1.0'>env.Gs</function>">
 <!ENTITY b-env-Install "<function xmlns='http://www.scons.org/dbxsd/v1.0'>env.Install</function>">
 <!ENTITY b-env-InstallAs "<function xmlns='http://www.scons.org/dbxsd/v1.0'>env.InstallAs</function>">
 <!ENTITY b-env-InstallVersionedLib "<function xmlns='http://www.scons.org/dbxsd/v1.0'>env.InstallVersionedLib</function>">
 <!ENTITY b-link-DocbookXInclude "<link linkend='b-DocbookXInclude' xmlns='http://www.scons.org/dbxsd/v1.0'><function>DocbookXInclude</function></link>">
 <!ENTITY b-link-DocbookXslt "<link linkend='b-DocbookXslt' xmlns='http://www.scons.org/dbxsd/v1.0'><function>DocbookXslt</function></link>">
 <!ENTITY b-link-DVI "<link linkend='b-DVI' xmlns='http://www.scons.org/dbxsd/v1.0'><function>DVI</function></link>">
+<!ENTITY b-link-Gs "<link linkend='b-Gs' xmlns='http://www.scons.org/dbxsd/v1.0'><function>Gs</function></link>">
 <!ENTITY b-link-Install "<link linkend='b-Install' xmlns='http://www.scons.org/dbxsd/v1.0'><function>Install</function></link>">
 <!ENTITY b-link-InstallAs "<link linkend='b-InstallAs' xmlns='http://www.scons.org/dbxsd/v1.0'><function>InstallAs</function></link>">
 <!ENTITY b-link-InstallVersionedLib "<link linkend='b-InstallVersionedLib' xmlns='http://www.scons.org/dbxsd/v1.0'><function>InstallVersionedLib</function></link>">
 <!ENTITY b-link-env-DocbookXInclude "<link linkend='b-DocbookXInclude' xmlns='http://www.scons.org/dbxsd/v1.0'><function>env.DocbookXInclude</function></link>">
 <!ENTITY b-link-env-DocbookXslt "<link linkend='b-DocbookXslt' xmlns='http://www.scons.org/dbxsd/v1.0'><function>env.DocbookXslt</function></link>">
 <!ENTITY b-link-env-DVI "<link linkend='b-DVI' xmlns='http://www.scons.org/dbxsd/v1.0'><function>env.DVI</function></link>">
+<!ENTITY b-link-env-Gs "<link linkend='b-Gs' xmlns='http://www.scons.org/dbxsd/v1.0'><function>env.Gs</function></link>">
 <!ENTITY b-link-env-Install "<link linkend='b-Install' xmlns='http://www.scons.org/dbxsd/v1.0'><function>env.Install</function></link>">
 <!ENTITY b-link-env-InstallAs "<link linkend='b-InstallAs' xmlns='http://www.scons.org/dbxsd/v1.0'><function>env.InstallAs</function></link>">
 <!ENTITY b-link-env-InstallVersionedLib "<link linkend='b-InstallVersionedLib' xmlns='http://www.scons.org/dbxsd/v1.0'><function>env.InstallVersionedLib</function></link>">

File doc/generated/tools.gen

     <term>gs</term>
     <listitem>
 <para xmlns="http://www.scons.org/dbxsd/v1.0">
-Set construction variables for Ghostscript.
+This Tool sets the required construction variables for working with
+the Ghostscript command. It also registers an appropriate Action
+with the PDF Builder (<link xmlns="http://www.scons.org/dbxsd/v1.0" linkend="b-PDF"><function>PDF</function></link>), such that the conversion from
+PS/EPS to PDF happens automatically for the TeX/LaTeX toolchain.
+Finally, it adds an explicit Ghostscript Builder (<link xmlns="http://www.scons.org/dbxsd/v1.0" linkend="b-Gs"><function>Gs</function></link>) to the
+environment.
 </para>
 <para>Sets:  &cv-link-GS;, &cv-link-GSCOM;, &cv-link-GSFLAGS;.</para><para>Uses:  &cv-link-GSCOMSTR;.</para></listitem>
   </varlistentry>

File doc/generated/variables.gen

     <term>GS</term>
     <listitem>
 <para xmlns="http://www.scons.org/dbxsd/v1.0">
-The Ghostscript program used to convert PostScript to PDF files.
+The Ghostscript program used, e.g. to convert PostScript to PDF files.
 </para>
 </listitem>
   </varlistentry>
     <term>GSCOM</term>
     <listitem>
 <para xmlns="http://www.scons.org/dbxsd/v1.0">
-The Ghostscript command line used to convert PostScript to PDF files.
+The full Ghostscript command line used for the conversion process. Its default
+value is <quote><literal>$GS $GSFLAGS -sOutputFile=$TARGET $SOURCES</literal></quote>.
 </para>
 </listitem>
   </varlistentry>
     <listitem>
 <para xmlns="http://www.scons.org/dbxsd/v1.0">
 The string displayed when
-Ghostscript is used to convert
-a PostScript file to a PDF file.
-If this is not set, then <link xmlns="http://www.scons.org/dbxsd/v1.0" linkend="cv-GSCOM"><envar>$GSCOM</envar></link> (the command line) is displayed.
+Ghostscript is called for the conversion process.
+If this is not set (the default), then <link xmlns="http://www.scons.org/dbxsd/v1.0" linkend="cv-GSCOM"><envar>$GSCOM</envar></link> (the command line) is displayed.
 </para>
 </listitem>
   </varlistentry>
     <term>GSFLAGS</term>
     <listitem>
 <para xmlns="http://www.scons.org/dbxsd/v1.0">
-General options passed to the Ghostscript program
-when converting PostScript to PDF files.
+General options passed to the Ghostscript program,
+when converting PostScript to PDF files for example. Its default value
+is <quote><literal>-dNOPAUSE -dBATCH -sDEVICE=pdfwrite</literal></quote>
 </para>
 </listitem>
   </varlistentry>
 Internal ``macro''. Computes locale (language) name based on target filename
 (default: <literal>'${TARGET.filebase}' </literal>).
 </para>
+<para xmlns="http://www.scons.org/dbxsd/v1.0">
+See <link xmlns="http://www.scons.org/dbxsd/v1.0" linkend="t-msginit"><literal>msginit</literal></link> tool and <link xmlns="http://www.scons.org/dbxsd/v1.0" linkend="b-POInit"><function>POInit</function></link> builder.
+</para>
 </listitem>
   </varlistentry>
   <varlistentry id="cv-MSGMERGE">

File src/engine/SCons/Tool/gs.py

 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import SCons.Action
+import SCons.Builder
 import SCons.Platform
 import SCons.Util
 
 def generate(env):
     """Add Builders and construction variables for Ghostscript to an
     Environment."""
+    global GhostscriptAction
+    # The following try-except block enables us to use the Tool
+    # in standalone mode (without the accompanying pdf.py),
+    # whenever we need an explicit call of gs via the Gs()
+    # Builder ...
+    try:
+        if GhostscriptAction is None:
+            GhostscriptAction = SCons.Action.Action('$GSCOM', '$GSCOMSTR')
+    
+        import pdf
+        pdf.generate(env)
+    
+        bld = env['BUILDERS']['PDF']
+        bld.add_action('.ps', GhostscriptAction)
+    except ImportError, e:
+        pass
 
-    global GhostscriptAction
-    if GhostscriptAction is None:
-        GhostscriptAction = SCons.Action.Action('$GSCOM', '$GSCOMSTR')
-
-    import pdf
-    pdf.generate(env)
-
-    bld = env['BUILDERS']['PDF']
-    bld.add_action('.ps', GhostscriptAction)
-
+    gsbuilder = SCons.Builder.Builder(action = SCons.Action.Action('$GSCOM', '$GSCOMSTR'),
+                                      env = env)
+    env['BUILDERS']['Gs'] = gsbuilder
+    
     env['GS']      = gs
     env['GSFLAGS'] = SCons.Util.CLVar('-dNOPAUSE -dBATCH -sDEVICE=pdfwrite')
     env['GSCOM']   = '$GS $GSFLAGS -sOutputFile=$TARGET $SOURCES'

File src/engine/SCons/Tool/gs.xml

 <tool name="gs">
 <summary>
 <para>
-Set construction variables for Ghostscript.
+This Tool sets the required construction variables for working with
+the Ghostscript command. It also registers an appropriate Action
+with the PDF Builder (&b-link-PDF;), such that the conversion from
+PS/EPS to PDF happens automatically for the TeX/LaTeX toolchain.
+Finally, it adds an explicit Ghostscript Builder (&b-link-Gs;) to the
+environment.
 </para>
 </summary>
 <sets>
 <cvar name="GS">
 <summary>
 <para>
-The Ghostscript program used to convert PostScript to PDF files.
+The Ghostscript program used, e.g. to convert PostScript to PDF files.
 </para>
 </summary>
 </cvar>
 <cvar name="GSCOM">
 <summary>
 <para>
-The Ghostscript command line used to convert PostScript to PDF files.
+The full Ghostscript command line used for the conversion process. Its default
+value is <quote><literal>$GS $GSFLAGS -sOutputFile=$TARGET $SOURCES</literal></quote>.
 </para>
 </summary>
 </cvar>
 <summary>
 <para>
 The string displayed when
-Ghostscript is used to convert
-a PostScript file to a PDF file.
-If this is not set, then &cv-link-GSCOM; (the command line) is displayed.
+Ghostscript is called for the conversion process.
+If this is not set (the default), then &cv-link-GSCOM; (the command line) is displayed.
 </para>
 </summary>
 </cvar>
 <cvar name="GSFLAGS">
 <summary>
 <para>
-General options passed to the Ghostscript program
-when converting PostScript to PDF files.
+General options passed to the Ghostscript program,
+when converting PostScript to PDF files for example. Its default value
+is <quote><literal>-dNOPAUSE -dBATCH -sDEVICE=pdfwrite</literal></quote>
 </para>
 </summary>
 </cvar>
 
+<builder name="Gs">
+<summary>
+<para>
+A Builder for explicitly calling the <literal>gs</literal> executable.
+Depending on the underlying OS, the different names <literal>gs</literal>,
+<literal>gsos2</literal> and <literal>gswin32c</literal>
+are tried.
+</para>
+<example_commands>env = Environment(tools=['gs'])
+env.Gs('cover.jpg','scons-scons.pdf',
+       GSFLAGS='-dNOPAUSE -dBATCH -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -q') 
+       )
+</example_commands>
+</summary>
+</builder>
+
 </sconsdoc>

File test/Ghostscript/GS.py

                   GSCOM = r'$GS $TARGET $SOURCE',
                   tools=['gs'])
 env.PDF(target = 'test1.pdf', source = 'test1.ps')
+env.Gs(target = 'test2.pdf', source = 'test1.ps')
 """ % locals())
 
 test.write('test1.ps', r"""This is a .ps test.
 test.run(arguments = '.', stderr = None)
 
 test.fail_test(test.read('test1.pdf') != "This is a .ps test.\n")
+test.fail_test(test.read('test2.pdf') != "This is a .ps test.\n")