Skip to content

Commit 0b01246

Browse files
committed
Support custom target folder for generated code
1 parent 942598b commit 0b01246

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

sbt-scala-native-bindgen/src/main/scala/org/scalanative/bindgen/sbt/ScalaNativeBindgenPlugin.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@ import org.scalanative.bindgen.Bindgen
3030
*
3131
* - `nativeBindgenPath`: Path to the `scala-native-bindgen` executable.
3232
* - `nativeBindgenHeader`: The C header file to read.
33-
*
3433
* - `nativeBindgenPackage`: Package of the enclosing object.
3534
* No package by default.
36-
*
3735
* - `name in nativeBindgen`: Name of the enclosing object.
38-
*
36+
* - `target in nativeBindgen`: Output folder of the generated code.
3937
* - `version in nativeBindgen`: Version of the `scala-native-bindgen`
4038
* to use when automatically downloading the executable.
41-
*
4239
* - `nativeBindgenLink`: Name of library to be linked.
43-
*
4440
* - `nativeBindgen`: Generate Scala Native bindings.
4541
*
4642
* @example
@@ -134,8 +130,10 @@ object ScalaNativeBindgenPlugin extends AutoPlugin {
134130
nativeBindgenExclude := None,
135131
sourceGenerators += Def.task { Seq(nativeBindgen.value) },
136132
name in nativeBindgen := "ScalaNativeBindgen",
133+
target in nativeBindgen := sourceManaged.value / "sbt-scala-native-bindgen",
137134
nativeBindgen := {
138-
val output = sourceManaged.value / "sbt-scala-native-bindgen" / "ScalaNativeBindgen.scala"
135+
val fileName = (name in nativeBindgen).value + ".scala"
136+
val output = (target in nativeBindgen).value / fileName
139137

140138
Bindgen()
141139
.bindgenExecutable(nativeBindgenPath.value)

sbt-scala-native-bindgen/src/sbt-test/bindgen/generate/build.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inConfig(Compile)(
1313
name in nativeBindgen := "AppAPI"
1414
))
1515

16+
val natigeBindgenCustomTarget = SettingKey[File]("natigeBindgenCustomTarget")
17+
SettingKey[File]("natigeBindgenCustomTarget") := baseDirectory.value / "src/main/scala/org/example"
18+
1619
TaskKey[Unit]("check") := {
1720
val file = (nativeBindgen in Compile).value
1821
val expected =
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
> check
2+
$ exists target/scala-2.11/src_managed/main/sbt-scala-native-bindgen/AppAPI.scala
3+
> set target in (Compile, nativeBindgen) := natigeBindgenCustomTarget.value
4+
> check
5+
$ exists src/main/scala/org/example/AppAPI.scala

0 commit comments

Comments
 (0)