Skip to content
Draft
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
8 changes: 7 additions & 1 deletion modules/build/src/main/scala/scala/build/LocalRepo.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package scala.build
import coursier.cache.FileCache
import coursier.paths.Util
import coursier.util.Task

import java.io.{BufferedInputStream, Closeable}
import java.nio.channels.{FileChannel, FileLock}
Expand All @@ -12,6 +14,9 @@ object LocalRepo {

private def resourcePath = Constants.localRepoResourcePath

private[build] def localRepoBaseDir(cache: FileCache[Task]): os.Path =
os.Path(cache.location, os.pwd) / "scalacli-local-repo"

private def using[S <: Closeable, T](is: => S)(f: S => T): T = {
var is0 = Option.empty[S]
try {
Expand Down Expand Up @@ -51,10 +56,11 @@ object LocalRepo {
}

def localRepo(
baseDir: os.Path,
cache: FileCache[Task],
logger: Logger,
loader: ClassLoader = Thread.currentThread().getContextClassLoader
): Option[String] = {
val baseDir = localRepoBaseDir(cache)
val archiveUrl = loader.getResource(resourcePath)
logger.debug(s"archive url: $archiveUrl")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import scala.build.Position.File
import scala.build.actionable.ActionableDiagnostic.*
import scala.build.actionable.ActionablePreprocessor
import scala.build.options.{BuildOptions, InternalOptions, SuppressWarningOptions}
import scala.build.{BuildThreads, Directories, LocalRepo}
import scala.build.{BuildThreads, LocalRepo}
import scala.jdk.CollectionConverters.*

class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {

val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-actionable-diagnostic-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-actionable-diagnostic-")
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger())
)
)
val buildThreads: BuildThreads = BuildThreads.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package scala.build.tests

import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.FileCache
import coursier.util.Task

import java.util.concurrent.TimeUnit

Expand All @@ -14,16 +16,18 @@ import scala.build.bsp.{
WrappedSourcesResult
}
import scala.build.options.{BuildOptions, InternalOptions, Scope}
import scala.build.{Build, BuildThreads, Directories, GeneratedSource, LocalRepo}
import scala.build.{Build, BuildThreads, GeneratedSource, LocalRepo}
import scala.collection.mutable.ArrayBuffer
import scala.jdk.CollectionConverters.*

class BspServerTests extends TestUtil.ScalaCliBuildSuite {
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-bsp-server-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-bsp-server-")
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger())
)
)
val buildThreads: BuildThreads = BuildThreads.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.eed3si9n.expecty.Expecty.assert as expect
import coursier.Repositories
import coursier.cache.FileCache
import coursier.maven.MavenRepository
import coursier.util.Task
import coursier.version.Version
import dependency.ScalaParameters

Expand All @@ -18,17 +19,19 @@ import scala.build.internal.Constants.*
import scala.build.internal.Regexes.{scala2NightlyRegex, scala3LtsRegex}
import scala.build.options.*
import scala.build.tests.util.BloopServer
import scala.build.{Build, BuildThreads, Directories, LocalRepo, Positioned, RepositoryUtils}
import scala.build.{Build, BuildThreads, LocalRepo, Positioned, RepositoryUtils}
import scala.concurrent.duration.DurationInt

class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
override def munitFlakyOK: Boolean = TestUtil.isCI
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val buildThreads: BuildThreads = BuildThreads.create()
val baseOptions = BuildOptions(
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)
val buildThreads: BuildThreads = BuildThreads.create()
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger()),
keepDiagnostics = true
)
)
Expand Down Expand Up @@ -374,7 +377,8 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
test("User scalac options shadow internal ones") {
val defaultOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger())
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package scala.build.tests

import bloop.rifle.BloopRifleLogger
import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.CacheLogger
import coursier.cache.{CacheLogger, FileCache}
import coursier.util.Task
import org.scalajs.logging.{Logger as ScalaJsLogger, NullLogger}

import java.io.PrintStream
Expand Down Expand Up @@ -61,13 +62,22 @@ class BuildProjectTests extends TestUtil.ScalaCliBuildSuite {
}

test("workspace for bsp") {
val options = BuildOptions(
internal = InternalOptions(localRepository =
LocalRepo.localRepo(scala.build.Directories.default().localRepoDir, TestLogger())
val cacheDir = os.temp.dir(prefix = "scala-cli-tests-build-project-")
val testCache = FileCache().withLocation(cacheDir.toIO)
val options = BuildOptions(
internal = InternalOptions(
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger())
)
)
val inputs = Inputs.empty("project")
val sources = Sources(Nil, Nil, None, Nil, options)
val inputs = Inputs.empty("project")
val sources = Sources(
paths = Nil,
inMemory = Nil,
defaultMainClass = None,
resourceDirs = Nil,
buildOptions = options
)
val logger = new LoggerMock()
val artifacts = options.artifacts(logger, Scope.Test).orThrow

Expand Down
10 changes: 7 additions & 3 deletions modules/build/src/test/scala/scala/build/tests/BuildTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import bloop.rifle.BloopRifleConfig
import ch.epfl.scala.bsp4j
import com.eed3si9n.expecty.Expecty.expect
import com.google.gson.Gson
import coursier.cache.FileCache
import coursier.util.Task
import dependency.parser.DependencyParser

import java.io.IOException
Expand All @@ -19,7 +21,7 @@ import scala.build.options.*
import scala.build.tastylib.TastyData
import scala.build.tests.TestUtil.*
import scala.build.tests.util.BloopServer
import scala.build.{Build, BuildThreads, Directories, LocalRepo, Positioned}
import scala.build.{Build, BuildThreads, LocalRepo, Positioned}
import scala.jdk.CollectionConverters.*
import scala.meta.internal.semanticdb.TextDocuments
import scala.util.Properties
Expand All @@ -32,7 +34,8 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
if server then Some(BloopServer.bloopConfig) else None

val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)

override def afterAll(): Unit = {
TestInputs.tryRemoveAll(extraRepoTmpDir)
Expand All @@ -41,7 +44,8 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {

val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package scala.build.tests

import bloop.rifle.BloopRifleConfig
import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.FileCache
import coursier.util.Task

import scala.build.Ops.EitherThrowOps
import scala.build.errors.{
Expand All @@ -19,13 +21,14 @@ import scala.build.options.{
Scope
}
import scala.build.tests.util.BloopServer
import scala.build.{Build, BuildThreads, Directories, LocalRepo, Position, Positioned}
import scala.build.{Build, BuildThreads, LocalRepo, Position, Positioned}

class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
val buildThreads: BuildThreads = BuildThreads.create()
def bloopConfigOpt: Option[BloopRifleConfig] = Some(BloopServer.bloopConfig)
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)

override def afterAll(): Unit = {
TestInputs.tryRemoveAll(extraRepoTmpDir)
Expand All @@ -34,7 +37,8 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {

val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
10 changes: 7 additions & 3 deletions modules/build/src/test/scala/scala/build/tests/InputsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ package scala.build.tests

import bloop.rifle.BloopRifleConfig
import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.FileCache
import coursier.util.Task

import scala.build.input.*
import scala.build.input.ElementsUtils.*
import scala.build.internal.Constants
import scala.build.options.{BuildOptions, InternalOptions}
import scala.build.tests.util.BloopServer
import scala.build.{Build, BuildThreads, Directories, LocalRepo}
import scala.build.{Build, BuildThreads, LocalRepo}

class InputsTests extends TestUtil.ScalaCliBuildSuite {
val buildThreads: BuildThreads = BuildThreads.create()
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)
def bloopConfigOpt: Option[BloopRifleConfig] = Some(BloopServer.bloopConfig)
val buildOptions: BuildOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package scala.build.tests

import coursier.cache.FileCache
import coursier.util.Task

import scala.build.LocalRepo

class LocalRepoTests extends TestUtil.ScalaCliBuildSuite {
test("localRepoBaseDir is anchored to the coursier cache location") {
val cacheDir = os.temp.dir(prefix = "scala-cli-cache-")
val cache = FileCache().withLocation(cacheDir.toIO)
assertEquals(LocalRepo.localRepoBaseDir(cache), cacheDir / "scalacli-local-repo")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ package scala.build.tests

import bloop.rifle.BloopRifleConfig
import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.FileCache
import coursier.util.Task

import scala.build.options.{BuildOptions, InternalOptions, PackageType}
import scala.build.tests.util.BloopServer
import scala.build.{BuildThreads, Directories, LocalRepo}
import scala.build.{BuildThreads, LocalRepo}

class PackagingUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {
val buildThreads: BuildThreads = BuildThreads.create()
def bloopConfig: Option[BloopRifleConfig] = Some(BloopServer.bloopConfig)

val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)

val buildOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ package scala.build.tests

import bloop.rifle.BloopRifleConfig
import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.FileCache
import coursier.util.Task

import scala.build.errors.UsingDirectiveValueNumError
import scala.build.options.{BuildOptions, InternalOptions}
import scala.build.tests.util.BloopServer
import scala.build.{BuildThreads, Directories, LocalRepo}
import scala.build.{BuildThreads, LocalRepo}

class ScalaNativeUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {
val buildThreads: BuildThreads = BuildThreads.create()
def bloopConfig: Option[BloopRifleConfig] = Some(BloopServer.bloopConfig)

val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)

val buildOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package scala.build.tests

import bloop.rifle.BloopRifleConfig
import com.eed3si9n.expecty.Expecty.expect
import coursier.cache.FileCache
import coursier.util.Task

import scala.build.Ops.EitherThrowOps
import scala.build.options.{
Expand All @@ -13,7 +15,7 @@ import scala.build.options.{
ScriptOptions
}
import scala.build.tests.util.BloopServer
import scala.build.{Build, BuildThreads, Directories, LocalRepo, Position, Positioned}
import scala.build.{Build, BuildThreads, LocalRepo, Position, Positioned}

class ScriptWrapperTests extends TestUtil.ScalaCliBuildSuite {

Expand Down Expand Up @@ -59,8 +61,9 @@ class ScriptWrapperTests extends TestUtil.ScalaCliBuildSuite {
val buildThreads: BuildThreads = BuildThreads.create()
def bloopConfigOpt: Option[BloopRifleConfig] = Some(BloopServer.bloopConfig)

val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val directories: Directories = Directories.under(extraRepoTmpDir)
val extraRepoTmpDir: os.Path = os.temp.dir(prefix = "scala-cli-tests-extra-repo-")
val testCache: FileCache[Task] =
FileCache().withLocation((extraRepoTmpDir / "cache").toIO)

override def afterAll(): Unit = {
TestInputs.tryRemoveAll(extraRepoTmpDir)
Expand All @@ -69,7 +72,8 @@ class ScriptWrapperTests extends TestUtil.ScalaCliBuildSuite {

val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
cache = Some(testCache),
localRepository = LocalRepo.localRepo(testCache, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Loading
Loading