Skip to content

[Shepherd] Treat Cygwin as a separate OS #10359

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 1 commit into from
Jun 28, 2017
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
3 changes: 0 additions & 3 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ function(handle_swift_sources
if (NOT SWIFTSOURCES_IS_MAIN)
list(APPEND swift_compile_flags "-module-link-name" "${name}")
endif()
if("${SWIFTSOURCES_SDK}" STREQUAL "CYGWIN")
list(APPEND swift_compile_flags -DCYGWIN)
endif()

if(swift_sources)
compute_library_subdir(SWIFTSOURCES_LIBRARY_SUBDIR
Expand Down
3 changes: 3 additions & 0 deletions lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static const StringRef SupportedConditionalCompilationOSs[] = {
"Windows",
"Android",
"PS4",
"Cygwin",
};

static const StringRef SupportedConditionalCompilationArches[] = {
Expand Down Expand Up @@ -157,6 +158,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
addPlatformConditionValue(PlatformConditionKind::OS, "FreeBSD");
else if (triple.isOSWindows())
addPlatformConditionValue(PlatformConditionKind::OS, "Windows");
else if (triple.isWindowsCygwinEnvironment())
addPlatformConditionValue(PlatformConditionKind::OS, "Cygwin");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Cygwin, triple.isOSWindows() and triple.isWindowsCygwinEnvironment() are all true.
The condition order should be changed. After changed, os(Windows) will be false and only os(Cygwin) will be true.

else if (triple.isPS4())
addPlatformConditionValue(PlatformConditionKind::OS, "PS4");
else
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/RaceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import SwiftPrivateLibcExtras
import SwiftPrivatePthreadExtras
#if os(OSX) || os(iOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
import Glibc
#endif

Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/StdlibCoreExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SwiftPrivate
import SwiftPrivateLibcExtras
#if os(OSX) || os(iOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
import Glibc
#endif

Expand Down
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SwiftPrivateLibcExtras

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
import Glibc
#endif

Expand Down Expand Up @@ -1497,7 +1497,7 @@ func _getOSVersion() -> OSVersion {
return .ps4
#elseif os(Android)
return .android
#elseif os(Windows) && CYGWIN
#elseif os(Cygwin)
return .windowsCygnus
#elseif os(Windows)
return .windows
Expand Down
11 changes: 6 additions & 5 deletions stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
import Glibc
#endif


#if !os(Windows) || CYGWIN
// posix_spawn is not available on Android or Windows.
#if !os(Windows)
// posix_spawn is not available on Windows.
// posix_spawn is not available on Android.
#if !os(Android)
// swift_posix_spawn isn't available in the public watchOS SDK, we sneak by the
// unavailable attribute declaration here of the APIs that we need.
Expand Down Expand Up @@ -264,7 +265,7 @@ public enum ProcessTerminationStatus : CustomStringConvertible {

public func posixWaitpid(_ pid: pid_t) -> ProcessTerminationStatus {
var status: CInt = 0
#if CYGWIN
#if os(Cygwin)
withUnsafeMutablePointer(to: &status) {
statusPtr in
let statusPtrWrapper = __wait_status_ptr_t(__int_ptr: statusPtr)
Expand Down Expand Up @@ -304,7 +305,7 @@ internal func _getEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<CChar>?
return environ
#elseif os(Android)
return environ
#elseif CYGWIN
#elseif os(Cygwin)
return environ
#else
return __environ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
import Glibc
#elseif os(Windows)
import ucrt
#endif

#if !os(Windows) || CYGWIN
#if !os(Windows)
public func _stdlib_mkstemps(_ template: inout String, _ suffixlen: CInt) -> CInt {
#if os(Android)
preconditionFailure("mkstemps doesn't work on Android")
Expand Down Expand Up @@ -85,7 +85,7 @@ public struct _stdlib_fd_set {
}
}

#if !os(Windows) || CYGWIN
#if !os(Windows)
public func _stdlib_select(
_ readfds: inout _stdlib_fd_set, _ writefds: inout _stdlib_fd_set,
_ errorfds: inout _stdlib_fd_set, _ timeout: UnsafeMutablePointer<timeval>?
Expand All @@ -99,7 +99,7 @@ public func _stdlib_select(
let readAddr = readfds.baseAddress
let writeAddr = writefds.baseAddress
let errorAddr = errorfds.baseAddress
#if CYGWIN
#if os(Cygwin)
typealias fd_set = _types_fd_set
#endif
func asFdSetPtr(
Expand All @@ -125,10 +125,10 @@ public func _stdlib_select(
public func _stdlib_pipe() -> (readEnd: CInt, writeEnd: CInt, error: CInt) {
var fds: [CInt] = [0, 0]
let ret = fds.withUnsafeMutableBufferPointer { unsafeFds -> CInt in
#if !os(Windows) || CYGWIN
return pipe(unsafeFds.baseAddress)
#else
#if os(Windows)
return _pipe(unsafeFds.baseAddress, 0, 0)
#else
return pipe(unsafeFds.baseAddress)
#endif
}
return (readEnd: fds[0], writeEnd: fds[1], error: ret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
import Glibc
#endif

Expand Down Expand Up @@ -43,7 +43,7 @@ public var _stdlib_PTHREAD_BARRIER_SERIAL_THREAD: CInt {
}

public struct _stdlib_pthread_barrier_t {
#if CYGWIN || os(FreeBSD)
#if os(Cygwin) || os(FreeBSD)
var mutex: UnsafeMutablePointer<pthread_mutex_t?>?
var cond: UnsafeMutablePointer<pthread_cond_t?>?
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
import Glibc
#endif

Expand Down Expand Up @@ -59,7 +59,7 @@ internal func invokeBlockContext(
return context.run()
}

#if CYGWIN || os(FreeBSD)
#if os(Cygwin) || os(FreeBSD)
public typealias _stdlib_pthread_attr_t = UnsafePointer<pthread_attr_t?>
#else
public typealias _stdlib_pthread_attr_t = UnsafePointer<pthread_attr_t>
Expand Down
64 changes: 31 additions & 33 deletions stdlib/public/Platform/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,23 @@ public func snprintf(ptr: UnsafeMutablePointer<Int8>, _ len: Int, _ format: Unsa
// fcntl.h
//===----------------------------------------------------------------------===//

#if !os(Windows) || CYGWIN
#if os(Windows)
@_silgen_name("_swift_Platform_open")
func _swift_Platform_open(
_ path: UnsafePointer<CChar>,
_ oflag: Int32,
_ mode: mode_t
_ mode: Int32
) -> Int32
#else
@_silgen_name("_swift_Platform_open")
func _swift_Platform_open(
_ path: UnsafePointer<CChar>,
_ oflag: Int32,
_ mode: Int32
_ mode: mode_t
) -> Int32
#endif

#if !os(Windows) || CYGWIN
#if !os(Windows)
@_silgen_name("_swift_Platform_openat")
func _swift_Platform_openat(
_ fd: Int32,
Expand All @@ -174,7 +174,15 @@ public func open(
return _swift_Platform_open(path, oflag, 0)
}

#if !os(Windows) || CYGWIN
#if os(Windows)
public func open(
_ path: UnsafePointer<CChar>,
_ oflag: Int32,
_ mode: Int32
) -> Int32 {
return _swift_Platform_open(path, oflag, mode)
}
#else
public func open(
_ path: UnsafePointer<CChar>,
_ oflag: Int32,
Expand All @@ -199,17 +207,9 @@ public func openat(
) -> Int32 {
return _swift_Platform_openat(fd, path, oflag, mode)
}
#else
public func open(
_ path: UnsafePointer<CChar>,
_ oflag: Int32,
_ mode: Int32
) -> Int32 {
return _swift_Platform_open(path, oflag, mode)
}
#endif

#if !os(Windows) || CYGWIN
#if !os(Windows)
@_silgen_name("_swift_Platform_fcntl")
internal func _swift_Platform_fcntl(
_ fd: Int32,
Expand Down Expand Up @@ -248,7 +248,18 @@ public func fcntl(
}
#endif

#if !os(Windows) || CYGWIN
#if os(Windows)
public var S_IFMT: Int32 { return Int32(0xf000) }

public var S_IFREG: Int32 { return Int32(0x8000) }
public var S_IFDIR: Int32 { return Int32(0x4000) }
public var S_IFCHR: Int32 { return Int32(0x2000) }
public var S_IFIFO: Int32 { return Int32(0x1000) }

public var S_IREAD: Int32 { return Int32(0x0100) }
public var S_IWRITE: Int32 { return Int32(0x0080) }
public var S_IEXEC: Int32 { return Int32(0x0040) }
#else
public var S_IFMT: mode_t { return mode_t(0o170000) }
public var S_IFIFO: mode_t { return mode_t(0o010000) }
public var S_IFCHR: mode_t { return mode_t(0o020000) }
Expand Down Expand Up @@ -286,24 +297,13 @@ public var S_IREAD: mode_t { return S_IRUSR }
public var S_IWRITE: mode_t { return S_IWUSR }
public var S_IEXEC: mode_t { return S_IXUSR }
#endif
#else
public var S_IFMT: Int32 { return Int32(0xf000) }

public var S_IFREG: Int32 { return Int32(0x8000) }
public var S_IFDIR: Int32 { return Int32(0x4000) }
public var S_IFCHR: Int32 { return Int32(0x2000) }
public var S_IFIFO: Int32 { return Int32(0x1000) }

public var S_IREAD: Int32 { return Int32(0x0100) }
public var S_IWRITE: Int32 { return Int32(0x0080) }
public var S_IEXEC: Int32 { return Int32(0x0040) }
#endif

//===----------------------------------------------------------------------===//
// ioctl.h
//===----------------------------------------------------------------------===//

#if !os(Windows) || CYGWIN
#if !os(Windows)
@_silgen_name("_swift_Platform_ioctl")
internal func _swift_Platform_ioctl(
_ fd: CInt,
Expand Down Expand Up @@ -380,8 +380,7 @@ public var SIG_ERR: sighandler_t {
public var SIG_HOLD: sighandler_t {
return unsafeBitCast(2, to: sighandler_t.self)
}
#elseif os(Windows)
#if CYGWIN
#elseif os(Cygwin)
public typealias sighandler_t = _sig_func_ptr

public var SIG_DFL: sighandler_t? { return nil }
Expand All @@ -394,15 +393,14 @@ public var SIG_ERR: sighandler_t {
public var SIG_HOLD: sighandler_t {
return unsafeBitCast(2, to: sighandler_t.self)
}
#else
#elseif os(Windows)
public var SIG_DFL: _crt_signal_t? { return nil }
public var SIG_IGN: _crt_signal_t {
return unsafeBitCast(1, to: _crt_signal_t.self)
}
public var SIG_ERR: _crt_signal_t {
return unsafeBitCast(-1, to: _crt_signal_t.self)
}
#endif
#else
internal var _ignore = _UnsupportedPlatformError()
#endif
Expand All @@ -411,13 +409,13 @@ internal var _ignore = _UnsupportedPlatformError()
// semaphore.h
//===----------------------------------------------------------------------===//

#if !os(Windows) || CYGWIN
#if !os(Windows)
/// The value returned by `sem_open()` in the case of failure.
public var SEM_FAILED: UnsafeMutablePointer<sem_t>? {
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
return UnsafeMutablePointer<sem_t>(bitPattern: -1)
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || CYGWIN
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin)
// The value is ABI. Value verified to be correct on Glibc.
return UnsafeMutablePointer<sem_t>(bitPattern: 0)
#else
Expand Down
Loading