forked from scala-steward-org/scala-steward
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract dependencies from scala-cli via sbt export (scala-steward-org…
…#2933) * Extract dependencies from scala-cli via sbt export * Fix BuildToolDispatcherTest * Install scala-cli in Docker container * Warn about missing Scalafix support in Scala CLI projects * Use Scope.Dependencies in all BuildToolAlg implementations * Remove unused import * Remove the export directory after calling sbtAlg * Do not install scala-cli with coursier Use the command from https://scala-cli.virtuslab.org/install instead. * Require a space after "using lib" * Use less vertical space * Ensure that using directives are in files below buildRoot * Add test * Test runMigration * Link to the Scala CLI issue about Scalafix support * Check that runMigration only logs
- Loading branch information
Showing
9 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
modules/core/src/main/scala/org/scalasteward/core/buildtool/scalacli/ScalaCliAlg.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2018-2023 Scala Steward contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.scalasteward.core.buildtool.scalacli | ||
|
||
import cats.Monad | ||
import cats.syntax.all._ | ||
import org.scalasteward.core.buildtool.sbt.SbtAlg | ||
import org.scalasteward.core.buildtool.{BuildRoot, BuildToolAlg} | ||
import org.scalasteward.core.data.Scope | ||
import org.scalasteward.core.edit.scalafix.ScalafixMigration | ||
import org.scalasteward.core.git.GitAlg | ||
import org.scalasteward.core.io.{FileAlg, ProcessAlg, WorkspaceAlg} | ||
import org.scalasteward.core.util.Nel | ||
import org.typelevel.log4cats.Logger | ||
|
||
final class ScalaCliAlg[F[_]](implicit | ||
fileAlg: FileAlg[F], | ||
gitAlg: GitAlg[F], | ||
logger: Logger[F], | ||
processAlg: ProcessAlg[F], | ||
sbtAlg: SbtAlg[F], | ||
workspaceAlg: WorkspaceAlg[F], | ||
F: Monad[F] | ||
) extends BuildToolAlg[F] { | ||
override def name: String = "Scala CLI" | ||
|
||
override def containsBuild(buildRoot: BuildRoot): F[Boolean] = { | ||
val buildRootPath = buildRoot.relativePath.dropWhile(Set('.', '/')) | ||
gitAlg | ||
.findFilesContaining(buildRoot.repo, "//> using lib ") | ||
.map(_.exists(_.startsWith(buildRootPath))) | ||
} | ||
|
||
override def getDependencies(buildRoot: BuildRoot): F[List[Scope.Dependencies]] = | ||
for { | ||
buildRootDir <- workspaceAlg.buildRootDir(buildRoot) | ||
exportDir = "tmp-sbt-build-for-scala-steward" | ||
exportCmd = | ||
Nel.of("scala-cli", "export", "--sbt", "--output", exportDir, buildRootDir.pathAsString) | ||
_ <- processAlg.execSandboxed(exportCmd, buildRootDir) | ||
exportBuildRoot = buildRoot.copy(relativePath = buildRoot.relativePath + s"/$exportDir") | ||
dependencies <- sbtAlg.getDependencies(exportBuildRoot) | ||
_ <- fileAlg.deleteForce(buildRootDir / exportDir) | ||
} yield dependencies | ||
|
||
override def runMigration(buildRoot: BuildRoot, migration: ScalafixMigration): F[Unit] = | ||
logger.warn( | ||
s"Scalafix migrations are currently not supported in $name projects, see https://github.com/VirtusLab/scala-cli/issues/647 for details" | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
modules/core/src/test/scala/org/scalasteward/core/buildtool/scalacli/ScalaCliAlgTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.scalasteward.core.buildtool.scalacli | ||
|
||
import munit.CatsEffectSuite | ||
import org.scalasteward.core.buildtool.BuildRoot | ||
import org.scalasteward.core.buildtool.sbt.command._ | ||
import org.scalasteward.core.data.{GroupId, Repo, Version} | ||
import org.scalasteward.core.edit.scalafix.ScalafixMigration | ||
import org.scalasteward.core.mock.MockContext.context._ | ||
import org.scalasteward.core.mock.MockState | ||
import org.scalasteward.core.mock.MockState.TraceEntry.{Cmd, Log} | ||
import org.scalasteward.core.util.Nel | ||
|
||
class ScalaCliAlgTest extends CatsEffectSuite { | ||
test("getDependencies") { | ||
val repo = Repo("user", "repo") | ||
val buildRoot = BuildRoot(repo, ".") | ||
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync() | ||
val sbtBuildDir = repoDir / "tmp-sbt-build-for-scala-steward" | ||
|
||
val obtained = scalaCliAlg.getDependencies(buildRoot).runS(MockState.empty) | ||
val expected = MockState.empty.copy(trace = | ||
Vector( | ||
Cmd( | ||
repoDir.toString, | ||
"firejail", | ||
"--quiet", | ||
s"--whitelist=$repoDir", | ||
"--env=VAR1=val1", | ||
"--env=VAR2=val2", | ||
"scala-cli", | ||
"export", | ||
"--sbt", | ||
"--output", | ||
"tmp-sbt-build-for-scala-steward", | ||
repoDir.toString | ||
), | ||
Cmd("read", s"$sbtBuildDir/project/build.properties"), | ||
Cmd("read", "classpath:StewardPlugin_1_3_11.scala"), | ||
Cmd("write", s"$sbtBuildDir/project/scala-steward-StewardPlugin_1_3_11.scala"), | ||
Cmd("write", s"$sbtBuildDir/project/project/scala-steward-StewardPlugin_1_3_11.scala"), | ||
Cmd( | ||
sbtBuildDir.toString, | ||
"firejail", | ||
"--quiet", | ||
s"--whitelist=$sbtBuildDir", | ||
"--env=VAR1=val1", | ||
"--env=VAR2=val2", | ||
"sbt", | ||
"-Dsbt.color=false", | ||
"-Dsbt.log.noformat=true", | ||
"-Dsbt.supershell=false", | ||
s";$crossStewardDependencies;$reloadPlugins;$stewardDependencies" | ||
), | ||
Cmd("rm", "-rf", s"$sbtBuildDir/project/project/scala-steward-StewardPlugin_1_3_11.scala"), | ||
Cmd("rm", "-rf", s"$sbtBuildDir/project/scala-steward-StewardPlugin_1_3_11.scala"), | ||
Cmd("rm", "-rf", s"$sbtBuildDir") | ||
) | ||
) | ||
|
||
assertIO(obtained, expected) | ||
} | ||
|
||
test("runMigration") { | ||
val repo = Repo("user", "repo") | ||
val buildRoot = BuildRoot(repo, ".") | ||
val migration = ScalafixMigration( | ||
GroupId("co.fs2"), | ||
Nel.of("fs2-core"), | ||
Version("1.0.0"), | ||
Nel.of("github:functional-streams-for-scala/fs2/v1?sha=v1.0.5") | ||
) | ||
val obtained = scalaCliAlg.runMigration(buildRoot, migration).runS(MockState.empty) | ||
assertIO(obtained.map(_.trace.collect { case Log(_) => () }.size), 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters