Skip to content

Commit 5ff01b1

Browse files
jeffhostetlergitster
authored andcommitted
compat/fsmonitor/fsm-listen-darwin: add MacOS header files for FSEvent
Include MacOS system declarations to allow us to use FSEvent and CoreFoundation APIs. We need different versions of the declarations for GCC vs. clang 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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1448edf commit 5ff01b1

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

compat/fsmonitor/fsm-darwin-gcc.h

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

compat/fsmonitor/fsm-listen-darwin.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
#ifndef __clang__
2+
#include "fsm-darwin-gcc.h"
3+
#else
4+
#include <CoreFoundation/CoreFoundation.h>
5+
#include <CoreServices/CoreServices.h>
6+
7+
#ifndef AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER
8+
/*
9+
* This enum value was added in 10.13 to:
10+
*
11+
* /Applications/Xcode.app/Contents/Developer/Platforms/ \
12+
* MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/ \
13+
* Library/Frameworks/CoreServices.framework/Frameworks/ \
14+
* FSEvents.framework/Versions/Current/Headers/FSEvents.h
15+
*
16+
* If we're compiling against an older SDK, this symbol won't be
17+
* present. Silently define it here so that we don't have to ifdef
18+
* the logging or masking below. This should be harmless since older
19+
* versions of macOS won't ever emit this FS event anyway.
20+
*/
21+
#define kFSEventStreamEventFlagItemCloned 0x00400000
22+
#endif
23+
#endif
24+
125
#include "cache.h"
226
#include "fsmonitor.h"
327
#include "fsm-listen.h"

0 commit comments

Comments
 (0)