Dear readers,

After some back and forth with various documentations of
ant, gcj/gij and ldconfig and the shared library howto
on Linux, I got the following to work for gcc 4.0.0
as a parallel path to javac, jar and junit.

It compiles a jar and a source package each to a shared
lib, and then runs junit informing the gcj class loader to
use the shared libs. For more than one shared lib the
full search mode is needed for class loading to work here.

Did someone start working on better ant tasks for gcj and gij?

Comments welcome.

Regards,
Paul Elschot


Assumptions:
- sharedlib1 and sharedlib2 are built in libbuild.dir,
- gcc 4.0.0 installed, this allow to use gcj and gij,
- junit running under ant.

  <!-- C O M P I L E  T O  S H A R E D  L I B  -->
  <macrodef name="package-to-sharedlib">
    <attribute name="xsource.dir"/>
    <attribute name="xsource.package"/> <!-- in source.dir -->
    <attribute name="xclasspath.package"/>
    <attribute name="xtarget.sharedlib"/>
    <sequential>
      <apply
        executable="gcj"
        dir="@{xsource.dir}"
        parallel="yes"
        failonerror="yes"
      >
        <fileset dir="@{xsource.dir}" includes="@{xsource.package}/**/*.java"/>
        <arg value="-classpath"/>
        <arg value="@{xclasspath.package}"/>
        <!-- arg value="-O2"/ takes more time to build -->
        <arg value="-shared"/>
        <arg value="-o"/>
        <arg value="@{xtarget.sharedlib}"/>
      </apply>
    </sequential>
  </macrodef>

  <uptodate property="sharedlib1.uptodate" targetfile="${sharedlib1}">
    <srcfiles dir= "${sourcejava.dir}" includes="org/**/*.java"/>
  </uptodate>
  
  <target name="compile-gcj"
    description="Compiles classes of package org to shared library"
    unless="sharedlib1.uptodate"
  >
    <mkdir dir="${libbuild.dir}"/>
    <package-to-sharedlib
      xsource.dir="${sourcejava.dir}"
      xsource.package="org"
      xclasspath.package="${some.jar}"
      xtarget.sharedlib="${sharedlib1}"
    />
    <echo message="Built ${sharedlib1}."/>
  </target>

  <!-- C O M P I L E  A   J A R  T O  S H A R E D  L I B -->
  <uptodate property="sharedlib2.uptodate"
    targetfile="${sharedlib2}"
    srcfile="${some.jar}"
  />
  <target name="sharedlib2"
    description="Compiles some jar to shared library"
    unless="sharedlib2.uptodate"
  >
    <mkdir dir="${libbuild.dir}"/>
    <exec executable="gcj" failonerror="yes">
      <arg value="${some.jar}"/>
      <arg value="-O2"/>
      <arg value="-shared"/>
      <arg value="-o"/>
      <arg value="${sharedlib2}"/>
    </exec>
    <echo message="Built ${sharedlib2}"/>
  </target>

  <!-- R U N  U N I T  T E S T S  B Y  G I J                              -->
  <target name="unit-test-gij"
    depends="sharedlib2,compile-gcj,compile-test"
    if="junit.present"
    description="Runs unit tests by gij (using the gcj compiled shared libs)."
  >
    <mkdir dir="${junit.output.dir}"/>
    <junit
        printsummary="off"
        haltonfailure="${test.haltonfailure}"
        haltonerror="${test.haltonerror}"
        errorProperty="tests.failed"
        failureProperty="tests.failed"
        jvm="gij"
        fork="yes"
        forkmode="once"
    >
      <!-- jvmarg and env ignored unless test.fork="yes" -->
      <env key="LD_LIBRARY_PATH" value="${libbuild.dir}"/> <!-- unix only -->
      <!-- For more than one shared lib need full search for classes loaded by 
gij: -->
      <jvmarg value="-Dgnu.gcj.runtime.VMClassLoader.library_control=full"/> 
      <classpath refid="junit.classpath.gij"/>
      <formatter type="xml"/>
      <formatter type="brief" usefile="false"/>
      <batchtest fork="${test.fork}" todir="${junit.output.dir}" 
unless="testcase">
        <fileset dir="${sourcetest.dir}" includes="**/Test*.java"/>
      </batchtest>
      <batchtest fork="${test.fork}" todir="${junit.output.dir}" if="testcase">
        <fileset dir="${sourcetest.dir}" includes="**/Test*${testcase}.java"/>
      </batchtest>
    </junit>

    <fail if="tests.failed">Tests failed!</fail>
  </target>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to