Skip to content

Commit 5aab44a

Browse files
authored
Avoid error if missing xattr support (#690)
When building on a darwin host (e.g. macOS) using a file-system that doesn't support xattrs (e.g. tmpfs) swift-build would fail trying to set the "CreatedByBuildSystem" xattribute. This commit changes swift-build to warn instead, allowing the build to complete.
1 parent ded59bc commit 5aab44a

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Sources/SWBCore/WorkspaceContext.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,21 @@ extension FSProxy {
401401
return try getExtendedAttribute(path, key: Self.CreatedByBuildSystemAttribute) == Self.CreatedByBuildSystemAttributeOnValue
402402
}
403403

404+
/// Sets the "CreatedByBuildSystem" extended attribute on the specified
405+
/// path.
406+
///
407+
/// - Important: The caller is responsible for catching and handling
408+
/// failures if the filesystem does not support extended attributes. Many
409+
/// filesystems (e.g. various non-ext4 temporary filesystems on Linux)
410+
/// don't support xattrs and will return `ENOTSUP`. In particular, tmpfs
411+
/// doesn't support xattrs on Linux unless `CONFIG_TMPFS_XATTR` is enabled
412+
/// in the kernel config.
413+
///
414+
/// - Parameter path: The path on which to set the extended attribute.
415+
/// - Throws: An error if the operation fails, including when the filesystem
416+
/// doesn't support extended attributes.
404417
public func setCreatedByBuildSystemAttribute(_ path: Path) throws {
405-
// Many filesystems on other platforms (e.g. various non-ext4 temporary filesystems on Linux) don't support xattrs and will return ENOTSUP.
406-
// In particular, tmpfs doesn't support xattrs on Linux unless `CONFIG_TMPFS_XATTR` is enabled in the kernel config.
407-
// FIXME: Detect whether the FS supports xattrs at runtime
408-
#if canImport(Darwin)
409418
try setExtendedAttribute(path, key: Self.CreatedByBuildSystemAttribute, value: Self.CreatedByBuildSystemAttributeOnValue)
410-
#endif
411419
}
412420

413421
public func commandLineArgumentsToApplyCreatedByBuildSystemAttribute(to path: Path) -> [String] {

Sources/SWBTaskExecution/TaskActions/CreateBuildDirectoryTaskAction.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@ public final class CreateBuildDirectoryTaskAction: TaskAction {
2828

2929
do {
3030
try fs.createDirectory(directoryPath, recursive: true)
31-
try fs.setCreatedByBuildSystemAttribute(directoryPath)
32-
return .succeeded
3331
} catch {
3432
outputDelegate?.emitError(error.localizedDescription)
3533
return .failed
3634
}
35+
36+
// Warn on Darwin if we are unable to set the "CreatedByBuildSystem"
37+
// attribute
38+
do {
39+
try fs.setCreatedByBuildSystemAttribute(directoryPath)
40+
} catch {
41+
#if canImport(Darwin)
42+
outputDelegate?.emitWarning("Failed to set build system attribute on \(directoryPath.str): \(error.localizedDescription)")
43+
#endif
44+
}
45+
46+
return .succeeded
3747
}
3848

3949
public override func performTaskAction(

0 commit comments

Comments
 (0)