Revision 121891 of Building PyXPCOM

  • Revision slug: Building_PyXPCOM
  • Revision title: Building PyXPCOM
  • Revision id: 121891
  • Created:
  • Creator: Mixedpuppy
  • Is current revision? No
  • Comment /* Installing Python */

Revision Content

Installing Python

PyXPCOM requires access to a shared Python library. The official Python installer for Windows installs this library automatically, so Windows users can simply install Python and skip to Compiling Mozilla.

For Linux users, if you already have Python installed and you have the file libpython2.*.so* in /usr/lib, you meet the shared library requirement and can skip to Compiling Mozilla. If you don't have that file then you'll need to compile Python with --enable-shared as outlined in this section.

For OS X 10.3 and 10.4 users, the Python 2.3 Framework is already available. If you want to build against Python 2.4, you will need to build your own from source, build via DarwinPorts or Fink, or install either MacPython or ActivePython. You can then skip to Compiling Mozilla. If you want to distribute your application, you might prefer to use the built in Python 2.3 Framework at first, since embedding the Python Framework into an application bundle may take some non-standard customizations to the Python build scripts.

Gentoo systems

Building a shared Python library seems to only be possible with python-2.3* or later, so you'll need to upgrade if you're using python-2.2* or earlier. For ebuilds python-2.3* and later the shared library is built and installed by default.

Other systems

If you don't use Windows or Gentoo, get the latest stable Python source tarball from python.org and do:

tar xjf Python-2.4.2.tar.bz2
cd Python-2.4.2
./configure --enable-shared --prefix=/usr  # Adjust --prefix to install over your current Python
make
sudo make install

Compiling Mozilla

Check out Mozilla from DOM_AGNOSTIC2_BRANCH in CVS and build it.

Linux and OS X:

cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot co -r DOM_AGNOSTIC2_BRANCH mozilla/client.mk
cd mozilla
cat > .mozconfig << "EOF"
mk_add_options MOZ_CO_PROJECT=suite
ac_add_options --enable-application=suite
ac_add_options --enable-default-toolkit=gtk2
ac_add_options --enable-xft
ac_add_options --enable-extensions=python/xpcom,python/dom,default
ac_add_options --disable-optimize
ac_add_options --enable-debug
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/suite-debug
EOF
make -f client.mk checkout
autoconf
make -f client.mk build

Windows:

TODO

Testing PyXPCOM

First test your fresh PyXPCOM build from within Mozilla's runtime environment.

Linux and OS X:

cd suite-debug/dist/bin
export PYTHONPATH=$PYTHONPATH:$HOME/mozilla/suite-debug/dist/bin/python # Adjust this to your PyXPCOM build path
./run-mozilla.sh ./seamonkey -chrome chrome://pyxultest/content

Windows:

TODO

A window with controls should pop up. Run the tests it contains.

In the same directory you can also perform a simple test of the Python xpcom module from a standalone Python environment.

Linux and OS X:

export MOZILLA_FIVE_HOME=$HOME/mozilla/suite-debug/dist/bin # Adjust this to your Mozilla build path
export LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
python -c 'from xpcom import components; print components.classes{{mediawiki.external('\"@mozilla.org/file/local;1\"')}}'

Windows:

TODO

You should see output similar to the following:

Type Manifest File: /home/you/mozilla/suite-debug/dist/bin/components/xpti.dat
<xpcom.components._Class instance at 0xb7c1be8c>
nsStringStats
 => mAllocCount:            431
 => mReallocCount:          270
 => mFreeCount:             423  --  LEAKED 8 !!!
 => mShareCount:            450
 => mAdoptCount:              0
 => mAdoptFreeCount:          0

If you see Python error messages instead, make sure $PYTHONPATH is still set the same as in the first test.

Revision Source

<h3 name="Installing_Python"> Installing Python </h3>
<p>PyXPCOM requires access to a shared Python library. The official Python installer for Windows installs this library automatically, so Windows users can simply install Python and skip to <a href="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a>.
</p><p>For Linux users, if you already have Python installed and you have the file <code>libpython2.*.so*</code> in <code>/usr/lib</code>, you meet the shared library requirement and can skip to <a href="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a>. If you don't have that file then you'll need to compile Python with <code>--enable-shared</code> as outlined in this section.
</p><p>For OS X 10.3 and 10.4 users, the Python 2.3 Framework is already available.  If you want to build against Python 2.4, you will need to build your own from <a class="external" href="http://www.python.org/download/">source</a>, build via <a class="external" href="http://darwinports.opendarwin.org/">DarwinPorts</a> or <a class="external" href="http://fink.sourceforge.net/">Fink</a>, or install either <a class="external" href="http://undefined.org/python/">MacPython</a> or <a class="external" href="http://www.ActiveState.com/">ActivePython</a>.  You can then skip to <a href="en/Building_PyXPCOM#Compiling_Mozilla">Compiling Mozilla</a>.  If you want to distribute your application, you might prefer to use the built in Python 2.3 Framework at first, since embedding the Python Framework into an application bundle may take some non-standard customizations to the Python build scripts.
</p>
<h4 name="Gentoo_systems"> Gentoo systems </h4>
<p>Building a shared Python library seems to only be possible with <code>python-2.3*</code> or later, so you'll need to upgrade if you're using <code>python-2.2*</code> or earlier. For ebuilds <code>python-2.3*</code> and later the shared library is built and installed by default.
</p>
<h4 name="Other_systems"> Other systems </h4>
<p>If you <i>don't</i> use Windows or Gentoo, get the latest stable Python source tarball from <a class="external" href="http://python.org/download/">python.org</a> and do:
</p>
<pre>tar xjf Python-2.4.2.tar.bz2
cd Python-2.4.2
./configure --enable-shared --prefix=/usr  # Adjust --prefix to install over your current Python
make
sudo make install
</pre>
<h3 name="Compiling_Mozilla"> Compiling Mozilla </h3>
<p>Check out Mozilla from <a class="external" href="http://wiki.mozilla.org/Breaking_the_grip_JS_has_on_the_DOM">DOM_AGNOSTIC2_BRANCH</a> in CVS and build it.
</p><p><i>Linux and OS X:</i>
</p>
<dl><dd><pre></pre></dd><dd>cvs -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot co -r DOM_AGNOSTIC2_BRANCH mozilla/client.mk
</dd><dd>cd mozilla
</dd><dd>cat &gt; .mozconfig &lt;&lt; "EOF"
</dd><dd>mk_add_options MOZ_CO_PROJECT=suite
</dd><dd>ac_add_options --enable-application=suite
</dd><dd>ac_add_options --enable-default-toolkit=gtk2
</dd><dd>ac_add_options --enable-xft
</dd><dd>ac_add_options --enable-extensions=python/xpcom,python/dom,default
</dd><dd>ac_add_options --disable-optimize
</dd><dd>ac_add_options --enable-debug
</dd><dd>mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/suite-debug
</dd><dd>EOF
</dd><dd>make -f client.mk checkout
</dd><dd>autoconf
</dd><dd>make -f client.mk build
</dd></dl>

<p><i>Windows:</i>
</p>
<dl><dd><pre></pre></dd><dd>TODO
</dd></dl>

<h3 name="Testing_PyXPCOM"> Testing PyXPCOM </h3>
<p>First test your fresh PyXPCOM build from within Mozilla's runtime environment.
</p><p><i>Linux and OS X:</i>
</p>
<dl><dd><pre></pre></dd><dd>cd suite-debug/dist/bin
</dd><dd>export PYTHONPATH=$PYTHONPATH:$HOME/mozilla/suite-debug/dist/bin/python # Adjust this to your PyXPCOM build path
</dd><dd>./run-mozilla.sh ./seamonkey -chrome chrome://pyxultest/content
</dd></dl>

<p><i>Windows:</i>
</p>
<dl><dd><pre></pre></dd><dd>TODO
</dd></dl>

<p>A window with controls should pop up. Run the tests it contains.
</p><p>In the same directory you can also perform a simple test of the Python <code>xpcom</code> module from a standalone Python environment.
</p><p><i>Linux and OS X:</i>
</p>
<dl><dd><pre></pre></dd><dd>export MOZILLA_FIVE_HOME=$HOME/mozilla/suite-debug/dist/bin # Adjust this to your Mozilla build path
</dd><dd>export LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
</dd><dd>python -c 'from xpcom import components; print components.classes{{mediawiki.external('\"@mozilla.org/file/local;1\"')}}'
</dd></dl>

<p><i>Windows:</i>
</p>
<dl><dd><pre></pre></dd><dd>TODO
</dd></dl>

<p>You should see output similar to the following:
</p>
<pre>Type Manifest File: /home/you/mozilla/suite-debug/dist/bin/components/xpti.dat
&lt;xpcom.components._Class instance at 0xb7c1be8c&gt;
nsStringStats
 =&gt; mAllocCount:            431
 =&gt; mReallocCount:          270
 =&gt; mFreeCount:             423  --  LEAKED 8 !!!
 =&gt; mShareCount:            450
 =&gt; mAdoptCount:              0
 =&gt; mAdoptFreeCount:          0
</pre>
<p>If you see Python error messages instead, make sure <code>$PYTHONPATH</code> is still set the same as in the first test.
</p>
Revert to this revision