Skip to content

Commit

Permalink
Make compiling decisions internal (#2942)
Browse files Browse the repository at this point in the history
* Make compiling decisions internal

* Revert removed convenience method

* Rename and docs

* Do not remove ll, just pass to compiler if out of date

* Add warning in docs to clean after changing settings
  • Loading branch information
ekrich committed Oct 29, 2022
1 parent b9c3d94 commit 7df0d71
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 370 deletions.
3 changes: 3 additions & 0 deletions docs/user/sbt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ Sbt settings and tasks
Use ``nativeConfig`` in `sbt` to provide settings. This is often
done in a project's `build.sbt`.

**Warning**: If you change settings you should clean your project to remove generated
code to be safe.

Scala Native starts execution with a NativeConfig object, called nativeConfig,
filled with default values::

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -136,70 +136,10 @@ object ScalaNativePluginInternal {
.withTestConfig(testConfig)
.withCompilerConfig(nativeConfig.value)

val outfile = config.artifactPath.toFile()

def buildNew(): Unit = {
interceptBuildException {
Build.build(config)(sharedScope)
}
}

def buildIfChanged(): Unit = {
import sbt.util.CacheImplicits._
import NativeLinkCacheImplicits._
import collection.JavaConverters._

// Products of compilation for Scala 2 are always defined in `target/scala-<scalaBinaryVersion` directory,
// but in case of Scala 3 there is always a dedicated directory for each (minor) Scala version.
// This allows us to cache binaries for each Scala version instead of each binary Scala version.
val scalaVersionDir =
if (scalaVersion.value.startsWith("2.")) scalaBinaryVersion.value
else scalaVersion.value
val cacheFactory =
streams.value.cacheStoreFactory / "fileInfo" / s"scala-${scalaVersionDir}"
val classpathTracker =
Tracked.inputChanged[
(Seq[HashFileInfo], build.Config),
HashFileInfo
](
cacheFactory.make("inputFileInfo")
) {
case (
changed: Boolean,
(filesInfo: Seq[HashFileInfo], config: build.Config)
) =>
val outputTracker =
Tracked
.lastOutput[Seq[HashFileInfo], HashFileInfo](
cacheFactory.make("outputFileInfo")
) { (_, prev) =>
val outputHashInfo = FileInfo.hash(outfile)
if (changed || !prev.contains(outputHashInfo)) {
buildNew()
FileInfo.hash(outfile)
} else outputHashInfo
}
outputTracker(filesInfo)
}

val classpathFilesInfo = config.classPath
.flatMap { classpath =>
if (Files.exists(classpath))
Files
.walk(classpath)
.iterator()
.asScala
.filter(path => Files.exists(path) && !Files.isDirectory(path))
.toList
else Nil
}
.map(path => FileInfo.hash(path.toFile()))

classpathTracker(classpathFilesInfo, config)
interceptBuildException {
// returns config.artifactPath
Build.build(config)(sharedScope).toFile()
}

buildIfChanged()
outfile
},
run := {
val env = (run / envVars).value.toSeq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ case class PartestTask(taskDef: TaskDef, args: Array[String]) extends Task {
resolvedVals = mutable.Map.empty
)

Build.findAndCompileNativeSources(config, linkerResult)
Build.findAndCompileNativeLibs(config, linkerResult)
}
}

0 comments on commit 7df0d71

Please sign in to comment.