1
1
package scala .cli .commands .pgp
2
2
3
- import coursier .cache .{ArchiveCache , Cache }
3
+ import coursier .Repositories
4
+ import coursier .cache .{ArchiveCache , Cache , FileCache }
5
+ import coursier .core .Version
4
6
import coursier .util .Task
5
7
import dependency ._
6
8
9
+ import java .io .File
10
+
7
11
import scala .build .EitherCps .{either , value }
8
- import scala .build .Logger
9
- import scala .build .errors . BuildException
12
+ import scala .build .errors .{ BuildException , ScalaJsLinkingError }
13
+ import scala .build .internal . Util .{ DependencyOps , ModuleOps }
10
14
import scala .build .internal .{
11
15
Constants ,
12
16
ExternalBinary ,
13
17
ExternalBinaryParams ,
14
18
FetchExternalBinary ,
15
- Runner
19
+ Runner ,
20
+ ScalaJsLinkerConfig
16
21
}
22
+ import scala .build .options .scalajs .ScalaJsLinkerOptions
23
+ import scala .build .{Logger , Positioned , options => bo }
17
24
import scala .cli .ScalaCli
18
25
import scala .cli .commands .util .JvmUtils
19
26
import scala .util .Properties
@@ -23,20 +30,26 @@ abstract class PgpExternalCommand extends ExternalCommand {
23
30
def externalCommand : Seq [String ]
24
31
25
32
def tryRun (
26
- cache : Cache [Task ],
27
- versionOpt : Option [String ],
33
+ cache : FileCache [Task ],
28
34
args : Seq [String ],
29
35
extraEnv : Map [String , String ],
30
36
logger : Logger ,
31
37
allowExecve : Boolean ,
32
- javaCommand : () => String
38
+ javaCommand : () => String ,
39
+ signingCliOptions : bo.ScalaSigningCliOptions
33
40
): Either [BuildException , Int ] = either {
34
41
35
42
val archiveCache = ArchiveCache ().withCache(cache)
36
43
37
- val binary = value(PgpExternalCommand .launcher(archiveCache, versionOpt, logger, javaCommand))
44
+ val binary = value(PgpExternalCommand .launcher(
45
+ cache,
46
+ archiveCache,
47
+ logger,
48
+ javaCommand,
49
+ signingCliOptions
50
+ ))
38
51
39
- val command = binary.command ++ externalCommand ++ args
52
+ val command = binary ++ externalCommand ++ args
40
53
41
54
Runner .run0(
42
55
progName,
@@ -49,19 +62,25 @@ abstract class PgpExternalCommand extends ExternalCommand {
49
62
}
50
63
51
64
def output (
52
- cache : Cache [Task ],
53
- versionOpt : Option [String ],
65
+ cache : FileCache [Task ],
54
66
args : Seq [String ],
55
67
extraEnv : Map [String , String ],
56
68
logger : Logger ,
57
- javaCommand : () => String
69
+ javaCommand : () => String ,
70
+ signingCliOptions : bo.ScalaSigningCliOptions
58
71
): Either [BuildException , String ] = either {
59
72
60
73
val archiveCache = ArchiveCache ().withCache(cache)
61
74
62
- val binary = value(PgpExternalCommand .launcher(archiveCache, versionOpt, logger, javaCommand))
75
+ val binary = value(PgpExternalCommand .launcher(
76
+ cache,
77
+ archiveCache,
78
+ logger,
79
+ javaCommand,
80
+ signingCliOptions
81
+ ))
63
82
64
- val command = binary.command ++ externalCommand ++ args
83
+ val command = binary ++ externalCommand ++ args
65
84
66
85
os.proc(command).call(stdin = os.Inherit , env = extraEnv)
67
86
.out.text()
@@ -82,7 +101,6 @@ abstract class PgpExternalCommand extends ExternalCommand {
82
101
val cache = options.coursier.coursierCache(logger.coursierLogger(" " ))
83
102
val retCode = tryRun(
84
103
cache,
85
- options.signingCliVersion.map(_.trim).filter(_.nonEmpty),
86
104
remainingArgs,
87
105
Map (),
88
106
logger,
@@ -92,7 +110,8 @@ abstract class PgpExternalCommand extends ExternalCommand {
92
110
ArchiveCache ().withCache(cache),
93
111
cache,
94
112
logger.verbosity
95
- ).value.javaCommand
113
+ ).value.javaCommand,
114
+ options.scalaSigning.cliOptions()
96
115
).orExit(logger)
97
116
98
117
if (retCode != 0 )
@@ -102,33 +121,69 @@ abstract class PgpExternalCommand extends ExternalCommand {
102
121
103
122
object PgpExternalCommand {
104
123
def launcher (
124
+ cache : FileCache [Task ],
105
125
archiveCache : ArchiveCache [Task ],
106
- versionOpt : Option [String ],
107
126
logger : Logger ,
108
- javaCommand : () => String
109
- ): Either [BuildException , ExternalBinary ] = {
110
-
111
- val platformSuffix = FetchExternalBinary .platformSuffix()
112
- val version = versionOpt
113
- .getOrElse(Constants .scalaCliSigningVersion)
114
- val (tag, changing) =
115
- if (version == " latest" ) (" launchers" , true )
116
- else (" v" + version, false )
117
- val ext = if (Properties .isWin) " .zip" else " .gz"
118
- val url =
119
- s " https://github.com/scala-cli/scala-cli-signing/releases/download/ $tag/scala-cli-signing- $platformSuffix$ext"
120
-
121
- val ver = if (version.startsWith(" latest" )) " latest.release" else version
122
- val params = ExternalBinaryParams (
123
- url,
124
- changing,
125
- " scala-cli-signing" ,
126
- Seq (
127
- dep " ${Constants .scalaCliSigningOrganization}: ${Constants .scalaCliSigningName}: $ver"
128
- ),
129
- " scala.cli.signing.ScalaCliSigning"
130
- )
131
-
132
- FetchExternalBinary .fetch(params, archiveCache, logger, javaCommand)
127
+ javaCommand : () => String ,
128
+ signingCliOptions : bo.ScalaSigningCliOptions
129
+ ): Either [BuildException , Seq [String ]] = either {
130
+
131
+ val version =
132
+ signingCliOptions.signingCliVersion
133
+ .getOrElse(Constants .scalaCliSigningVersion)
134
+ val ver = if (version.startsWith(" latest" )) " latest.release" else version
135
+ val signingMainClass = " scala.cli.signing.ScalaCliSigning"
136
+ val jvmSigningDep =
137
+ dep " ${Constants .scalaCliSigningOrganization}: ${Constants .scalaCliSigningName}_3: $ver"
138
+
139
+ if (signingCliOptions.useJvm.getOrElse(false )) {
140
+ val extraRepos =
141
+ if (version.endsWith(" SNAPSHOT" ))
142
+ Seq (Repositories .sonatype(" snapshots" ).root)
143
+ else
144
+ Nil
145
+
146
+ val signingClassPath = value {
147
+ scala.build.Artifacts .fetch0(
148
+ Positioned .none(Seq (jvmSigningDep.toCs)),
149
+ extraRepos,
150
+ None ,
151
+ Nil ,
152
+ logger,
153
+ cache,
154
+ None
155
+ )
156
+ }.files
157
+
158
+ val command = Seq [os.Shellable ](
159
+ javaCommand(),
160
+ signingCliOptions.javaArgs,
161
+ " -cp" ,
162
+ signingClassPath.map(_.getAbsolutePath).mkString(File .pathSeparator),
163
+ signingMainClass
164
+ )
165
+
166
+ command.flatMap(_.value)
167
+ }
168
+ else {
169
+ val platformSuffix = FetchExternalBinary .platformSuffix()
170
+ val (tag, changing) =
171
+ if (version == " latest" ) (" launchers" , true )
172
+ else (" v" + version, false )
173
+ val ext = if (Properties .isWin) " .zip" else " .gz"
174
+ val url =
175
+ s " https://github.com/scala-cli/scala-cli-signing/releases/download/ $tag/scala-cli-signing- $platformSuffix$ext"
176
+ val params = ExternalBinaryParams (
177
+ url,
178
+ changing,
179
+ " scala-cli-signing" ,
180
+ Seq (jvmSigningDep),
181
+ signingMainClass
182
+ )
183
+ val binary = value {
184
+ FetchExternalBinary .fetch(params, archiveCache, logger, javaCommand)
185
+ }
186
+ binary.command
187
+ }
133
188
}
134
189
}
0 commit comments