Obi is born
In an effort to learn Scala I’ve been playing around with creating a build tool, called Obi. This is nothing more than me looking for a nice way to learn Scala, but after a couple of days of thinking it looks quite doable.
Obi has three goals; 1) allow me to learn Scala, 2) provide a nice DSL that is expressive and allows use of Scala APIs and idioms and 3) provide the type safety of the Scala language, e.g. a javac task will not compile if you do not pass it a source file.
Here’s an example of the current syntax we’re playing with, this doesn’t actually do anything as yet, but does compile (well, most of it compiles). Each call is pure (side effect free), you need to apply the ! to actually execute the tasks.
import SrcDir._
import Javac._
import AntJavac._
// Two compile targets, Java code and Scala code
val jc = javac(srcdir("src/main/java")).srcfiles(
List("Foo.java", "Bar.java"))
val sc = scalac.srcdir("src/main/scala").srcfiles(
List("Foo.scala", "Bar.scala"))
// Equivalent of an Ant "target", Java compile is performed
// before Scala compile, both tasks are executed when called.
def compile {
!jc
!sc
}
// Compile Foo.java & Bar.java in src/main/java
!javac(srcdir("src/main/java")).srcfiles(
List("Foo.java", "Bar.java"))
// Create a compile for Foo.java & Bar.java in src/main.java
List("Foo.java", "Bar.java") >>: javac(srcdir("src/main/java"))
// Create a compile for all files in src/main.java
Dir("src/main/scala") >>: scala(srcdir("src/main/scala"))
// compile all Scala source files in an "obi" directory
val scalaCompile = Dir("src/main/scala")
.filter(_.matches("""obi.*\.scala$""")) >>: scalac
!scalaCompile
For those that want to look at other Scala tools, it looks like the only tool available currently is SAnt, Maven and Ant.
If you are interested, Obi is not named after Obi-Wan Kenobi, but after Obi Obi Creek on the Sunshine Coast of Queensland (where I’m doing a throughwalk later this year).
>the only tool available currently is SAnt, and of course Ant itself.
maven ???
Arioch
17 Jan 08 at 11:09 pm
I say go the “Obi-wan”, mainly because “Obi Obi” is anti scala => because it repeats itself!
sanj
18 Jan 08 at 8:42 am
@Arioch: Yep, you’re correct, there’s also Maven. I’ll correct that.
Tom Adams
18 Jan 08 at 9:04 am
Hey tom - slight suggestion:
val sc = scalac.srcdir(”src/main/scala”).srcfiles(
List(”Foo.scala”, “Bar.scala”))
could be
val sc = scalac
srcdir(”src/main/scala”)
srcfiles(List(”Foo.scala”, “Bar.scala”))
Kind of looks more build-ey (not sure if it works though). Probably more syntax tricks to use as well.
maybe have some helper functions to get listings:
val sc = scalac
srcdir(”src/main/scala”)
srcfiles( dir(”/src/scala”) include(”.scala”))
Michael Neale
18 Jan 08 at 12:23 pm
Yeah, helper functions are good. I think the blog software screwed up the formatting, I assume you had some indentation there?
You can get this:
scalac srcdir “src/main/scala” include “.scala”
Pretty easily.
Tom Adams
18 Jan 08 at 1:38 pm