Skip to content

Commit

Permalink
Merge pull request #1 from alexarchambault/main
Browse files Browse the repository at this point in the history
Allow users to put options in front of option list, and to explicitly state if a launcher is compressed
  • Loading branch information
alexarchambault authored May 25, 2022
2 parents 69f66df + ef88dd4 commit b71e15f
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions src/ScalaCliCompile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,31 @@ trait ScalaCliCompile extends ScalaModule {
new FallbackRefreshDisplay
)
val cache = FileCache().withLogger(logger)
val artifact = Artifact(url).withChanging(compileScalaCliIsChanging)
val archiveCache = ArchiveCache()
.withCache(cache)
val artifact = Artifact(url).withChanging(compileScalaCliIsChanging)
val file = archiveCache.get(artifact).unsafeRun()(cache.ec) match {
case Left(e) => throw new Exception(e)
case Right(f) =>
if (Properties.isWin)
os.list(os.Path(f, os.pwd)).filter(_.last.endsWith(".exe")).headOption match {
case None => sys.error(s"No .exe found under $f")
case Some(exe) => exe
if (compileScalaCliIsCompressed)
archiveCache.get(artifact).unsafeRun()(cache.ec) match {
case Left(e) => throw new Exception(e)
case Right(f) =>
if (Properties.isWin)
os.list(os.Path(f, os.pwd)).filter(_.last.endsWith(".exe")).headOption match {
case None => sys.error(s"No .exe found under $f")
case Some(exe) => exe
}
else {
f.setExecutable(true)
os.Path(f, os.pwd)
}
else {
f.setExecutable(true)
}
else
cache.file(artifact).run.unsafeRun()(cache.ec) match {
case Left(e) => throw new Exception(e)
case Right(f) =>
if (!Properties.isWin)
f.setExecutable(true)
os.Path(f, os.pwd)
}
}
PathRef(file)
}
}
}
import ScalaCliInternal._
Expand All @@ -74,8 +82,15 @@ trait ScalaCliCompile extends ScalaModule {
else None
}
def compileScalaCliIsChanging: Boolean = false
def compileScalaCliIsCompressed: Boolean =
compileScalaCliUrl.exists(url => url.endsWith(".gz") || url.endsWith(".zip"))

def compileScalaCli: Option[PathRef] = compileScalaCliImpl
def compileScalaCli: Option[os.Path] = compileScalaCliImpl

def extraScalaCliHeadOptions: T[List[String]] =
T {
List.empty[String]
}

def extraScalaCliOptions: T[List[String]] =
T {
Expand All @@ -84,7 +99,7 @@ trait ScalaCliCompile extends ScalaModule {

override def compile: T[CompilationResult] =
if (enableScalaCli)
compileScalaCli.map(_.path) match {
compileScalaCli match {
case None => super.compile
case Some(cli) =>
T.persistent {
Expand All @@ -103,6 +118,7 @@ trait ScalaCliCompile extends ScalaModule {

val proc = os.proc(
cli,
extraScalaCliHeadOptions(),
Seq("compile", "--classpath"),
Seq("-S", scalaVersion()),
asOpt("-O", scalacOptions()),
Expand Down

0 comments on commit b71e15f

Please sign in to comment.