Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle improvements #1497

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ case class BloopParametersExtension(project: Project) {
includeJavadoc_.set(false)
@Input @Optional def getIncludeJavadoc: Property[java.lang.Boolean] = includeJavadoc_

def createParameters: BloopParameters =
def createParameters: BloopParameters = {
val defaultTargetDir = project.getRootProject.workspacePath.resolve(".bloop").toFile
BloopParameters(
targetDir_.getOrElse(project.getRootProject.getProjectDir / ".bloop"),
targetDir_.getOrElse(defaultTargetDir),
compilerName_.getOrElse("scala-compiler"),
stdLibName_.getOrElse("scala-library"),
includeSources_.get,
includeJavadoc_.get,
getDottyVersionOption
)
}
}

case class BloopParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class BloopConverter(parameters: BloopParameters) {

val DottyVersion = raw"""0\.(\d+)(.*)""".r
val Scala3Version = raw"""3\.(\d+)\.(\d+)-(\w+)(.*)""".r
val Scala3VersionReleased = raw"""3\.(\d+)(.*)""".r
val (dottyOrgName, dottyLibrary, artifactAndVersion) = version match {
case DottyVersion(minor, patch) =>
val artifactID = s"dotty-compiler_0.$minor"
Expand All @@ -159,6 +160,12 @@ class BloopConverter(parameters: BloopParameters) {
val artifactVersion =
if (remaining.isEmpty) "+" else s"3.$minor.$patch-$milestone$remaining"
("org.scala-lang", "SCALA3-LIBRARY", s"$artifactID:$artifactVersion")
case Scala3VersionReleased(minor, patch) =>
val artifactID = s"scala3-compiler_3"
val artifactVersion = if (patch.isEmpty) "+" else s"3.$minor$patch"
("org.scala-lang", "SCALA3-LIBRARY", s"$artifactID:$artifactVersion")
case "3" =>
("org.scala-lang", "SCALA3-LIBRARY", s"scala3-compiler_3:+")
}

val compilerDependencyName = s"$dottyOrgName:$artifactAndVersion"
Expand Down Expand Up @@ -253,7 +260,7 @@ class BloopConverter(parameters: BloopParameters) {
bloopProject = Config.Project(
name = projectName,
directory = project.getProjectDir.toPath,
workspaceDir = Option(project.getRootProject.getProjectDir.toPath),
workspaceDir = Option(project.getRootProject.workspacePath),
sources = sources,
sourcesGlobs = None,
sourceRoots = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.gradle.api.{Project, Task, GradleException}
import scala.collection.JavaConverters._
import scala.reflect.ClassTag
import scala.util.control.NonFatal
import java.nio.file.Path

object syntax {

Expand Down Expand Up @@ -49,6 +50,25 @@ object syntax {
def getExtension[T](implicit t: ClassTag[T]): T = {
project.getExtensions.getByType(t.runtimeClass.asInstanceOf[Class[T]])
}

private def getCommonRootPath(path1: Path, path2: Path): Path = {
var idx = 0
var finished = false
while (!finished) {
if (idx < path1.getNameCount() && idx < path2.getNameCount() && path1.getName(idx) == path2
.getName(idx))
idx = idx + 1
else
finished = true
}
path1.getRoot().resolve(path1.subpath(0, idx))
}

def workspacePath: Path = {
project.getAllprojects.asScala
.map(_.getProjectDir().toPath())
.foldLeft(project.getRootDir().toPath())(getCommonRootPath)
}
}

/**
Expand Down
Loading