Skip to content
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

Add scopes to the tasks defined by the sbt plugin #714

Merged
merged 4 commits into from May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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.")
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is a fix of #692

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I mentioned it in the commit message, but forgot to in the PR description. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that sys.error will be deprecated in 2.13: scala/scala#5677. It's better to use throw new RuntimeException instead.

}
}
}

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