@@ -2,7 +2,7 @@ package org.scalanative.bindgen
22
33import java .io .File
44
5- import scala .collection .mutable
5+ import scala .collection .immutable
66import scala .sys .process .Process
77
88sealed trait Bindgen {
@@ -42,12 +42,12 @@ sealed trait Bindgen {
4242 /**
4343 * Additional argument to append to the compiler command line
4444 */
45- def extraArg (arg : String ): Bindgen
45+ def extraArg (args : String * ): Bindgen
4646
4747 /**
4848 * Additional argument to append to the compiler command line
4949 */
50- def extraArgBefore (arg : String ): Bindgen
50+ def extraArgBefore (args : String * ): Bindgen
5151
5252 /**
5353 * Run binding generator
@@ -58,62 +58,55 @@ sealed trait Bindgen {
5858object Bindgen {
5959 def apply (): Bindgen = Impl ()
6060
61- private final case class Impl () extends Bindgen {
62- private var executable : File = _
63- private var library : String = _
64- private var header : File = _
65- private var scalaObjectName : String = _
66- private var packageName : String = _
67- private var excludePrefix : String = _
68- private val extraArg : mutable.Seq [String ] = mutable.Seq ()
69- private val extraArgBefore : mutable.Seq [String ] = mutable.Seq ()
61+ private final case class Impl (
62+ executable : File = null ,
63+ library : String = null ,
64+ header : File = null ,
65+ scalaObjectName : String = null ,
66+ packageName : String = null ,
67+ excludePrefix : String = null ,
68+ extraArg : immutable.Seq [String ] = immutable.Seq [String ](),
69+ extraArgBefore : immutable.Seq [String ] = immutable.Seq [String ]())
70+ extends Bindgen {
7071
7172 def bindgenExecutable (executable : File ): Bindgen = {
7273 require(executable.exists())
73- this .executable = executable
74- this
74+ copy(executable = executable)
7575 }
7676
7777 def header (header : File ): Bindgen = {
7878 require(header.exists())
79- this .header = header
80- this
79+ copy(header = header)
8180 }
8281
8382 def link (library : String ): Bindgen = {
8483 require(! library.isEmpty)
85- this .library = library
86- this
84+ copy(library = library)
8785 }
8886
8987 def scalaObjectName (scalaObjectName : String ): Bindgen = {
9088 require(! scalaObjectName.isEmpty)
91- this .scalaObjectName = scalaObjectName
92- this
89+ copy(scalaObjectName = scalaObjectName)
9390 }
9491
9592 def packageName (packageName : String ): Bindgen = {
9693 require(! packageName.isEmpty)
97- this .packageName = packageName
98- this
94+ copy(packageName = packageName)
9995 }
10096
10197 def excludePrefix (prefix : String ): Bindgen = {
10298 require(! prefix.isEmpty)
103- excludePrefix = prefix
104- this
99+ copy(excludePrefix = prefix)
105100 }
106101
107- def extraArg (arg : String ): Bindgen = {
108- require(! arg.isEmpty)
109- extraArg :+ arg
110- this
102+ def extraArg (args : String * ): Bindgen = {
103+ require(args.forall(_.nonEmpty))
104+ copy(extraArg = extraArg ++ args)
111105 }
112106
113- def extraArgBefore (arg : String ): Bindgen = {
114- require(! arg.isEmpty)
115- extraArgBefore :+ arg
116- this
107+ def extraArgBefore (args : String * ): Bindgen = {
108+ require(args.forall(_.nonEmpty))
109+ copy(extraArgBefore = extraArgBefore ++ args)
117110 }
118111
119112 private def validateFields (): Unit = {
@@ -131,9 +124,12 @@ object Bindgen {
131124 def generate (): Bindings = {
132125 validateFields()
133126
134- if (scalaObjectName == null ) {
135- scalaObjectName = library
136- }
127+ val scalaObjectName =
128+ if (this .scalaObjectName != null )
129+ this .scalaObjectName
130+ else
131+ library
132+
137133 var cmd = Seq (
138134 executable.getAbsolutePath,
139135 header.getAbsolutePath,
@@ -151,8 +147,8 @@ object Bindgen {
151147 cmd ++= Seq (" --exclude-prefix" , excludePrefix)
152148 }
153149
154- for (arg <- extraArg) cmd ++= Seq (" --extra-arg" , arg)
155- for (arg <- extraArgBefore) cmd ++= Seq (" --extra-arg-before" , arg)
150+ extraArg.foreach (arg => cmd ++= Seq (" --extra-arg" , arg) )
151+ extraArgBefore.foreach (arg => cmd ++= Seq (" --extra-arg-before" , arg) )
156152
157153 cmd :+= " --"
158154
0 commit comments