Skip to content

Commit 8ff74e3

Browse files
authored
Workaround in ZipArchiver when posix_spawn_file_actions_addchdir_np is unavailable (#7187)
Motivation: `swift package-registry publish` tool doesn't work in Amazon Linux 2 because it has an older version of Glibc that doesn't support `posix_spawn_file_actions_addchdir_np`. Modifications: Add workaround in `ZipArchiver` that does `cd <working directory> && zip ...` when `posix_spawn_file_actions_addchdir_np` is not available.
1 parent 6995433 commit 8ff74e3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Sources/Basics/Archiver/ZipArchiver.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2022 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -91,9 +91,18 @@ public struct ZipArchiver: Archiver, Cancellable {
9191
workingDirectory: directory.parentDirectory.underlying
9292
)
9393
#else
94+
// This is to work around `swift package-registry publish` tool failing on
95+
// Amazon Linux 2 due to it having an earlier Glibc version (rdar://116370323)
96+
// and therefore posix_spawn_file_actions_addchdir_np is unavailable.
97+
// Instead of passing `workingDirectory` param to TSC.Process, which will trigger
98+
// SPM_posix_spawn_file_actions_addchdir_np_supported check, we shell out and
99+
// do `cd` explicitly before `zip`.
94100
let process = TSCBasic.Process(
95-
arguments: ["zip", "-r", destinationPath.pathString, directory.basename],
96-
workingDirectory: directory.parentDirectory.underlying
101+
arguments: [
102+
"/bin/sh",
103+
"-c",
104+
"cd \(directory.parentDirectory.underlying.pathString) && zip -r \(destinationPath.pathString) \(directory.basename)",
105+
]
97106
)
98107
#endif
99108

0 commit comments

Comments
 (0)