Skip to content

Commit b35b170

Browse files
committed
Change the scala compiler version, not scala library version + tests.
1 parent 37207d5 commit b35b170

File tree

4 files changed

+102
-8
lines changed

4 files changed

+102
-8
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package mill.constants;
2+
3+
public class CacheFiles {
4+
/** Prefix for all cache files. */
5+
public static final String prefix = "mill-";
6+
7+
public static String filename(String name) {
8+
return prefix + name;
9+
}
10+
11+
public static final String javaHome = "java-home";
12+
13+
/** Caches the classpath for the mill runner. */
14+
public static final String resolveRunner = "resolve-runner";
15+
}

integration/feature/mill-scala-version/resources/.directory

Whitespace-only changes.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package mill.integration
2+
3+
import mill.constants.CacheFiles
4+
import mill.testkit.{IntegrationTester, UtestIntegrationTestSuite}
5+
import utest.*
6+
7+
object MillScalaVersionTests extends UtestIntegrationTestSuite {
8+
private def writeBuildMill(tester: IntegrationTester, scalaVersion: Option[String]): Unit = {
9+
val scalaVersionLine = scalaVersion.fold("")(v => s"//| mill-scala-version: $v")
10+
os.write.over(
11+
tester.workspacePath / "build.mill",
12+
s"""$scalaVersionLine
13+
|package build
14+
|
15+
|// empty file
16+
|""".stripMargin
17+
)
18+
}
19+
20+
private def readResolveRunner(tester: IntegrationTester) =
21+
os.read.lines(tester.workspacePath / "out" / CacheFiles.filename(CacheFiles.resolveRunner))
22+
23+
private def scalaLibraryFor(version: String) =
24+
s"org/scala-lang/scala3-library_3/$version/scala3-library_3-$version.jar"
25+
26+
private def scalaCompilerFor(version: String) =
27+
s"org/scala-lang/scala3-compiler_3/$version/scala3-compiler_3-$version.jar"
28+
29+
private val ScalaVersion = "3.7.2-RC1"
30+
31+
val tests: Tests = Tests {
32+
test("noDirective") - integrationTest { tester =>
33+
import tester.*
34+
35+
writeBuildMill(tester, scalaVersion = None)
36+
val res = eval("version")
37+
assert(res.isSuccess)
38+
39+
val lines = readResolveRunner(tester)
40+
assert(!lines.exists(_.contains(scalaCompilerFor(ScalaVersion))))
41+
assert(!lines.exists(_.contains(scalaLibraryFor(ScalaVersion))))
42+
}
43+
44+
test("withDirective") - integrationTest { tester =>
45+
import tester.*
46+
47+
writeBuildMill(tester, scalaVersion = Some(ScalaVersion))
48+
val res = eval("version")
49+
assert(res.isSuccess)
50+
51+
val lines = readResolveRunner(tester)
52+
assert(lines.exists(_.contains(scalaCompilerFor(ScalaVersion))))
53+
assert(lines.exists(_.contains(scalaLibraryFor(ScalaVersion))))
54+
}
55+
56+
test("withDirectiveAndThenWithout") - integrationTest { tester =>
57+
import tester.*
58+
59+
{
60+
writeBuildMill(tester, scalaVersion = Some(ScalaVersion))
61+
val res = eval("version")
62+
assert(res.isSuccess)
63+
64+
val lines = readResolveRunner(tester)
65+
assert(lines.exists(_.contains(scalaCompilerFor(ScalaVersion))))
66+
assert(lines.exists(_.contains(scalaLibraryFor(ScalaVersion))))
67+
}
68+
69+
{
70+
// This should recompile the build with the new version.
71+
writeBuildMill(tester, scalaVersion = None)
72+
val res = eval("version")
73+
assert(res.isSuccess)
74+
75+
val lines = readResolveRunner(tester)
76+
assert(!lines.exists(_.contains(scalaCompilerFor(ScalaVersion))))
77+
assert(!lines.exists(_.contains(scalaLibraryFor(ScalaVersion))))
78+
}
79+
}
80+
81+
}
82+
}

runner/launcher/src/mill/launcher/MillProcessLauncher.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
import java.util.function.Supplier;
1616
import java.util.stream.Stream;
1717
import mill.client.ClientUtil;
18-
import mill.constants.BuildInfo;
19-
import mill.constants.CodeGenConstants;
20-
import mill.constants.DaemonFiles;
21-
import mill.constants.EnvVars;
18+
import mill.constants.*;
2219
import scala.Option$;
2320

2421
public class MillProcessLauncher {
@@ -192,7 +189,7 @@ static String javaHome() throws Exception {
192189
if (jvmId != null) {
193190
final String jvmIdFinal = jvmId;
194191
javaHome = cachedComputedValue0(
195-
"java-home",
192+
CacheFiles.javaHome,
196193
jvmId,
197194
() -> new String[] {CoursierClient.resolveJavaHome(jvmIdFinal).getAbsolutePath()},
198195
// Make sure we check to see if the saved java home exists before using
@@ -241,10 +238,10 @@ static List<String> millLaunchJvmCommand() throws Exception {
241238
vmOptions.add("-XX:+HeapDumpOnOutOfMemoryError");
242239
vmOptions.add("-cp");
243240
var classPathCacheKey =
244-
"mill:" + BuildInfo.millVersion +
241+
"mill:" + BuildInfo.millVersion +
245242
",scala:" + (maybeScalaVersion == null ? "default" : maybeScalaVersion);
246243
String[] runnerClasspath = cachedComputedValue0(
247-
"resolve-runner", classPathCacheKey,
244+
CacheFiles.resolveRunner, classPathCacheKey,
248245
() -> CoursierClient.resolveMillDaemon(Option$.MODULE$.apply(maybeScalaVersion)),
249246
arr -> {
250247
for (String s : arr) {
@@ -277,7 +274,7 @@ static String[] cachedComputedValue(String name, String key, Supplier<String[]>
277274
static String[] cachedComputedValue0(
278275
String name, String key, Supplier<String[]> block, Function<String[], Boolean> validate) {
279276
try {
280-
Path cacheFile = Paths.get(".").resolve(out).resolve("mill-" + name);
277+
Path cacheFile = Paths.get(".").resolve(out).resolve(CacheFiles.filename(name));
281278
String[] value = null;
282279
if (Files.exists(cacheFile)) {
283280
String[] savedInfo = Files.readString(cacheFile).split("\n");

0 commit comments

Comments
 (0)