Skip to content

Commit 0cb2407

Browse files
committed
fsm-listen-darwin: add macos header files for FSEvent
Include MacOS system declarations to allow us to use FSEvent and CoreFoundation APIs. We need GCC and clang versions because of compiler and header file conflicts. While it is quite possible to #include Apple's CoreServices.h when compiling C source code with clang, trying to build it with GCC currently fails with this error: In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Security.framework/Headers/AuthSession.h:32, from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Security.framework/Headers/Security.h:42, from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/CSIdentity.h:43, from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/OSServices.framework/Headers/OSServices.h:29, from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/IconsCore.h:23, from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/LaunchServices.h:23, from /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreServices.framework/Headers/CoreServices.h:45, /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Security.framework/Headers/Authorization.h:193:7: error: variably modified 'bytes' at file scope 193 | char bytes[kAuthorizationExternalFormLength]; | ^~~~~ The underlying reason is that GCC (rightfully) objects that an `enum` value such as `kAuthorizationExternalFormLength` is not a constant (because it is not, the preprocessor has no knowledge of it, only the actual C compiler does) and can therefore not be used to define the size of a C array. This is a known problem and tracked in GCC's bug tracker: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93082 In the meantime, let's not block things and go the slightly ugly route of declaring/defining the FSEvents constants, data structures and functions that we need, so that we can avoid above-mentioned issue. Let's do this _only_ for GCC, though, so that the CI/PR builds (which build both with clang and with GCC) can guarantee that we _are_ using the correct data types. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Jeff Hostetler <[email protected]>
1 parent 95ec3cb commit 0cb2407

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

compat/fsmonitor/fsm-listen-darwin.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,99 @@
1+
#if defined(__GNUC__)
2+
/*
3+
* It is possible to #include CoreFoundation/CoreFoundation.h when compiling
4+
* with clang, but not with GCC as of time of writing.
5+
*
6+
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93082 for details.
7+
*/
8+
typedef unsigned int FSEventStreamCreateFlags;
9+
#define kFSEventStreamEventFlagNone 0x00000000
10+
#define kFSEventStreamEventFlagMustScanSubDirs 0x00000001
11+
#define kFSEventStreamEventFlagUserDropped 0x00000002
12+
#define kFSEventStreamEventFlagKernelDropped 0x00000004
13+
#define kFSEventStreamEventFlagEventIdsWrapped 0x00000008
14+
#define kFSEventStreamEventFlagHistoryDone 0x00000010
15+
#define kFSEventStreamEventFlagRootChanged 0x00000020
16+
#define kFSEventStreamEventFlagMount 0x00000040
17+
#define kFSEventStreamEventFlagUnmount 0x00000080
18+
#define kFSEventStreamEventFlagItemCreated 0x00000100
19+
#define kFSEventStreamEventFlagItemRemoved 0x00000200
20+
#define kFSEventStreamEventFlagItemInodeMetaMod 0x00000400
21+
#define kFSEventStreamEventFlagItemRenamed 0x00000800
22+
#define kFSEventStreamEventFlagItemModified 0x00001000
23+
#define kFSEventStreamEventFlagItemFinderInfoMod 0x00002000
24+
#define kFSEventStreamEventFlagItemChangeOwner 0x00004000
25+
#define kFSEventStreamEventFlagItemXattrMod 0x00008000
26+
#define kFSEventStreamEventFlagItemIsFile 0x00010000
27+
#define kFSEventStreamEventFlagItemIsDir 0x00020000
28+
#define kFSEventStreamEventFlagItemIsSymlink 0x00040000
29+
#define kFSEventStreamEventFlagOwnEvent 0x00080000
30+
#define kFSEventStreamEventFlagItemIsHardlink 0x00100000
31+
#define kFSEventStreamEventFlagItemIsLastHardlink 0x00200000
32+
#define kFSEventStreamEventFlagItemCloned 0x00400000
33+
34+
typedef struct __FSEventStream *FSEventStreamRef;
35+
typedef const FSEventStreamRef ConstFSEventStreamRef;
36+
37+
typedef unsigned int CFStringEncoding;
38+
#define kCFStringEncodingUTF8 0x08000100
39+
40+
typedef const struct __CFString *CFStringRef;
41+
typedef const struct __CFArray *CFArrayRef;
42+
typedef const struct __CFRunLoop *CFRunLoopRef;
43+
44+
struct FSEventStreamContext {
45+
long long version;
46+
void *cb_data, *retain, *release, *copy_description;
47+
};
48+
49+
typedef struct FSEventStreamContext FSEventStreamContext;
50+
typedef unsigned int FSEventStreamEventFlags;
51+
#define kFSEventStreamCreateFlagNoDefer 0x02
52+
#define kFSEventStreamCreateFlagWatchRoot 0x04
53+
#define kFSEventStreamCreateFlagFileEvents 0x10
54+
55+
typedef unsigned long long FSEventStreamEventId;
56+
#define kFSEventStreamEventIdSinceNow 0xFFFFFFFFFFFFFFFFULL
57+
58+
typedef void (*FSEventStreamCallback)(ConstFSEventStreamRef streamRef,
59+
void *context,
60+
__SIZE_TYPE__ num_of_events,
61+
void *event_paths,
62+
const FSEventStreamEventFlags event_flags[],
63+
const FSEventStreamEventId event_ids[]);
64+
typedef double CFTimeInterval;
65+
FSEventStreamRef FSEventStreamCreate(void *allocator,
66+
FSEventStreamCallback callback,
67+
FSEventStreamContext *context,
68+
CFArrayRef paths_to_watch,
69+
FSEventStreamEventId since_when,
70+
CFTimeInterval latency,
71+
FSEventStreamCreateFlags flags);
72+
CFStringRef CFStringCreateWithCString(void *allocator, const char *string,
73+
CFStringEncoding encoding);
74+
CFArrayRef CFArrayCreate(void *allocator, const void **items, long long count,
75+
void *callbacks);
76+
void CFRunLoopRun(void);
77+
void CFRunLoopStop(CFRunLoopRef run_loop);
78+
CFRunLoopRef CFRunLoopGetCurrent(void);
79+
extern CFStringRef kCFRunLoopDefaultMode;
80+
void FSEventStreamScheduleWithRunLoop(FSEventStreamRef stream,
81+
CFRunLoopRef run_loop,
82+
CFStringRef run_loop_mode);
83+
unsigned char FSEventStreamStart(FSEventStreamRef stream);
84+
void FSEventStreamStop(FSEventStreamRef stream);
85+
void FSEventStreamInvalidate(FSEventStreamRef stream);
86+
void FSEventStreamRelease(FSEventStreamRef stream);
87+
#else
88+
/*
89+
* Let Apple's headers declare `isalnum()` first, before
90+
* Git's headers override it via a constant
91+
*/
92+
#include <string.h>
93+
#include <CoreFoundation/CoreFoundation.h>
94+
#include <CoreServices/CoreServices.h>
95+
#endif
96+
197
#include "cache.h"
298
#include "fsmonitor.h"
399
#include "fsm-listen.h"

0 commit comments

Comments
 (0)