Skip to content

Commit 8572437

Browse files
Merge branch 'master' of github.com:apple/swift-corelibs-foundation into url-session-task/input-stream
2 parents 4f67097 + d839794 commit 8572437

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+8962
-1439
lines changed

CMakeLists.txt

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ExternalProject_Add(CoreFoundation
3939
-DCF_ENABLE_LIBDISPATCH=${FOUNDATION_ENABLE_LIBDISPATCH}
4040
-DCF_PATH_TO_LIBDISPATCH_SOURCE=${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE}
4141
-DCF_PATH_TO_LIBDISPATCH_BUILD=${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}
42+
-DICU_INCLUDE_DIR=${ICU_INCLUDE_DIR}
4243
INSTALL_COMMAND
4344
${CMAKE_COMMAND} -E env --unset=DESTDIR ${CMAKE_COMMAND} --build . --target install)
4445
ExternalProject_Get_Property(CoreFoundation install_dir)
@@ -47,14 +48,20 @@ set(swift_optimization_flags)
4748
if(CMAKE_BUILD_TYPE MATCHES Release)
4849
set(swift_optimization_flags -O)
4950
endif()
51+
if(ENABLE_TESTING)
52+
set(swift_enable_testing -enable-testing)
53+
endif()
5054

5155
set(deployment_enable_libdispatch)
5256
set(libdispatch_cflags)
5357
set(libdispatch_ldflags)
5458
if(FOUNDATION_ENABLE_LIBDISPATCH)
5559
set(deployment_enable_libdispatch -DDEPLOYMENT_ENABLE_LIBDISPATCH)
5660
set(libdispatch_cflags -I;${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE};-I;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src/swift;-Xcc;-fblocks)
57-
set(libdispatch_ldflags -L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src;-ldispatch)
61+
set(libdispatch_ldflags -L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD};-L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src;-ldispatch)
62+
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
63+
list(APPEND libdispatch_ldflags -Xlinker;-rpath;-Xlinker;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
64+
endif()
5865
endif()
5966

6067
add_swift_library(Foundation
@@ -90,6 +97,7 @@ add_swift_library(Foundation
9097
Foundation/ExtraStringAPIs.swift
9198
Foundation/FileHandle.swift
9299
Foundation/FileManager.swift
100+
Foundation/FileManager_XDG.swift
93101
Foundation/Formatter.swift
94102
Foundation/FoundationErrors.swift
95103
Foundation/Host.swift
@@ -196,16 +204,14 @@ add_swift_library(Foundation
196204
Foundation/URLProtocol.swift
197205
Foundation/URLRequest.swift
198206
Foundation/URLResponse.swift
199-
# NOTE: must precede HTTPMessage.swift
207+
Foundation/URLSession/BodySource.swift
208+
Foundation/URLSession/Configuration.swift
200209
Foundation/URLSession/Message.swift
201210
Foundation/URLSession/http/HTTPMessage.swift
202211
Foundation/URLSession/http/HTTPURLProtocol.swift
203212
Foundation/URLSession/libcurl/EasyHandle.swift
204213
Foundation/URLSession/libcurl/libcurlHelpers.swift
205214
Foundation/URLSession/libcurl/MultiHandle.swift
206-
Foundation/URLSession/BodySource.swift
207-
Foundation/URLSession/Configuration.swift
208-
# Foundation/URLSession/Message.swift
209215
Foundation/URLSession/NativeProtocol.swift
210216
Foundation/URLSession/TaskRegistry.swift
211217
Foundation/URLSession/TransferState.swift
@@ -226,6 +232,7 @@ add_swift_library(Foundation
226232
${CMAKE_C_COMPILER_TARGET}
227233
CFLAGS
228234
${deployment_enable_libdispatch}
235+
-F${install_dir}/System/Library/Frameworks
229236
LINK_FLAGS
230237
-L${install_dir}/usr/lib
231238
-lCoreFoundation
@@ -234,11 +241,13 @@ add_swift_library(Foundation
234241
${LIBXML2_LIBRARIES}
235242
${libdispatch_ldflags}
236243
${uuid_LIBRARIES}
244+
-Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN"
237245
SWIFT_FLAGS
238246
-DDEPLOYMENT_RUNTIME_SWIFT
239247
${deployment_enable_libdispatch}
240-
-Fsystem;${install_dir}/System/Library/Frameworks
248+
-I;${ICU_INCLUDE_DIR}
241249
${libdispatch_cflags}
250+
${swift_enable_testing}
242251
${swift_optimization_flags})
243252
add_dependencies(Foundation CoreFoundation)
244253

@@ -247,31 +256,52 @@ add_swift_executable(plutil
247256
Tools/plutil/main.swift
248257
CFLAGS
249258
${deployment_enable_libdispatch}
259+
-F${install_dir}/System/Library/Frameworks
250260
LINK_FLAGS
251261
-L${CMAKE_CURRENT_BINARY_DIR}
262+
${libdispatch_ldflags}
252263
-lFoundation
253264
SWIFT_FLAGS
254265
-DDEPLOYMENT_RUNTIME_SWIFT
255266
${deployment_enable_libdispatch}
256-
-Fsystem;${install_dir}/System/Library/Frameworks
257267
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
268+
-I;${ICU_INCLUDE_DIR}
258269
${libdispatch_cflags}
270+
${swift_enable_testing}
259271
${swift_optimization_flags})
260272
add_dependencies(plutil Foundation CoreFoundation)
261273

262274
if(ENABLE_TESTING)
275+
add_swift_executable(xdgTestHelper
276+
CFLAGS
277+
${deployment_enable_libdispatch}
278+
-F${install_dir}/System/Library/Frameworks
279+
LINK_FLAGS
280+
${libdispatch_ldflags}
281+
-L${CMAKE_CURRENT_BINARY_DIR}
282+
-lFoundation
283+
SOURCES
284+
TestFoundation/xdgTestHelper/main.swift
285+
SWIFT_FLAGS
286+
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
287+
-I;${ICU_INCLUDE_DIR}
288+
${libdispatch_cflags})
289+
add_dependencies(xdgTestHelper Foundation CoreFoundation)
290+
263291
add_swift_executable(TestFoundation
264292
SOURCES
265293
TestFoundation/main.swift
266294
TestFoundation/HTTPServer.swift
267295
Foundation/ProgressFraction.swift
296+
TestFoundation/Utilities.swift
268297
# Test Cases
269298
TestFoundation/TestAffineTransform.swift
270299
TestFoundation/TestBundle.swift
271300
TestFoundation/TestByteCountFormatter.swift
272301
TestFoundation/TestCalendar.swift
273302
TestFoundation/TestCharacterSet.swift
274303
TestFoundation/TestCodable.swift
304+
TestFoundation/TestDateComponents.swift
275305
TestFoundation/TestDateFormatter.swift
276306
TestFoundation/TestDate.swift
277307
TestFoundation/TestDecimal.swift
@@ -295,6 +325,7 @@ if(ENABLE_TESTING)
295325
TestFoundation/TestNSArray.swift
296326
TestFoundation/TestNSAttributedString.swift
297327
TestFoundation/TestNSCache.swift
328+
TestFoundation/TestNSCalendar.swift
298329
TestFoundation/TestNSCompoundPredicate.swift
299330
TestFoundation/TestNSData.swift
300331
TestFoundation/TestNSDictionary.swift
@@ -336,6 +367,7 @@ if(ENABLE_TESTING)
336367
TestFoundation/TestUnitConverter.swift
337368
TestFoundation/TestUnit.swift
338369
TestFoundation/TestURLCredential.swift
370+
TestFoundation/TestURLProtectionSpace.swift
339371
TestFoundation/TestURLProtocol.swift
340372
TestFoundation/TestURLRequest.swift
341373
TestFoundation/TestURLResponse.swift
@@ -347,11 +379,13 @@ if(ENABLE_TESTING)
347379
TestFoundation/TestXMLParser.swift
348380
CFLAGS
349381
${deployment_enable_libdispatch}
382+
-F${install_dir}/System/Library/Frameworks
350383
LINK_FLAGS
351384
${libdispatch_ldflags}
352385
-L${CMAKE_CURRENT_BINARY_DIR}
353386
-lFoundation
354387
-L${FOUNDATION_PATH_TO_XCTEST_BUILD}
388+
-lXCTest
355389
RESOURCES
356390
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/Info.plist
357391
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSURLTestData.plist
@@ -375,29 +409,25 @@ if(ENABLE_TESTING)
375409
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-URLTest.plist
376410
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-UUIDTest.plist
377411
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/NSKeyedUnarchiver-OrderedSetTest.plist
412+
${CMAKE_SOURCE_DIR}/TestFoundation/Resources/TestFileWithZeros.txt
378413
SWIFT_FLAGS
379414
${deployment_enable_libdispatch}
380-
-Fsystem;${install_dir}/System/Library/Frameworks
381415
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
382416
-I;${FOUNDATION_PATH_TO_XCTEST_BUILD}/swift
417+
-I;${ICU_INCLUDE_DIR}
383418
${libdispatch_cflags}
384419
${swift_optimization_flags})
385-
add_dependencies(TestFoundation Foundation CoreFoundation)
386-
387-
add_swift_executable(xdgTestHelper
388-
SOURCES
389-
TestFoundation/xdgTestHelper/main.swift
390-
CFLAGS
391-
${deployment_enable_libdispatch}
392-
LINK_FLAGS
393-
-L${CMAKE_CURRENT_BINARY_DIR}
394-
-lFoundation
395-
SWIFT_FLAGS
396-
-Fsystem;${install_dir}/System/Library/Frameworks
397-
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
398-
${libdispatch_cflags})
399-
add_dependencies(xdgTestHelper Foundation CoreFoundation)
420+
add_dependencies(TestFoundation Foundation CoreFoundation xdgTestHelper)
400421

422+
add_custom_command(TARGET TestFoundation
423+
POST_BUILD
424+
BYPRODUCTS
425+
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX}
426+
COMMAND
427+
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX}
428+
DEPENDS
429+
TestFoundation
430+
xdgTestHelper)
401431
add_test(NAME
402432
TestFoundation
403433
COMMAND
@@ -407,20 +437,41 @@ if(ENABLE_TESTING)
407437
set_tests_properties(TestFoundation
408438
PROPERTIES
409439
ENVIRONMENT
410-
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src)
440+
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src
441+
DEPENDS
442+
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX})
411443
endif()
412444

445+
string(TOLOWER ${CMAKE_SYSTEM_NAME} swift_os)
446+
get_swift_host_arch(swift_arch)
447+
448+
# TODO(compnerd) honour lib vs lib64
413449
install(FILES
414450
${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftdoc
415451
${CMAKE_CURRENT_BINARY_DIR}/swift/Foundation.swiftmodule
416452
DESTINATION
417-
${CMAKE_INSTALL_FULL_LIBDIR}/swift/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
453+
lib/swift/${swift_os}/${swift_arch})
418454
install(FILES
419455
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}Foundation${CMAKE_SHARED_LIBRARY_SUFFIX}
420456
DESTINATION
421-
${CMAKE_INSTALL_FULL_LIBDIR})
457+
lib/swift/${swift_os})
458+
# TODO(compnerd) install as a Framework as that is how swift actually is built
459+
install(DIRECTORY
460+
${install_dir}/System/Library/Frameworks/CoreFoundation.framework/Headers/
461+
DESTINATION
462+
lib/swift/CoreFoundation
463+
FILES_MATCHING PATTERN "*.h")
464+
install(FILES
465+
CoreFoundation/Base.subproj/module.map
466+
DESTINATION
467+
lib/swift/CoreFoundation)
468+
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
469+
install(FILES
470+
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}Foundation${CMAKE_SHARED_LIBRARY_SUFFIX}
471+
DESTINATION
472+
lib/swift/${swift_os}/${swift_arch})
473+
endif()
422474
install(FILES
423475
${CMAKE_CURRENT_BINARY_DIR}/plutil
424476
DESTINATION
425477
${CMAKE_INSTALL_FULL_BINDIR})
426-

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ CF_EXTERN_C_BEGIN
110110
#include <pthread.h>
111111

112112
#if !DEPLOYMENT_RUNTIME_SWIFT && __has_include(<os/log.h>)
113-
#import <os/log.h>
113+
#include <os/log.h>
114114
#else
115115
typedef struct os_log_s *os_log_t;
116116
#define os_log(...) do { } while (0)
@@ -421,7 +421,7 @@ CF_PRIVATE Boolean __CFProcessIsRestricted(void);
421421

422422
CF_EXPORT void * __CFConstantStringClassReferencePtr;
423423

424-
#if DEPLOYMENT_RUNTIME_SWIFT
424+
#if DEPLOYMENT_RUNTIME_SWIFT && TARGET_OS_MAC
425425

426426
#if DEPLOYMENT_TARGET_LINUX
427427
#define CONST_STRING_SECTION __attribute__((section(".cfstr.data")))
@@ -1005,6 +1005,12 @@ enum {
10051005
__kCFZombieMessagedEvent = 21,
10061006
};
10071007

1008+
#define _CFReleaseDeferred __attribute__((__cleanup__(_CFReleaseOnCleanup)))
1009+
static inline void _CFReleaseOnCleanup(void * CF_RELEASES_ARGUMENT ptr) {
1010+
CFTypeRef cf = *(CFTypeRef *)ptr;
1011+
if (cf) CFRelease(cf);
1012+
}
1013+
10081014
#pragma mark - CF Private Globals
10091015

10101016
CF_PRIVATE void *__CFAppleLanguages;

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ CF_PRIVATE int asprintf(char **ret, const char *format, ...) {
13111311
#endif
13121312

13131313
#if DEPLOYMENT_RUNTIME_SWIFT
1314-
#import <fcntl.h>
1314+
#include <fcntl.h>
13151315

13161316
extern void swift_retain(void *);
13171317
extern void swift_release(void *);

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ static CFRuntimeClass const * __CFRuntimeClassTable[__CFRuntimeClassTableSize] _
229229

230230
#if TARGET_OS_MAC
231231
[_kCFRuntimeIDCFMachPort] = &__CFMachPortClass,
232+
[_kCFRuntimeIDCFMessagePort] = &__CFMessagePortClass,
232233
#endif
233234

234235

235-
[_kCFRuntimeIDCFMessagePort] = &__CFMessagePortClass,
236236
[_kCFRuntimeIDCFRunLoopMode] = &__CFRunLoopModeClass,
237237
[_kCFRuntimeIDCFRunLoop] = &__CFRunLoopClass,
238238
[_kCFRuntimeIDCFRunLoopSource] = &__CFRunLoopSourceClass,

CoreFoundation/Base.subproj/CFUtilities.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include <crt_externs.h>
4747
#include <dlfcn.h>
4848
#include <vproc.h>
49-
#import <libproc.h>
49+
#include <libproc.h>
5050
#include <sys/sysctl.h>
5151
#include <sys/stat.h>
5252
#include <mach/mach.h>

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ typedef char * Class;
7474
#define CRSetCrashLogMessage2(A) do {} while (0)
7575

7676
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
77-
#import <libkern/OSAtomic.h>
78-
#import <pthread.h>
77+
#include <libkern/OSAtomic.h>
78+
#include <pthread.h>
7979
#endif
8080

8181

@@ -145,7 +145,7 @@ typedef int boolean_t;
145145

146146
#if DEPLOYMENT_TARGET_LINUX
147147

148-
#define CF_PRIVATE __attribute__((visibility("hidden")))
148+
#define CF_PRIVATE extern __attribute__((visibility("hidden")))
149149
#define __weak
150150

151151
#define strtod_l(a,b,locale) strtod(a,b)
@@ -235,7 +235,7 @@ CF_INLINE uint64_t mach_absolute_time() {
235235
#if DEPLOYMENT_TARGET_FREEBSD
236236
#define HAVE_STRUCT_TIMESPEC 1
237237

238-
#define CF_PRIVATE __attribute__((visibility("hidden")))
238+
#define CF_PRIVATE extern __attribute__((visibility("hidden")))
239239
#define __strong
240240
#define __weak
241241

@@ -455,7 +455,7 @@ CF_EXPORT int64_t OSAtomicAdd64Barrier( int64_t __theAmount, volatile int64_t *_
455455
#endif
456456

457457
#if !defined(CF_PRIVATE)
458-
#define CF_PRIVATE __attribute__((__visibility__("hidden"))) extern
458+
#define CF_PRIVATE extern __attribute__((__visibility__("hidden")))
459459
#endif
460460

461461
// [FIXED_35517899] We can't currently support this, but would like to leave things annotated

CoreFoundation/Base.subproj/ForFoundationOnly.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,6 @@ CF_EXPORT Boolean _CFCalendarComposeAbsoluteTimeV(CFCalendarRef calendar, /* out
602602
CF_EXPORT Boolean _CFCalendarDecomposeAbsoluteTimeV(CFCalendarRef calendar, CFAbsoluteTime at, const char *componentDesc, int32_t *_Nonnull * _Nonnull vector, int32_t count);
603603
CF_EXPORT Boolean _CFCalendarAddComponentsV(CFCalendarRef calendar, /* inout */ CFAbsoluteTime *atp, CFOptionFlags options, const char *componentDesc, int32_t *vector, int32_t count);
604604
CF_EXPORT Boolean _CFCalendarGetComponentDifferenceV(CFCalendarRef calendar, CFAbsoluteTime startingAT, CFAbsoluteTime resultAT, CFOptionFlags options, const char *componentDesc, int32_t *_Nonnull * _Nonnull vector, int32_t count);
605-
CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarIsWeekend(CFCalendarRef calendar, CFAbsoluteTime at);
606-
607-
typedef struct {
608-
CFTimeInterval onsetTime;
609-
CFTimeInterval ceaseTime;
610-
CFIndex start;
611-
CFIndex end;
612-
} _CFCalendarWeekendRange;
613-
614-
CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarGetNextWeekend(CFCalendarRef calendar, _CFCalendarWeekendRange *range);
615605

616606
CF_CROSS_PLATFORM_EXPORT Boolean _CFLocaleInit(CFLocaleRef locale, CFStringRef identifier);
617607

0 commit comments

Comments
 (0)