diff --git a/main/Defaults.scala b/main/Defaults.scala index 6dd46bc6c..c77a5224b 100755 --- a/main/Defaults.scala +++ b/main/Defaults.scala @@ -543,10 +543,15 @@ object Defaults extends BuildCommon val hasScala = srcs.exists(_.name.endsWith(".scala")) val hasJava = srcs.exists(_.name.endsWith(".java")) val cp = in.config.classpath.toList - in.config.classesDirectory - if(hasScala) - Doc(in.config.maxErrors, in.compilers.scalac).cached(cache / "scala", nameForSrc(config.name), srcs, cp, out, in.config.options, s.log) - else if(hasJava) - Doc(in.config.maxErrors, in.compilers.javac).cached(cache / "java", nameForSrc(config.name), srcs, cp, out, in.config.javacOptions, s.log) + val label = nameForSrc(config.name) + val (options, runDoc) = + if(hasScala) + (in.config.options, Doc.scaladoc(label, cache / "scala", in.compilers.scalac)) + else if(hasJava) + (in.config.javacOptions, Doc.javadoc(label, cache / "java", in.compilers.javac)) + else + (Nil, RawCompileLike.nop) + runDoc(srcs, cp, out, options, in.config.maxErrors, s.log) out } )) diff --git a/main/actions/Doc.scala b/main/actions/Doc.scala index 96f5fc70d..d233da224 100644 --- a/main/actions/Doc.scala +++ b/main/actions/Doc.scala @@ -15,10 +15,23 @@ package sbt import Tracked.{inputChanged, outputChanged} import FilesInfo.{exists, hash, lastModified} -object Doc { +object Doc +{ + import RawCompileLike._ + def scaladoc(label: String, cache: File, compiler: AnalyzingCompiler): Gen = + cached(cache, prepare(label + " Scala API documentation", compiler.doc)) + def javadoc(label: String, cache: File, doc: sbt.compiler.Javadoc): Gen = + cached(cache, prepare(label + " Scala API documentation", filterSources(javaSourcesOnly, doc.doc))) + + val javaSourcesOnly: File => Boolean = _.getName.endsWith(".java") + + @deprecated("Use `scaladoc`", "0.13.0") def apply(maximumErrors: Int, compiler: AnalyzingCompiler) = new Scaladoc(maximumErrors, compiler) + + @deprecated("Use `javadoc`", "0.13.0") def apply(maximumErrors: Int, compiler: sbt.compiler.Javadoc) = new Javadoc(maximumErrors, compiler) } +@deprecated("No longer used. See `Doc.javadoc` or `Doc.scaladoc`", "0.13.0") sealed trait Doc { type Gen = (Seq[File], Seq[File], File, Seq[String], Int, Logger) => Unit @@ -55,6 +68,7 @@ sealed trait Doc { cachedDoc(inputs)(() => exists(outputDirectory.***.get.toSet)) } } +@deprecated("No longer used. See `Doc.scaladoc`", "0.13.0") final class Scaladoc(maximumErrors: Int, compiler: AnalyzingCompiler) extends Doc { def apply(label: String, sources: Seq[File], classpath: Seq[File], outputDirectory: File, options: Seq[String], log: Logger) @@ -62,6 +76,7 @@ final class Scaladoc(maximumErrors: Int, compiler: AnalyzingCompiler) extends Do generate("Scala", label, compiler.doc, sources, classpath, outputDirectory, options, maximumErrors, log) } } +@deprecated("No longer used. See `Doc.javadoc`", "0.13.0") final class Javadoc(maximumErrors: Int, doc: sbt.compiler.Javadoc) extends Doc { def apply(label: String, sources: Seq[File], classpath: Seq[File], outputDirectory: File, options: Seq[String], log: Logger) diff --git a/main/actions/RawCompileLike.scala b/main/actions/RawCompileLike.scala new file mode 100644 index 000000000..244873f64 --- /dev/null +++ b/main/actions/RawCompileLike.scala @@ -0,0 +1,64 @@ +/* sbt -- Simple Build Tool + * Copyright 2008, 2009, 2010, 2011 Mark Harrah, Indrajit Raychaudhuri + */ +package sbt + + import java.io.File + import compiler.{AnalyzingCompiler, JavaCompiler} + + import Predef.{conforms => _, _} + import Types.:+: + import Path._ + + import sbinary.DefaultProtocol.FileFormat + import Cache.{defaultEquiv, hConsCache, hNilCache, IntFormat, seqCache, seqFormat, streamFormat, StringFormat, UnitFormat, wrapIn} + import Tracked.{inputChanged, outputChanged} + import FilesInfo.{exists, hash, lastModified} + +object RawCompileLike +{ + type Gen = (Seq[File], Seq[File], File, Seq[String], Int, Logger) => Unit + + def cached(cache: File, doCompile: Gen): Gen = (sources, classpath, outputDirectory, options, maxErrors, log) => + { + type Inputs = FilesInfo[HashFileInfo] :+: FilesInfo[ModifiedFileInfo] :+: String :+: File :+: Seq[String] :+: Int :+: HNil + val inputs: Inputs = hash(sources.toSet) :+: lastModified(classpath.toSet) :+: classpath.absString :+: outputDirectory :+: options :+: maxErrors :+: HNil + implicit val stringEquiv: Equiv[String] = defaultEquiv + implicit val fileEquiv: Equiv[File] = defaultEquiv + implicit val intEquiv: Equiv[Int] = defaultEquiv + val cachedComp = inputChanged(cache / "inputs") { (inChanged, in: Inputs) => + outputChanged(cache / "output") { (outChanged, outputs: FilesInfo[PlainFileInfo]) => + if(inChanged || outChanged) + doCompile(sources, classpath, outputDirectory, options, maxErrors, log) + else + log.debug("Uptodate: " + outputDirectory.getAbsolutePath) + } + } + cachedComp(inputs)(() => exists(outputDirectory.***.get.toSet)) + } + def prepare(description: String, doCompile: Gen): Gen = (sources, classpath, outputDirectory, options, maxErrors, log) => + { + if(sources.isEmpty) + log.info("No sources available, skipping " + description + "...") + else + { + log.info(description.capitalize + " to " + outputDirectory.absolutePath + "...") + IO.delete(outputDirectory) + IO.createDirectory(outputDirectory) + doCompile(sources, classpath, outputDirectory, options, maxErrors, log) + log.info(description.capitalize + " successful.") + } + } + def filterSources(f: File => Boolean, doCompile: Gen): Gen = (sources, classpath, outputDirectory, options, maxErrors, log) => + doCompile(sources filter f, classpath, outputDirectory, options, maxErrors, log) + + def rawCompile(instance: ScalaInstance, cpOptions: ClasspathOptions): Gen = (sources, classpath, outputDirectory, options, maxErrors, log) => + { + val compiler = new sbt.compiler.RawCompiler(instance, cpOptions, log) + compiler(sources, classpath, outputDirectory, options) + } + def compile(label: String, cache: File, instance: ScalaInstance, cpOptions: ClasspathOptions): Gen = + cached(cache, prepare(label + " sources", rawCompile(instance, cpOptions))) + + val nop: Gen = (sources, classpath, outputDirectory, options, maxErrors, log) => () +}