Skip to content
Draft
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
1 change: 0 additions & 1 deletion .mill-version

This file was deleted.

14 changes: 3 additions & 11 deletions build.sc → build.mill
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import $ivy.`com.github.lolgab::mill-mima::0.0.24`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
//| mill-version: 1.1.4
import $dep.`com.github.lolgab::mill-mima::0.2.1`
import $dep.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1`
import $file.deps, deps.{Deps, Scala, Versions}

import java.io.File
Expand Down Expand Up @@ -76,15 +77,6 @@ trait DependencyMima extends Mima {
.sorted
.map(_.repr)
}
// Remove once 0.3.0 is out
def mimaPreviousArtifacts = T {
val versions = mimaPreviousVersions()
val organization = pomSettings().organization
val artifactId0 = artifactId()
Agg.from(
versions.map(version => ivy"$organization:$artifactId0:$version")
)
}
}

private def scalaDirNames(sv: String): Seq[String] = {
Expand Down
10 changes: 5 additions & 5 deletions deps.sc → deps.mill
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ object Scala {
}

object Deps {
def expecty = ivy"com.eed3si9n.expecty::expecty::0.17.0"
def interface = ivy"io.get-coursier:interface:1.0.28"
def munit = ivy"org.scalameta::munit::1.0.4"
def pprint = ivy"com.lihaoyi::pprint::0.9.0"
def scalaReflect(sv: String) = ivy"org.scala-lang:scala-reflect:$sv"
def expecty = mvn"com.eed3si9n.expecty::expecty::0.17.0"
def interface = mvn"io.get-coursier:interface:1.0.28"
def munit = mvn"org.scalameta::munit::1.0.4"
def pprint = mvn"com.lihaoyi::pprint::0.9.0"
def scalaReflect(sv: String) = mvn"org.scala-lang:scala-reflect:$sv"
}

object Versions {
Expand Down
251 changes: 165 additions & 86 deletions mill
Original file line number Diff line number Diff line change
@@ -1,120 +1,199 @@
#!/usr/bin/env sh

# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with --mill-version parameter
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
#
# Project page: https://github.com/lefou/millw
#
# If you want to improve this script, please also contribute your changes back!
#
# Licensed under the Apache License, Version 2.0
set -e

if [ -z "${DEFAULT_MILL_VERSION}" ] ; then DEFAULT_MILL_VERSION="1.1.3"; fi

DEFAULT_MILL_VERSION=0.9.5
if [ -z "${GITHUB_RELEASE_CDN}" ] ; then GITHUB_RELEASE_CDN=""; fi

set -e
if [ -z "$MILL_MAIN_CLI" ] ; then MILL_MAIN_CLI="${0}"; fi

MILL_REPO_URL="https://github.com/com-lihaoyi/mill"

# Explicit commandline argument takes precedence over all other methods
if [ "x$1" = "x--mill-version" ] ; then
shift
if [ "x$1" != "x" ] ; then
MILL_VERSION="$1"
shift
else
echo "You specified --mill-version without a version."
echo "Please provide a version that matches one provided on"
echo "${MILL_REPO_URL}/releases"
false
fi
MILL_BUILD_SCRIPT=""

if [ -f "build.mill" ] ; then
MILL_BUILD_SCRIPT="build.mill"
elif [ -f "build.mill.scala" ] ; then
MILL_BUILD_SCRIPT="build.mill.scala"
elif [ -f "build.sc" ] ; then
MILL_BUILD_SCRIPT="build.sc"
fi

# Please note, that if a MILL_VERSION is already set in the environment,
# We reuse it's value and skip searching for a value.
# `s/.*://`:
# This is a greedy match that removes everything from the beginning of the line up to (and including) the last
# colon (:). This effectively isolates the value part of the declaration.
#
# `s/#.*//`:
# This removes any comments at the end of the line.
#
# `s/['\"]//g`:
# This removes all single and double quotes from the string, wherever they appear (g is for "global").
#
# `s/^[[:space:]]*//; s/[[:space:]]*$//`:
# These two expressions trim any leading or trailing whitespace ([[:space:]] matches spaces and tabs).
TRIM_VALUE_SED="s/.*://; s/#.*//; s/['\"]//g; s/^[[:space:]]*//; s/[[:space:]]*$//"

# If not already set, read .mill-version file
if [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; then
if [ -f ".mill-version" ] ; then
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
MILL_VERSION="$(tr '\r' '\n' < .mill-version | head -n 1 2> /dev/null)"
elif [ -f ".config/mill-version" ] ; then
MILL_VERSION="$(tr '\r' '\n' < .config/mill-version | head -n 1 2> /dev/null)"
elif [ -f "build.mill.yaml" ] ; then
MILL_VERSION="$(grep -E "mill-version:" "build.mill.yaml" | sed -E "$TRIM_VALUE_SED")"
elif [ -n "${MILL_BUILD_SCRIPT}" ] ; then
MILL_VERSION="$(grep -E "//\|.*mill-version" "${MILL_BUILD_SCRIPT}" | sed -E "$TRIM_VALUE_SED")"
fi
fi

if [ "x${XDG_CACHE_HOME}" != "x" ] ; then
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download"
else
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download"
fi
if [ -z "${MILL_VERSION}" ] ; then MILL_VERSION="${DEFAULT_MILL_VERSION}"; fi

# If not already set, try to fetch newest from Github
if [ "x${MILL_VERSION}" = "x" ] ; then
# TODO: try to load latest version from release page
echo "No mill version specified."
echo "You should provide a version via '.mill-version' file or --mill-version option."

mkdir -p "${MILL_DOWNLOAD_PATH}"
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest"
if [ "${MILL_DOWNLOAD_PATH}/.latest" -nt "${MILL_DOWNLOAD_PATH}/.expire_latest" ] ; then
# we know a current latest version
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
fi
MILL_USER_CACHE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/mill"

if [ "x${MILL_VERSION}" = "x" ] ; then
# we don't know a current latest version
echo "Retrieving latest mill version ..."
LANG=C curl -s -i -f -I ${MILL_REPO_URL}/releases/latest 2> /dev/null | grep --ignore-case Location: | sed s'/^.*tag\///' | tr -d '\r\n' > "${MILL_DOWNLOAD_PATH}/.latest"
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
fi
if [ -z "${MILL_FINAL_DOWNLOAD_FOLDER}" ] ; then MILL_FINAL_DOWNLOAD_FOLDER="${MILL_USER_CACHE_DIR}/download"; fi

if [ "x${MILL_VERSION}" = "x" ] ; then
# Last resort
MILL_VERSION="${DEFAULT_MILL_VERSION}"
echo "Falling back to hardcoded mill version ${MILL_VERSION}"
MILL_NATIVE_SUFFIX="-native"
MILL_JVM_SUFFIX="-jvm"
ARTIFACT_SUFFIX=""

# Check if GLIBC version is at least the required version
# Returns 0 (true) if GLIBC >= required version, 1 (false) otherwise
check_glibc_version() {
required_version="2.39"
required_major=$(echo "$required_version" | cut -d. -f1)
required_minor=$(echo "$required_version" | cut -d. -f2)
# Get GLIBC version from ldd --version (first line contains version like "ldd (GNU libc) 2.31")
glibc_version=$(ldd --version 2>/dev/null | head -n 1 | grep -oE '[0-9]+\.[0-9]+$' || echo "")
if [ -z "$glibc_version" ]; then
# If we can't determine GLIBC version, assume it's too old
return 1
fi
glibc_major=$(echo "$glibc_version" | cut -d. -f1)
glibc_minor=$(echo "$glibc_version" | cut -d. -f2)
if [ "$glibc_major" -gt "$required_major" ]; then
return 0
elif [ "$glibc_major" -eq "$required_major" ] && [ "$glibc_minor" -ge "$required_minor" ]; then
return 0
else
echo "Using mill version ${MILL_VERSION}"
return 1
fi
fi
}

set_artifact_suffix() {
if [ "$(uname -s 2>/dev/null | cut -c 1-5)" = "Linux" ]; then
# Native binaries require new enough GLIBC; fall back to JVM launcher if older
if ! check_glibc_version; then
return
fi
if [ "$(uname -m)" = "aarch64" ]; then ARTIFACT_SUFFIX="-native-linux-aarch64"
else ARTIFACT_SUFFIX="-native-linux-amd64"; fi
elif [ "$(uname)" = "Darwin" ]; then
if [ "$(uname -m)" = "arm64" ]; then ARTIFACT_SUFFIX="-native-mac-aarch64"
else ARTIFACT_SUFFIX="-native-mac-amd64"; fi
else
echo "This native mill launcher supports only Linux and macOS." 1>&2
exit 1
fi
}

MILL="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"
case "$MILL_VERSION" in
*"$MILL_NATIVE_SUFFIX")
MILL_VERSION=${MILL_VERSION%"$MILL_NATIVE_SUFFIX"}
set_artifact_suffix
;;

# If not already downloaded, download it
if [ ! -s "${MILL}" ] ; then

# support old non-XDG download dir
MILL_OLD_DOWNLOAD_PATH="${HOME}/.mill/download"
OLD_MILL="${MILL_OLD_DOWNLOAD_PATH}/${MILL_VERSION}"
if [ -x "${OLD_MILL}" ] ; then
MILL="${OLD_MILL}"
else
VERSION_PREFIX="$(echo -n $MILL_VERSION | cut -b -4)"
case $VERSION_PREFIX in
0.0. | 0.1. | 0.2. | 0.3. | 0.4. )
DOWNLOAD_SUFFIX=""
*"$MILL_JVM_SUFFIX")
MILL_VERSION=${MILL_VERSION%"$MILL_JVM_SUFFIX"}
;;

*)
case "$MILL_VERSION" in
0.1.* | 0.2.* | 0.3.* | 0.4.* | 0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.* | 0.12.*)
;;
*)
DOWNLOAD_SUFFIX="-assembly"
set_artifact_suffix
;;
esac
unset VERSION_PREFIX

DOWNLOAD_FILE=$(mktemp mill.XXXX)
# TODO: handle command not found
echo "Downloading mill ${MILL_VERSION} from ${MILL_REPO_URL}/releases ..."
curl -L -o "${DOWNLOAD_FILE}" "${MILL_REPO_URL}/releases/download/${MILL_VERSION%%-*}/${MILL_VERSION}${DOWNLOAD_SUFFIX}"
chmod +x "${DOWNLOAD_FILE}"
mkdir -p "${MILL_DOWNLOAD_PATH}"
mv "${DOWNLOAD_FILE}" "${MILL}"

unset DOWNLOAD_FILE
unset DOWNLOAD_SUFFIX
;;
esac

MILL="${MILL_FINAL_DOWNLOAD_FOLDER}/$MILL_VERSION$ARTIFACT_SUFFIX"

# If not already downloaded, download it
if [ ! -s "${MILL}" ] || [ "$MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT" = "1" ] ; then
case $MILL_VERSION in
0.0.* | 0.1.* | 0.2.* | 0.3.* | 0.4.*)
MILL_DOWNLOAD_SUFFIX=""
MILL_DOWNLOAD_FROM_MAVEN=0
;;
0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.0-M*)
MILL_DOWNLOAD_SUFFIX="-assembly"
MILL_DOWNLOAD_FROM_MAVEN=0
;;
*)
MILL_DOWNLOAD_SUFFIX="-assembly"
MILL_DOWNLOAD_FROM_MAVEN=1
;;
esac
case $MILL_VERSION in
0.12.0 | 0.12.1 | 0.12.2 | 0.12.3 | 0.12.4 | 0.12.5 | 0.12.6 | 0.12.7 | 0.12.8 | 0.12.9 | 0.12.10 | 0.12.11)
MILL_DOWNLOAD_EXT="jar"
;;
0.12.*)
MILL_DOWNLOAD_EXT="exe"
;;
0.*)
MILL_DOWNLOAD_EXT="jar"
;;
*)
MILL_DOWNLOAD_EXT="exe"
;;
esac

MILL_TEMP_DOWNLOAD_FILE="${MILL_OUTPUT_DIR:-out}/mill-temp-download"
mkdir -p "$(dirname "${MILL_TEMP_DOWNLOAD_FILE}")"

if [ "$MILL_DOWNLOAD_FROM_MAVEN" = "1" ] ; then
MILL_DOWNLOAD_URL="https://repo1.maven.org/maven2/com/lihaoyi/mill-dist${ARTIFACT_SUFFIX}/${MILL_VERSION}/mill-dist${ARTIFACT_SUFFIX}-${MILL_VERSION}.${MILL_DOWNLOAD_EXT}"
else
MILL_VERSION_TAG=$(echo "$MILL_VERSION" | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
MILL_DOWNLOAD_URL="${GITHUB_RELEASE_CDN}${MILL_REPO_URL}/releases/download/${MILL_VERSION_TAG}/${MILL_VERSION}${MILL_DOWNLOAD_SUFFIX}"
unset MILL_VERSION_TAG
fi


if [ "$MILL_TEST_DRY_RUN_LAUNCHER_SCRIPT" = "1" ] ; then
echo "$MILL_DOWNLOAD_URL"
echo "$MILL"
exit 0
fi

echo "Downloading mill ${MILL_VERSION} from ${MILL_DOWNLOAD_URL} ..." 1>&2
curl -f -L -o "${MILL_TEMP_DOWNLOAD_FILE}" "${MILL_DOWNLOAD_URL}"

chmod +x "${MILL_TEMP_DOWNLOAD_FILE}"

mkdir -p "${MILL_FINAL_DOWNLOAD_FOLDER}"
mv "${MILL_TEMP_DOWNLOAD_FILE}" "${MILL}"

unset MILL_TEMP_DOWNLOAD_FILE
unset MILL_DOWNLOAD_SUFFIX
fi

MILL_FIRST_ARG=""
if [ "$1" = "--bsp" ] || [ "${1#"-i"}" != "$1" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--no-daemon" ] || [ "$1" = "--help" ] ; then
# Need to preserve the first position of those listed options
MILL_FIRST_ARG=$1
shift
fi

unset MILL_DOWNLOAD_PATH
unset MILL_FINAL_DOWNLOAD_FOLDER
unset MILL_OLD_DOWNLOAD_PATH
unset OLD_MILL
unset MILL_VERSION
unset MILL_REPO_URL

exec $MILL "$@"
# -D mill.main.cli is for compatibility with Mill 0.10.9 - 0.13.0-M2
# We don't quote MILL_FIRST_ARG on purpose, so we can expand the empty value without quotes
# shellcheck disable=SC2086
exec "${MILL}" $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@"
Loading
Loading