Add Pants build tool (#709)

This commit is contained in:
Yi Cheng 2017-12-11 08:50:04 -08:00 committed by Alexandre Archambault
parent 930ac74dd8
commit 1296459de3
12 changed files with 400 additions and 5 deletions

View File

@ -53,6 +53,11 @@ matrix:
- env: SCALA_VERSION=2.10.6 SCALA_JS=1
os: linux
jdk: oraclejdk8
- os: linux
jdk: oraclejdk8
script:
# Sanity check for Pants build path.
- ./pants run cli/src/main/scala-2.11:coursier-cli -- fetch --help
env:
global:
- secure: miHFMwVRD/yjOLy794nOwc2lJTMyL5O0MXABT9ksg5ejQy1FrFVc2YH86Agp80W02/lGLGl0qWCiK1TBcs9q4Apt01nkD1a/0/iuTRm//bdhnu8BbRxFITf+2cyYJVytKPsF585aHldMv1rwZs3TDaTzEEecAEki5r50yyTVo7ycG0lVj9aVWXerKRMIT54Wb8M6nqbyRB1jGWT0ETNU13vOvQznPTUXQG5hsiKnGYRf8T3umOMdOHpV0rvdwYqAIMsikaAFcYCS5P/pLXMtmRHICH9KUG8TV/ST07p1BXtbBg9y1Q+lpnXotXh4ZNoWOp8B6v7fxJ/WlLYTDROWCiHJ4s2V4Di00db/nW4OWrEEBlrh7vJ/npZqyt9V9YeNv6alxi+DCESwusgvD4Cx5c3zh+2X6RB6BYwWHlFnd80rmsLe4R4fFUcc8E/ZR9vUFjP1CsQKqfJ5yfKR6V+n8jK8FjLpoaU9PHPo2H4V3FZM/fCLcxhE37vfaYI7/O7MqE/cdGpZIuz7g3c4toWCgNZJDn8iJCPmrgcbW5zbfDxvWU2K816ycgnUwSQ5dufrJpAbLNrjR1O8EPRkMDDp9bB7/4RVQvfDfP9GGoiHPHHgxGzY0Lf5bm+Bj1mRfB5/SXHd3IjhUCD9q7eD1/ANifEYALC5BJ4TB8RhQUPU8uM=

171
3rdparty/jvm/BUILD vendored Normal file
View File

@ -0,0 +1,171 @@
# This file should match the 3rdparty jars in project/Deps.scala
jar_library(
name = "scala-xml",
jars = [
scala_jar(
name = "scala-xml",
org = "org.scala-lang.modules",
rev = "1.0.6",
),
],
)
jar_library(
name = "quasiQuotes",
jars = [
scala_jar(
name = "quasiquotes",
org = "org.scalamacros",
rev = "2.1.0",
),
],
)
jar_library(
name = "fastParse",
jars = [
scala_jar(
name = "fastparse",
org = "com.lihaoyi",
rev = "1.0.0",
),
],
)
jar_library(
name = "scalaz-concurrent",
jars = [
scala_jar(
name = "scalaz-concurrent",
org = "org.scalaz",
rev = "7.2.16",
),
],
)
jar_library(
name = "scalaz-core",
jars = [
scala_jar(
name = "scalaz-core",
org = "org.scalaz",
rev = "7.2.16",
),
],
)
jar_library(
name = "jsoup",
jars = [jar(
name = "jsoup",
org = "org.jsoup",
rev = "1.10.3",
)],
)
SCALAJS_REV = "0.9.3"
jar_library(
name = "cli",
jars = [
scala_jar(
name = "scalajs-cli",
org = "org.scala-js",
rev = SCALAJS_REV,
),
],
)
jar_library(
name = "compiler",
jars = [
jar(
name = "scalajs-compiler_2.11.8",
org = "org.scala-js",
rev = SCALAJS_REV,
),
],
)
jar_library(
name = "library",
jars = [
scala_jar(
name = "scalajs-library",
org = "org.scala-js",
rev = SCALAJS_REV,
),
],
)
jar_library(
name = "dom",
jars = [
scala_jar(
name = "scalajs-dom_sjs0.6",
org = "org.scala-js",
rev = "0.9.1",
),
],
)
jar_library(
name = "jackson-module-scala",
jars = [
scala_jar(
name = "jackson-module-scala",
org = "com.fasterxml.jackson.module",
rev = "2.8.4",
),
],
)
jar_library(
name = "caseapp",
jars = [
scala_jar(
name = "case-app",
org = "com.github.alexarchambault",
rev = "1.1.3",
),
],
)
jar_library(
name = "argonaut-shapeless",
jars = [
scala_jar(
name = "argonaut-shapeless_6.2",
org = "com.github.alexarchambault",
rev = "1.2.0-M6",
),
],
)
jar_library(
name = "soc",
jars = [
jar(
name = "directories",
org = "io.github.soc",
rev = "5",
),
],
)
jar_library(
name = "scala-native",
jars = [
jar(
name = "nativelib_native0.3_2.11",
org = "org.scala-native",
rev = "0.3.3",
),
jar(
name = "tools_2.11",
org = "io.get-coursier.scala-native",
rev = "0.3.0-coursier-1",
),
],
)

View File

@ -137,3 +137,23 @@ Then run the proxy ITs with
```
$ sbt ++2.12.4 proxy-tests/it:test
```
### Build with Pants
[Pants](https://github.com/pantsbuild/pants) build tool is also added to an experimental path to build the software
Currently only the CLI command can be built via Pants with Scala 2.11.11.
To iterate on code changes:
```
./pants run cli/src/main/scala-2.11:coursier-cli -- fetch --help
```
To build a distributable binary
```
./pants run cli/src/main/scala-2.11:coursier-cli
# Artifact will be placed under dist/
java -jar dist/coursier-cli.jar fetch --help
```

9
cache/src/main/scala/BUILD vendored Normal file
View File

@ -0,0 +1,9 @@
scala_library(
name = "cache",
dependencies = [
"core:core",
"3rdparty/jvm:scalaz-concurrent",
"paths/src/main/java:paths",
],
sources = rglobs("*.scala"),
)

View File

@ -0,0 +1,21 @@
scala_library(
name = "cli",
dependencies = [
"3rdparty/jvm:argonaut-shapeless",
"3rdparty/jvm:caseapp",
"core:core",
"cache/src/main/scala:cache",
"extra/src/main/scala/coursier/extra:extra",
"extra/src/main/scala-2.11/coursier/extra:native",
],
sources = rglobs("*.scala"),
)
jvm_binary(
name = "coursier-cli",
basename = "coursier-cli",
dependencies = [
":cli",
],
main = "coursier.cli.Coursier",
)

12
core/BUILD Normal file
View File

@ -0,0 +1,12 @@
scala_library(
name = "core",
dependencies = [
"3rdparty/jvm:fastParse",
"3rdparty/jvm:scalaz-core",
"3rdparty/jvm:jsoup",
# TODO(wisechengyi) for some reason there is no compile error
# and this is needed at runtime.
"3rdparty/jvm:scala-xml",
],
sources = rglobs("jvm/*.scala", "shared/*.scala"),
)

View File

@ -6,11 +6,16 @@ object Properties {
private lazy val props = {
val p = new JProperties()
p.load(
getClass
.getClassLoader
.getResourceAsStream("coursier/coursier.properties")
)
try {
p.load(
getClass
.getClassLoader
.getResourceAsStream("coursier/coursier.properties")
)
}
catch {
case e: NullPointerException =>
}
p
}

View File

@ -0,0 +1,8 @@
scala_library(
name = "native",
dependencies = [
"3rdparty/jvm:scala-native",
"core:core",
],
sources = rglobs("*.scala"),
)

View File

@ -0,0 +1,7 @@
scala_library(
name = "extra",
dependencies = [
"core:core",
],
sources = rglobs("*.scala"),
)

102
pants Executable file
View File

@ -0,0 +1,102 @@
#!/usr/bin/env bash
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
# =============================== NOTE ===============================
# This pants bootstrap script comes from the pantsbuild/setup
# project and is intended to be checked into your code repository so
# that any developer can check out your code and be building it with
# pants with no prior setup needed.
#
# You can learn more here: https://pantsbuild.github.io/setup
# ====================================================================
set -e
PYTHON=${PYTHON:-$(which python2.7)}
PANTS_HOME="${PANTS_HOME:-${HOME}/.cache/pants/setup}"
PANTS_BOOTSTRAP="${PANTS_HOME}/bootstrap-$(uname -s)-$(uname -m)"
VENV_VERSION=15.0.2
# This requirement is installed before pantsbuild.pants to hack around
# interpreters that have newer setuptools already installed, effectively
# re-installing an older setuptools and pinning low to a version known to be
# ingestable by both pants and pex for all reasonable versions of pants.
# See:
# https://github.com/pantsbuild/pants/issues/3948
# https://github.com/pantsbuild/setup/issues/14
# https://github.com/pantsbuild/setup/issues/19
SETUPTOOLS_REQUIREMENT="setuptools==5.4.1"
VENV_PACKAGE=virtualenv-${VENV_VERSION}
VENV_TARBALL=${VENV_PACKAGE}.tar.gz
# The high-level flow:
# 1.) Grab pants version from pants.ini or default to latest.
# 2.) Check for a venv via a naming/path convention and execute if found.
# 3.) Otherwise create venv and re-exec self.
#
# After that pants itself will handle making sure any requested plugins
# are installed and up to date.
function tempdir {
mktemp -d "$1"/pants.XXXXXX
}
# TODO(John Sirois): GC race loser tmp dirs leftover from bootstrap_XXX
# functions. Any tmp dir w/o a symlink pointing to it can go.
function bootstrap_venv {
if [[ ! -d "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}" ]]
then
(
mkdir -p "${PANTS_BOOTSTRAP}" && \
staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") && \
cd "${staging_dir}" && \
curl -LO https://pypi.io/packages/source/v/virtualenv/${VENV_TARBALL} && \
tar -xzf ${VENV_TARBALL} && \
ln -s "${staging_dir}/${VENV_PACKAGE}" "${staging_dir}/latest" && \
mv "${staging_dir}/latest" "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}"
) 1>&2
fi
echo "${PANTS_BOOTSTRAP}/${VENV_PACKAGE}"
}
function bootstrap_pants {
pants_requirement="pantsbuild.pants"
pants_version=$(
grep -E "^[[:space:]]*pants_version" pants.ini 2>/dev/null | \
cut -f2 -d: | tr -d " "
)
if [[ -n "${pants_version}" ]]
then
pants_requirement="${pants_requirement}==${pants_version}"
else
pants_version="unspecified"
fi
if [[ ! -d "${PANTS_BOOTSTRAP}/${pants_version}" ]]
then
(
# NB: We setup the virtualenv with no setuptools to ensure our
# ${SETUPTOOLS_REQUIREMENT} wins.
venv_path="$(bootstrap_venv)" && \
staging_dir=$(tempdir "${PANTS_BOOTSTRAP}") && \
"${PYTHON}" "${venv_path}/virtualenv.py" --no-setuptools --no-download \
"${staging_dir}/install" && \
"${staging_dir}/install/bin/python" \
"${staging_dir}/install/bin/pip" install \
"${SETUPTOOLS_REQUIREMENT}" && \
"${staging_dir}/install/bin/python" \
"${staging_dir}/install/bin/pip" install \
"${pants_requirement}" && \
ln -s "${staging_dir}/install" "${staging_dir}/${pants_version}" && \
mv "${staging_dir}/${pants_version}" "${PANTS_BOOTSTRAP}/${pants_version}"
) 1>&2
fi
echo "${PANTS_BOOTSTRAP}/${pants_version}"
}
pants_dir=$(bootstrap_pants) && \
exec "${pants_dir}/bin/python" "${pants_dir}/bin/pants" "$@"

28
pants.ini Normal file
View File

@ -0,0 +1,28 @@
[GLOBAL]
pants_version: 1.2.1
[jvm]
options: ['-Xmx4g', '-XX:MaxMetaspaceSize=256m']
[scala-platform]
version: 2.11
[jvm-platform]
default_platform: java8
platforms: {
'java6': {'source': '6', 'target': '6', 'args': [] },
'java7': {'source': '7', 'target': '7', 'args': [] },
'java8': {'source': '8', 'target': '8', 'args': [] },
}
[compile.scalafmt]
skip: True
[compile.zinc]
jvm_options: [
'-Xss10M', '-Xms5500m', '-Xmx5500m', '-XX:MaxMetaspaceSize=512m', '-XX:+UseParallelOldGC', '-XX:ParallelGCThreads=4',
'-XX:NewSize=2000m', '-XX:NewRatio=2', '-XX:SurvivorRatio=8',
# TODO: Remove after https://github.com/pantsbuild/pants/issues/4477 is pulled in.
'-Dzinc.analysis.cache.limit=5000',
]

View File

@ -0,0 +1,7 @@
java_library(
name = "paths",
dependencies = [
"3rdparty/jvm:soc",
],
sources = rglobs("*.java"),
)