tags:

views:

100

answers:

0

Hello experts,

I have an ant file I use to compile my scala project. I'm using fsc which works wonders to avoid the 2~3 seconds my core 2 needs to just load the compiler.
My problem is: the ant fsc task does incur the same 2~3 seconds penalty, to the best of my knowledge. It is pretty annoying, because there is fsc specifically for this reason. It is even more annoying since it's really starting time and not processing time, so I have to wait 3 seconds on the fsc task even when there is nothing to re-compile. Each and every time, it becomes aggravating.

My investigation seems to show that most the time is spent reading scala-compiler.jar. Indeed, it makes sense the scalac and fsc tasks need this, since they run the compiler directly. Besides, removing scala-compiler.jar from the classpath of the ant task results, of course, in the task failing for lack of the dependency.
Logically speaking, the fsc task is only connecting to the compilation dæmon I suppose, so it shouldn't need that dependency, but I suppose it's about how it's implemented (the fsc task inherits from the scala task). Maybe it will come in a next version.

The solution I am looking at at the moment is, rewrite my fsc task as an apply task and invoke fsc manually. I won't have the delay then. It's just a pity to have to redo manually the work that the tasks included with scala were specifically written to handle.

Does anyone have experience with this problem? Is anything wrong in my analysis? And can you suggest a better solution than the one I am planning to implement?

For reference, here is what my task looks like (yes, it compiles an android project):

<target name="compile-scala" description="Compile scala files">
  <taskdef resource="scala/tools/ant/antlib.xml" classpath="${scala-library.jar}:${scala-compiler.jar}" />
  <mkdir dir="${out.classes.absolute.dir}" />
  <fsc encoding="utf-8" deprecation="on" destdir="${out.classes.absolute.dir}">
    <src>
      <dirset dir="." includes="src"/>
      <dirset dir="." includes="gen"/>
    </src>
    <classpath>
      <pathelement location="${android.jar}" />
      <fileset dir="${sdk.dir}/tools/lib" includes="*.jar" />
    </classpath>
  </fsc>
</target>

Edit: Here is what the task with apply looks like. It seems to work. It is however quite unsatisfying, so the question still holds.

<target name="fast-compile-scala"
    description="Compile scala files without loading the compiler inside ant">
  <mkdir dir="${out.classes.absolute.dir}" />
  <apply executable="fsc" failonerror="true" parallel="true">
    <arg value="-encoding" />
    <arg value="utf-8" />
    <arg value="-deprecation" />
    <arg value="-dependencyfile" />
    <arg value="${out.classes.absolute.dir}/${scala.deps}" />
    <arg value="-g:vars" />
    <arg value="-d" />
    <arg value="${out.classes.absolute.dir}" />
    <arg value="-make:transitivenocp" />
    <arg value="-classpath" />
    <arg value="${android.jar}:${out.classes.absolute.dir}" />
    <!-- <arg value="-optimize" /> -->
    <!-- <arg value="-verbose" /> -->
    <!-- <arg value="-explaintypes" /> -->
    <fileset dir="src" includes="**/*.scala" />
    <fileset dir="src" includes="**/*.java" />
    <fileset dir="gen" includes="**/*.java" />
  </apply>
</target>