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

Updates #16

Merged
merged 9 commits into from
Dec 27, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI
on:
push:
branches:
- master
- main
tags:
- "v*"
pull_request:
Expand All @@ -18,7 +18,7 @@ jobs:
- uses: coursier/cache-action@v6
- uses: coursier/setup-action@v1
with:
jvm: 8
jvm: "zulu:21"
- name: Compile
run: ./mill -i __.test.compile
- name: Test
Expand All @@ -38,7 +38,7 @@ jobs:
- uses: coursier/cache-action@v6
- uses: coursier/setup-action@v1
with:
jvm: 8
jvm: "zulu:21"
- run: .github/scripts/gpg-setup.sh
shell: bash
env:
Expand Down
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.12
0.12.4
19 changes: 14 additions & 5 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import $file.deps, deps.{Deps, Scala, WindowsJvm}
import $file.deps, deps.{Deps, Scala}
import $file.settings, settings.{GenerateHeaders, HasCSources, JniUtilsPublishModule, JniUtilsPublishVersion, WithDllNameJava}

import mill._, scalalib._
Expand All @@ -25,6 +25,10 @@ object `windows-jni-utils` extends MavenModule with JniUtilsPublishVersion with
if (dir.getName == "jre") dir.getParent
else value
}

def javacOptions = super.javacOptions() ++ Seq(
"--release", "8"
)
}

object `windows-jni-utils-graalvm` extends WindowsUtils with JniUtilsPublishModule {
Expand All @@ -46,7 +50,7 @@ object `windows-jni-utils-coursierapi` extends WindowsUtils with JniUtilsPublish
object `windows-jni-utils-tests` extends ScalaModule with JniUtilsPublishModule {
def scalaVersion = Scala.scala213
def moduleDeps = Seq(`windows-jni-utils`)
object test extends Tests {
object test extends ScalaTests {
def moduleDeps = super.moduleDeps ++ Seq(
`windows-jni-utils-bootstrap`,
`windows-jni-utils-lmcoursier`,
Expand All @@ -73,12 +77,15 @@ object headers extends Module {
def cDirectory = `windows-jni-utils`.cDirectory()
}

implicit def millModuleBasePath: define.BasePath =
define.BasePath(super.millModuleBasePath.value / os.up)
implicit def millModuleBasePath: define.Ctx.BasePath =
define.Ctx.BasePath(super.millModuleBasePath.value / os.up)
}

trait WindowsUtils extends MavenModule with JniUtilsPublishVersion {
def compileIvyDeps = Agg(Deps.svm)
def javacOptions = super.javacOptions() ++ Seq(
"--release", "8"
)
}

def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) =
Expand All @@ -93,6 +100,8 @@ def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) =
pgpPassword = pgpPassword,
data = data,
timeout = timeout,
log = T.ctx().log
log = T.ctx().log,
workspace = T.workspace,
env = T.env
)
}
7 changes: 1 addition & 6 deletions deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@ object Deps {
}

object Scala {
def scala213 = "2.13.5"
}

object WindowsJvm {
val url = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_windows_hotspot_11.0.10_9.zip"
val archiveName = url.drop(url.lastIndexOf('/') + 1)
def scala213 = "2.13.15"
}
191 changes: 156 additions & 35 deletions mill
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,41 @@
# 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
# Original Project page: https://github.com/lefou/millw
# Script Version: 0.4.12
#
# If you want to improve this script, please also contribute your changes back!
#
# Licensed under the Apache License, Version 2.0

set -e

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


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

set -e

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

if [ -z "${CURL_CMD}" ] ; then
CURL_CMD=curl
fi

# Explicit commandline argument takes precedence over all other methods
if [ "x$1" = "x--mill-version" ] ; then
if [ "$1" = "--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"
echo "You specified --mill-version without a version." 1>&2
echo "Please provide a version that matches one provided on" 1>&2
echo "${MILL_REPO_URL}/releases" 1>&2
false
fi
fi
Expand All @@ -35,73 +47,169 @@ fi
# We reuse it's value and skip searching for a value.

# 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)"
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"
MILL_USER_CACHE_DIR="${XDG_CACHE_HOME:-${HOME}/.cache}/mill"

if [ -z "${MILL_DOWNLOAD_PATH}" ] ; then
MILL_DOWNLOAD_PATH="${MILL_USER_CACHE_DIR}/download"
fi

# If not already set, try to fetch newest from Github
if [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; 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."
echo "No mill version specified." 1>&2
echo "You should provide a version via '.mill-version' file or --mill-version option." 1>&2

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
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest" 2>/dev/null || (
# we might be on OSX or BSD which don't have -d option for touch
# but probably a -A [-][[hh]mm]SS
touch "${MILL_DOWNLOAD_PATH}/.expire_latest"; touch -A -010000 "${MILL_DOWNLOAD_PATH}/.expire_latest"
) || (
# in case we still failed, we retry the first touch command with the intention
# to show the (previously suppressed) error message
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest"
)

# POSIX shell variant of bash's -nt operator, see https://unix.stackexchange.com/a/449744/6993
# if [ "${MILL_DOWNLOAD_PATH}/.latest" -nt "${MILL_DOWNLOAD_PATH}/.expire_latest" ] ; then
if [ -n "$(find -L "${MILL_DOWNLOAD_PATH}/.latest" -prune -newer "${MILL_DOWNLOAD_PATH}/.expire_latest")" ]; then
# we know a current latest version
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)"
MILL_VERSION=$(head -n 1 "${MILL_DOWNLOAD_PATH}"/.latest 2> /dev/null)
fi

if [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; 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)"
echo "Retrieving latest mill version ..." 1>&2
LANG=C ${CURL_CMD} -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 [ "x${MILL_VERSION}" = "x" ] ; then
if [ -z "${MILL_VERSION}" ] ; then
# Last resort
MILL_VERSION="${DEFAULT_MILL_VERSION}"
echo "Falling back to hardcoded mill version ${MILL_VERSION}"
echo "Falling back to hardcoded mill version ${MILL_VERSION}" 1>&2
else
echo "Using mill version ${MILL_VERSION}"
echo "Using mill version ${MILL_VERSION}" 1>&2
fi
fi

MILL="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}"

try_to_use_system_mill() {
if [ "$(uname)" != "Linux" ]; then
return 0
fi

MILL_IN_PATH="$(command -v mill || true)"

if [ -z "${MILL_IN_PATH}" ]; then
return 0
fi

SYSTEM_MILL_FIRST_TWO_BYTES=$(head --bytes=2 "${MILL_IN_PATH}")
if [ "${SYSTEM_MILL_FIRST_TWO_BYTES}" = "#!" ]; then
# MILL_IN_PATH is (very likely) a shell script and not the mill
# executable, ignore it.
return 0
fi

SYSTEM_MILL_PATH=$(readlink -e "${MILL_IN_PATH}")
SYSTEM_MILL_SIZE=$(stat --format=%s "${SYSTEM_MILL_PATH}")
SYSTEM_MILL_MTIME=$(stat --format=%y "${SYSTEM_MILL_PATH}")

if [ ! -d "${MILL_USER_CACHE_DIR}" ]; then
mkdir -p "${MILL_USER_CACHE_DIR}"
fi

SYSTEM_MILL_INFO_FILE="${MILL_USER_CACHE_DIR}/system-mill-info"
if [ -f "${SYSTEM_MILL_INFO_FILE}" ]; then
parseSystemMillInfo() {
LINE_NUMBER="${1}"
# Select the line number of the SYSTEM_MILL_INFO_FILE, cut the
# variable definition in that line in two halves and return
# the value, and finally remove the quotes.
sed -n "${LINE_NUMBER}p" "${SYSTEM_MILL_INFO_FILE}" |\
cut -d= -f2 |\
sed 's/"\(.*\)"/\1/'
}

CACHED_SYSTEM_MILL_PATH=$(parseSystemMillInfo 1)
CACHED_SYSTEM_MILL_VERSION=$(parseSystemMillInfo 2)
CACHED_SYSTEM_MILL_SIZE=$(parseSystemMillInfo 3)
CACHED_SYSTEM_MILL_MTIME=$(parseSystemMillInfo 4)

if [ "${SYSTEM_MILL_PATH}" = "${CACHED_SYSTEM_MILL_PATH}" ] \
&& [ "${SYSTEM_MILL_SIZE}" = "${CACHED_SYSTEM_MILL_SIZE}" ] \
&& [ "${SYSTEM_MILL_MTIME}" = "${CACHED_SYSTEM_MILL_MTIME}" ]; then
if [ "${CACHED_SYSTEM_MILL_VERSION}" = "${MILL_VERSION}" ]; then
MILL="${SYSTEM_MILL_PATH}"
return 0
else
return 0
fi
fi
fi

SYSTEM_MILL_VERSION=$(${SYSTEM_MILL_PATH} --version | head -n1 | sed -n 's/^Mill.*version \(.*\)/\1/p')

cat <<EOF > "${SYSTEM_MILL_INFO_FILE}"
CACHED_SYSTEM_MILL_PATH="${SYSTEM_MILL_PATH}"
CACHED_SYSTEM_MILL_VERSION="${SYSTEM_MILL_VERSION}"
CACHED_SYSTEM_MILL_SIZE="${SYSTEM_MILL_SIZE}"
CACHED_SYSTEM_MILL_MTIME="${SYSTEM_MILL_MTIME}"
EOF

if [ "${SYSTEM_MILL_VERSION}" = "${MILL_VERSION}" ]; then
MILL="${SYSTEM_MILL_PATH}"
fi
}
try_to_use_system_mill

# 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. )
case $MILL_VERSION in
0.0.* | 0.1.* | 0.2.* | 0.3.* | 0.4.* )
DOWNLOAD_SUFFIX=""
DOWNLOAD_FROM_MAVEN=0
;;
0.5.* | 0.6.* | 0.7.* | 0.8.* | 0.9.* | 0.10.* | 0.11.0-M* )
DOWNLOAD_SUFFIX="-assembly"
DOWNLOAD_FROM_MAVEN=0
;;
*)
DOWNLOAD_SUFFIX="-assembly"
DOWNLOAD_FROM_MAVEN=1
;;
esac
unset VERSION_PREFIX

DOWNLOAD_FILE=$(mktemp mill.XXXX)
DOWNLOAD_FILE=$(mktemp mill.XXXXXX)

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

# 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}"
echo "Downloading mill ${MILL_VERSION} from ${DOWNLOAD_URL} ..." 1>&2
${CURL_CMD} -f -L -o "${DOWNLOAD_FILE}" "${DOWNLOAD_URL}"
chmod +x "${DOWNLOAD_FILE}"
mkdir -p "${MILL_DOWNLOAD_PATH}"
mv "${DOWNLOAD_FILE}" "${MILL}"
Expand All @@ -111,10 +219,23 @@ if [ ! -s "${MILL}" ] ; then
fi
fi

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

MILL_FIRST_ARG=""
if [ "$1" = "--bsp" ] || [ "$1" = "-i" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$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_OLD_DOWNLOAD_PATH
unset OLD_MILL
unset MILL_VERSION
unset MILL_REPO_URL

exec $MILL "$@"
# 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