• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dart-lang / ffigen / 5305585135

18 Jun 2023 08:33PM CUT coverage: 85.041% (-6.8%) from 91.879%
5305585135

Pull #586

github

web-flow
Merge 27e2ea8df into 9030eb512
Pull Request #586: Add ffigen schema and refer them in example config yaml using modeline

603 of 603 new or added lines in 3 files covered. (100.0%)

3462 of 4071 relevant lines covered (85.04%)

25.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/lib/src/strings.dart
1
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4
import 'dart:io';
5

6
import 'package:ffigen/src/code_generator.dart';
7
import 'package:ffigen/src/header_parser/clang_bindings/clang_bindings.dart'
8
    as clang;
9

10
/// Name of the dynamic library file according to current platform.
11
String get dylibFileName {
50✔
12
  String name;
13
  if (Platform.isLinux) {
50✔
14
    name = libclang_dylib_linux;
15
  } else if (Platform.isMacOS) {
50✔
16
    name = libclang_dylib_macos;
17
  } else if (Platform.isWindows) {
×
18
    name = libclang_dylib_windows;
19
  } else {
20
    throw Exception('Unsupported Platform.');
×
21
  }
22
  return name;
23
}
24

25
const llvmPath = 'llvm-path';
26

27
/// Name of the parent folder of dynamic library `lib` or `bin` (on windows).
28
String get dynamicLibParentName => Platform.isWindows ? 'bin' : 'lib';
×
29

30
const output = 'output';
31

32
// Sub-keys of output.
33
const bindings = "bindings";
34
const symbolFile = 'symbol-file';
35

36
const language = 'language';
37

38
// String mappings for the Language enum.
39
const langC = 'c';
40
const langObjC = 'objc';
41

42
// Clang command line args for Objective C.
43
const clangLangObjC = ['-x', 'objective-c'];
44
const clangObjCBoolDefine = '__OBJC_BOOL_IS_BOOL';
45
const clangInclude = '-include';
46

47
// Special objective C types.
48
const objcBOOL = 'BOOL';
49
const objcInstanceType = 'instancetype';
50

51
const headers = 'headers';
52

53
// Sub-fields of headers
54
const entryPoints = 'entry-points';
55
const includeDirectives = 'include-directives';
56

57
const compilerOpts = 'compiler-opts';
58

59
const compilerOptsAuto = 'compiler-opts-automatic';
60
// Sub-fields of compilerOptsAuto.
61
const macos = 'macos';
62
// Sub-fields of macos.
63
const includeCStdLib = 'include-c-standard-library';
64

65
// Declarations.
66
const functions = 'functions';
67
const structs = 'structs';
68
const unions = 'unions';
69
const enums = 'enums';
70
const unnamedEnums = 'unnamed-enums';
71
const globals = 'globals';
72
const macros = 'macros';
73
const typedefs = 'typedefs';
74
const objcInterfaces = 'objc-interfaces';
75

76
const excludeAllByDefault = 'exclude-all-by-default';
77

78
// Sub-fields of Declarations.
79
const include = 'include';
80
const exclude = 'exclude';
81
const rename = 'rename';
82
const memberRename = 'member-rename';
83
const symbolAddress = 'symbol-address';
84

85
// Nested under `functions`
86
const exposeFunctionTypedefs = 'expose-typedefs';
87
const leafFunctions = 'leaf';
88
const varArgFunctions = 'variadic-arguments';
89

90
// Nested under varArg entries
91
const postfix = "postfix";
92
const types = "types";
93

94
// Sub-fields of ObjC interfaces.
95
const objcModule = 'module';
96

97
const dependencyOnly = 'dependency-only';
98
// Values for `compoundDependencies`.
99
const fullCompoundDependencies = 'full';
100
const opaqueCompoundDependencies = 'opaque';
101

102
const structPack = 'pack';
103
const Map<Object, int?> packingValuesMap = {
104
  'none': null,
105
  1: 1,
106
  2: 2,
107
  4: 4,
108
  8: 8,
109
  16: 16,
110
};
111

112
// Sizemap values.
113
const SChar = 'char';
114
const UChar = 'unsigned char';
115
const Short = 'short';
116
const UShort = 'unsigned short';
117
const Int = 'int';
118
const UInt = 'unsigned int';
119
const Long = 'long';
120
const ULong = 'unsigned long';
121
const LongLong = 'long long';
122
const ULongLong = 'unsigned long long';
123
const Enum = 'enum';
124

125
// Used for validation and extraction of sizemap.
126
const sizemap_native_mapping = <String, int>{
127
  SChar: clang.CXTypeKind.CXType_SChar,
128
  UChar: clang.CXTypeKind.CXType_UChar,
129
  Short: clang.CXTypeKind.CXType_Short,
130
  UShort: clang.CXTypeKind.CXType_UShort,
131
  Int: clang.CXTypeKind.CXType_Int,
132
  UInt: clang.CXTypeKind.CXType_UInt,
133
  Long: clang.CXTypeKind.CXType_Long,
134
  ULong: clang.CXTypeKind.CXType_ULong,
135
  LongLong: clang.CXTypeKind.CXType_LongLong,
136
  ULongLong: clang.CXTypeKind.CXType_ULongLong,
137
  Enum: clang.CXTypeKind.CXType_Enum
138
};
139

140
// Library imports.
141
const libraryImports = 'library-imports';
142

143
// Sub Keys of symbol file.
144
const symbols = 'symbols';
145

146
// Symbol file yaml.
147
const formatVersion = "format_version";
148

149
/// Current symbol file format version.
150
///
151
/// This is generated when generating any symbol file. When importing any other
152
/// symbol file, this version is compared according to `semantic` versioning
153
/// to determine compatibility.
154
const symbolFileFormatVersion = "1.0.0";
155
const files = "files";
156
const usedConfig = "used-config";
157

158
const import = 'import';
159
const defaultSymbolFileImportPrefix = 'imp';
160

161
// Sub keys of import.
162
const symbolFilesImport = 'symbol-files';
163
// Sub-Sub keys of symbolFilesImport.
164
const importPath = 'import-path';
165

166
final predefinedLibraryImports = {
9✔
167
  ffiImport.name: ffiImport,
9✔
168
  ffiPkgImport.name: ffiPkgImport
9✔
169
};
170

171
const typeMap = 'type-map';
172

173
// Sub-fields for type-map.
174
const typeMapTypedefs = 'typedefs';
175
const typeMapStructs = 'structs';
176
const typeMapUnions = 'unions';
177
const typeMapNativeTypes = 'native-types';
178

179
// Sub-sub-keys for fields under typeMap.
180
const lib = 'lib';
181
const cType = 'c-type';
182
const dartType = 'dart-type';
183

184
const supportedNativeType_mappings = <String, SupportedNativeType>{
185
  'Void': SupportedNativeType.Void,
186
  'Uint8': SupportedNativeType.Uint8,
187
  'Uint16': SupportedNativeType.Uint16,
188
  'Uint32': SupportedNativeType.Uint32,
189
  'Uint64': SupportedNativeType.Uint64,
190
  'Int8': SupportedNativeType.Int8,
191
  'Int16': SupportedNativeType.Int16,
192
  'Int32': SupportedNativeType.Int32,
193
  'Int64': SupportedNativeType.Int64,
194
  'IntPtr': SupportedNativeType.IntPtr,
195
  'Float': SupportedNativeType.Float,
196
  'Double': SupportedNativeType.Double,
197
};
198

199
// Boolean flags.
200
const sort = 'sort';
201
const useSupportedTypedefs = 'use-supported-typedefs';
202
const useDartHandle = 'use-dart-handle';
203

204
const comments = 'comments';
205
// Sub-fields of comments.
206
const style = 'style';
207
const length = 'length';
208

209
// Sub-fields of style.
210
const doxygen = 'doxygen';
211
const any = 'any';
212
// Sub-fields of length.
213
const brief = 'brief';
214
const full = 'full';
215
// Cmd line comment option.
216
const fparseAllComments = '-fparse-all-comments';
217

218
// Library input.
219
const name = 'name';
220
const description = 'description';
221
const preamble = 'preamble';
222

223
// Dynamic library names.
224
const libclang_dylib_linux = 'libclang.so';
225
const libclang_dylib_macos = 'libclang.dylib';
226
const libclang_dylib_windows = 'libclang.dll';
227

228
// Dynamic library default locations.
229
const linuxDylibLocations = {
230
  '/usr/lib/llvm-9/lib/',
231
  '/usr/lib/llvm-10/lib/',
232
  '/usr/lib/llvm-11/lib/',
233
  '/usr/lib/llvm-12/lib/',
234
  '/usr/lib/llvm-13/lib/',
235
  '/usr/lib/llvm-14/lib/',
236
  '/usr/lib/llvm-15/lib/',
237
  '/usr/lib/',
238
  '/usr/lib64/',
239
};
240
const windowsDylibLocations = {
241
  r'C:\Program Files\LLVM\bin\',
242
};
243
const macOsDylibLocations = {
244
  // Default Xcode commandline tools installation.
245
  '/Library/Developer/CommandLineTools/usr/',
246
  // Default path for LLVM installed with apt-get.
247
  '/usr/local/opt/llvm/lib/',
248
  // Default path for LLVM installed with brew.
249
  '/opt/homebrew/opt/llvm/lib/',
250
  // Default Xcode installation.
251
  // Last because it does not include ObjectiveC headers by default.
252
  // See https://github.com/dart-lang/ffigen/pull/402#issuecomment-1154348670.
253
  '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/',
254
};
255
const xcodeDylibLocation = 'Toolchains/XcodeDefault.xctoolchain/usr/lib/';
256

257
// Writen doubles.
258
const doubleInfinity = 'double.infinity';
259
const doubleNegativeInfinity = 'double.negativeInfinity';
260
const doubleNaN = 'double.nan';
261

262
/// USR for struct `_Dart_Handle`.
263
const dartHandleUsr = 'c:@S@_Dart_Handle';
264

265
const ffiNative = 'ffi-native';
266
const ffiNativeAsset = 'asset';
267

268
Directory? _tmpDir;
269

270
/// A path to a unique temporary directory that should be used for files meant
271
/// to be discarded after the current execution is finished.
272
String get tmpDir {
26✔
273
  if (Platform.environment.containsKey('TEST_TMPDIR')) {
52✔
274
    return Platform.environment['TEST_TMPDIR']!;
×
275
  }
276

277
  _tmpDir ??= Directory.systemTemp.createTempSync();
52✔
278
  return _tmpDir!.path;
26✔
279
}
280

281
const ffigenJsonSchemaIndent = '    ';
282
const ffigenJsonSchemaId = "https://json.schemastore.org/ffigen";
283
const ffigenJsonSchemaFileName = "ffigen.schema.json";
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc