@@ -125,39 +125,59 @@ enum SummarizerBackend {
125
125
doclet,
126
126
}
127
127
128
+ class CCodeOutputConfig {
129
+ CCodeOutputConfig ({
130
+ required this .path,
131
+ required this .libraryName,
132
+ this .subdir,
133
+ });
134
+
135
+ /// Directory to write JNI C Bindings, in C+Dart mode.
136
+ ///
137
+ /// Strictly speaking, this is the root to place the `CMakeLists.txt` file
138
+ /// for the generated C bindings. It may be desirable to use the [subdir]
139
+ /// options to write C files to a subdirectory of [path] . For instance,
140
+ /// when generated code is required to be in `third_party` directory.
141
+ Uri path;
142
+
143
+ /// Name of generated library in CMakeLists.txt configuration.
144
+ ///
145
+ /// This will also determine the name of shared object file.
146
+ String libraryName;
147
+
148
+ /// Subfolder relative to [path] to write generated C code.
149
+ String ? subdir;
150
+ }
151
+
152
+ class DartCodeOutputConfig {
153
+ // TODO(#90): Support output_structure = single_file | package_structure.
154
+
155
+ DartCodeOutputConfig ({required this .path});
156
+
157
+ /// Path to write generated Dart bindings.
158
+ Uri path;
159
+ }
160
+
161
+ class OutputConfig {
162
+ // TODO(#60): Add bindings_type = dart_only | c_based.
163
+
164
+ OutputConfig ({required this .cConfig, required this .dartConfig});
165
+ DartCodeOutputConfig dartConfig;
166
+ CCodeOutputConfig cConfig;
167
+ }
168
+
128
169
class BindingExclusions {
129
170
BindingExclusions ({this .methods, this .fields, this .classes});
130
171
MethodFilter ? methods;
131
172
FieldFilter ? fields;
132
173
ClassFilter ? classes;
133
174
}
134
175
135
- enum BindingsType {
136
- cBased, // C+Dart bindings
137
- singleFile,
138
- packageStructured,
139
- }
140
-
141
- BindingsType getBindingsType (String ? type, BindingsType defaultType) {
142
- const names = {
143
- 'c_based' : BindingsType .cBased,
144
- 'single_file' : BindingsType .singleFile,
145
- 'package_structured' : BindingsType .packageStructured,
146
- };
147
- return names[type] ?? defaultType;
148
- }
149
-
150
176
/// Configuration for jnigen binding generation.
151
177
class Config {
152
178
Config ({
179
+ required this .outputConfig,
153
180
required this .classes,
154
- this .bindingsType = BindingsType .cBased,
155
- this .outputPath,
156
- this .libraryName,
157
- this .cRoot,
158
- this .dartRoot,
159
- this .cSubdir,
160
- this .rootPackage,
161
181
this .exclude,
162
182
this .sourcePath,
163
183
this .classPath,
@@ -168,16 +188,10 @@ class Config {
168
188
this .summarizerOptions,
169
189
this .logLevel = Level .INFO ,
170
190
this .dumpJsonTo,
171
- }) {
172
- if (bindingsType == BindingsType .cBased) {
173
- if (cRoot == null || dartRoot == null || libraryName == null ) {
174
- throw ArgumentError ("In c_based mode these values must be specified: "
175
- "c_root, dart_root, library_name" );
176
- }
177
- } else {
178
- throw UnimplementedError ("BindingsType not yet supported: $bindingsType " );
179
- }
180
- }
191
+ });
192
+
193
+ /// Output configuration for generated bindings
194
+ OutputConfig outputConfig;
181
195
182
196
/// List of classes or packages for which bindings have to be generated.
183
197
///
@@ -188,41 +202,6 @@ class Config {
188
202
/// name suffix is `.class` .
189
203
List <String > classes;
190
204
191
- /// Type of bindings to generate.
192
- final BindingsType bindingsType;
193
-
194
- /// Name of generated library in CMakeLists.txt configuration.
195
- ///
196
- /// This will also determine the name of shared object file.
197
- final String ? libraryName;
198
-
199
- /// Directory to write JNI C Bindings, in C+Dart mode.
200
- ///
201
- /// Strictly speaking, this is the root to place the `CMakeLists.txt` file
202
- /// for the generated C bindings. It may be desirable to use the [cSubdir]
203
- /// options to write C files to a subdirectory of [cRoot] . For instance,
204
- /// when generated code is required to be in `third_party` directory.
205
- Uri ? cRoot;
206
-
207
- /// Directory to write Dart bindings, in C + Dart mode.
208
- Uri ? dartRoot;
209
-
210
- /// Subfolder relative to [cRoot] to write generated C code.
211
- String ? cSubdir;
212
-
213
- /// Java package corresponding to the dart_root directory.
214
- ///
215
- /// By default, the complete java hierarchy is mirrored. For instance,
216
- /// `org.apache.pdfbox.text` becomes `org/apache/pdfbox/text.dart` .
217
- /// This is often undesirable, when all packages have a common package. In
218
- /// such cases, a super-package name can be provided. This will be assumed as
219
- /// the prefix of all packages and hierarchy will be created relative to this
220
- /// package.
221
- String ? rootPackage;
222
-
223
- /// Output file or folder in non-legacy modes
224
- Uri ? outputPath;
225
-
226
205
/// Methods and fields to be excluded from generated bindings.
227
206
final BindingExclusions ? exclude;
228
207
@@ -288,7 +267,6 @@ class Config {
288
267
return res;
289
268
}
290
269
291
- Uri ? fileUri (String ? path) => path != null ? Uri .file (path) : null ;
292
270
Uri ? directoryUri (String ? path) =>
293
271
path != null ? Uri .directory (path) : null ;
294
272
@@ -339,15 +317,17 @@ class Config {
339
317
methods: regexFilter <Method >(_Props .excludeMethods),
340
318
fields: regexFilter <Field >(_Props .excludeFields),
341
319
),
342
- bindingsType: getBindingsType (
343
- prov.getString (_Props .bindingsType), BindingsType .cBased),
344
- cRoot: directoryUri (prov.getString (_Props .cRoot)),
345
- dartRoot: directoryUri (prov.getString (_Props .dartRoot)),
346
- outputPath: fileUri (prov.getString (_Props .outputPath)),
347
- cSubdir: prov.getString (_Props .cSubdir),
348
- rootPackage: prov.getString (_Props .rootPackage),
320
+ outputConfig: OutputConfig (
321
+ cConfig: CCodeOutputConfig (
322
+ libraryName: must (prov.getString, '' , _Props .libraryName),
323
+ path: Uri .directory (must (prov.getString, '.' , _Props .cRoot)),
324
+ subdir: prov.getString (_Props .cSubdir),
325
+ ),
326
+ dartConfig: DartCodeOutputConfig (
327
+ path: Uri .directory (must (prov.getString, '.' , _Props .dartRoot)),
328
+ ),
329
+ ),
349
330
preamble: prov.getString (_Props .preamble),
350
- libraryName: must (prov.getString, '' , _Props .libraryName),
351
331
importMap: prov.getStringMap (_Props .importMap),
352
332
mavenDownloads: prov.hasValue (_Props .mavenDownloads)
353
333
? MavenDownloads (
@@ -411,14 +391,14 @@ class _Props {
411
391
static const excludeFields = '$exclude .fields' ;
412
392
413
393
static const importMap = 'import_map' ;
414
- static const outputPath = 'output_path' ;
415
- static const bindingsType = 'bindings_type' ;
416
- static const dartRoot = 'dart_root' ;
417
- static const cRoot = 'c_root' ;
418
- static const cSubdir = 'c_subdir' ;
419
- static const rootPackage = 'root_package' ;
394
+ static const outputConfig = 'output' ;
395
+ static const cCodeOutputConfig = '$outputConfig .c' ;
396
+ static const dartCodeOutputConfig = '$outputConfig .dart' ;
397
+ static const cRoot = '$cCodeOutputConfig .path' ;
398
+ static const cSubdir = '$cCodeOutputConfig .subdir' ;
399
+ static const dartRoot = '$dartCodeOutputConfig .path' ;
400
+ static const libraryName = '$cCodeOutputConfig .library_name' ;
420
401
static const preamble = 'preamble' ;
421
- static const libraryName = 'library_name' ;
422
402
static const logLevel = 'log_level' ;
423
403
424
404
static const mavenDownloads = 'maven_downloads' ;
0 commit comments