Skip to content

Commit

Permalink
Add scopes to the tasks defined by the sbt plugin (scala-native#714)
Browse files Browse the repository at this point in the history
* Scope Scala Native's tasks to `Compile` and `Test`

* Report native lib compilation failures

* Adapt scripted tests to scoping changes

* Remove unused imports

Fixes scala-native#692
  • Loading branch information
Duhemm authored and muxanick committed May 25, 2017
1 parent baf5568 commit 7e0d37a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
@@ -1,8 +1,6 @@
package scala.scalanative
package sbtplugin

import util._

import sbtcrossproject.CrossPlugin.autoImport._
import ScalaNativePlugin.autoImport._

Expand All @@ -12,13 +10,11 @@ import scalanative.io.VirtualDirectory
import scalanative.util.{Scope => ResourceScope}

import sbt._, Keys._, complete.DefaultParsers._
import xsbti.{Maybe, Reporter, Position, Severity, Problem}
import KeyRanks.DTask

import scala.util.Try

import System.{lineSeparator => nl}
import java.io.File
import java.io.ByteArrayInputStream

object ScalaNativePluginInternal {

Expand Down Expand Up @@ -96,22 +92,27 @@ object ScalaNativePluginInternal {
}

lazy val projectSettings =
unscopedSettings ++
inConfig(Compile)(externalDependenciesTask(compile)) ++
inConfig(Test)(externalDependenciesTask(compile in Test)) ++
inConfig(Compile)(availableDependenciesTask(compile)) ++
inConfig(Test)(availableDependenciesTask(compile in Test)) ++
inConfig(Compile)(nativeMissingDependenciesTask) ++
inConfig(Test)(nativeMissingDependenciesTask)

lazy val unscopedSettings = Seq(
dependencies ++
inConfig(Compile)(scalaNativeSettings) ++
inConfig(Test)(scalaNativeSettings)

lazy val scalaNativeSettings =
scopedSettings ++
externalDependenciesTask(compile) ++
availableDependenciesTask(compile) ++
nativeMissingDependenciesTask

lazy val dependencies = Seq(
libraryDependencies ++= Seq(
"org.scala-native" %%% "nativelib" % nativeVersion,
"org.scala-native" %%% "javalib" % nativeVersion,
"org.scala-native" %%% "scalalib" % nativeVersion
),
addCompilerPlugin(
"org.scala-native" % "nscplugin" % nativeVersion cross CrossVersion.full),
"org.scala-native" % "nscplugin" % nativeVersion cross CrossVersion.full)
)

lazy val scopedSettings = Seq(
nativeWarnOldJVM := {
val logger = nativeLogger.value
Try(Class.forName("java.util.function.Function")).toOption match {
Expand Down Expand Up @@ -184,13 +185,13 @@ object ScalaNativePluginInternal {
},
nativeMode := "debug",
artifactPath in nativeLink := {
(crossTarget in Compile).value / (moduleName.value + "-out")
crossTarget.value / (moduleName.value + "-out")
},
nativeLinkerReporter := tools.LinkerReporter.empty,
nativeOptimizerReporter := tools.OptimizerReporter.empty,
nativeOptimizerDriver := tools.OptimizerDriver(nativeConfig.value),
nativeWorkdir := {
val workdir = (Keys.crossTarget in Compile).value / "native"
val workdir = crossTarget.value / "native"
IO.delete(workdir)
IO.createDirectory(workdir)
workdir
Expand Down Expand Up @@ -245,18 +246,18 @@ object ScalaNativePluginInternal {
logger.running(compilec)
val result = Process(compilec, cwd) ! logger
if (result != 0) {
println("Failed to compile native library runtime code.")
sys.error("Failed to compile native library runtime code.")
}
}
}

lib
},
nativeConfig := {
val mainClass = (selectMainClass in Compile).value.getOrElse(
val mainClass = selectMainClass.value.getOrElse(
throw new MessageOnlyException("No main class detected.")
)
val classpath = (fullClasspath in Compile).value.map(_.data)
val classpath = fullClasspath.value.map(_.data)
val entry = nir.Global.Top(mainClass.toString + "$")
val cwd = nativeWorkdir.value

Expand Down Expand Up @@ -375,7 +376,7 @@ object ScalaNativePluginInternal {
nativeWarnOldJVM.value
// We explicitly mention all of the steps in the pipeline
// although only the last one is strictly necessary.
(compile in Compile).value
compile.value
nativeLinkNIR.value
nativeOptimizeNIR.value
nativeGenerateLL.value
Expand Down
2 changes: 1 addition & 1 deletion scripted-tests/run/execution-context/build.sbt
Expand Up @@ -5,7 +5,7 @@ scalaVersion := "2.11.11"
lazy val runAndCheck = taskKey[Unit]("...")

runAndCheck := {
val bin = nativeLink.value
val bin = (nativeLink in Compile).value
val out = Process(bin.getAbsolutePath).lines_!.toList
assert(
out == List(
Expand Down
3 changes: 2 additions & 1 deletion scripted-tests/run/linker-reporter/build.sbt
Expand Up @@ -5,7 +5,8 @@ enablePlugins(ScalaNativePlugin)

scalaVersion := "2.11.11"

nativeLinkerReporter := LinkerReporter.toFile(target.value / "out.dot")
nativeLinkerReporter in Compile := LinkerReporter.toFile(
target.value / "out.dot")

lazy val check = taskKey[Unit]("Check that dot file was created.")

Expand Down
3 changes: 2 additions & 1 deletion scripted-tests/run/optimizer-reporter/build.sbt
Expand Up @@ -5,7 +5,8 @@ enablePlugins(ScalaNativePlugin)

scalaVersion := "2.11.11"

nativeOptimizerReporter := OptimizerReporter.toDirectory(crossTarget.value)
nativeOptimizerReporter in Compile := OptimizerReporter.toDirectory(
crossTarget.value)

lazy val check = taskKey[Unit]("Check that dot file was created.")

Expand Down

0 comments on commit 7e0d37a

Please sign in to comment.