diff --git a/.travis.yml b/.travis.yml index fff3df2..06ca32c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,22 @@ language: scala -script: - - sbt ++$TRAVIS_SCALA_VERSION sourcecodeJVM/test:run sourcecodeJS/test:run + scala: - - 2.10.6 - - 2.11.8 - - 2.12.0 + - 2.11.11 + +sudo: true + jdk: - - openjdk7 - oraclejdk8 -matrix: - exclude: - - scala: 2.12.0 - jdk: openjdk7 -sudo: false + +before_install: +- sudo apt-get -qq update +- sudo apt-get install -y nodejs +- sudo sh -c "echo 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.7 main' >> /etc/apt/sources.list" +- sudo sh -c "echo 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise main' >> /etc/apt/sources.list" +- wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add - +- sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test +- sudo apt-get -qq update +- sudo apt-get install -y libgc-dev clang++-3.7 llvm-3.7 llvm-3.7-dev llvm-3.7-runtime llvm-3.7-tool libunwind7-dev + +script: + - sbt testall \ No newline at end of file diff --git a/build.sbt b/build.sbt index e82cd12..9169277 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,15 @@ +import sbtcrossproject.{crossProject, CrossType} -crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0") +lazy val testAllCommand = Command.command("testall"){state => + "project sourcecodeNative" :: "clean" :: "test:run" :: + "project sourcecodeJVM" :: "clean" :: "+test:run" :: + "project sourcecodeJS" :: "clean" :: "+test:run" :: + state +} + +commands += testAllCommand + +lazy val crossVersions = Seq("2.10.6", "2.11.11", "2.12.2") def macroDependencies(version: String) = Seq( @@ -12,42 +22,75 @@ def macroDependencies(version: String) = else Seq()) -lazy val sourcecode = crossProject.settings( - version := "0.1.3", - 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 - - +lazy val commonScalacOptions = Seq( + "-deprecation", + "-unchecked", + "-explaintypes", + "-encoding", + "UTF-8", + "-feature", + "-Xlog-reflective-calls", + "-Ywarn-dead-code", + "-Ywarn-inaccessible", + "-Ywarn-value-discard", + "-Xlint", + "-Ywarn-nullary-override", + "-Ywarn-nullary-unit", + "-Xfuture" ) -lazy val js = sourcecode.js -lazy val jvm = sourcecode.jvm +lazy val scalacOptionsExt = Seq( + "-Ywarn-infer-any", + "-Ywarn-unused" + ) + +def scalacCompileOptions(version: String) = if(version.startsWith("2.10")) commonScalacOptions + else scalacOptionsExt ++ commonScalacOptions + +lazy val sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) + .settings( + version := "0.1.4-SNAPSHOT", + scalaVersion := "2.11.11", + name := "sourcecode", + organization := "com.lihaoyi", + commands += testAllCommand, + libraryDependencies ++= macroDependencies(scalaVersion.value), + scalacOptions ++= scalacCompileOptions(scalaVersion.value), + incOptions := incOptions.value.withLogRecompileOnMacro(false), + 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 + + + ) + +lazy val js = sourcecode.js.settings( + crossScalaVersions := crossVersions + ) +lazy val jvm = sourcecode.jvm.settings( + crossScalaVersions := crossVersions + ) +lazy val native = sourcecode.native 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 bfdab78..91f8ede 100644 --- a/project/build.sbt +++ b/project/build.sbt @@ -1 +1,7 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.15") + +addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.1.0") + +addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.1.0") + +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.2.1") \ No newline at end of file diff --git a/sourcecode/native/src/test/scala/sourcecode/Main.scala b/sourcecode/native/src/test/scala/sourcecode/Main.scala new file mode 100644 index 0000000..dea5d2b --- /dev/null +++ b/sourcecode/native/src/test/scala/sourcecode/Main.scala @@ -0,0 +1,8 @@ +package sourcecode +object Main{ + def main(args: Array[String]): Unit = { + Tests.run() + } +} + + diff --git a/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala b/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala index 31ba2e0..6dcbbbe 100644 --- a/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala +++ b/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala @@ -22,4 +22,8 @@ object Compat{ com.asMethod.paramss } } + def posExtractor(c: Context)(pos: c.universe.Position): Int = pos match { + case c.universe.NoPosition ⇒ Int.MaxValue + case p ⇒ p.startOrPoint + } } \ No newline at end of file diff --git a/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala b/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala index b3c08e4..a44cbc9 100644 --- a/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala +++ b/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala @@ -12,4 +12,8 @@ object Compat{ nearestEnclosingMethod(enclosingOwner(c)).asMethod.paramLists } + def posExtractor(c: Context)(pos: c.universe.Position): Int = pos match { + case c.universe.NoPosition ⇒ Int.MaxValue + case p ⇒ p.start + } } \ No newline at end of file diff --git a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala index 66d67f7..7cb6c81 100644 --- a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala +++ b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala @@ -1,14 +1,14 @@ package sourcecode import language.experimental.macros - +import language.{existentials, implicitConversions} object Util{ def isSynthetic(c: Compat.Context)(s: c.Symbol) = isSyntheticName(getName(c)(s)) def isSyntheticName(name: String) = { name == "" || (name.startsWith("")) } - def getName(c: Compat.Context)(s: c.Symbol) = s.name.decoded.toString.trim + def getName(c: Compat.Context)(s: c.Symbol) = s.name.decodedName.toString.trim } abstract class SourceValue[T]{ def value: T @@ -129,10 +129,7 @@ object Impls{ import c.universe._ val fileContent = new String(v.tree.pos.source.content) val start = v.tree.collect { - case treeVal => treeVal.pos match { - case NoPosition ⇒ Int.MaxValue - case p ⇒ p.startOrPoint - } + case treeVal => Compat.posExtractor(c)(treeVal.pos) }.min val g = c.asInstanceOf[reflect.macros.runtime.Context].global val parser = g.newUnitParser(fileContent.drop(start)) diff --git a/sourcecode/shared/src/test/scala/sourcecode/TextTests.scala b/sourcecode/shared/src/test/scala/sourcecode/TextTests.scala index 2500120..42b7bde 100644 --- a/sourcecode/shared/src/test/scala/sourcecode/TextTests.scala +++ b/sourcecode/shared/src/test/scala/sourcecode/TextTests.scala @@ -2,11 +2,11 @@ package sourcecode object TextTests { def apply() = { - assert(foo(1) == (1, "1")) + assert(foo(1) == ((1, "1"))) val bar = Seq("lols") - assert(foo(bar) == (Seq("lols"), "bar")) - assert(foo('lol.toString * 2) == ("'lol'lol", "'lol.toString * 2")) - assert(foo{println("Hello"); 'lol.toString * 2} == ("'lol'lol", "'lol.toString * 2")) + assert(foo(bar) == ((Seq("lols"), "bar"))) + assert(foo('lol.toString * 2) == (("'lol'lol", "'lol.toString * 2"))) + assert(foo{println("Hello"); 'lol.toString * 2} == (("'lol'lol", "'lol.toString * 2"))) } def foo[T](v: sourcecode.Text[T]) = (v.value, v.source) }