From 96e0480d2aaa4a2dfa9ad7a6a0b04602473d2759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Mass=C3=A9?= Date: Sat, 6 May 2017 17:36:33 +0200 Subject: [PATCH 1/5] cross build to 2.13 --- .travis.yml | 37 +++++++++++++----- build.sbt | 83 ++++++++++++++++++++-------------------- project/build.properties | 2 +- project/build.sbt | 2 +- 4 files changed, 71 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index fff3df2..fdcca42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,32 @@ language: scala -script: - - sbt ++$TRAVIS_SCALA_VERSION sourcecodeJVM/test:run sourcecodeJS/test:run -scala: - - 2.10.6 - - 2.11.8 - - 2.12.0 + +sudo: required + +dist: trusty + jdk: - - openjdk7 - oraclejdk8 +scala: + - 2.10.6 + - 2.11.11 + - 2.12.2 + - 2.13.0-M1 matrix: - exclude: - - scala: 2.12.0 + include: + - scala: 2.10.6 jdk: openjdk7 -sudo: false + +# Taken from https://github.com/typelevel/cats/blob/master/.travis.yml +cache: + directories: + - $HOME/.sbt/0.13/dependency + - $HOME/.sbt/boot/scala* + - $HOME/.sbt/launchers + - $HOME/.ivy2/cache + - $HOME/.nvm + +before_cache: + - du -h -d 1 $HOME/.ivy2/cache + - du -h -d 2 $HOME/.sbt/ + - find $HOME/.sbt -name "*.lock" -type f -delete + - find $HOME/.ivy2/cache -name "ivydata-*.properties" -type f -delete diff --git a/build.sbt b/build.sbt index 0d7b644..1ad96c7 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,26 @@ import OsgiKeys._ -crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0") +val baseSettings = Seq( + organization := "com.lihaoyi", + name := "sourcecode", + version := "0.1.4", + scalaVersion := "2.11.11", + crossScalaVersions := Seq("2.10.6", "2.11.11", "2.12.2", "2.13.0-M1"), + scmInfo := Some(ScmInfo( + browseUrl = url("https://github.com/lihaoyi/sourcecode"), + connection = "scm:git:git@github.com:lihaoyi/sourcecode.git" + )), + homepage := Some(url("https://github.com/lihaoyi/sourcecode")), + licenses := Seq("MIT" -> url("http://www.opensource.org/licenses/mit-license.html")), + developers += Developer( + email = "haoyi.sg@gmail.com", + id = "lihaoyi", + name = "Li Haoyi", + url = url("https://github.com/lihaoyi") + ) +) + +baseSettings def macroDependencies(version: String) = Seq( @@ -13,46 +33,27 @@ def macroDependencies(version: String) = else Seq()) -lazy val sourcecode = crossProject.settings( - version := "0.1.4", - scalaVersion := "2.11.8", - name := "sourcecode" , - organization := "com.lihaoyi", - libraryDependencies ++= macroDependencies(scalaVersion.value), - unmanagedSourceDirectories in Compile ++= { - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, n)) if n >= 12 => - Seq(baseDirectory.value / ".."/"shared"/"src"/ "main" / "scala-2.11") - case _ => - Seq() - } - }, - publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"), - - pomExtra := - https://github.com/lihaoyi/sourcecode - - - MIT license - http://www.opensource.org/licenses/mit-license.php - - - - git://github.com/lihaoyi/sourcecode.git - scm:git://github.com/lihaoyi/sourcecode.git - - - - lihaoyi - Li Haoyi - https://github.com/lihaoyi - - -).enablePlugins(SbtOsgi).settings(osgiSettings).settings( - exportPackage := Seq("sourcecode.*"), - privatePackage := Seq(), - dynamicImportPackage := Seq("*") -) +lazy val sourcecode = crossProject + .settings(baseSettings) + .settings( + libraryDependencies ++= macroDependencies(scalaVersion.value), + unmanagedSourceDirectories in Compile ++= { + CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, n)) if n >= 12 => + Seq(baseDirectory.value / ".." / "shared" / "src" / "main" / "scala-2.11") + case _ => + Seq() + } + }, + publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2") + ) + .enablePlugins(SbtOsgi) + .settings( + osgiSettings, + exportPackage := Seq("sourcecode.*"), + privatePackage := Seq(), + dynamicImportPackage := Seq("*") + ) lazy val js = sourcecode.js lazy val jvm = sourcecode.jvm diff --git a/project/build.properties b/project/build.properties index 27e88aa..64317fd 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.13 +sbt.version=0.13.15 diff --git a/project/build.sbt b/project/build.sbt index 173f9d8..5148142 100644 --- a/project/build.sbt +++ b/project/build.sbt @@ -1,2 +1,2 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16") addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.8.0") From 4f2fe77b6fb304e4484305d3d26ac6bdcbccb08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Sun, 9 Jul 2017 01:06:35 +0200 Subject: [PATCH 2/5] Make `test` run tests. Previously, nothing ran on CI because the tests are not using an sbt test framework runner. --- build.sbt | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sbt b/build.sbt index 1ad96c7..de0bc28 100644 --- a/build.sbt +++ b/build.sbt @@ -37,6 +37,7 @@ lazy val sourcecode = crossProject .settings(baseSettings) .settings( libraryDependencies ++= macroDependencies(scalaVersion.value), + test in Test := (run in Test).toTask("").value, unmanagedSourceDirectories in Compile ++= { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, n)) if n >= 12 => From a65a1aa6ca3891e89229c5f92f321f52394cfda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Sun, 9 Jul 2017 01:16:42 +0200 Subject: [PATCH 3/5] Port built to Scala Native. Scala.js 0.6.18 added support for JVM-style main functions which makes it possible to use the same entry point for the tests on all platforms. --- .travis.yml | 8 +--- bin/travis_setup.sh | 42 +++++++++++++++++++ build.sbt | 18 ++++++-- project/build.sbt | 5 ++- .../js/src/test/scala/sourcecode/Main.scala | 9 ---- .../src/test/scala/sourcecode/Main.scala | 0 6 files changed, 63 insertions(+), 19 deletions(-) create mode 100755 bin/travis_setup.sh delete mode 100644 sourcecode/js/src/test/scala/sourcecode/Main.scala rename sourcecode/{jvm => shared}/src/test/scala/sourcecode/Main.scala (100%) diff --git a/.travis.yml b/.travis.yml index fdcca42..8c9f927 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ language: scala - sudo: required - dist: trusty - jdk: - oraclejdk8 scala: @@ -15,8 +12,8 @@ matrix: include: - scala: 2.10.6 jdk: openjdk7 - -# Taken from https://github.com/typelevel/cats/blob/master/.travis.yml +before_install: + - bash bin/travis_setup.sh cache: directories: - $HOME/.sbt/0.13/dependency @@ -24,7 +21,6 @@ cache: - $HOME/.sbt/launchers - $HOME/.ivy2/cache - $HOME/.nvm - before_cache: - du -h -d 1 $HOME/.ivy2/cache - du -h -d 2 $HOME/.sbt/ diff --git a/bin/travis_setup.sh b/bin/travis_setup.sh new file mode 100755 index 0000000..9aeea8d --- /dev/null +++ b/bin/travis_setup.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# Original script from https://github.com/scala-native/scala-native/blob/c4eac0707bebc08f4979a0d0eaed16427b734171/bin/travis_setup.sh + +# Enable strict mode and fail the script on non-zero exit code, +# unresolved variable or pipe failure. +set -euo pipefail +IFS=$'\n\t' + +if [ "$(uname)" == "Darwin" ]; then + + brew update + brew install sbt + brew install bdw-gc + brew link bdw-gc + brew install jq + brew install re2 + brew install llvm@4 + export PATH="/usr/local/opt/llvm@4/bin:$PATH" + +else + + # Install LLVM/Clang, Boehm GC, libunwind + sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test + sudo apt-get -qq update + sudo apt-get install -y -qq \ + clang++-3.8 \ + libgc-dev \ + libunwind8-dev + + # Install re2 + # Starting from Ubuntu 16.04 LTS, it'll be available as http://packages.ubuntu.com/xenial/libre2-dev + sudo apt-get install -y make + export CXX=clang++-3.8 + git clone https://code.googlesource.com/re2 + pushd re2 + git checkout 2017-03-01 + make -j4 test + sudo make install prefix=/usr + make testinstall prefix=/usr + popd + +fi diff --git a/build.sbt b/build.sbt index de0bc28..b789516 100644 --- a/build.sbt +++ b/build.sbt @@ -1,11 +1,16 @@ +import sbtcrossproject.{crossProject, CrossType} import OsgiKeys._ +val scala210 = "2.10.6" +val scala211 = "2.11.11" +val scala212 = "2.12.2" +val scala213 = "2.13.0-M1" val baseSettings = Seq( organization := "com.lihaoyi", name := "sourcecode", version := "0.1.4", - scalaVersion := "2.11.11", - crossScalaVersions := Seq("2.10.6", "2.11.11", "2.12.2", "2.13.0-M1"), + scalaVersion := scala211, + crossScalaVersions := Seq(scala210, scala211, scala212, scala213), scmInfo := Some(ScmInfo( browseUrl = url("https://github.com/lihaoyi/sourcecode"), connection = "scm:git:git@github.com:lihaoyi/sourcecode.git" @@ -33,7 +38,7 @@ def macroDependencies(version: String) = else Seq()) -lazy val sourcecode = crossProject +lazy val sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) .settings(baseSettings) .settings( libraryDependencies ++= macroDependencies(scalaVersion.value), @@ -55,6 +60,13 @@ lazy val sourcecode = crossProject privatePackage := Seq(), dynamicImportPackage := Seq("*") ) + .jsSettings( + scalaJSUseMainModuleInitializer in Test := true // use JVM-style main. + ) + .nativeSettings( + crossScalaVersions := Seq(scala211) + ) lazy val js = sourcecode.js lazy val jvm = sourcecode.jvm +lazy val native = sourcecode.native diff --git a/project/build.sbt b/project/build.sbt index 5148142..d373fd4 100644 --- a/project/build.sbt +++ b/project/build.sbt @@ -1,2 +1,5 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.16") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.18") addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.8.0") +addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.2.0") +addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.2.0") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.1") diff --git a/sourcecode/js/src/test/scala/sourcecode/Main.scala b/sourcecode/js/src/test/scala/sourcecode/Main.scala deleted file mode 100644 index 45dc90d..0000000 --- a/sourcecode/js/src/test/scala/sourcecode/Main.scala +++ /dev/null @@ -1,9 +0,0 @@ -package sourcecode - -object Main extends scalajs.js.JSApp{ - def main(): Unit = { - Tests.run() - } -} - - diff --git a/sourcecode/jvm/src/test/scala/sourcecode/Main.scala b/sourcecode/shared/src/test/scala/sourcecode/Main.scala similarity index 100% rename from sourcecode/jvm/src/test/scala/sourcecode/Main.scala rename to sourcecode/shared/src/test/scala/sourcecode/Main.scala From 3de215a72b78c39bc06511de416fc6274bdec456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Sun, 9 Jul 2017 01:19:35 +0200 Subject: [PATCH 4/5] Refactor build.sbt. It's important to skip publish in the root build to avoid publishing an empty package. --- build.sbt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index b789516..853afe5 100644 --- a/build.sbt +++ b/build.sbt @@ -22,10 +22,17 @@ val baseSettings = Seq( id = "lihaoyi", name = "Li Haoyi", url = url("https://github.com/lihaoyi") - ) + ), + publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2") +) +lazy val noPublish = Seq( + publishArtifact := false, + publish := {}, + publishLocal := {} ) baseSettings +noPublish def macroDependencies(version: String) = Seq( @@ -39,8 +46,8 @@ def macroDependencies(version: String) = Seq()) lazy val sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) - .settings(baseSettings) .settings( + baseSettings, libraryDependencies ++= macroDependencies(scalaVersion.value), test in Test := (run in Test).toTask("").value, unmanagedSourceDirectories in Compile ++= { @@ -51,15 +58,13 @@ lazy val sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) Seq() } }, - publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2") - ) - .enablePlugins(SbtOsgi) - .settings( + // Osgi settings osgiSettings, exportPackage := Seq("sourcecode.*"), privatePackage := Seq(), dynamicImportPackage := Seq("*") ) + .enablePlugins(SbtOsgi) .jsSettings( scalaJSUseMainModuleInitializer in Test := true // use JVM-style main. ) From fdbe6d15a893557022fdf75b1dc06101fd67746d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Sun, 9 Jul 2017 01:23:57 +0200 Subject: [PATCH 5/5] Use sbt-doge to skipping native on 2.10/2.12. Scala Native currently only support 2.11. 2.12 support is expected in the next release but not 2.10. sbt-doge is an sbt plugin that adds two helpful commands to deal with the crossScalaVersions gaps in the native project: - `pls $SCALA_VERSION test`, like `++SCALA_VERSION test` except skip tests that don't define that SCALA_VERSION in crossScalaVersions. - `very test`, runs `test` for all projects for all crossScalaVersions defined for each individual project. Same works for publishing. --- .travis.yml | 3 +++ project/build.sbt | 1 + 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8c9f927..d0623d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: scala sudo: required dist: trusty +script: + # plz is like ++ except it skips projects that are not defined for that scala version. + - sbt "plz $TRAVIS_SCALA_VERSION test" jdk: - oraclejdk8 scala: diff --git a/project/build.sbt b/project/build.sbt index d373fd4..9e7adc8 100644 --- a/project/build.sbt +++ b/project/build.sbt @@ -1,3 +1,4 @@ +addSbtPlugin("com.eed3si9n" % "sbt-doge" % "0.1.5") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.18") addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.8.0") addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.2.0")