From cb78258ee769a545bf014f2f60c52fb2e9d6e808 Mon Sep 17 00:00:00 2001 From: Harshad Deo Date: Mon, 1 May 2017 11:47:56 +0530 Subject: [PATCH 1/5] basic builds working --- build.sbt | 76 ++++++++++--------- project/build.sbt | 8 +- .../src/test/scala/sourcecode/Main.scala | 8 ++ 3 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 sourcecode/native/src/test/scala/sourcecode/Main.scala diff --git a/build.sbt b/build.sbt index e82cd12..390d97e 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,6 @@ +import sbtcrossproject.{crossProject, CrossType} -crossScalaVersions := Seq("2.10.6", "2.11.8", "2.12.0") +crossScalaVersions := Seq("2.10.6", "2.11.11", "2.12.0") def macroDependencies(version: String) = Seq( @@ -12,42 +13,43 @@ 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 sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) + .settings( + version := "0.1.4-SNAPSHOT", + scalaVersion := "2.11.11", + 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 js = sourcecode.js lazy val jvm = sourcecode.jvm +lazy val native = sourcecode.native 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() + } +} + + From f69d7c75711e836b0155e653570e76550feb8f46 Mon Sep 17 00:00:00 2001 From: Harshad Deo Date: Mon, 1 May 2017 11:59:52 +0530 Subject: [PATCH 2/5] add testall command for cross testing --- build.sbt | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 390d97e..151075e 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,15 @@ import sbtcrossproject.{crossProject, CrossType} -crossScalaVersions := Seq("2.10.6", "2.11.11", "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.0") def macroDependencies(version: String) = Seq( @@ -17,8 +26,9 @@ lazy val sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) .settings( version := "0.1.4-SNAPSHOT", scalaVersion := "2.11.11", - name := "sourcecode" , + name := "sourcecode", organization := "com.lihaoyi", + commands += testAllCommand, libraryDependencies ++= macroDependencies(scalaVersion.value), unmanagedSourceDirectories in Compile ++= { CrossVersion.partialVersion(scalaVersion.value) match { @@ -50,6 +60,10 @@ lazy val sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) ) -lazy val js = sourcecode.js -lazy val jvm = sourcecode.jvm +lazy val js = sourcecode.js.settings( + crossScalaVersions := crossVersions + ) +lazy val jvm = sourcecode.jvm.settings( + crossScalaVersions := crossVersions + ) lazy val native = sourcecode.native From e04ebfa8c4825aa791b13d0a06d4314342ed67e6 Mon Sep 17 00:00:00 2001 From: Harshad Deo Date: Mon, 1 May 2017 12:48:27 +0530 Subject: [PATCH 3/5] add scalac options, fix feature and deprecation warnings in lib --- build.sbt | 29 ++++++++++++++++++- .../main/scala-2.10/sourcecode/Compat.scala | 4 +++ .../main/scala-2.11/sourcecode/Compat.scala | 4 +++ .../main/scala/sourcecode/SourceContext.scala | 9 ++---- .../src/test/scala/sourcecode/TextTests.scala | 8 ++--- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/build.sbt b/build.sbt index 151075e..9169277 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,7 @@ lazy val testAllCommand = Command.command("testall"){state => commands += testAllCommand -lazy val crossVersions = Seq("2.10.6", "2.11.11", "2.12.0") +lazy val crossVersions = Seq("2.10.6", "2.11.11", "2.12.2") def macroDependencies(version: String) = Seq( @@ -22,6 +22,31 @@ def macroDependencies(version: String) = else Seq()) +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 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", @@ -30,6 +55,8 @@ lazy val sourcecode = crossProject(JSPlatform, JVMPlatform, NativePlatform) 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 => 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) } From 6b0cddf8e73fc81fcfd56341d3433e49f32d7aee Mon Sep 17 00:00:00 2001 From: Harshad Deo Date: Mon, 1 May 2017 12:53:16 +0530 Subject: [PATCH 4/5] update travis script --- .travis.yml | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) 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 From 11b4bf49e431d5e12ad1944824e33f9897cb20f8 Mon Sep 17 00:00:00 2001 From: Harshad Deo Date: Mon, 1 May 2017 13:00:35 +0530 Subject: [PATCH 5/5] sbt version bump --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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