1
1
import $ivy .`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1`
2
2
import $ivy .`io.github.alexarchambault.mill::mill-native-image::0.1.31-1`
3
3
import $ivy .`io.github.alexarchambault.mill::mill-native-image-upload:0.1.31-1`
4
-
5
4
import de .tobiasroeser .mill .vcs .version ._
6
5
import io .github .alexarchambault .millnativeimage .NativeImage
7
6
import io .github .alexarchambault .millnativeimage .upload .Upload
8
7
import mill ._
9
8
import mill .scalalib ._
10
- import coursier .core .Version
11
- import scala . concurrent . duration . DurationInt
9
+ import coursier .core .{ Dependency , DependencyManagement }
10
+ import coursier . version . VersionConstraint
12
11
12
+ import scala .concurrent .duration .DurationInt
13
13
import java .io .File
14
14
15
15
object Versions {
@@ -23,8 +23,7 @@ object Versions {
23
23
}
24
24
25
25
trait JavaMainClassNativeImage extends NativeImage {
26
-
27
- def nativeImageOptions = T {
26
+ def nativeImageOptions = T {
28
27
super .nativeImageOptions() ++ Seq (
29
28
" --no-fallback"
30
29
)
@@ -33,37 +32,45 @@ trait JavaMainClassNativeImage extends NativeImage {
33
32
def nativeImageGraalVmJvmId = s " graalvm-java17: ${Versions .graalVmVersion}"
34
33
def nativeImageName = " java-class-name"
35
34
def nativeImageMainClass = " scala.cli.javaclassname.JavaClassName"
36
-
37
35
def nameSuffix = " "
36
+
38
37
def copyToArtifacts (directory : String = " artifacts/" ) = T .command {
39
- val _ = Upload .copyLauncher (
40
- nativeImage().path,
41
- directory,
42
- " java-class-name" ,
38
+ val _ = Upload .copyLauncher0 (
39
+ nativeLauncher = nativeImage().path,
40
+ directory = directory ,
41
+ name = " java-class-name" ,
43
42
compress = true ,
43
+ workspace = T .workspace,
44
44
suffix = nameSuffix
45
45
)
46
46
}
47
47
}
48
48
49
49
trait JavaClassNameModule extends ScalaModule {
50
50
override def scalaVersion = Versions .scala
51
- override def transitiveIvyDeps = T {
52
- super .transitiveIvyDeps()
53
- .map(_.exclude(" org.jline" -> " jline-reader" ))
54
- .map(_.exclude(" org.jline" -> " jline-terminal" ))
55
- .map(_.exclude(" org.jline" -> " jline-terminal-jna" ))
56
- .map(_.exclude(" org.jline" -> " jline-terminal-jni" ))
57
- .map(_.exclude(" org.jline" -> " jline-native" ))
58
- }
51
+
52
+ private def jlineOrg = " org.jline"
59
53
def jlineDeps = Agg (
60
- ivy " org.jline :jline-reader: ${Versions .jline}" ,
61
- ivy " org.jline :jline-terminal: ${Versions .jline}" ,
62
- ivy " org.jline :jline-terminal-jna: ${Versions .jline}" ,
63
- ivy " org.jline :jline-terminal-jni: ${Versions .jline}" ,
64
- ivy " org.jline :jline-native: ${Versions .jline}"
54
+ ivy " $jlineOrg :jline-reader: ${Versions .jline}" ,
55
+ ivy " $jlineOrg :jline-terminal: ${Versions .jline}" ,
56
+ ivy " $jlineOrg :jline-terminal-jna: ${Versions .jline}" ,
57
+ ivy " $jlineOrg :jline-terminal-jni: ${Versions .jline}" ,
58
+ ivy " $jlineOrg :jline-native: ${Versions .jline}"
65
59
)
66
- override def ivyDeps = super .ivyDeps() ++ jlineDeps
60
+
61
+ override def coursierDependency : Dependency =
62
+ super .coursierDependency
63
+ .addOverrides(
64
+ jlineDeps.toSeq.map(jd => DependencyManagement .Key .from(jd.toDependency(jd.version, jd.version, " " )) ->
65
+ DependencyManagement .Values .empty.withVersionConstraint(VersionConstraint .Lazy (Versions .jline)))
66
+ )
67
+
68
+ override def allIvyDeps = T {
69
+ super .allIvyDeps()
70
+ .map(_.exclude(jlineOrg -> " jline-*" )) ++ jlineDeps
71
+ }
72
+
73
+ override def ivyDeps = super .ivyDeps().map(_.exclude(" org.jline" -> " jline-*" )) ++ jlineDeps
67
74
}
68
75
69
76
object `scala3-graal-processor` extends JavaClassNameModule {
@@ -78,41 +85,47 @@ object `java-class-name` extends JavaClassNameModule with JavaMainClassNativeIma
78
85
// adapted from https://github.com/VirtusLab/scala-cli/blob/b19086697401827a6f8185040ceb248d8865bf21/build.sc#L732-L744
79
86
80
87
val classpath = runClasspath().map(_.path).mkString(File .pathSeparator)
81
- val cache = T .dest / " native-cp"
88
+ val cache = T .dest / " native-cp"
82
89
// `scala3-graal-processor`.run() do not give me output and I cannot pass dynamically computed values like classpath
83
90
System .err.println(" Calling scala3 graal processor on" )
84
91
for (f <- classpath.split(File .pathSeparator))
85
92
System .err.println(s " $f" )
86
- val res = mill.modules .Jvm .callSubprocess (
93
+ val res = mill.util .Jvm .callProcess (
87
94
mainClass = `scala3-graal-processor`.finalMainClass(),
88
95
classPath = `scala3-graal-processor`.runClasspath().map(_.path),
89
- mainArgs = Seq (cache.toNIO.toString, classpath),
90
- workingDir = os.pwd
96
+ mainArgs = Seq (cache.toNIO.toString, classpath)
91
97
)
92
98
val cp = res.out.text.trim
99
+ if (cp.isBlank) System .err.println(" class path can't be empty!" )
100
+ assert(cp.nonEmpty)
93
101
System .err.println(" Processed class path:" )
94
102
for (f <- cp.split(File .pathSeparator))
95
103
System .err.println(s " $f" )
96
104
cp.split(File .pathSeparator).toSeq.map(p => mill.PathRef (os.Path (p)))
97
105
}
106
+
98
107
override def ivyDeps = super .ivyDeps() ++ jlineDeps ++ Agg (
99
108
ivy " org.scala-lang::scala3-compiler: ${Versions .scala}"
100
109
)
110
+
101
111
override def compileIvyDeps = super .compileIvyDeps() ++ Agg (
102
112
ivy " org.graalvm.nativeimage:svm: ${Versions .graalVmVersion}"
103
113
)
104
114
105
115
object static extends JavaMainClassNativeImage {
106
116
def nameSuffix = " -static"
107
- def nativeImageClassPath = T {
117
+
118
+ def nativeImageClassPath = T {
108
119
`java-class-name`.nativeImageClassPath()
109
120
}
121
+
110
122
def buildHelperImage = T {
111
123
os.proc(" docker" , " build" , " -t" , " scala-cli-base-musl:latest" , " ." )
112
- .call(cwd = os.pwd / " musl-image" , stdout = os.Inherit )
124
+ .call(cwd = T .workspace / " musl-image" , stdout = os.Inherit )
113
125
()
114
126
}
115
- def nativeImageDockerParams = T {
127
+
128
+ def nativeImageDockerParams = T {
116
129
buildHelperImage()
117
130
Some (
118
131
NativeImage .linuxStaticParams(
@@ -121,6 +134,7 @@ object `java-class-name` extends JavaClassNameModule with JavaMainClassNativeIma
121
134
)
122
135
)
123
136
}
137
+
124
138
def writeNativeImageScript (scriptDest : String , imageDest : String = " " ) = T .command {
125
139
buildHelperImage()
126
140
super .writeNativeImageScript(scriptDest, imageDest)()
@@ -129,9 +143,10 @@ object `java-class-name` extends JavaClassNameModule with JavaMainClassNativeIma
129
143
130
144
object `mostly-static` extends JavaMainClassNativeImage {
131
145
def nameSuffix = " -mostly-static"
132
- def nativeImageClassPath = T {
146
+ def nativeImageClassPath = T {
133
147
`java-class-name`.nativeImageClassPath()
134
148
}
149
+
135
150
def nativeImageDockerParams = Some (
136
151
NativeImage .linuxMostlyStaticParams(
137
152
" ubuntu:18.04" , // TODO Pin that?
@@ -148,18 +163,23 @@ object `java-class-name-tests` extends JavaClassNameModule with SbtModule {
148
163
ivy " com.lihaoyi::os-lib: ${Versions .osLib}" ,
149
164
ivy " com.lihaoyi::utest: ${Versions .uTest}"
150
165
)
166
+
151
167
def testFramework = " utest.runner.Framework"
168
+
152
169
def forkEnv = super .forkEnv() ++ Seq (
153
170
" JAVA_CLASS_NAME_CLI" -> launcher().path.toString
154
171
)
155
172
}
173
+
156
174
object test extends Tests {
157
175
def launcher = `java-class-name`.nativeImage()
158
176
}
177
+
159
178
object static extends Tests {
160
179
def sources = T .sources(`java-class-name-tests`.test.sources())
161
180
def launcher = `java-class-name`.static.nativeImage()
162
181
}
182
+
163
183
object `mostly-static` extends Tests {
164
184
def sources = T .sources(`java-class-name-tests`.test.sources())
165
185
def launcher = `java-class-name`.`mostly-static`.nativeImage()
@@ -190,8 +210,11 @@ def publishVersion0 = T {
190
210
191
211
def ghOrg = " VirtusLab"
192
212
def ghName = " java-class-name"
213
+
193
214
trait JavaClassNamePublishModule extends PublishModule {
215
+
194
216
import mill .scalalib .publish ._
217
+
195
218
def pomSettings = PomSettings (
196
219
description = artifactName(),
197
220
organization = " org.virtuslab.scala-cli.java-class-name" ,
@@ -213,6 +236,7 @@ trait JavaClassNamePublishModule extends PublishModule {
213
236
)
214
237
)
215
238
)
239
+
216
240
def publishVersion =
217
241
publishVersion0()
218
242
}
@@ -226,9 +250,9 @@ object ci extends Module {
226
250
}
227
251
228
252
private def publishSonatype0 (
229
- data : Seq [PublishModule .PublishData ],
230
- log : mill.api.Logger
231
- ): Unit = {
253
+ data : Seq [PublishModule .PublishData ],
254
+ log : mill.api.Logger
255
+ ): Unit = {
232
256
233
257
val credentials = sys.env(" SONATYPE_USERNAME" ) + " :" + sys.env(" SONATYPE_PASSWORD" )
234
258
val pgpPassword = sys.env(" PGP_PASSWORD" )
0 commit comments