5 Commits
2.0.0 ... main

Author SHA1 Message Date
T. R. Bernstein
10943f9ce3 Make events property of Inotify nonisolated
Some checks failed
Docs / docs (push) Has been cancelled
Docs / deploy (push) Has been cancelled
Properties of actors are implicitly isolated. To be able to read the
events stream from any concurrent context, we need to declare it
nonisolated. And as AsyncStream conforms to Sendable, it is safe to make
both events and the private eventStream nonisolated.
2026-03-23 20:15:57 +01:00
T. R. Bernstein
6927464d47 Use Subprocess instead of Shwift
Some checks failed
Docs / docs (push) Has been cancelled
Docs / deploy (push) Has been cancelled
Drop Shwift: it is incompatible with musl (used by the Swift static
linking SDK), and its API is not meaningfully more concise than
Subprocess upon closer inspection.
2026-03-23 19:50:58 +01:00
T. R. Bernstein
31ed16c828 Cache build directory of linux containers
SwiftPM uses caches heavily to reduce compilation and download time.
Before this change, we through these caches away with each container.
2026-03-22 17:51:24 +01:00
T. R. Bernstein
ac1c86c431 Run linux container with same architechture as host
As the development team uses both Intel and Apple Silicon Macs,
we have to get the host CPU architecture at compilation time instead of
harcoding it.
If the container has a different architecture, the guest has to be
emulated.
2026-03-22 17:51:24 +01:00
T. R. Bernstein
4b28c293cb Use Shwift library instead of Subprocess
Shwift has a concise API, which makes writing shell code nice and easy.
This is an opinionated decision.
2026-03-22 17:51:05 +01:00
6 changed files with 55 additions and 57 deletions

View File

@@ -1,5 +1,5 @@
{
"originHash" : "fd1e824e418c767633bb79b055a4e84d9c86165746bc881d5d27457ad34b0c20",
"originHash" : "17ce26ba5c862ca674cd3ceeb43a9fe8a5c5251c5561de65e632a06d79916342",
"pins" : [
{
"identity" : "noora",
@@ -33,17 +33,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "c5d11a805e765f52ba34ec7284bd4fcd6ba68615",
"version" : "1.7.0"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms",
"state" : {
"revision" : "9d349bcc328ac3c31ce40e746b5882742a0d1272",
"version" : "1.1.3"
"revision" : "626b5b7b2f45e1b0b1c6f4a309296d1d21d7311b",
"version" : "1.7.1"
}
},
{

View File

@@ -11,8 +11,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0"),
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.1.3"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.1"),
.package(url: "https://github.com/apple/swift-log", from: "1.10.1"),
.package(url: "https://github.com/apple/swift-nio", from: "2.95.0"),
.package(url: "https://github.com/apple/swift-system", from: "1.6.4"),
@@ -41,7 +40,6 @@ let package = Package(
name: "InotifyTaskCLI",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "Logging", package: "swift-log"),
.product(name: "_NIOFileSystem", package: "swift-nio"),
.product(name: "Subprocess", package: "swift-subprocess"),

View File

@@ -6,8 +6,8 @@ public actor Inotify {
private var excludedItemNames: Set<String> = []
private var watches = InotifyWatchManager()
private var eventReader: any DispatchSourceRead
private var eventStream: AsyncStream<RawInotifyEvent>
public var events: AsyncCompactMapSequence<AsyncStream<RawInotifyEvent>, InotifyEvent> {
private nonisolated let eventStream: AsyncStream<RawInotifyEvent>
public nonisolated var events: AsyncCompactMapSequence<AsyncStream<RawInotifyEvent>, InotifyEvent> {
self.eventStream.compactMap(self.transform(_:))
}

View File

@@ -0,0 +1,9 @@
struct Docker {
static func getLinuxPlatformStringWithHostArchitecture() -> String {
#if arch(x86_64)
return "linux/amd64"
#else
return "linux/arm64"
#endif
}
}

View File

@@ -1,5 +1,4 @@
import ArgumentParser
import AsyncAlgorithms
import Foundation
import Logging
import Noora
@@ -43,28 +42,21 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
let script = Self.makeRunScript(for: targets)
logger.debug("Container script", metadata: ["script": "\(script)"])
let dockerResult = try await Subprocess.run(
let dockerRunResult = try await Subprocess.run(
.name("docker"),
arguments: [
"run", "--rm",
"-v", "\(tempDirectory.path(percentEncoded: false)):/code",
"--platform", "linux/arm64",
"-v", "\(tempDirectory.path):/code",
"-v", "swift-inotify-build-cache:/code/.build",
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
"-w", "/code",
"swift:latest",
"/bin/bash", "-c", script,
"/bin/bash", "-c", script
],
preferredBufferSize: 10,
) { execution, standardInput, standardOutput, standardError in
print("")
let stdout = standardOutput.lines()
let stderr = standardError.lines()
for try await line in merge(stdout, stderr) {
noora.passthrough("\(line)")
}
print("")
}
guard dockerResult.terminationStatus.isSuccess else {
output: .standardOutput,
error: .standardError
)
if !dockerRunResult.terminationStatus.isSuccess {
noora.error("Documentation generation failed.")
return
}
@@ -116,10 +108,11 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
}
private static func packageTargets() async throws -> [(name: String, path: String)] {
let packageDescription = try await Subprocess.run(
let packageDescriptionResult = try await Subprocess.run(
.name("swift"),
arguments: ["package", "describe", "--type", "json"],
output: .data(limit: 20_000)
output: .data(limit: 10_000),
error: .standardError
)
struct PackageDescription: Codable {
@@ -130,7 +123,11 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
let path: String
}
let package = try JSONDecoder().decode(PackageDescription.self, from: packageDescription.standardOutput)
if !packageDescriptionResult.terminationStatus.isSuccess {
throw GenerateDocumentationError.unableToReadPackageDescription
}
let package = try JSONDecoder().decode(PackageDescription.self, from: packageDescriptionResult.standardOutput)
return package.targets.map { ($0.name, $0.path) }
}
@@ -175,15 +172,16 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
// MARK: - Dependency Injection
private func injectDoccPluginDependency(in directory: URL, logger: Logger) async throws {
let result = try await Subprocess.run(
let swiftRunResult = try await Subprocess.run(
.name("swift"),
arguments: [
"package", "--package-path", directory.path(percentEncoded: false),
"add-dependency", "--from", Self.doccPluginMinVersion, Self.doccPluginURL
],
) { _ in }
guard result.terminationStatus.isSuccess else {
output: .standardOutput,
error: .standardError
)
if !swiftRunResult.terminationStatus.isSuccess {
throw GenerateDocumentationError.dependencyInjectionFailed
}
@@ -193,11 +191,14 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
enum GenerateDocumentationError: Error, CustomStringConvertible {
case dependencyInjectionFailed
case unableToReadPackageDescription
var description: String {
switch self {
case .dependencyInjectionFailed:
"Failed to add swift-docc-plugin dependency to Package.swift."
case .unableToReadPackageDescription:
"Failed to read the package description."
}
}
}

View File

@@ -1,8 +1,7 @@
import ArgumentParser
import AsyncAlgorithms
import Foundation
import Subprocess
import Noora
import Subprocess
struct TestCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
@@ -22,21 +21,21 @@ struct TestCommand: AsyncParsableCommand {
noora.info("Running tests on Linux.")
logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"])
async let monitorResult = Subprocess.run(
let dockerRunResult = try await Subprocess.run(
.name("docker"),
arguments: ["run", "-v", "\(currentDirectory):/code", "--security-opt", "systempaths=unconfined", "--platform", "linux/arm64", "-w", "/code", "swift:latest", "/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"],
preferredBufferSize: 10,
) { execution, standardInput, standardOutput, standardError in
print("")
let stdout = standardOutput.lines()
let stderr = standardError.lines()
for try await line in merge(stdout, stderr) {
noora.passthrough("\(line)")
}
print("")
}
if (try await monitorResult.terminationStatus.isSuccess) {
arguments: [
"run",
"-v", "\(currentDirectory):/code",
"-v", "swift-inotify-build-cache:/code/.build",
"--security-opt", "systempaths=unconfined",
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
"-w", "/code", "swift:latest",
"/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"
],
output: .standardOutput,
error: .standardError
)
if dockerRunResult.terminationStatus.isSuccess {
noora.success("All tests completed successfully.")
} else {
noora.error("Not all tests completed successfully.")