@@ -53,7 +53,9 @@ object ScalaNativeBindgenPlugin extends AutoPlugin {
5353 val NativeBinding = BindingOptions
5454 val ScalaNativeBindgen = config(" scala-native-bindgen" ).hide
5555 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" )
5759 val nativeBindings =
5860 settingKey[Seq [NativeBinding ]](" Configuration for each bindings" )
5961 val nativeBindgen = taskKey[Seq [File ]](" Generate Scala Native bindings" )
@@ -69,40 +71,52 @@ object ScalaNativeBindgenPlugin extends AutoPlugin {
6971 Def .settings(
7072 ivyConfigurations += ScalaNativeBindgen ,
7173 version in nativeBindgen := BuildInfo .version,
74+ nativeBindgenPath := None ,
7275 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"
7781
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+ }
8087 },
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 }
8591 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
9495
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+ }
103106
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
106120 )
107121
108122 private val artifactName =
@@ -115,10 +129,19 @@ object ScalaNativeBindgenPlugin extends AutoPlugin {
115129 inConfig(conf)(
116130 Def .settings(
117131 nativeBindings := Seq .empty,
118- sourceGenerators += Def .task { nativeBindgen.value },
119132 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+ },
120143 nativeBindgen := {
121- val bindgen = Bindgen (nativeBindgenPath .value)
144+ val bindgen = Bindgen (nativeBindgenResolvedPath .value)
122145 val optionsList = nativeBindings.value
123146 val outputDirectory = (target in nativeBindgen).value
124147 val logger = streams.value.log
0 commit comments