From 1ee5af39d6a4b73e6e92d909f8f655dd0d2e80bb Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Tue, 10 Aug 2010 09:19:37 -0400 Subject: [PATCH] allow discovery on both modules/classes, not just one or the other --- main/build/Build.scala | 32 +++++++++++++++++--------------- main/build/LoadCommand.scala | 10 ++++++++-- main/build/Parse.scala | 12 ++++++------ 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/main/build/Build.scala b/main/build/Build.scala index dffbc2d3f..ff089a6d0 100644 --- a/main/build/Build.scala +++ b/main/build/Build.scala @@ -34,7 +34,7 @@ object Build { val buildDir = base / "project" / "build" val sources = (buildDir * "*.scala") +++ (buildDir / "src" / "main" / "scala" ** "*.scala") - source(Nil, sources.get.toSeq, Some(buildDir / "target" asFile), false, auto, name, configuration, allowMultiple) + source(Nil, sources.get.toSeq, Some(buildDir / "target" asFile), None, auto, name, configuration, allowMultiple) } def binary(classpath: Seq[File], module: Boolean, name: String, parent: ClassLoader, allowMultiple: Boolean): Seq[Any] = @@ -44,7 +44,7 @@ object Build else { val names = if(allowMultiple) name.split(",").toSeq else Seq(name) - binaries(classpath, module, names, parent) + binaries(classpath, names.map(n => ToLoad(n,module)), parent) } } @@ -69,38 +69,40 @@ object Build val agg = new AggressiveCompile(cacheDirectory) agg(compiler, javac, sources, compileClasspath, outputDirectory, Nil, options)(log) } - def source(classpath: Seq[File], sources: Seq[File], output: Option[File], module: Boolean, auto: Auto.Value, name: String, configuration: xsbti.AppConfiguration, allowMultiple: Boolean = false): Seq[Any] = + def source(classpath: Seq[File], sources: Seq[File], output: Option[File], module: Option[Boolean], auto: Auto.Value, name: String, configuration: xsbti.AppConfiguration, allowMultiple: Boolean = false): Seq[Any] = { val conf = new Compile(classpath, sources, output, Nil, configuration) val analysis = compile(conf) val discovered = discover(analysis, module, auto, name) - binaries(conf.projectClasspath, module, check(discovered, allowMultiple), loader(configuration)) + binaries(conf.projectClasspath, check(discovered, allowMultiple), loader(configuration)) } - def discover(analysis: inc.Analysis, module: Boolean, auto: Auto.Value, name: String): Seq[String] = + def discover(analysis: inc.Analysis, module: Option[Boolean], auto: Auto.Value, name: String): Seq[ToLoad] = { import Auto.{Annotation, Explicit, Subclass} auto match { - case Explicit => if(name.isEmpty) error("No name specified to load explicitly.") else Seq(name) + case Explicit => if(name.isEmpty) error("No name specified to load explicitly.") else Seq(new ToLoad(name)) case Subclass => discover(analysis, module, new inc.Discovery(Set(name), Set.empty)) case Annotation => discover(analysis, module, new inc.Discovery(Set.empty, Set(name))) } } - def discover(analysis: inc.Analysis, command: DiscoverCommand): Seq[String] = + def discover(analysis: inc.Analysis, command: DiscoverCommand): Seq[ToLoad] = discover(analysis, command.module, command.discovery) - def discover(analysis: inc.Analysis, module: Boolean, discovery: inc.Discovery): Seq[String] = + def discover(analysis: inc.Analysis, module: Option[Boolean], discovery: inc.Discovery): Seq[ToLoad] = { for(src <- analysis.apis.internal.values.toSeq; - (df, found) <- discovery(src.definitions) if !found.isEmpty && found.isModule == module) + (df, found) <- discovery(src.definitions) if !found.isEmpty && moduleMatches(found.isModule, module)) yield - df.name + new ToLoad(df.name, found.isModule) } + def moduleMatches(isModule: Boolean, expected: Option[Boolean]): Boolean = + expected.isEmpty || (Some(isModule) == expected) - def binaries(classpath: Seq[File], module: Boolean, names: Seq[String], parent: ClassLoader): Seq[Any] = - loadBinaries(names, module, toLoader(classpath, parent)) + def binaries(classpath: Seq[File], toLoad: Seq[ToLoad], parent: ClassLoader): Seq[Any] = + loadBinaries(toLoad, toLoader(classpath, parent)) - def loadBinaries(names: Seq[String], module: Boolean, loader: ClassLoader): Seq[Any] = - for(name <- names if !name.isEmpty) yield + def loadBinaries(toLoad: Seq[ToLoad], loader: ClassLoader): Seq[Any] = + for(ToLoad(name, module) <- toLoad if !name.isEmpty) yield loadBinary(name, module, loader) def loadBinary(name: String, module: Boolean, loader: ClassLoader): Any = @@ -112,7 +114,7 @@ object Build clazz.newInstance } - def check(discovered: Seq[String], allowMultiple: Boolean): Seq[String] = + def check[T](discovered: Seq[T], allowMultiple: Boolean): Seq[T] = discovered match { case Seq() => error("No project found") diff --git a/main/build/LoadCommand.scala b/main/build/LoadCommand.scala index 965be134f..6caee4c65 100644 --- a/main/build/LoadCommand.scala +++ b/main/build/LoadCommand.scala @@ -8,7 +8,7 @@ import java.io.File sealed trait LoadCommand final case class BinaryLoad(classpath: Seq[File], module: Boolean, name: String) extends LoadCommand -final case class SourceLoad(classpath: Seq[File], sourcepath: Seq[File], output: Option[File], module: Boolean, auto: Auto.Value, name: String) extends LoadCommand +final case class SourceLoad(classpath: Seq[File], sourcepath: Seq[File], output: Option[File], module: Option[Boolean], auto: Auto.Value, name: String) extends LoadCommand final case class ProjectLoad(base: File, auto: Auto.Value, name: String) extends LoadCommand object Auto extends Enumeration @@ -17,4 +17,10 @@ object Auto extends Enumeration } final case class CompileCommand(classpath: Seq[File], sources: Seq[File], output: Option[File], options: Seq[String]) -final case class DiscoverCommand(module: Boolean, discovery: inc.Discovery) \ No newline at end of file +final case class DiscoverCommand(module: Option[Boolean], discovery: inc.Discovery) + +final case class ToLoad(name: String, isModule: Boolean = false) +{ + override def toString = tpe + " " + name + def tpe = if(isModule) "object" else "class" +} \ No newline at end of file diff --git a/main/build/Parse.scala b/main/build/Parse.scala index 0f504e447..e4da4155d 100644 --- a/main/build/Parse.scala +++ b/main/build/Parse.scala @@ -55,7 +55,7 @@ The command has the following syntax: if(!srcs.isEmpty) SourceLoad(cp, srcs, output(args), mod, auto(args), nme) else if(!cp.isEmpty) - BinaryLoad(cp, mod, nme) + BinaryLoad(cp, mod.getOrElse(false), nme) else ProjectLoad(proj, auto(args), nme) } @@ -83,11 +83,11 @@ The command has the following syntax: case Some(x) => error("Illegal auto argument '" + x + "'") } - def module(args: Seq[String]): Boolean = - getArg(args, "module") match { - case None | Some("false") => false - case Some("true") => true - case Some(x) => error("Expected boolean, got '" + x + "'") + def module(args: Seq[String]): Option[Boolean] = + getArg(args, "module") map { + case "false" => false + case "true" => true + case x => error("Expected boolean, got '" + x + "'") } def names(label: String, args: Seq[String]): Set[String] =