Skip to content

Commit b71e15f

Browse files
Merge pull request #1 from alexarchambault/main
Allow users to put options in front of option list, and to explicitly state if a launcher is compressed
2 parents 69f66df + ef88dd4 commit b71e15f

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

src/ScalaCliCompile.scala

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,31 @@ trait ScalaCliCompile extends ScalaModule {
3434
new FallbackRefreshDisplay
3535
)
3636
val cache = FileCache().withLogger(logger)
37+
val artifact = Artifact(url).withChanging(compileScalaCliIsChanging)
3738
val archiveCache = ArchiveCache()
3839
.withCache(cache)
39-
val artifact = Artifact(url).withChanging(compileScalaCliIsChanging)
40-
val file = archiveCache.get(artifact).unsafeRun()(cache.ec) match {
41-
case Left(e) => throw new Exception(e)
42-
case Right(f) =>
43-
if (Properties.isWin)
44-
os.list(os.Path(f, os.pwd)).filter(_.last.endsWith(".exe")).headOption match {
45-
case None => sys.error(s"No .exe found under $f")
46-
case Some(exe) => exe
40+
if (compileScalaCliIsCompressed)
41+
archiveCache.get(artifact).unsafeRun()(cache.ec) match {
42+
case Left(e) => throw new Exception(e)
43+
case Right(f) =>
44+
if (Properties.isWin)
45+
os.list(os.Path(f, os.pwd)).filter(_.last.endsWith(".exe")).headOption match {
46+
case None => sys.error(s"No .exe found under $f")
47+
case Some(exe) => exe
48+
}
49+
else {
50+
f.setExecutable(true)
51+
os.Path(f, os.pwd)
4752
}
48-
else {
49-
f.setExecutable(true)
53+
}
54+
else
55+
cache.file(artifact).run.unsafeRun()(cache.ec) match {
56+
case Left(e) => throw new Exception(e)
57+
case Right(f) =>
58+
if (!Properties.isWin)
59+
f.setExecutable(true)
5060
os.Path(f, os.pwd)
51-
}
52-
}
53-
PathRef(file)
61+
}
5462
}
5563
}
5664
import ScalaCliInternal._
@@ -74,8 +82,15 @@ trait ScalaCliCompile extends ScalaModule {
7482
else None
7583
}
7684
def compileScalaCliIsChanging: Boolean = false
85+
def compileScalaCliIsCompressed: Boolean =
86+
compileScalaCliUrl.exists(url => url.endsWith(".gz") || url.endsWith(".zip"))
7787

78-
def compileScalaCli: Option[PathRef] = compileScalaCliImpl
88+
def compileScalaCli: Option[os.Path] = compileScalaCliImpl
89+
90+
def extraScalaCliHeadOptions: T[List[String]] =
91+
T {
92+
List.empty[String]
93+
}
7994

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

85100
override def compile: T[CompilationResult] =
86101
if (enableScalaCli)
87-
compileScalaCli.map(_.path) match {
102+
compileScalaCli match {
88103
case None => super.compile
89104
case Some(cli) =>
90105
T.persistent {
@@ -103,6 +118,7 @@ trait ScalaCliCompile extends ScalaModule {
103118

104119
val proc = os.proc(
105120
cli,
121+
extraScalaCliHeadOptions(),
106122
Seq("compile", "--classpath"),
107123
Seq("-S", scalaVersion()),
108124
asOpt("-O", scalacOptions()),

0 commit comments

Comments
 (0)