@@ -53,7 +53,9 @@ object ScalaNativeBindgenPlugin extends AutoPlugin {
53
53
val NativeBinding = BindingOptions
54
54
val ScalaNativeBindgen = config(" scala-native-bindgen" ).hide
55
55
val nativeBindgenPath =
56
- taskKey[File ](" Path to the scala-native-bindgen executable" )
56
+ settingKey[Option [File ]](" Path to the scala-native-bindgen executable" )
57
+ val nativeBindgenResolvedPath =
58
+ taskKey[File ](" Resolved path to the scala-native-bindgen executable" )
57
59
val nativeBindings =
58
60
settingKey[Seq [NativeBinding ]](" Configuration for each bindings" )
59
61
val nativeBindgen = taskKey[Seq [File ]](" Generate Scala Native bindings" )
@@ -69,40 +71,52 @@ object ScalaNativeBindgenPlugin extends AutoPlugin {
69
71
Def .settings(
70
72
ivyConfigurations += ScalaNativeBindgen ,
71
73
version in nativeBindgen := BuildInfo .version,
74
+ nativeBindgenPath := None ,
72
75
libraryDependencies ++= {
73
- artifactName.map { name =>
74
- val bindgenVersion = (version in nativeBindgen).value
75
- val url =
76
- s " ${BuildInfo .projectUrl}/releases/download/v $bindgenVersion/ $name"
76
+ (nativeBindgenPath.value, artifactName) match {
77
+ case (None , Some (name)) =>
78
+ val bindgenVersion = (version in nativeBindgen).value
79
+ val url =
80
+ s " ${BuildInfo .projectUrl}/releases/download/v $bindgenVersion/ $name"
77
81
78
- BuildInfo .organization % name % bindgenVersion % ScalaNativeBindgen from (url)
79
- }.toSeq
82
+ Seq (
83
+ BuildInfo .organization % name % bindgenVersion % ScalaNativeBindgen from (url))
84
+ case _ =>
85
+ Seq .empty
86
+ }
80
87
},
81
- nativeBindgenPath := {
82
- val scalaNativeBindgenUpdate = (update in ScalaNativeBindgen ).value
83
-
84
- val artifactFile = artifactName match {
88
+ nativeBindgenResolvedPath := Def .taskDyn {
89
+ nativeBindgenPath.value match {
90
+ case Some (path) => Def .task { path }
85
91
case None =>
86
- sys.error(
87
- " No downloadable binaries available for your OS, " +
88
- " please provide path via `nativeBindgenPath`" )
89
- case Some (name) =>
90
- scalaNativeBindgenUpdate
91
- .select(artifact = artifactFilter(name = name))
92
- .head
93
- }
92
+ Def .task {
93
+ val scalaNativeBindgenUpdate =
94
+ (update in ScalaNativeBindgen ).value
94
95
95
- // Set the executable bit on the expected path to fail if it doesn't exist
96
- for (view <- Option (
97
- Files .getFileAttributeView(artifactFile.toPath,
98
- classOf [PosixFileAttributeView ]))) {
99
- val permissions = view.readAttributes.permissions
100
- if (permissions.add(PosixFilePermission .OWNER_EXECUTE ))
101
- view.setPermissions(permissions)
102
- }
96
+ val artifactFile = artifactName match {
97
+ case None =>
98
+ sys.error(
99
+ " No downloadable binaries available for your OS, " +
100
+ " please provide path via `nativeBindgenPath`" )
101
+ case Some (name) =>
102
+ scalaNativeBindgenUpdate
103
+ .select(artifact = artifactFilter(name = name))
104
+ .head
105
+ }
103
106
104
- artifactFile
105
- }
107
+ // Set the executable bit on the expected path to fail if it doesn't exist
108
+ for (view <- Option (Files .getFileAttributeView(
109
+ artifactFile.toPath,
110
+ classOf [PosixFileAttributeView ]))) {
111
+ val permissions = view.readAttributes.permissions
112
+ if (permissions.add(PosixFilePermission .OWNER_EXECUTE ))
113
+ view.setPermissions(permissions)
114
+ }
115
+
116
+ artifactFile
117
+ }
118
+ }
119
+ }.value
106
120
)
107
121
108
122
private val artifactName =
@@ -115,10 +129,19 @@ object ScalaNativeBindgenPlugin extends AutoPlugin {
115
129
inConfig(conf)(
116
130
Def .settings(
117
131
nativeBindings := Seq .empty,
118
- sourceGenerators += Def .task { nativeBindgen.value },
119
132
target in nativeBindgen := sourceManaged.value / " sbt-scala-native-bindgen" ,
133
+ sourceGenerators += Def .taskDyn {
134
+ val nativeBindgenTarget = (target in nativeBindgen).value.toPath
135
+ val managedSource = sourceManaged.value.toPath
136
+
137
+ if (nativeBindgenTarget.startsWith(managedSource)) {
138
+ Def .task { nativeBindgen.value }
139
+ } else {
140
+ Def .task { Seq .empty[File ] }
141
+ }
142
+ },
120
143
nativeBindgen := {
121
- val bindgen = Bindgen (nativeBindgenPath .value)
144
+ val bindgen = Bindgen (nativeBindgenResolvedPath .value)
122
145
val optionsList = nativeBindings.value
123
146
val outputDirectory = (target in nativeBindgen).value
124
147
val logger = streams.value.log
0 commit comments