Skip to content

Commit ace9af5

Browse files
committed
Write flags into file instead of passing tons of them
1 parent 0dff473 commit ace9af5

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

modules/cli/src/main/scala/CommandLineApp.scala

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import java.io.File
1111
import java.nio.file.Paths
1212
import scala.util.Using
1313
import java.io.FileWriter
14+
import java.nio.file.Files
15+
import cats.syntax.writer
16+
import util.chaining.*
1417

1518
enum Compiler:
1619
case Clang, ClangPP
@@ -515,26 +518,65 @@ object VcpkgCLI extends VcpkgPluginImpl, VcpkgPluginNativeImpl:
515518
scalaCliArgs.addOne(scalaCliBin)
516519
scalaCliArgs.addAll(rest)
517520

518-
computeNativeFlags(
521+
val flags = computeNativeFlags(
519522
OutputOptions(compile = true, linking = true),
520523
allDeps,
521524
result.filter((k, v) => allDeps.contains(k)),
522525
rename
523-
).foreach {
524-
case NativeFlag.Compilation(value) =>
525-
scalaCliArgs.addOne("--native-compile")
526-
scalaCliArgs.addOne(value)
526+
)
527+
528+
val (linkingFlags, compileFlags) =
529+
val (l, c) = flags.partition:
530+
case NativeFlag.Compilation(value) => false
531+
case NativeFlag.Linking(value) => true
532+
533+
(l.map(_.get), c.map(_.get))
534+
535+
val linkFlagsFile = Files
536+
.createTempFile("linking", ".txt")
537+
.toFile()
538+
.tap(_.deleteOnExit())
539+
540+
val linkFlagsFileWriter =
541+
new FileWriter(
542+
linkFlagsFile
543+
)
544+
545+
val compileFlagsFile = Files
546+
.createTempFile("compile", ".txt")
547+
.toFile()
548+
.tap(_.deleteOnExit())
527549

528-
case NativeFlag.Linking(value) =>
529-
scalaCliArgs.addOne("--native-linking")
530-
scalaCliArgs.addOne(value)
531-
}
550+
val compileFlagsFileWriter =
551+
new FileWriter(
552+
compileFlagsFile
553+
)
554+
555+
Using(linkFlagsFileWriter): linkFlagsFileWriter =>
556+
linkingFlags.foreach(f => linkFlagsFileWriter.write(f + "\n"))
557+
558+
Using(compileFlagsFileWriter): compileFlagsWriter =>
559+
compileFlags.foreach(f => compileFlagsWriter.write(f + "\n"))
560+
561+
scalaCliArgs.addAll(
562+
Seq(
563+
"--native-linking",
564+
s"@${linkFlagsFile.toPath().toAbsolutePath().toString}"
565+
)
566+
)
567+
scalaCliArgs.addAll(
568+
Seq(
569+
"--native-compile",
570+
s"@${compileFlagsFile.toPath().toAbsolutePath().toString}"
571+
)
572+
)
532573

533574
scribe.debug(
534575
s"Invoking Scala CLI with arguments: [${scalaCliArgs.result().mkString(" ")}]"
535576
)
536577

537-
val exitCode = scala.sys.process.Process(scalaCliArgs.result()).!
578+
val exitCode =
579+
scala.sys.process.Process(scalaCliArgs.result()).!
538580

539581
sys.exit(exitCode)
540582

0 commit comments

Comments
 (0)