Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up dist/package.mill #4339

Merged
merged 8 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.5-130-8f256f-DIRTY3537ab30-native
0.12.5-131-1e6358-native
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ jobs:
include:
# bootstrap tests
- java-version: 11 # Have one job on oldest JVM
buildcmd: ci/test-mill-dev.sh && ci/test-mill-release.sh && ./mill -i -k __.ivyDepsTree && ./mill -i -k __.ivyDepsTree --withRuntime
buildcmd: ci/test-dist-run.sh && ci/test-install-local.sh && ./mill -i -k __.ivyDepsTree && ./mill -i -k __.ivyDepsTree --withRuntime
- java-version: 17 # Have one job on default JVM
buildcmd: ci/test-mill-bootstrap.sh

Expand Down
File renamed without changes.
File renamed without changes.
118 changes: 47 additions & 71 deletions dist/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ trait InstallModule extends build.MillPublishJavaModule{
}
def moduleDeps = Seq(build.runner, build.idea, build.main.init)

def jar: T[PathRef]
def executableRaw: T[PathRef]

def executable = Task{
Task.traverse(allPublishModules)(m => m.publishLocalCached)()
jar()
executableRaw()
}

def localBinName: String
Expand Down Expand Up @@ -91,7 +91,13 @@ object `package` extends RootModule with InstallModule {

def genTask(m: ScalaModule) = Task.Anon { Seq(m.jar(), m.sourceJar()) ++ m.runClasspath() }

def forkArgs: T[Seq[String]] = Task {

def localBinName = "mill-assembly.jar"

def launcher = Task {
val isWin = scala.util.Properties.isWin
val outputPath = Task.dest / (if (isWin) "run.bat" else "run")

val genIdeaArgs =
genTask(build.main.define)() ++
genTask(build.main.eval)() ++
Expand All @@ -103,21 +109,36 @@ object `package` extends RootModule with InstallModule {
genTask(build.javascriptlib)() ++
genTask(build.pythonlib)()

testArgs() ++
val launcherForkArgs = testArgs() ++
Seq(
"-DMILL_CLASSPATH=" + runClasspath().map(_.path.toString).mkString(","),
"-DMILL_BUILD_LIBRARIES=" + genIdeaArgs.map(_.path).mkString(","),
s"-DBSP4J_VERSION=${build.Deps.bsp4j.dep.version}"

)
}
val (millArgs, otherArgs) =
launcherForkArgs.partition(arg => arg.startsWith("-DMILL") && !arg.startsWith("-DMILL_VERSION"))

def localBinName = "mill-assembly.jar"
// Pass Mill options via file, due to small max args limit in Windows
val vmOptionsFile = Task.dest / "mill.properties"
val millOptionsContent = millArgs
.map(_.drop(2).replace("\\", "/")) // drop -D prefix, replace \ with /
.mkString("\r\n")

def launcher = Task {
val isWin = scala.util.Properties.isWin
val outputPath = Task.dest / (if (isWin) "run.bat" else "run")
os.write(vmOptionsFile, millOptionsContent)
val jvmArgs = otherArgs ++ List(s"-DMILL_OPTIONS_PATH=$vmOptionsFile")
val classpath = runClasspath().map(_.path.toString)
val classpathJar = Task.dest / "classpath.jar"
Jvm.createClasspathPassingJar(classpathJar, runClasspath().map(_.path))

val script = Jvm.launcherUniversalScript(
mainClass = "mill.runner.client.MillClientMain",
shellClassPath = classpath,
cmdClassPath = Agg(classpathJar.toString()),
jvmArgs = jvmArgs,
)

os.write(outputPath, script)

os.write(outputPath, prependShellScript())
if (!isWin) os.perms.set(outputPath, "rwxrwxrwx")

PathRef(outputPath)
Expand All @@ -131,49 +152,21 @@ object `package` extends RootModule with InstallModule {
mill.scalalib.Assembly.Rule.ExcludePattern("mill/local-test-overrides/.*")
)

def jar = Task {
val version = build.millVersion()
val devRunClasspath = runClasspath().map(_.path)
val filename = if (scala.util.Properties.isWin) "mill.bat" else "mill"
val commonArgs = Seq(
// Workaround for Zinc/JNA bug
// https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130
"-Djna.nosys=true"
)
val shellArgs = Seq("-DMILL_CLASSPATH=$0") ++ commonArgs
val cmdArgs = Seq(""""-DMILL_CLASSPATH=%~dpnx0"""") ++ commonArgs
os.move(
mill.scalalib.Assembly.createAssembly(
devRunClasspath,
prependShellScript = launcherScript(shellArgs, cmdArgs, Agg("$0"), Agg("%~dpnx0")),
assemblyRules = assemblyRules
).path,
Task.dest / filename
)
PathRef(Task.dest / filename)
}
def forkArgs = Seq(
// Workaround for Zinc/JNA bug
// https://github.com/sbt/sbt/blame/6718803ee6023ab041b045a6988fafcfae9d15b5/main/src/main/scala/sbt/Main.scala#L130
"-Djna.nosys=true"
)

def prependShellScript = Task {
val (millArgs, otherArgs) =
forkArgs().partition(arg => arg.startsWith("-DMILL") && !arg.startsWith("-DMILL_VERSION"))
// Pass Mill options via file, due to small max args limit in Windows
val vmOptionsFile = Task.dest / "mill.properties"
val millOptionsContent =
millArgs.map(_.drop(2).replace("\\", "/")).mkString(
"\r\n"
) // drop -D prefix, replace \ with /
os.write(vmOptionsFile, millOptionsContent)
val jvmArgs = otherArgs ++ List(s"-DMILL_OPTIONS_PATH=$vmOptionsFile")
val classpath = runClasspath().map(_.path.toString)
val classpathJar = Task.dest / "classpath.jar"
Jvm.createClasspathPassingJar(classpathJar, runClasspath().map(_.path))
def forkShellArgs = Seq("-DMILL_CLASSPATH=$0")
def forkCmdArgs = Seq(""""-DMILL_CLASSPATH=%~dpnx0"""")

launcherScript(
jvmArgs,
jvmArgs,
classpath,
Agg(classpathJar.toString()) // TODO not working yet on Windows! see #791
)
def mainClass = Some("mill.runner.client.MillClientMain")

def executableRaw = Task {
val filename = if (scala.util.Properties.isWin) "mill.bat" else "mill"
os.copy(assembly().path, Task.dest / filename)
PathRef(Task.dest / filename)
}

def run(args: Task[Args] = Task.Anon(Args())) = Task.Command(exclusive = true) {
Expand All @@ -195,23 +188,6 @@ object `package` extends RootModule with InstallModule {
}
}
}
def launcherScript(
shellJvmArgs: Seq[String],
cmdJvmArgs: Seq[String],
shellClassPath: Agg[String],
cmdClassPath: Agg[String]
) = {

Jvm.launcherUniversalScript(
mainClass = "mill.runner.client.MillClientMain",
shellClassPath = shellClassPath,
cmdClassPath = cmdClassPath,
jvmArgs = Nil,
shebang = false,
shellJvmArgs = shellJvmArgs,
cmdJvmArgs = cmdJvmArgs
)
}

def millBootstrap = Task.Source(Task.workspace / "mill")
def millBootstrapBat = Task.Source(Task.workspace / "mill.bat")
Expand Down Expand Up @@ -266,7 +242,7 @@ object `package` extends RootModule with InstallModule {

def uploadToGithub(authKey: String) = Task.Command {
val vcsState = VcsVersion.vcsState()
val label = vcsState.format()
val label = vcsState.copy(dirtyHash = None).format()
if (label != build.millVersion()) sys.error("Modified mill version detected, aborting upload")
val releaseTag = vcsState.lastTag.getOrElse(sys.error(
"Incomplete git history. No tag found.\nIf on CI, make sure your git checkout job includes enough history."
Expand Down Expand Up @@ -318,7 +294,7 @@ object `package` extends RootModule with InstallModule {

def localBinName = "mill-native"

def jar = Task {
def executableRaw = Task {
val previous = nativeImage().path
val executable = Task.dest / previous.baseName

Expand Down
2 changes: 1 addition & 1 deletion integration/ide/bsp-modules/src/BspModulesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill.bsp.Constants
import utest._

object BspModulesTests extends UtestIntegrationTestSuite {
val bsp4jVersion: String = sys.props.getOrElse("BSP4J_VERSION", ???)
val bsp4jVersion: String = sys.props.getOrElse("BSP4J_VERSION", Constants.bspProtocolVersion)

def tests: Tests = Tests {
test("BSP module with foreign modules") {
Expand Down
2 changes: 1 addition & 1 deletion integration/ide/bsp-server/src/BspInstallDebugTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object BspInstallDebugTests extends UtestIntegrationTestSuite {
override protected def workspaceSourcePath: os.Path =
super.workspaceSourcePath / "project"

val bsp4jVersion: String = sys.props.getOrElse("BSP4J_VERSION", ???)
val bsp4jVersion: String = sys.props.getOrElse("BSP4J_VERSION", Constants.bspProtocolVersion)
// we purposely enable debugging in this simulated test env
override val debugLog: Boolean = true

Expand Down
Loading