Skip to content

Commit

Permalink
fix: Append -root to synthetic root
Browse files Browse the repository at this point in the history
**Problem**
I notice that the synthetic root project ends up conflicting with
the projectMatrix on Scala 3, when the name of the matrix
matches the directory name, which is fairly common.

Also when the matrix is located at the root, we still want
the synthetic root for aggregation purpose, but we don't want
the root to end up capturing the source files.

**Solution**
1. Append `-root` to the root project.
2. Blank out the source files.
  • Loading branch information
eed3si9n committed Oct 3, 2024
1 parent eb5c3cf commit 356a900
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
15 changes: 13 additions & 2 deletions main/src/main/scala/sbt/internal/BuildDef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ package sbt
package internal

import java.io.File
import Keys.{ organization, thisProject, autoGeneratedProject, publish, publishLocal, skip }
import Keys.{
organization,
thisProject,
autoGeneratedProject,
publish,
publishLocal,
skip,
sources,
}
import Def.Setting
// import sbt.ProjectExtra.apply
import sbt.io.Hash
import sbt.internal.util.{ Attributed, StringAttributeMap }
import sbt.internal.inc.{ FileAnalysisStore, ReflectUtilities }
import sbt.SlashSyntax0.*
import sbt.librarymanagement.Configurations.{ Compile, Test }
import sbt.SlashSyntax0.given
import xsbti.{ FileConverter, VirtualFileRef }
import xsbti.compile.CompileAnalysis

Expand Down Expand Up @@ -67,6 +76,8 @@ private[sbt] object BuildDef:
defaultProjectSettings,
publish / skip := true,
publishLocal / skip := true,
Compile / sources := Nil,
Test / sources := Nil,
)

private[sbt] def defaultProjectSettings: Seq[Setting[_]] = Seq(
Expand Down
20 changes: 11 additions & 9 deletions main/src/main/scala/sbt/internal/Load.scala
Original file line number Diff line number Diff line change
Expand Up @@ -866,22 +866,24 @@ private[sbt] object Load {
localBase: File,
context: PluginManagement.Context,
existingIDs: Seq[String]
): String = {
def normalizeID(f: File) = Project.normalizeProjectID(f.getName) match {
): String =
def normalizeID(f: File) = Project.normalizeProjectID(f.getName) match
case Right(id) => id
case Left(msg) => sys.error(autoIDError(f, msg))
}
@tailrec def nthParentName(f: File, i: Int): String =
if (f eq null) BuildDef.defaultID(localBase)
else if (i <= 0) normalizeID(f)
if f eq null then BuildDef.defaultID(localBase)
else if i <= 0 then normalizeID(f)
else nthParentName(f.getParentFile, i - 1)
val pluginDepth = context.pluginProjectDepth
val postfix = "-build" * pluginDepth
val postfix =
if pluginDepth == 0 then "-root"
else "-build" * pluginDepth
val idBase =
if (context.globalPluginProject) "global-plugins" else nthParentName(localBase, pluginDepth)
if context.globalPluginProject then "global-plugins"
else nthParentName(localBase, pluginDepth)
val tryID = idBase + postfix
if (existingIDs.contains(tryID)) BuildDef.defaultID(localBase) else tryID
}
if existingIDs.contains(tryID) then BuildDef.defaultID(localBase)
else tryID

private[this] def autoIDError(base: File, reason: String): String =
"Could not derive root project ID from directory " + base.getAbsolutePath + ":\n" +
Expand Down

0 comments on commit 356a900

Please sign in to comment.