[ffigen] Don't automatically include system headers (#342)
* Don't automatically include system headers
* Add more filtering to header parser tests
diff --git a/pkgs/ffigen/lib/src/header_parser/parser.dart b/pkgs/ffigen/lib/src/header_parser/parser.dart
index 33c7072..b400d84 100644
--- a/pkgs/ffigen/lib/src/header_parser/parser.dart
+++ b/pkgs/ffigen/lib/src/header_parser/parser.dart
@@ -67,11 +67,6 @@
/// If the config targets Objective C, add a compiler opt for it.
if (config.language == Language.objc) {
compilerOpts.addAll(strings.clangLangObjC);
- compilerOpts.add('-I' + strings.clangDefaultObjCSystemHeaderPath);
- for (final sysHdr in strings.clangDefaultObjCSystemHeaders) {
- compilerOpts.add(strings.clangInclude);
- compilerOpts.add(sysHdr);
- }
}
_logger.fine('CompilerOpts used: $compilerOpts');
diff --git a/pkgs/ffigen/lib/src/strings.dart b/pkgs/ffigen/lib/src/strings.dart
index 8e138f8..f3bfb79 100644
--- a/pkgs/ffigen/lib/src/strings.dart
+++ b/pkgs/ffigen/lib/src/strings.dart
@@ -39,15 +39,12 @@
const clangLangObjC = ['-x', 'objective-c'];
const clangObjCBoolDefine = '__OBJC_BOOL_IS_BOOL';
const clangInclude = '-include';
-const clangDefaultObjCSystemHeaderPath =
- '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include';
-const clangDefaultObjCSystemHeaders = ['objc/NSObject.h'];
const objcBOOL = 'BOOL';
// Internal objective C directories that are automatically pulled in by clang,
// and should be excluded from output (unless explicitly used).
const objCInternalDirectories = [
- clangDefaultObjCSystemHeaderPath,
+ '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include',
'/Applications/Xcode.app/Contents/Developer',
'/usr/local/opt/llvm/lib',
];
diff --git a/pkgs/ffigen/test/header_parser_tests/objc_basic_types.h b/pkgs/ffigen/test/header_parser_tests/objc_basic_types.h
index f2e5125..34b4550 100644
--- a/pkgs/ffigen/test/header_parser_tests/objc_basic_types.h
+++ b/pkgs/ffigen/test/header_parser_tests/objc_basic_types.h
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+#import <Foundation/NSObject.h>
+
struct Foo {
BOOL someBool;
id anId;
diff --git a/pkgs/ffigen/test/header_parser_tests/objc_basic_types_test.dart b/pkgs/ffigen/test/header_parser_tests/objc_basic_types_test.dart
index 252683e..ce5e76c 100644
--- a/pkgs/ffigen/test/header_parser_tests/objc_basic_types_test.dart
+++ b/pkgs/ffigen/test/header_parser_tests/objc_basic_types_test.dart
@@ -32,6 +32,24 @@
${strings.structs}:
${strings.include}:
- 'Foo'
+${strings.functions}:
+ ${strings.exclude}:
+ - '.*'
+${strings.unions}:
+ ${strings.exclude}:
+ - '.*'
+${strings.enums}:
+ ${strings.exclude}:
+ - '.*'
+${strings.unnamedEnums}:
+ ${strings.exclude}:
+ - '.*'
+${strings.macros}:
+ ${strings.exclude}:
+ - '.*'
+${strings.globals}:
+ ${strings.exclude}:
+ - '.*'
''') as yaml.YamlMap),
);
});
diff --git a/pkgs/ffigen/test/header_parser_tests/objc_config.h b/pkgs/ffigen/test/header_parser_tests/objc_config.h
index 6d3685e..1dc3007 100644
--- a/pkgs/ffigen/test/header_parser_tests/objc_config.h
+++ b/pkgs/ffigen/test/header_parser_tests/objc_config.h
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+#import <Foundation/NSObject.h>
+
@interface Foo : NSObject {}
@end
diff --git a/pkgs/ffigen/test/header_parser_tests/objc_config_test.dart b/pkgs/ffigen/test/header_parser_tests/objc_config_test.dart
index 03d608a..94a7001 100644
--- a/pkgs/ffigen/test/header_parser_tests/objc_config_test.dart
+++ b/pkgs/ffigen/test/header_parser_tests/objc_config_test.dart
@@ -36,6 +36,27 @@
- 'Excluded'
${strings.rename}:
'_(.*)': '\$1'
+${strings.functions}:
+ ${strings.exclude}:
+ - '.*'
+${strings.structs}:
+ ${strings.exclude}:
+ - '.*'
+${strings.unions}:
+ ${strings.exclude}:
+ - '.*'
+${strings.enums}:
+ ${strings.exclude}:
+ - '.*'
+${strings.unnamedEnums}:
+ ${strings.exclude}:
+ - '.*'
+${strings.macros}:
+ ${strings.exclude}:
+ - '.*'
+${strings.globals}:
+ ${strings.exclude}:
+ - '.*'
''') as yaml.YamlMap),
);
});
diff --git a/pkgs/ffigen/test/header_parser_tests/objc_interface.h b/pkgs/ffigen/test/header_parser_tests/objc_interface.h
index cf9f5b2..d1b6007 100644
--- a/pkgs/ffigen/test/header_parser_tests/objc_interface.h
+++ b/pkgs/ffigen/test/header_parser_tests/objc_interface.h
@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+#import <Foundation/NSObject.h>
+
// This is the Foo interface.
@interface Foo : NSObject {
// This is an instance variable. They are private, so are ignored.
diff --git a/pkgs/ffigen/test/header_parser_tests/objc_interface_test.dart b/pkgs/ffigen/test/header_parser_tests/objc_interface_test.dart
index 5d77f87..5a53385 100644
--- a/pkgs/ffigen/test/header_parser_tests/objc_interface_test.dart
+++ b/pkgs/ffigen/test/header_parser_tests/objc_interface_test.dart
@@ -32,6 +32,27 @@
${strings.objcInterfaces}:
${strings.include}:
- 'Foo'
+${strings.functions}:
+ ${strings.exclude}:
+ - '.*'
+${strings.structs}:
+ ${strings.exclude}:
+ - '.*'
+${strings.unions}:
+ ${strings.exclude}:
+ - '.*'
+${strings.enums}:
+ ${strings.exclude}:
+ - '.*'
+${strings.unnamedEnums}:
+ ${strings.exclude}:
+ - '.*'
+${strings.macros}:
+ ${strings.exclude}:
+ - '.*'
+${strings.globals}:
+ ${strings.exclude}:
+ - '.*'
''') as yaml.YamlMap),
);
});