-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to pass Scala Native c interop file as an Input
This should provide simpler interop functionality, removing to rely on passing c files through resource directories. A new resource caching mechanizm was also added, to smoothen the development experience. Before, it would be easy for SN linking errors to appear - any rename or move of an interop file would cause it to be duplicated. The mappingremoves those issues, as long as users will not tamper with the newly added file (.project_native_resources) to output directory. This can be extended for use with regular JVM resources, to solve a similar issue.
- Loading branch information
1 parent
37af853
commit ef1f76a
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
modules/build/src/main/scala/scala/build/internal/resource/NativeResourceMapper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package scala.build.internal.resource | ||
|
||
import scala.build.{Build, Inputs} | ||
|
||
object NativeResourceMapper { | ||
|
||
private def scalaNativeCFileMapping(build: Build.Successful): Map[os.Path, os.RelPath] = | ||
build | ||
.inputs | ||
.flattened() | ||
.collect { | ||
case cfile: Inputs.CFile => | ||
val inputPath = cfile.path | ||
val destPath = os.rel / "scala-native" / cfile.subPath | ||
(inputPath, destPath) | ||
} | ||
.toMap | ||
|
||
private def resolveProjectCFileRegistryPath(nativeWorkDir: os.Path) = | ||
nativeWorkDir / ".native_registry" | ||
|
||
/** Copies and maps c file resources from their original path to the destination path in build | ||
* output, also caching output paths in a file. | ||
* | ||
* Remembering the mapping this way allows for the resource to be removed if the original file is | ||
* renamed/deleted. | ||
*/ | ||
def copyCFilesToScalaNativeDir(build: Build.Successful, nativeWorkDir: os.Path): Unit = { | ||
val mappingFilePath = resolveProjectCFileRegistryPath(nativeWorkDir) | ||
ResourceMapper.copyResourcesToDirWithMapping( | ||
build.output, | ||
mappingFilePath, | ||
scalaNativeCFileMapping(build) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters