Skip to content

Android changes for Swift 4.1 cherrypicked into 4.2 #1631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ extern void __CFGenericValidateType_(CFTypeRef cf, CFTypeID type, const char *fu
#define __CFBitfield64GetValue(V, N1, N2) (((V) & __CFBitfield64Mask(N1, N2)) >> (N2))
#define __CFBitfield64SetValue(V, N1, N2, X) ((V) = ((V) & ~__CFBitfield64Mask(N1, N2)) | ((((uint64_t)X) << (N2)) & __CFBitfield64Mask(N1, N2)))

#if __LP64__
#if __LP64__ || DEPLOYMENT_TARGET_ANDROID
typedef uint64_t __CFInfoType;
#define __CFInfoMask(N1, N2) __CFBitfield64Mask(N1, N2)
#else
Expand Down
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFKnownLocations.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUs
}

}
#elif !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#elif !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

/*
Building for an OS that uses the FHS, BSD's hier(7), and/or the XDG specification for paths:
Expand Down
3 changes: 3 additions & 0 deletions CoreFoundation/Base.subproj/CFPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ CF_EXPORT CFStringRef CFCopyFullUserName(void) {
uid_t euid;
__CFGetUGIDs(&euid, NULL);
struct passwd *upwd = getpwuid(euid ? euid : getuid());
#if DEPLOYMENT_TARGET_ANDROID
#define pw_gecos pw_name
#endif
if (upwd && upwd->pw_gecos) {
result = CFStringCreateWithCString(kCFAllocatorSystemDefault, upwd->pw_gecos, kCFPlatformInterfaceStringEncoding);
}
Expand Down
1 change: 1 addition & 0 deletions CoreFoundation/Base.subproj/CFUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ void CFLog1(CFLogLevel lev, CFStringRef message) {
CFStringGetCString(message, buffer, maxLength, encoding);

__android_log_print(priority, tag, "%s", buffer);
fprintf(stderr, "%s\n", buffer);

if (buffer != &stack_buffer[0]) free(buffer);
#else
Expand Down
2 changes: 2 additions & 0 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((n
static inline int _direntNameLength(struct dirent *entry) {
#ifdef _D_EXACT_NAMLEN // defined on Linux
return _D_EXACT_NAMLEN(entry);
#elif DEPLOYMENT_TARGET_ANDROID
return strlen(entry->d_name);
#else
return entry->d_namlen;
#endif
Expand Down
9 changes: 9 additions & 0 deletions CoreFoundation/NumberDate.subproj/CFTimeZone.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,15 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) {
CFRelease(name);
if (result) return result;
}
#if DEPLOYMENT_TARGET_ANDROID
// Timezone database by name not available on Android.
// Approximate with gmtoff - could be general default.
struct tm info;
time_t now = time(NULL);
if (NULL != localtime_r(&now, &info)) {
return CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorSystemDefault, info.tm_gmtoff);
}
#endif
return CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorSystemDefault, 0.0);
}

Expand Down
8 changes: 4 additions & 4 deletions CoreFoundation/PlugIn.subproj/CFBundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void _CFBundleEnsureBundlesExistForImagePaths(CFArrayRef imagePaths);

#pragma mark -

#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

// Functions and constants for FHS bundles:
#define _CFBundleFHSDirectory_share CFSTR("share")
Expand All @@ -162,10 +162,10 @@ static Boolean _CFBundleURLIsForFHSInstalledBundle(CFURLRef bundleURL) {

return isFHSBundle;
}
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

Boolean _CFBundleSupportsFHSBundles() {
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID
return true;
#else
return false;
Expand Down Expand Up @@ -714,7 +714,7 @@ static CFBundleRef _CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL,

bundle->_url = newURL;

#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID
bundle->_isFHSInstalledBundle = _CFBundleURLIsForFHSInstalledBundle(newURL);
#endif

Expand Down
14 changes: 7 additions & 7 deletions CoreFoundation/PlugIn.subproj/CFBundle_Executable.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <dlfcn.h>
#endif

#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

#if DEPLOYMENT_TARGET_LINUX
#if __LP64__
Expand Down Expand Up @@ -48,7 +48,7 @@
_kCFBundleFHSDirectory_lib
#endif // DEPLOYMENT_TARGET_LINUX

#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

// This is here because on iPhoneOS with the dyld shared cache, we remove binaries from their
// original locations on disk, so checking whether a binary's path exists is no longer sufficient.
Expand All @@ -73,7 +73,7 @@ static CFURLRef _CFBundleCopyExecutableURLRaw(CFURLRef urlPath, CFStringRef exeN
CFURLRef executableURL = NULL;
if (!urlPath || !exeName) return NULL;

#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID
if (!executableURL) {
executableURL = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, exeName, kCFURLPOSIXPathStyle, false, urlPath);
if (!_binaryLoadable(executableURL)) {
Expand Down Expand Up @@ -203,7 +203,7 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL
Boolean doExecSearch = true;
#endif

#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID
if (lookupMainExe && bundle && bundle->_isFHSInstalledBundle) {
// For a FHS installed bundle, the URL points to share/Bundle.resources, and the binary is in:

Expand All @@ -227,13 +227,13 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL

CFRelease(prefixPath);
}
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

// Now, look for the executable inside the bundle.
if (!foundIt && doExecSearch && 0 != version) {
CFURLRef exeDirURL = NULL;

#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID
if (bundle && bundle->_isFHSInstalledBundle) {
CFURLRef withoutExtension = CFURLCreateCopyDeletingPathExtension(kCFAllocatorSystemDefault, url);
CFStringRef lastPathComponent = CFURLCopyLastPathComponent(withoutExtension);
Expand All @@ -248,7 +248,7 @@ static CFURLRef _CFBundleCopyExecutableURLInDirectory2(CFBundleRef bundle, CFURL
CFRelease(libexec);
CFRelease(exeDirName);
} else
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID
if (1 == version) {
exeDirURL = CFURLCreateWithString(kCFAllocatorSystemDefault, _CFBundleExecutablesURLFromBase1, url);
} else if (2 == version) {
Expand Down
4 changes: 2 additions & 2 deletions CoreFoundation/PlugIn.subproj/CFBundle_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CF_EXTERN_C_BEGIN
#endif

// FHS bundles are supported on the Swift and C runtimes, except on Windows.
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

#if DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
#define _CFBundleFHSSharedLibraryFilenamePrefix CFSTR("lib")
Expand All @@ -43,7 +43,7 @@ CF_EXTERN_C_BEGIN
#error Disable FHS bundles or specify shared library prefixes and suffixes for this platform.
#endif // DEPLOYMENT_TARGET_…

#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
#endif // !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID

#define CFBundleExecutableNotFoundError 4
#define CFBundleExecutableNotLoadableError 3584
Expand Down
6 changes: 3 additions & 3 deletions CoreFoundation/URL.subproj/CFURL.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#if __has_include(<sys/syslog.h>)
#include <sys/syslog.h>
#elif __has_include(<syslog.h>)
#if __has_include(<syslog.h>)
#include <syslog.h>
#else
#include <sys/syslog.h>
#endif
#include <CoreFoundation/CFURLPriv.h>
#endif
Expand Down
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
B9974B9A1EDF4A22007F15B8 /* HTTPMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9974B931EDF4A22007F15B8 /* HTTPMessage.swift */; };
B9974B9B1EDF4A22007F15B8 /* BodySource.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9974B941EDF4A22007F15B8 /* BodySource.swift */; };
B9974B9C1EDF4A22007F15B8 /* EasyHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B9974B951EDF4A22007F15B8 /* EasyHandle.swift */; };
BB3D7558208A1E500085CFDC /* TestImports.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB3D7557208A1E500085CFDC /* TestImports.swift */; };
BD8042161E09857800487EB8 /* TestLengthFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8042151E09857800487EB8 /* TestLengthFormatter.swift */; };
BDBB65901E256BFA001A7286 /* TestEnergyFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDBB658F1E256BFA001A7286 /* TestEnergyFormatter.swift */; };
BDFDF0A71DFF5B3E00C04CC5 /* TestPersonNameComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFDF0A61DFF5B3E00C04CC5 /* TestPersonNameComponents.swift */; };
Expand Down Expand Up @@ -825,6 +826,7 @@
B9974B931EDF4A22007F15B8 /* HTTPMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HTTPMessage.swift; path = http/HTTPMessage.swift; sourceTree = "<group>"; };
B9974B941EDF4A22007F15B8 /* BodySource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BodySource.swift; sourceTree = "<group>"; };
B9974B951EDF4A22007F15B8 /* EasyHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EasyHandle.swift; sourceTree = "<group>"; };
BB3D7557208A1E500085CFDC /* TestImports.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestImports.swift; sourceTree = "<group>"; };
BD8042151E09857800487EB8 /* TestLengthFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestLengthFormatter.swift; sourceTree = "<group>"; };
BDBB658F1E256BFA001A7286 /* TestEnergyFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestEnergyFormatter.swift; sourceTree = "<group>"; };
BDFDF0A61DFF5B3E00C04CC5 /* TestPersonNameComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestPersonNameComponents.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1431,6 +1433,7 @@
children = (
1520469A1D8AEABE00D02E36 /* HTTPServer.swift */,
EA66F6381BF1619600136161 /* main.swift */,
BB3D7557208A1E500085CFDC /* TestImports.swift */,
9F4ADBCF1ECD4F56001F0B3D /* xdgTestHelper */,
EA66F65A1BF1976100136161 /* Tests */,
EA66F6391BF1619600136161 /* Resources */,
Expand Down Expand Up @@ -2442,6 +2445,7 @@
90E645DF1E4C89A400D0D47C /* TestNSCache.swift in Sources */,
5B13B34A1C582D4C00651CE2 /* TestURL.swift in Sources */,
EA54A6FB1DB16D53009E0809 /* TestObjCRuntime.swift in Sources */,
BB3D7558208A1E500085CFDC /* TestImports.swift in Sources */,
5B13B34D1C582D4C00651CE2 /* TestNSUUID.swift in Sources */,
5B13B3281C582D4C00651CE2 /* TestBundle.swift in Sources */,
5B13B32A1C582D4C00651CE2 /* TestCharacterSet.swift in Sources */,
Expand Down
6 changes: 4 additions & 2 deletions Foundation/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ open class Bundle: NSObject {
self.init(path: url.path)
}

public init(for aClass: AnyClass) { NSUnimplemented() }

public init(for aClass: AnyClass) {
NSUnimplemented()
}

public init?(identifier: String) {
super.init()

Expand Down
11 changes: 7 additions & 4 deletions Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,13 @@ open class FileManager : NSObject {

This method replaces fileSystemAttributesAtPath:.
*/
#if os(Android)
@available(*, unavailable, message: "Unsuppported on this platform")
open func attributesOfFileSystem(forPath path: String) throws -> [FileAttributeKey : Any] {
NSUnsupported()
}
#else
open func attributesOfFileSystem(forPath path: String) throws -> [FileAttributeKey : Any] {
#if os(Android)
NSUnimplemented()
#else
// statvfs(2) doesn't support 64bit inode on Darwin (apfs), fallback to statfs(2)
#if os(macOS) || os(iOS)
var s = statfs()
Expand Down Expand Up @@ -407,8 +410,8 @@ open class FileManager : NSObject {
result[.systemFreeNodes] = NSNumber(value: UInt64(s.f_ffree))

return result
#endif
}
#endif

/* createSymbolicLinkAtPath:withDestination:error: returns YES if the symbolic link that point at 'destPath' was able to be created at the location specified by 'path'. If this method returns NO, the link was unable to be created and an NSError will be returned by reference in the 'error' parameter. This method does not traverse a terminal symlink.

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSCFString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ internal final class _NSCFConstantString : _NSCFString {
// FIXME: Split expression as a work-around for slow type
// checking (tracked by SR-5322).
let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<uintptr_t>.size
let offTemp2 = MemoryLayout<_CFInfo>.size
return offTemp1 + offTemp2 + MemoryLayout<UnsafePointer<UInt8>>.size
let offset = offTemp1 + MemoryLayout<_CFInfo>.size
return offset + MemoryLayout<UnsafePointer<UInt8>>.size
}

private var _lenPtr : UnsafeMutableRawPointer {
Expand Down
8 changes: 0 additions & 8 deletions Foundation/NSTimeZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ open class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding {
extension NSTimeZone {

open class var system: TimeZone {
#if os(Android)
var now = time(nil), info = tm()
if localtime_r(&now, &info) != nil {
// NOTE: this is not a real time zone but a fixed offset from GMT.
// It will be incorrect outside the current daylight saving period.
return TimeZone(reference: NSTimeZone(forSecondsFromGMT: info.tm_gmtoff))
}
#endif
return CFTimeZoneCopySystem()._swiftObject
}

Expand Down
12 changes: 2 additions & 10 deletions TestFoundation/HTTPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@

import Dispatch

#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif

#if os(macOS) || os(iOS)
#if canImport(Darwin)
import Darwin
#elseif os(Linux)
#elseif canImport(Glibc)
import Glibc
#endif

Expand Down
11 changes: 0 additions & 11 deletions TestFoundation/TestAffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//



#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif


class TestAffineTransform : XCTestCase {
private let accuracyThreshold = 0.001

Expand Down
9 changes: 0 additions & 9 deletions TestFoundation/TestBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//


#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif

import CoreFoundation

internal func testBundle() -> Bundle {
Expand Down
12 changes: 0 additions & 12 deletions TestFoundation/TestByteCountFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//



#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif



class TestByteCountFormatter : XCTestCase {

static var allTests: [(String, (TestByteCountFormatter) -> () throws -> Void)] {
Expand Down
8 changes: 0 additions & 8 deletions TestFoundation/TestCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif

class TestCalendar: XCTestCase {

static var allTests: [(String, (TestCalendar) -> () throws -> Void)] {
Expand Down
8 changes: 0 additions & 8 deletions TestFoundation/TestCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif

private struct Box: Equatable {
private let ns: NSCharacterSet
private let swift: CharacterSet
Expand Down
Loading