Skip to content

Commit

Permalink
housekeeping: (#413)
Browse files Browse the repository at this point in the history
* housekeeping:
- remove most unused warnings
- introduce `bleep.Discard` to do so
- bump bleep
- optimize imports
- fmt
- enforce `model.` prefix
- bump deps/normalize build
- bump to scala 3.4.2. Source level 3.3 is probably a far as we can go if we want to keep 2.13 cross compiled
- put `compile` back in `GenNativeImage` script. There were some problems with the bloop upgrade
  • Loading branch information
oyvindberg authored Aug 10, 2024
1 parent f07a447 commit 8415b25
Show file tree
Hide file tree
Showing 74 changed files with 220 additions and 244 deletions.
11 changes: 5 additions & 6 deletions bleep-cli/src/scala/bleep/Main.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bleep

import bleep.bsp.BspImpl
import bleep.internal.{bleepLoggers, fatal, FileUtils}
import bleep.internal.{bleepLoggers, fatal, FileUtils, Throwables}
import bleep.logging.Logger
import bleep.model.{BleepVersion, Os}
import bleep.packaging.ManifestCreator
import cats.data.NonEmptyList
import cats.syntax.apply.*
import cats.syntax.foldable.*
Expand All @@ -13,7 +13,6 @@ import coursier.jvm.Execve
import java.nio.file.{Path, Paths}
import scala.concurrent.ExecutionContext
import scala.util.{Failure, Properties, Success, Try}
import bleep.packaging.ManifestCreator

object Main {
private def isGraalvmNativeImage: Boolean =
Expand Down Expand Up @@ -392,15 +391,15 @@ object Main {
case _ => true
}

def go(wantedVersion: BleepVersion): ExitCode = {
def go(wantedVersion: model.BleepVersion): ExitCode = {
val cacheLogger = new BleepCacheLogger(logger)

OsArch.current match {
case hasNativeImage: OsArch.HasNativeImage =>
FetchBleepRelease(wantedVersion, cacheLogger, ec, hasNativeImage) match {
case Left(buildException) =>
fatal("couldn't download bleep release", logger, buildException)
case Right(binaryPath) if OsArch.current.os == Os.Windows || !isGraalvmNativeImage =>
case Right(binaryPath) if OsArch.current.os == model.Os.Windows || !isGraalvmNativeImage =>
val status = scala.sys.process.Process(binaryPath.toString :: args.toList, FileUtils.cwd.toFile, sys.env.toSeq: _*).!<
sys.exit(status)
case Right(path) =>
Expand Down Expand Up @@ -550,7 +549,7 @@ object Main {

bootstrap.from(pre, GenBloopFiles.SyncToDisk, rewrites = Nil, config, CoursierResolver.Factory.default) match {
case Left(th) =>
fatal("couldn't load build", stderr, th)
Throwables.log("couldn't load build", stderr, th)
Completer.Res.NoMatch

case Right(started) =>
Expand Down
5 changes: 2 additions & 3 deletions bleep-cli/src/scala/bleep/bsp/BspImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package bleep
package bsp

import bleep.internal.Throwables
import bloop.rifle.*
import bloop.rifle.internal.Operations
import ch.epfl.scala.bsp4j
import org.eclipse.lsp4j.jsonrpc

import java.net.Socket
import java.nio.file.{Files, Path}
import bloop.rifle.{BloopServer, BloopThreads, BuildServer}
import bloop.rifle.internal.Operations
import bloop.rifle.{BloopRifle, BloopRifleConfig, BloopRifleLogger, FailedToStartServerException}
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.util.{Failure, Success, Try}
Expand Down
3 changes: 1 addition & 2 deletions bleep-cli/src/scala/bleep/commands/BuildUpdateDeps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package commands

import bleep.internal.writeYamlLogged
import bleep.logging.Logger
import bleep.model.{CrossProjectName, Dep}
import bleep.rewrites.{normalizeBuild, UpgradeDependencies}
import coursier.Repository
import coursier.cache.FileCache
Expand Down Expand Up @@ -45,7 +44,7 @@ case object BuildUpdateDeps extends BleepBuildCommand {
}

class UpgradeLogger(logger: Logger) extends UpgradeDependencies.UpgradeLogger {
override def upgraded(project: CrossProjectName, dep: Dep, newVersion: String): Unit =
override def upgraded(project: model.CrossProjectName, dep: model.Dep, newVersion: String): Unit =
logger
.withContext(project)
.info(s"${dep.organization.value}:${dep.baseModuleName.value} ${dep.version} => $newVersion")
Expand Down
20 changes: 11 additions & 9 deletions bleep-cli/src/scala/bleep/commands/CompileServerStopAll.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package commands
import bleep.bsp.BleepRifleLogger
import bleep.internal.FileUtils
import bleep.logging.Logger
import bloop.rifle.BloopRifleConfig
import bloop.rifle.internal.Operations

import java.io.OutputStream
import java.nio.file.{Files, Path}
import bloop.rifle.BloopRifleConfig
import bloop.rifle.internal.Operations
import scala.jdk.StreamConverters.StreamHasToScala

case class CompileServerStopAll(logger: Logger, userPaths: UserPaths) extends BleepCommand {
Expand All @@ -23,13 +23,15 @@ case class CompileServerStopAll(logger: Logger, userPaths: UserPaths) extends Bl
val address = BloopRifleConfig.Address.DomainSocket(socketDir)
if (Operations.check(address, rifleLogger)) {
logger.info(s"stopping bloop server running at socket $socketDir")
Operations.exit(
address = address,
workingDir = FileUtils.TempDir,
out = rifleLogger.bloopBspStdout.getOrElse(OutputStream.nullOutputStream()),
err = rifleLogger.bloopBspStderr.getOrElse(OutputStream.nullOutputStream()),
logger = rifleLogger
)
Operations
.exit(
address = address,
workingDir = FileUtils.TempDir,
out = rifleLogger.bloopBspStdout.getOrElse(OutputStream.nullOutputStream()),
err = rifleLogger.bloopBspStderr.getOrElse(OutputStream.nullOutputStream()),
logger = rifleLogger
)
.discard()
FileUtils.deleteDirectory(socketDir)
} else
logger.info(s"bloop server was not running at socket $socketDir")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ case class InstallZshTabCompletions(userPaths: UserPaths, logger: Logger, stdout
println(completionScript)
} else {
logger.info(s"Writing $completionScriptDest")
FileSync.softWriteBytes(completionScriptDest, completionScript.getBytes(StandardCharsets.UTF_8)): Unit
FileSync.softWriteBytes(completionScriptDest, completionScript.getBytes(StandardCharsets.UTF_8)).discard()
val zshRc = Option(System.getenv("ZDOTDIR")).map(Path.of(_)).getOrElse(FileUtils.Home) / ".zshrc"

PatchRcFile(None, logger, zshRc)(
Expand Down
2 changes: 1 addition & 1 deletion bleep-cli/src/scala/bleep/commands/Scalafmt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ case class Scalafmt(check: Boolean) extends BleepBuildCommand {
cmd,
logger = started.logger,
out = cli.Out.ViaLogger(started.logger)
)
).discard()
Right(())
}
}
8 changes: 3 additions & 5 deletions bleep-cli/src/scala/bleep/sbtimport/ImportInputData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ package bleep
package sbtimport

import bleep.internal.{codecs, parseBloopFile, FileUtils, GeneratedFile}
import bleep.logging.Logger
import bleep.nosbt.librarymanagement
import bloop.config.Config
import coursier.core.Configuration
import io.circe.Codec
import io.circe.generic.semiauto.*
import bleep.logging.Logger

import java.nio.file.{Files, Path}
import scala.collection.immutable.{SortedMap, SortedSet}
import scala.jdk.CollectionConverters.IteratorHasAsScala
import scala.jdk.StreamConverters.StreamHasToScala
import scala.util.Try
import scala.util.Failure
import scala.util.Success
import scala.util.{Failure, Success, Try}

/** Absolutely everything that the import cares about from the sbt build is dumped in this structure. It's all read up front, so the import is a pure function.
*
Expand Down Expand Up @@ -116,7 +114,7 @@ case class ImportInputData(

object ImportInputData {
import codecs.*
model.assertUsed(codecPath)
codecPath.discard()
implicit val codec: Codec.AsObject[ImportInputData] = deriveCodec

def collectFromFileSystem(
Expand Down
5 changes: 2 additions & 3 deletions bleep-cli/src/scala/bleep/sbtimport/ImportOptions.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bleep
package sbtimport

import bleep.model.Jvm
import cats.data.{Validated, ValidatedNel}
import cats.syntax.apply.*
import com.monovore.decline.{Argument, Opts}
Expand Down Expand Up @@ -31,8 +30,8 @@ object ImportOptions {
val skipGeneratedResourcesScript: Opts[Boolean] =
Opts.flag("skip-generated-resources-script", "disable creating a script to regenerate discovered generated sources/resources ").orFalse

implicit val jvmArgument: Argument[model.Jvm] = new Argument[Jvm] {
override def read(string: String): ValidatedNel[String, Jvm] = Validated.Valid(model.Jvm(string, None))
implicit val jvmArgument: Argument[model.Jvm] = new Argument[model.Jvm] {
override def read(string: String): ValidatedNel[String, model.Jvm] = Validated.Valid(model.Jvm(string, None))
override def defaultMetavar: String = "metavar-jvm"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object ReadSbtExportFile {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): ExportedProject =
jsOpt match {
case Some(j) =>
unbuilder.beginObject(j)
unbuilder.beginObject(j).discard()
val organization = unbuilder.readField[String]("organization")
val bloopName = unbuilder.readField[String]("bloopName")
val sbtName = unbuilder.readField[String]("sbtName")
Expand Down
8 changes: 4 additions & 4 deletions bleep-cli/src/scala/bleep/sbtimport/runSbt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,18 @@ object runSbt {
while (i < lines.length) {
val line = lines(i)

def handleScalaVersion(projectName: String) = {
def handleScalaVersion(projectName: String): Unit = {
i = i + 1
val nextLine = lines(i)
val scalaVersion = model.VersionScala(nextLine.split("\\s").last)
scalaVersionsBuilder.getOrElseUpdate(scalaVersion, mutable.Set.empty).add(projectName)
scalaVersionsBuilder.getOrElseUpdate(scalaVersion, mutable.Set.empty).add(projectName).discard()
}

def handleCrossScalaVersions(projectName: String) = {
def handleCrossScalaVersions(projectName: String): Unit = {
i = i + 1
val nextLine = lines(i)
val versions = nextLine.dropWhile(_ != '(').drop(1).takeWhile(_ != ')').split(",").map(_.trim).filterNot(_.isEmpty)
versions.map { scalaVersion =>
versions.foreach { scalaVersion =>
crossVersionsBuilder.getOrElseUpdate(model.VersionScala(scalaVersion), mutable.Set.empty).add(projectName)
}
}
Expand Down
4 changes: 2 additions & 2 deletions bleep-core/src/scala/bleep/BleepCommandRemote.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package bleep

import bleep.bsp.{BleepRifleLogger, BspCommandFailed, SetupBloopRifle}
import bleep.internal.{BspClientDisplayProgress, Throwables, TransitiveProjects}
import bloop.rifle.internal.Operations
import bloop.rifle.*
import bloop.rifle.internal.Operations
import ch.epfl.scala.bsp4j

import java.nio.file.Files
Expand Down Expand Up @@ -60,7 +60,7 @@ abstract class BleepCommandRemote(watch: Boolean) extends BleepBuildCommand {
try
if (watch) {
// run once initially
runWithServer(started, server.server)
runWithServer(started, server.server).discard()

var currentStarted = started

Expand Down
6 changes: 1 addition & 5 deletions bleep-core/src/scala/bleep/BleepFileWatching.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package bleep

import bleep.internal.TransitiveProjects
import bleep.model.ScriptDef

import java.nio.file.Path
import scala.collection.compat.*

object BleepFileWatching {
model.assertUsed(immutable.LazyList) // silence warning

def projectPathsMapping(started: Started, projects: TransitiveProjects): Map[Path, Seq[model.CrossProjectName]] = {
val sourceProjectPairs: Iterator[(Path, model.CrossProjectName)] =
projects.all.iterator.flatMap { name =>
val p = started.build.explodedProjects(name)
val paths = started.buildPaths.project(name, p)
val allPaths = paths.sourcesDirs.all.iterator ++ paths.resourcesDirs.all
val fromSourceGen: Iterator[Path] =
p.sourcegen.values.iterator.flatMap { case ScriptDef.Main(_, _, sourceGlobs) =>
p.sourcegen.values.iterator.flatMap { case model.ScriptDef.Main(_, _, sourceGlobs) =>
sourceGlobs.values.iterator.map(relPath => paths.dir / relPath)
}
(allPaths ++ fromSourceGen).map(path => (path, name))
Expand Down
4 changes: 2 additions & 2 deletions bleep-core/src/scala/bleep/FileWatching.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ object FileWatching {
private[FileWatching] var isShutdown = false
private[FileWatching] var mapping: Map[Path, Seq[K]] = Map.empty

def addObserver(observer: Observer[PathWatchers.Event]): List[Int] =
List(watcher.addObserver(observer))
def addObserver(observer: Observer[PathWatchers.Event]): Unit =
watcher.addObserver(observer).discard()

// todo: imperfect, but good enough for now
// - path.getParent may clobber `path` if that was its own mapping, and we may lose events under that (depending on order)
Expand Down
5 changes: 2 additions & 3 deletions bleep-core/src/scala/bleep/bsp/BleepBspServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package bsp

import bleep.internal.{DoSourceGen, Throwables, TransitiveProjects}
import bleep.logging.Logger
import bloop.rifle.BuildServer
import bloop.rifle.internal.BuildInfo
import ch.epfl.scala.bsp4j
import ch.epfl.scala.bsp4j.CompileResult
import com.google.gson.{JsonObject, JsonPrimitive}
Expand All @@ -12,9 +14,6 @@ import org.eclipse.lsp4j.jsonrpc.messages.{ResponseError, ResponseErrorCode}
import java.util
import java.util.concurrent.{CompletableFuture, TimeUnit}
import java.util.function.BiFunction
import bloop.rifle.BuildServer
import bloop.rifle.internal.BuildInfo

import scala.concurrent.{Future, Promise}
import scala.jdk.CollectionConverters.*
import scala.util.{Random, Try}
Expand Down
2 changes: 1 addition & 1 deletion bleep-core/src/scala/bleep/bsp/BleepRifleLogger.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package bleep.bsp

import bleep.logging.{Logger, LoggerFn}
import bloop.rifle.BloopRifleLogger

import java.io.OutputStream
import java.nio.charset.StandardCharsets
import bloop.rifle.BloopRifleLogger

class BleepRifleLogger(val logger: Logger) extends BloopRifleLogger {
val bloopLogger = logger.withPath("bloop")
Expand Down
4 changes: 2 additions & 2 deletions bleep-core/src/scala/bleep/bsp/BspCommandFailed.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bleep.bsp
package bleep
package bsp

import bleep.{model, BleepException}
import ch.epfl.scala.bsp4j
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError

Expand Down
3 changes: 2 additions & 1 deletion bleep-core/src/scala/bleep/bsp/BspThreads.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package bleep.bsp

import bloop.rifle.BloopThreads

import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{ExecutorService, Executors, ThreadFactory}
import bloop.rifle.BloopThreads

final case class BspThreads(
buildThreads: BloopThreads,
Expand Down
3 changes: 1 addition & 2 deletions bleep-core/src/scala/bleep/bsp/SetupBloopRifle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bsp

import bleep.internal.FileUtils
import bleep.logging.Logger
import bleep.model.CompileServerMode
import bloop.rifle.BloopRifleConfig

import java.io.File
Expand All @@ -15,7 +14,7 @@ import scala.util.{Failure, Properties, Random, Success, Try}

object SetupBloopRifle {
def apply(
compileServerMode: CompileServerMode,
compileServerMode: model.CompileServerMode,
resolvedJvm: ResolvedJvm,
userPaths: UserPaths,
resolver: CoursierResolver,
Expand Down
2 changes: 1 addition & 1 deletion bleep-core/src/scala/bleep/commands/Clean.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case class Clean(projects: Array[model.CrossProjectName]) extends BleepBuildComm
cmd = List(Array("rm", "-Rf"), outDirectories.map(_.toString)).flatten,
logger = started.logger,
out = cli.Out.ViaLogger(started.logger)
)
).discard()
outDirectories.foreach(directory => started.logger.info(s"Deleted $directory"))
}
}
Expand Down
3 changes: 1 addition & 2 deletions bleep-core/src/scala/bleep/commands/Compile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package commands

import bleep.bsp.BspCommandFailed
import bleep.internal.{DoSourceGen, TransitiveProjects}
import ch.epfl.scala.bsp4j

import bloop.rifle.BuildServer
import ch.epfl.scala.bsp4j

case class Compile(watch: Boolean, projects: Array[model.CrossProjectName]) extends BleepCommandRemote(watch) with BleepCommandRemote.OnlyChanged {

Expand Down
2 changes: 1 addition & 1 deletion bleep-core/src/scala/bleep/commands/Dist.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package commands

import bleep.internal.TransitiveProjects
import bleep.packaging.dist
import bloop.rifle.BuildServer

import java.nio.file.Path
import bloop.rifle.BuildServer

object Dist {
case class Options(
Expand Down
3 changes: 1 addition & 2 deletions bleep-core/src/scala/bleep/commands/Evicted.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bleep
package commands

import bleep.depcheck.CheckEvictions
import bleep.model.VersionCombo
import bleep.nosbt.librarymanagement
import cats.implicits.toTraverseOps

Expand All @@ -11,7 +10,7 @@ case class Evicted(projectNames: Array[model.CrossProjectName]) extends BleepBui
projectNames.toList
.traverse { projectName =>
val project = started.build.explodedProjects(projectName)
val versionCombo = VersionCombo.fromExplodedProject(project).orThrowText
val versionCombo = model.VersionCombo.fromExplodedProject(project).orThrowText
val bleepDeps = project.dependencies.values

val res = for {
Expand Down
2 changes: 1 addition & 1 deletion bleep-core/src/scala/bleep/commands/ListTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case class ListTests(projects: Array[model.CrossProjectName]) extends BleepComma
override def runWithServer(started: Started, bloop: BuildServer): Either[BleepException, Unit] = {
val all: Iterator[(model.CrossProjectName, String)] = testsByCrossProject(started, bloop)

all.toList.groupBy { case (pn, cls) => pn.name }.foreach { case (pn, tuples) =>
all.toList.groupBy { case (pn, _) => pn.name }.foreach { case (pn, tuples) =>
started.logger.info(s"${pn.value}:")
tuples.foreach { case (_, cls) => started.logger.info(s" $cls") }
}
Expand Down
Loading

0 comments on commit 8415b25

Please sign in to comment.