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

dart-lang / ffigen / 4428795187

pending completion
4428795187

Pull #534

github

GitHub
Merge e0c7e1bbb into 92dc22649
Pull Request #534: Detect LLVM installation using scoop

4 of 4 new or added lines in 1 file covered. (100.0%)

3190 of 3457 relevant lines covered (92.28%)

24.69 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 {
48✔
12
  String name;
13
  if (Platform.isLinux) {
48✔
14
    name = libclang_dylib_linux;
15
  } else if (Platform.isMacOS) {
48✔
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

89
// Sub-fields of ObjC interfaces.
90
const objcModule = 'module';
91

92
const dependencyOnly = 'dependency-only';
93
// Values for `compoundDependencies`.
94
const fullCompoundDependencies = 'full';
95
const opaqueCompoundDependencies = 'opaque';
96

97
const structPack = 'pack';
98
const Map<Object, int?> packingValuesMap = {
99
  'none': null,
100
  1: 1,
101
  2: 2,
102
  4: 4,
103
  8: 8,
104
  16: 16,
105
};
106

107
// Sizemap values.
108
const SChar = 'char';
109
const UChar = 'unsigned char';
110
const Short = 'short';
111
const UShort = 'unsigned short';
112
const Int = 'int';
113
const UInt = 'unsigned int';
114
const Long = 'long';
115
const ULong = 'unsigned long';
116
const LongLong = 'long long';
117
const ULongLong = 'unsigned long long';
118
const Enum = 'enum';
119

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

135
// Library imports.
136
const libraryImports = 'library-imports';
137

138
// Sub Keys of symbol file.
139
const symbols = 'symbols';
140

141
// Symbol file yaml.
142
const formatVersion = "format_version";
143

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

153
const import = 'import';
154
const defaultSymbolFileImportPrefix = 'imp';
155

156
// Sub keys of import.
157
const symbolFilesImport = 'symbol-files';
158
// Sub-Sub keys of symbolFilesImport.
159
const importPath = 'import-path';
160

161
final predefinedLibraryImports = {
9✔
162
  ffiImport.name: ffiImport,
9✔
163
  ffiPkgImport.name: ffiPkgImport
9✔
164
};
165

166
const typeMap = 'type-map';
167

168
// Sub-fields for type-map.
169
const typeMapTypedefs = 'typedefs';
170
const typeMapStructs = 'structs';
171
const typeMapUnions = 'unions';
172
const typeMapNativeTypes = 'native-types';
173

174
// Sub-sub-keys for fields under typeMap.
175
const lib = 'lib';
176
const cType = 'c-type';
177
const dartType = 'dart-type';
178

179
const supportedNativeType_mappings = <String, SupportedNativeType>{
180
  'Void': SupportedNativeType.Void,
181
  'Uint8': SupportedNativeType.Uint8,
182
  'Uint16': SupportedNativeType.Uint16,
183
  'Uint32': SupportedNativeType.Uint32,
184
  'Uint64': SupportedNativeType.Uint64,
185
  'Int8': SupportedNativeType.Int8,
186
  'Int16': SupportedNativeType.Int16,
187
  'Int32': SupportedNativeType.Int32,
188
  'Int64': SupportedNativeType.Int64,
189
  'IntPtr': SupportedNativeType.IntPtr,
190
  'Float': SupportedNativeType.Float,
191
  'Double': SupportedNativeType.Double,
192
};
193

194
// Boolean flags.
195
const sort = 'sort';
196
const useSupportedTypedefs = 'use-supported-typedefs';
197
const useDartHandle = 'use-dart-handle';
198

199
const comments = 'comments';
200
// Sub-fields of comments.
201
const style = 'style';
202
const length = 'length';
203

204
// Sub-fields of style.
205
const doxygen = 'doxygen';
206
const any = 'any';
207
// Sub-fields of length.
208
const brief = 'brief';
209
const full = 'full';
210
// Cmd line comment option.
211
const fparseAllComments = '-fparse-all-comments';
212

213
// Library input.
214
const name = 'name';
215
const description = 'description';
216
const preamble = 'preamble';
217

218
// Dynamic library names.
219
const libclang_dylib_linux = 'libclang.so';
220
const libclang_dylib_macos = 'libclang.dylib';
221
const libclang_dylib_windows = 'libclang.dll';
222

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

252
// Writen doubles.
253
const doubleInfinity = 'double.infinity';
254
const doubleNegativeInfinity = 'double.negativeInfinity';
255
const doubleNaN = 'double.nan';
256

257
/// USR for struct `_Dart_Handle`.
258
const dartHandleUsr = 'c:@S@_Dart_Handle';
259

260
const ffiNative = 'ffi-native';
261
const ffiNativeAsset = 'asset';
262

263
Directory? _tmpDir;
264

265
/// A path to a unique temporary directory that should be used for files meant
266
/// to be discarded after the current execution is finished.
267
String get tmpDir {
24✔
268
  if (Platform.environment.containsKey('TEST_TMPDIR')) {
48✔
269
    return Platform.environment['TEST_TMPDIR']!;
×
270
  }
271

272
  _tmpDir ??= Directory.systemTemp.createTempSync();
48✔
273
  return _tmpDir!.path;
24✔
274
}
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