Skip to content

Commit 9d987fe

Browse files
committed
stdlib: use stubs for unit tests as well
This unifies the behaviour for imports across the private libc extras and the public libc shims.
1 parent ee1f150 commit 9d987fe

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_swift_library(swiftSwiftPrivateLibcExtras SHARED IS_STDLIB
1313
# This file should be listed the first. Module name is inferred from the
1414
# filename.
1515
SwiftPrivateLibcExtras.swift
16+
Subprocess.c
1617
Subprocess.swift
1718

1819
SWIFT_MODULE_DEPENDS ${swift_private_darwin_extras_module_depends}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//===--- Subprocess.cpp - Subprocess Stubs --------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// NOTE: preprocess away the availability information to allow use of
14+
// unsupported APIs on certain targets (i.e. tvOS)
15+
#define availability(...)
16+
#include <spawn.h>
17+
#include <sys/types.h>
18+
#if defined(__APPLE__)
19+
// NOTE: forward declare this rather than including crt_externs.h as not all
20+
// SDKs provide it
21+
extern char ***_NSGetEnviron(void);
22+
#endif
23+
24+
int swift_posix_spawn_file_actions_init(
25+
posix_spawn_file_actions_t *file_actions) {
26+
return posix_spawn_file_actions_init(file_actions);
27+
}
28+
29+
int swift_posix_spawn_file_actions_destroy(
30+
posix_spawn_file_actions_t *file_actions) {
31+
return posix_spawn_file_actions_destroy(file_actions);
32+
}
33+
34+
int swift_posix_spawn_file_actions_addclose(
35+
posix_spawn_file_actions_t *file_actions, int filedes) {
36+
return posix_spawn_file_actions_addclose(file_actions, filedes);
37+
}
38+
39+
int swift_posix_spawn_file_actions_adddup2(
40+
posix_spawn_file_actions_t *file_actions, int filedes, int newfiledes) {
41+
return posix_spawn_file_actions_adddup2(file_actions, filedes, newfiledes);
42+
}
43+
44+
int swift_posix_spawn(pid_t *__restrict pid, const char * __restrict path,
45+
const posix_spawn_file_actions_t *file_actions,
46+
const posix_spawnattr_t *__restrict attrp,
47+
char *const argv[__restrict],
48+
char *const envp[__restrict]) {
49+
return posix_spawn(pid, path, file_actions, attrp, argv, envp);
50+
}
51+
52+
#if defined(__APPLE__)
53+
char ***swift_SwiftPrivateLibcExtras_NSGetEnviron(void) {
54+
return _NSGetEnviron();
55+
}
56+
#endif
57+

stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@ typealias swift_posix_spawn_file_actions_t = posix_spawn_file_actions_t
3131
typealias swift_posix_spawn_file_actions_t = posix_spawn_file_actions_t?
3232
#endif
3333

34-
@_silgen_name("posix_spawn_file_actions_init")
34+
@_silgen_name("swift_posix_spawn_file_actions_init")
3535
func swift_posix_spawn_file_actions_init(
3636
_ file_actions: UnsafeMutablePointer<swift_posix_spawn_file_actions_t>
3737
) -> CInt
3838

39-
@_silgen_name("posix_spawn_file_actions_destroy")
39+
@_silgen_name("swift_posix_spawn_file_actions_destroy")
4040
func swift_posix_spawn_file_actions_destroy(
4141
_ file_actions: UnsafeMutablePointer<swift_posix_spawn_file_actions_t>
4242
) -> CInt
4343

44-
@_silgen_name("posix_spawn_file_actions_addclose")
44+
@_silgen_name("swift_posix_spawn_file_actions_addclose")
4545
func swift_posix_spawn_file_actions_addclose(
4646
_ file_actions: UnsafeMutablePointer<swift_posix_spawn_file_actions_t>,
4747
_ filedes: CInt) -> CInt
4848

49-
@_silgen_name("posix_spawn_file_actions_adddup2")
49+
@_silgen_name("swift_posix_spawn_file_actions_adddup2")
5050
func swift_posix_spawn_file_actions_adddup2(
5151
_ file_actions: UnsafeMutablePointer<swift_posix_spawn_file_actions_t>,
5252
_ filedes: CInt,
5353
_ newfiledes: CInt) -> CInt
5454

55-
@_silgen_name("posix_spawn")
55+
@_silgen_name("swift_posix_spawn")
5656
func swift_posix_spawn(
5757
_ pid: UnsafeMutablePointer<pid_t>?,
5858
_ file: UnsafePointer<Int8>,
@@ -276,7 +276,7 @@ public func posixWaitpid(_ pid: pid_t) -> ProcessTerminationStatus {
276276
}
277277

278278
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
279-
@_silgen_name("_NSGetEnviron")
279+
@_silgen_name("swift_SwiftPrivateLibcExtras_NSGetEnviron")
280280
func _NSGetEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>>
281281
#endif
282282

0 commit comments

Comments
 (0)