@@ -2,7 +2,7 @@ package org.scalanative.bindgen
2
2
3
3
import java .io .File
4
4
5
- import scala .collection .mutable
5
+ import scala .collection .immutable
6
6
import scala .sys .process .Process
7
7
8
8
sealed trait Bindgen {
@@ -42,12 +42,12 @@ sealed trait Bindgen {
42
42
/**
43
43
* Additional argument to append to the compiler command line
44
44
*/
45
- def extraArg (arg : String ): Bindgen
45
+ def extraArg (args : String * ): Bindgen
46
46
47
47
/**
48
48
* Additional argument to append to the compiler command line
49
49
*/
50
- def extraArgBefore (arg : String ): Bindgen
50
+ def extraArgBefore (args : String * ): Bindgen
51
51
52
52
/**
53
53
* Run binding generator
@@ -58,62 +58,55 @@ sealed trait Bindgen {
58
58
object Bindgen {
59
59
def apply (): Bindgen = Impl ()
60
60
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 {
70
71
71
72
def bindgenExecutable (executable : File ): Bindgen = {
72
73
require(executable.exists())
73
- this .executable = executable
74
- this
74
+ copy(executable = executable)
75
75
}
76
76
77
77
def header (header : File ): Bindgen = {
78
78
require(header.exists())
79
- this .header = header
80
- this
79
+ copy(header = header)
81
80
}
82
81
83
82
def link (library : String ): Bindgen = {
84
83
require(! library.isEmpty)
85
- this .library = library
86
- this
84
+ copy(library = library)
87
85
}
88
86
89
87
def scalaObjectName (scalaObjectName : String ): Bindgen = {
90
88
require(! scalaObjectName.isEmpty)
91
- this .scalaObjectName = scalaObjectName
92
- this
89
+ copy(scalaObjectName = scalaObjectName)
93
90
}
94
91
95
92
def packageName (packageName : String ): Bindgen = {
96
93
require(! packageName.isEmpty)
97
- this .packageName = packageName
98
- this
94
+ copy(packageName = packageName)
99
95
}
100
96
101
97
def excludePrefix (prefix : String ): Bindgen = {
102
98
require(! prefix.isEmpty)
103
- excludePrefix = prefix
104
- this
99
+ copy(excludePrefix = prefix)
105
100
}
106
101
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)
111
105
}
112
106
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)
117
110
}
118
111
119
112
private def validateFields (): Unit = {
@@ -131,9 +124,12 @@ object Bindgen {
131
124
def generate (): Bindings = {
132
125
validateFields()
133
126
134
- if (scalaObjectName == null ) {
135
- scalaObjectName = library
136
- }
127
+ val scalaObjectName =
128
+ if (this .scalaObjectName != null )
129
+ this .scalaObjectName
130
+ else
131
+ library
132
+
137
133
var cmd = Seq (
138
134
executable.getAbsolutePath,
139
135
header.getAbsolutePath,
@@ -151,8 +147,8 @@ object Bindgen {
151
147
cmd ++= Seq (" --exclude-prefix" , excludePrefix)
152
148
}
153
149
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) )
156
152
157
153
cmd :+= " --"
158
154
0 commit comments