sbt/project/build/XSbt.scala

201 lines
10 KiB
Scala
Raw Normal View History

2009-08-16 20:29:08 +02:00
import sbt._
2009-11-03 05:02:00 +01:00
import java.io.File
class XSbt(info: ProjectInfo) extends ParentProject(info) with NoCrossPaths
2009-08-16 20:29:08 +02:00
{
/* Subproject declarations*/
val launchInterfaceSub = project(launchPath / "interface", "Launcher Interface", new LaunchInterfaceProject(_))
2009-08-21 14:12:43 +02:00
val launchSub = project(launchPath, "Launcher", new LaunchProject(_), launchInterfaceSub)
val interfaceSub = project("interface", "Interface", new InterfaceProject(_))
val apiSub = baseProject(compilePath / "api", "API", interfaceSub)
2009-08-16 20:29:08 +02:00
2009-11-09 15:34:52 +01:00
val controlSub = baseProject(utilPath / "control", "Control")
val collectionSub = baseProject(utilPath / "collection", "Collections")
val ioSub = project(utilPath / "io", "IO", new IOProject(_), controlSub)
2009-11-09 15:34:52 +01:00
val classpathSub = baseProject(utilPath / "classpath", "Classpath")
2009-08-16 20:29:08 +02:00
val ivySub = project("ivy", "Ivy", new IvyProject(_), interfaceSub, launchInterfaceSub)
2009-11-09 15:34:52 +01:00
val logSub = baseProject(utilPath / "log", "Logging", interfaceSub)
val datatypeSub = baseProject("util" /"datatype", "Datatype Generator", ioSub)
2009-11-09 15:34:52 +01:00
2009-11-11 14:30:39 +01:00
val testSub = project("scripted", "Test", new TestProject(_), ioSub)
val compileInterfaceSub = project(compilePath / "interface", "Compiler Interface", new CompilerInterfaceProject(_), interfaceSub)
2009-08-16 20:29:08 +02:00
val taskSub = project(tasksPath, "Tasks", new TaskProject(_), controlSub, collectionSub)
2009-08-31 16:45:32 +02:00
val cacheSub = project(cachePath, "Cache", new CacheProject(_), taskSub, ioSub)
2009-11-09 15:34:52 +01:00
val trackingSub = baseProject(cachePath / "tracking", "Tracking", cacheSub)
val compilerSub = project(compilePath, "Compile", new CompileProject(_),
2009-11-22 01:00:49 +01:00
launchInterfaceSub, interfaceSub, ivySub, ioSub, classpathSub, compileInterfaceSub)
val stdTaskSub = project(tasksPath / "standard", "Standard Tasks", new StandardTaskProject(_), trackingSub, compilerSub, apiSub)
val altCompilerSub = baseProject("main", "Alternate Compiler Test", stdTaskSub, logSub)
2009-08-16 20:29:08 +02:00
2010-03-24 01:36:16 +01:00
val sbtSub = project("sbt", "Simple Build Tool", new SbtProject(_) {}, compilerSub, launchInterfaceSub)
2009-11-11 14:30:39 +01:00
def baseProject(path: Path, name: String, deps: Project*) = project(path, name, new Base(_), deps : _*)
2009-11-09 15:34:52 +01:00
/* Multi-subproject paths */
2009-08-31 16:45:32 +02:00
def cachePath = path("cache")
def tasksPath = path("tasks")
2009-08-21 14:12:43 +02:00
def launchPath = path("launch")
2009-08-18 06:51:08 +02:00
def utilPath = path("util")
def compilePath = path("compile")
def compilerInterfaceClasspath = compileInterfaceSub.projectClasspath(Configurations.Test)
//run in parallel
2010-02-08 05:45:19 +01:00
override def parallelExecution = true
def jlineRev = "0.9.94"
2010-01-23 02:17:49 +01:00
def jlineDep = "jline" % "jline" % jlineRev intransitive()
// publish locally when on repository server
2009-10-24 04:04:15 +02:00
override def managedStyle = ManagedStyle.Ivy
2009-11-03 05:02:00 +01:00
val publishTo = Resolver.file("test-repo", new File("/var/dbwww/repo/"))
2009-10-24 04:04:15 +02:00
/* Subproject configurations*/
class LaunchProject(info: ProjectInfo) extends Base(info) with TestWithIO with TestDependencies with ProguardLaunch with NoCrossPaths
2009-08-21 14:12:43 +02:00
{
2010-01-23 02:17:49 +01:00
val jline = jlineDep
2009-08-21 14:12:43 +02:00
val ivy = "org.apache.ivy" % "ivy" % "2.0.0"
override def deliverProjectDependencies = Nil
// defines the package that proguard operates on
def rawJarPath = jarPath
def rawPackage = `package`
override def packagePaths = super.packagePaths +++ launchInterfaceSub.packagePaths
// configure testing
override def testClasspath = super.testClasspath +++ interfaceSub.compileClasspath +++ interfaceSub.mainResourcesPath
override def testCompileAction = super.testCompileAction dependsOn(interfaceSub.publishLocal, testSamples.publishLocal)
// used to test the retrieving and loading of an application: sample app is packaged and published to the local repository
lazy val testSamples = project("test-sample", "Launch Test", new TestSamples(_), interfaceSub, launchInterfaceSub)
class TestSamples(info: ProjectInfo) extends Base(info) with NoCrossPaths with NoPublish {
override def deliverProjectDependencies = Nil
}
2009-08-21 14:12:43 +02:00
}
trait TestDependencies extends Project
2009-08-16 20:29:08 +02:00
{
val sc = "org.scala-tools.testing" %% "scalacheck" % "1.6" % "test"
2009-10-15 02:53:15 +02:00
val sp = "org.scala-tools.testing" % "specs" % "1.6.0" % "test"
2009-08-16 20:29:08 +02:00
}
class StandardTaskProject(info: ProjectInfo) extends Base(info)
{
override def testClasspath = super.testClasspath +++ compilerSub.testClasspath --- compilerInterfaceClasspath
}
class IOProject(info: ProjectInfo) extends Base(info) with TestDependencies
class TaskProject(info: ProjectInfo) extends Base(info) with TestDependencies
2009-08-16 20:29:08 +02:00
class CacheProject(info: ProjectInfo) extends Base(info)
{
// these compilation options are useful for debugging caches and task composition
2009-08-16 20:29:08 +02:00
//override def compileOptions = super.compileOptions ++ List(Unchecked,ExplainTypes, CompileOption("-Xlog-implicits"))
2010-01-26 05:06:23 +01:00
val sbinary = "org.scala-tools.sbinary" %% "sbinary" % "0.3"
2009-08-16 20:29:08 +02:00
}
2010-02-08 05:45:19 +01:00
class Base(info: ProjectInfo) extends DefaultProject(info) with ManagedBase with Component with Licensed
2009-08-16 20:29:08 +02:00
{
override def scratch = true
override def consoleClasspath = testClasspath
2009-08-16 20:29:08 +02:00
}
2010-02-08 05:45:19 +01:00
trait Licensed extends BasicScalaProject
{
def notice = path("NOTICE")
abstract override def mainResources = super.mainResources +++ notice +++ Path.lazyPathFinder( extractLicenses )
lazy val seeRegex = """\(see (.*?)\)""".r
def licensePath(str: String): Path = { val path = Path.fromString(XSbt.this.info.projectPath, str); if(path.exists) path else error("Referenced license '" + str + "' not found at " + path) }
def seePaths(noticeString: String): List[Path] = seeRegex.findAllIn(noticeString).matchData.map(d => licensePath(d.group(1))).toList
def extractLicenses = if(!notice.exists) Nil else FileUtilities.readString(notice asFile, log).fold(_ => { log.warn("Could not read NOTICE"); Nil} , seePaths _)
}
class CompileProject(info: ProjectInfo) extends Base(info) with TestWithLog with TestWithLaunch
{
override def testCompileAction = super.testCompileAction dependsOn(compileInterfaceSub.`package`, interfaceSub.`package`)
2009-11-03 05:02:00 +01:00
override def testClasspath = super.testClasspath +++ compileInterfaceSub.jarPath +++ interfaceSub.jarPath --- compilerInterfaceClasspath --- interfaceSub.mainCompilePath
override def compileOptions = super.compileOptions ++ Seq(CompileOption("-Xno-varargs-conversion")) //needed for invoking nsc.scala.tools.Main.process(Array[String])
}
class IvyProject(info: ProjectInfo) extends Base(info) with TestWithIO with TestWithLog with TestWithLaunch
2009-08-16 20:29:08 +02:00
{
val ivy = "org.apache.ivy" % "ivy" % "2.1.0"
2009-08-16 20:29:08 +02:00
}
abstract class BaseInterfaceProject(info: ProjectInfo) extends DefaultProject(info) with ManagedBase with TestWithLog with Component with JavaProject
class InterfaceProject(info: ProjectInfo) extends BaseInterfaceProject(info)
{
override def componentID: Option[String] = Some("xsbti")
override def packageAction = super.packageAction dependsOn generateVersions
def versionPropertiesPath = mainResourcesPath / "xsbt.version.properties"
lazy val generateVersions = task {
import java.util.{Date, TimeZone}
val formatter = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss")
formatter.setTimeZone(TimeZone.getTimeZone("GMT"))
val timestamp = formatter.format(new Date)
val content = "version=" + version + "\ntimestamp=" + timestamp
log.info("Writing version information to " + versionPropertiesPath + " :\n" + content)
FileUtilities.write(versionPropertiesPath.asFile, content, log)
}
2009-11-16 14:46:47 +01:00
override def watchPaths = super.watchPaths +++ apiDefinitionPaths --- sources(generatedBasePath)
override def mainSourceRoots = super.mainSourceRoots +++ (generatedBasePath ##)
def srcManagedPath = path("src_managed")
def generatedBasePath = srcManagedPath / "main" / "java"
/** Files that define the datatypes.*/
def apiDefinitionPaths: PathFinder = "definition"
/** Delete up the generated sources*/
lazy val cleanManagedSrc = cleanTask(srcManagedPath)
override def cleanAction = super.cleanAction dependsOn(cleanManagedSrc)
/** Runs the generator compiled by 'compile', putting the classes in src_managed and processing the definitions 'apiDefinitions'. */
lazy val generateSource = generateSourceAction dependsOn(cleanManagedSrc, datatypeSub.compile)
2010-01-23 02:17:49 +01:00
def generateSourceTask(immutable: Boolean, pkg: String, apiDefinitions: PathFinder): Task =
{
val m = if(immutable) "immutable" else "mutable"
generateSourceTask(m :: pkg :: generatedBasePath.absolutePath :: apiDefinitions.get.toList.map(_.absolutePath))
}
def generateSourceTask(args: List[String]): Task =
runTask(datatypeSub.getMainClass(true), datatypeSub.runClasspath, args)
def generateSourceAction =
//generateSourceTask(false, "xsbti.api", "definition" +++ "type") &&
generateSourceTask(true, "xsbti.api", "other" +++ "definition" +++ "type")
2009-11-16 14:46:47 +01:00
/** compiles the generated sources */
override def compileAction = super.compileAction dependsOn(generateSource)
}
2010-03-24 01:36:16 +01:00
class LaunchInterfaceProject(info: ProjectInfo) extends BaseInterfaceProject(info)
{
override def componentID = None
}
2009-11-09 15:34:52 +01:00
class TestProject(info: ProjectInfo) extends Base(info)
{
val process = "org.scala-tools.sbt" % "process" % "0.1"
}
class CompilerInterfaceProject(info: ProjectInfo) extends Base(info) with SourceProject with TestWithIO with TestWithLog
{
def xTestClasspath = projectClasspath(Configurations.Test)
def cID = "compiler-interface-src"
override def componentID = Some(cID)
2010-01-23 02:17:49 +01:00
// necessary because jline is not distributed with 2.8 and we will get a compile error
//val jline = jlineDep artifacts(Artifact("jline", Map("e:component" -> cID)))
override def ivyXML =
<dependencies>
<dependency org="jline" name="jline" rev={jlineRev} transitive="false">
<artifact name="jline" type="jar" e:component={cID}/>
</dependency>
</dependencies>
}
trait TestWithIO extends TestWith {
override def testWithTestClasspath = super.testWithTestClasspath ++ Seq(ioSub)
}
trait TestWithLaunch extends TestWith {
override def testWithTestClasspath = super.testWithTestClasspath ++ Seq(launchSub)
}
trait TestWithLog extends TestWith {
override def testWithCompileClasspath = super.testWithCompileClasspath ++ Seq(logSub)
}
trait TestWith extends BasicScalaProject
{
def testWithCompileClasspath: Seq[BasicScalaProject] = Nil
def testWithTestClasspath: Seq[BasicScalaProject] = Nil
override def testCompileAction = super.testCompileAction dependsOn((testWithTestClasspath.map(_.testCompile) ++ testWithCompileClasspath.map(_.compile)) : _*)
override def testClasspath = (super.testClasspath /: (testWithTestClasspath.map(_.testClasspath) ++ testWithCompileClasspath.map(_.compileClasspath) ))(_ +++ _)
}
2009-08-16 20:29:08 +02:00
}