Skip to content

Commit

Permalink
Add extra try-catch clause + extra logging in LocalRepo
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Aug 19, 2024
1 parent 052ed4d commit 5c90059
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 18 deletions.
12 changes: 8 additions & 4 deletions modules/build/src/main/scala/scala/build/LocalRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ object LocalRepo {

def localRepo(
baseDir: os.Path,
logger: Logger,
loader: ClassLoader = Thread.currentThread().getContextClassLoader
): Option[String] = {
val archiveUrl = loader.getResource(resourcePath)

if (archiveUrl == null) None
if archiveUrl == null then None
else {

val version =
using(archiveUrl.openStream()) { is =>
using(WrappedZipInputStream.create(new BufferedInputStream(is))) { zis =>
Expand All @@ -75,10 +75,14 @@ object LocalRepo {

val repoDir = baseDir / version

if (!os.exists(repoDir))
if !os.exists(repoDir) then
withLock((repoDir / os.up).toNIO, version) {
val tmpRepoDir = repoDir / os.up / s".$version.tmp"
os.remove.all(tmpRepoDir)
try os.remove.all(tmpRepoDir)
catch {
case t: Throwable =>
logger.message(s"Error removing $tmpRepoDir: ${t.getMessage}")
}
using(archiveUrl.openStream()) { is =>
using(WrappedZipInputStream.create(new BufferedInputStream(is))) { zis =>
extractZip(zis, tmpRepoDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {
val directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir)
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
)
)
val buildThreads = BuildThreads.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BspServerTests extends TestUtil.ScalaCliBuildSuite {
val directories = Directories.under(extraRepoTmpDir)
val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir)
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
)
)
val buildThreads = BuildThreads.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class BuildOptionsTests extends TestUtil.ScalaCliBuildSuite {
test("User scalac options shadow internal ones") {
val defaultOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir)
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BuildProjectTests extends TestUtil.ScalaCliBuildSuite {
test("workspace for bsp") {
val options = BuildOptions(
internal = InternalOptions(localRepository =
LocalRepo.localRepo(scala.build.Directories.default().localRepoDir)
LocalRepo.localRepo(scala.build.Directories.default().localRepoDir, TestLogger())
)
)
val inputs = Inputs.empty("project")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {

val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir),
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {

val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir),
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InputsTests extends TestUtil.ScalaCliBuildSuite {
def bloopConfigOpt: Option[BloopRifleConfig] = Some(BloopServer.bloopConfig)
val buildOptions: BuildOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir),
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PackagingUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {

val buildOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir),
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ScalaNativeUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {

val buildOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir),
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ScriptWrapperTests extends TestUtil.ScalaCliBuildSuite {

val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir),
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SourceGeneratorTests extends TestUtil.ScalaCliBuildSuite {

val baseOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir),
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger()),
keepDiagnostics = true
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ final case class SharedOptions(
),
internal = bo.InternalOptions(
cache = Some(coursierCache),
localRepository = LocalRepo.localRepo(Directories.directories.localRepoDir),
localRepository = LocalRepo.localRepo(Directories.directories.localRepoDir, logger),
verbosity = Some(logging.verbosity),
strictBloopJsonCheck = strictBloopJsonCheck,
interactive = Some(() => interactive),
Expand Down
3 changes: 2 additions & 1 deletion modules/cli/src/test/scala/cli/tests/CachedBinaryTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scala.build.tests.util.BloopServer
import scala.build.{BuildThreads, Directories, LocalRepo}
import scala.cli.internal.CachedBinary
import scala.util.{Properties, Random}
import scala.build.tests.TestLogger

class CachedBinaryTests extends munit.FunSuite {

Expand All @@ -34,7 +35,7 @@ class CachedBinaryTests extends munit.FunSuite {

val defaultOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir)
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
)
)

Expand Down
3 changes: 2 additions & 1 deletion modules/cli/src/test/scala/cli/tests/PackageTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import scala.cli.commands.package0.Package
import scala.cli.internal.CachedBinary
import scala.cli.packaging.Library
import scala.util.{Properties, Random}
import scala.build.tests.TestLogger

class PackageTests extends munit.FunSuite {

Expand All @@ -24,7 +25,7 @@ class PackageTests extends munit.FunSuite {

val defaultOptions = BuildOptions(
internal = InternalOptions(
localRepository = LocalRepo.localRepo(directories.localRepoDir)
localRepository = LocalRepo.localRepo(directories.localRepoDir, TestLogger())
)
)

Expand Down

0 comments on commit 5c90059

Please sign in to comment.