Skip to content

Commit

Permalink
Fix metabuild loading
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Dec 18, 2023
1 parent 264bd01 commit 96f945d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
9 changes: 6 additions & 3 deletions main/src/main/scala/sbt/internal/Load.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ private[sbt] object Load {
val launcher = scalaProvider.launcher
val stagingDirectory = getStagingDirectory(state, globalBase).getCanonicalFile
val javaHome = Paths.get(sys.props("java.home"))
val out = baseDirectory.toPath.resolve("target").resolve("out")
val rootPaths = Map(
"OUT" -> out,
"BASE" -> baseDirectory.toPath,
"SBT_BOOT" -> launcher.bootDirectory.toPath,
"IVY_HOME" -> launcher.ivyHome.toPath,
Expand Down Expand Up @@ -1430,7 +1432,7 @@ private[sbt] object Load {
config: LoadBuildConfiguration,
dependencyClasspath: Def.Classpath,
definitionClasspath: Def.Classpath
): ClassLoader = {
): ClassLoader =
val manager = config.pluginManagement
val converter = config.converter
val parentLoader: ClassLoader =
Expand All @@ -1448,8 +1450,9 @@ private[sbt] object Load {
loader
// Load the definition classpath separately to avoid conflicts, see #511.
if definitionClasspath.isEmpty then parentLoader
else ClasspathUtil.toLoader(data(definitionClasspath).map(converter.toPath), parentLoader)
}
else
val cp = data(definitionClasspath).map(converter.toPath)
ClasspathUtil.toLoader(cp, parentLoader)

def buildPluginDefinition(dir: File, s: State, config: LoadBuildConfiguration): PluginData = {
val (eval, pluginDef) = apply(dir, s, config)
Expand Down
22 changes: 11 additions & 11 deletions main/src/main/scala/sbt/internal/PluginDiscovery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import xsbti.compile.CompileAnalysis
import sbt.internal.inc.ModuleUtilities

import sbt.io.IO
import scala.reflect.ClassTag

object PluginDiscovery {
object PluginDiscovery:

/**
* Relative paths of resources that list top-level modules that are available.
Expand All @@ -40,8 +41,8 @@ object PluginDiscovery {

/** Discovers and loads the sbt-plugin-related top-level modules from the classpath and source analysis in `data` and using the provided class `loader`. */
def discoverAll(data: PluginData, loader: ClassLoader): DetectedPlugins = {
def discover[T](resource: String)(implicit manifest: Manifest[T]) =
binarySourceModules[T](data, loader, resource)
def discover[A1: ClassTag](resource: String) =
binarySourceModules[A1](data, loader, resource)
import Paths._
// TODO - Fix this once we can autodetect AutoPlugins defined by sbt itself.
val defaultAutoPlugins = Seq(
Expand Down Expand Up @@ -146,15 +147,16 @@ object PluginDiscovery {
val cpFiles = classpath.map(_.data).map(converter.toPath).map(_.toFile)
IO.urlAsFile(url) exists (cpFiles.contains _)

private[sbt] def binarySourceModules[A](
private[sbt] def binarySourceModules[A: ClassTag](
data: PluginData,
loader: ClassLoader,
resourceName: String
)(implicit classTag: reflect.ClassTag[A]): DetectedModules[A] = {
): DetectedModules[A] =
val classpath = data.classpath
val classTag = summon[ClassTag[A]]
val namesAndValues =
if (classpath.isEmpty) Nil
else {
if classpath.isEmpty then Nil
else
val names =
binarySourceModuleNames(
classpath,
Expand All @@ -164,9 +166,7 @@ object PluginDiscovery {
classTag.runtimeClass.getName
)
loadModules[A](data, names, loader)
}
new DetectedModules(namesAndValues)
}
DetectedModules(namesAndValues)

private[this] def loadModules[A: reflect.ClassTag](
data: PluginData,
Expand Down Expand Up @@ -196,4 +196,4 @@ object PluginDiscovery {
)
throw new IncompatiblePluginsException(msgBase + msgExtra, t)
}
}
end PluginDiscovery
3 changes: 1 addition & 2 deletions sbt-app/src/sbt-test/actions/aggregate/test
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ $ exists ran
$ delete ran

# switch to multi-project, no aggregation yet. 'reload' will drop session settings
$ touch multi
$ copy-file changes/build.sbt build.sbt
$ mkdir sub sub/sub
$ copy-file changes/build.sbt build.sbt
> reload

# define in root project only
Expand Down

0 comments on commit 96f945d

Please sign in to comment.