Skip to content

Support for scalanative #29

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

Closed
wants to merge 5 commits into from
Closed
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
29 changes: 18 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- 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
119 changes: 81 additions & 38 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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 =>
Copy link
Contributor

@MasseGuillaume MasseGuillaume May 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also do

.nativeSetting(
  crossScalaVersions --= Seq("2.10.6", "2.12.2")
)

"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(
Expand All @@ -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 :=
<url>https://github.com/lihaoyi/sourcecode</url>
<licenses>
<license>
<name>MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<scm>
<url>git://github.com/lihaoyi/sourcecode.git</url>
<connection>scm:git://github.com/lihaoyi/sourcecode.git</connection>
</scm>
<developers>
<developer>
<id>lihaoyi</id>
<name>Li Haoyi</name>
<url>https://github.com/lihaoyi</url>
</developer>
</developers>
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 :=
<url>https://github.com/lihaoyi/sourcecode</url>
<licenses>
<license>
<name>MIT license</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>
</licenses>
<scm>
<url>git://github.com/lihaoyi/sourcecode.git</url>
<connection>scm:git://github.com/lihaoyi/sourcecode.git</connection>
</scm>
<developers>
<developer>
<id>lihaoyi</id>
<name>Li Haoyi</name>
<url>https://github.com/lihaoyi</url>
</developer>
</developers>
)

lazy val js = sourcecode.js.settings(
crossScalaVersions := crossVersions
)
lazy val jvm = sourcecode.jvm.settings(
crossScalaVersions := crossVersions
)
lazy val native = sourcecode.native
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=0.13.15
8 changes: 7 additions & 1 deletion project/build.sbt
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions sourcecode/native/src/test/scala/sourcecode/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package sourcecode
object Main{
def main(args: Array[String]): Unit = {
Tests.run()
}
}


4 changes: 4 additions & 0 deletions sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 4 additions & 0 deletions sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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 == "<init>" || (name.startsWith("<local ") && name.endsWith(">"))
}
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
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions sourcecode/shared/src/test/scala/sourcecode/TextTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}