Skip to content

Commit 34096c8

Browse files
committed
Fix the Android build
1 parent f2a5c16 commit 34096c8

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

Sources/Basics/Concurrency/AsyncProcess.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,9 @@ package final class AsyncProcess {
567567
return stdinPipe.fileHandleForWriting
568568
#elseif(!canImport(Darwin) || os(macOS))
569569
// Initialize the spawn attributes.
570-
#if canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
570+
#if os(Android)
571+
var attributes: posix_spawnattr_t! = nil
572+
#elseif canImport(Darwin) || os(OpenBSD) || os(FreeBSD)
571573
var attributes: posix_spawnattr_t? = nil
572574
#else
573575
var attributes = posix_spawnattr_t()
@@ -612,7 +614,9 @@ package final class AsyncProcess {
612614
posix_spawnattr_setflags(&attributes, Int16(flags))
613615

614616
// Setup the file actions.
615-
#if canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
617+
#if os(Android)
618+
var fileActions: posix_spawn_file_actions_t! = nil
619+
#elseif canImport(Darwin) || os(Android) || os(OpenBSD) || os(FreeBSD)
616620
var fileActions: posix_spawn_file_actions_t? = nil
617621
#else
618622
var fileActions = posix_spawn_file_actions_t()

Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ private func readpassword(_ prompt: String) throws -> String {
8282

8383
return String(cString: passwordPtr)
8484
}
85+
#elseif canImport(Android)
86+
throw StringError("unable to read input - not implemented on this platform")
8587
#else
8688
// GNU C implementation of getpass has no limit on the password length
8789
// (https://man7.org/linux/man-pages/man3/getpass.3.html)

Sources/SPMBuildCore/Plugins/DefaultPluginScriptRunner.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import class Basics.AsyncProcess
2323

2424
import struct TSCUtility.SerializedDiagnostics
2525

26+
#if os(Android)
27+
import Android
28+
#endif
29+
2630
/// A plugin script runner that compiles the plugin source files as an executable binary for the host platform, and invokes it as a subprocess.
2731
public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
2832
private let fileSystem: FileSystem
@@ -51,7 +55,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
5155
self.cancellator = Cancellator(observabilityScope: .none)
5256
self.verboseOutput = verboseOutput
5357
}
54-
58+
5559
/// Starts evaluating a plugin by compiling it and running it as a subprocess. The name is used as the basename for the executable and auxiliary files. The tools version controls the availability of APIs in PackagePlugin, and should be set to the tools version of the package that defines the plugin (not the package containing the target to which it is being applied). This function returns immediately and then repeated calls the output handler on the given callback queue as plain-text output is received from the plugin, and then eventually calls the completion handler on the given callback queue once the plugin is done.
5660
public func runPluginScript(
5761
sourceFiles: [Basics.AbsolutePath],
@@ -109,7 +113,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
109113
public var hostTriple: Triple {
110114
return self.toolchain.targetTriple
111115
}
112-
116+
113117
/// Starts compiling a plugin script asynchronously and when done, calls the completion handler on the callback queue with the results (including the path of the compiled plugin executable and with any emitted diagnostics, etc). Existing compilation results that are still valid are reused, if possible. This function itself returns immediately after starting the compile. Note that the completion handler only receives a `.failure` result if the compiler couldn't be invoked at all; a non-zero exit code from the compiler still returns `.success` with a full compilation result that notes the error in the diagnostics (in other words, a `.failure` result only means "failure to invoke the compiler").
114118
public func compilePluginScript(
115119
sourceFiles: [Basics.AbsolutePath],
@@ -136,7 +140,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
136140

137141
// We use the toolchain's Swift compiler for compiling the plugin.
138142
var commandLine = [self.toolchain.swiftCompilerPathForManifests.pathString]
139-
143+
140144
observabilityScope.emit(debug: "Using compiler \(self.toolchain.swiftCompilerPathForManifests.pathString)")
141145

142146
// Get access to the path containing the PackagePlugin module and library.
@@ -246,7 +250,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
246250
completion(.failure(DefaultPluginScriptRunnerError.compilationPreparationFailed(error: error)))
247251
}
248252
}
249-
253+
250254
// Hash the compiler inputs to decide whether we really need to recompile.
251255
let compilerInputHash: String?
252256
do {
@@ -267,7 +271,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
267271
observabilityScope.emit(debug: "Couldn't compute hash of plugin compilation inputs", underlyingError: error)
268272
compilerInputHash = .none
269273
}
270-
274+
271275
/// Persisted information about the last time the compiler was invoked.
272276
struct PersistedCompilationState: Codable {
273277
var commandLine: [String]
@@ -279,7 +283,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
279283
case exit(code: Int32)
280284
case abnormal(exception: UInt32)
281285
case signal(number: Int32)
282-
286+
283287
init(_ processExitStatus: AsyncProcessResult.ExitStatus) {
284288
switch processExitStatus {
285289
case .terminated(let code):
@@ -294,12 +298,12 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
294298
}
295299
}
296300
}
297-
301+
298302
var succeeded: Bool {
299303
return result == .exit(code: 0)
300304
}
301305
}
302-
306+
303307
// Check if we already have a compiled executable and a persisted state (we only recompile if things have changed).
304308
let stateFilePath = self.cacheDir.appending(component: execName + "-state" + ".json")
305309
var compilationState: PersistedCompilationState? = .none
@@ -310,7 +314,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
310314
path: stateFilePath,
311315
fileSystem: fileSystem,
312316
as: PersistedCompilationState.self)
313-
317+
314318
// If it succeeded last time and the compiler inputs are the same, we don't need to recompile.
315319
if previousState.succeeded && previousState.inputHash == compilerInputHash {
316320
compilationState = previousState
@@ -321,7 +325,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
321325
observabilityScope.emit(debug: "Couldn't read previous compilation state", underlyingError: error)
322326
}
323327
}
324-
328+
325329
// If we still have a compilation state, it means the executable is still valid and we don't need to do anything.
326330
if let compilationState {
327331
// Just call the completion handler with the persisted results.
@@ -350,7 +354,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
350354
catch {
351355
observabilityScope.emit(debug: "Couldn't clean up before invoking compiler", underlyingError: error)
352356
}
353-
357+
354358
// Now invoke the compiler asynchronously.
355359
AsyncProcess.popen(arguments: commandLine, environment: environment, queue: callbackQueue) {
356360
// We are now on our caller's requested callback queue, so we just call the completion handler directly.
@@ -388,7 +392,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
388392

389393
// Tell the delegate that we're done compiling the plugin, passing it the result.
390394
delegate.didCompilePlugin(result: result)
391-
395+
392396
// Also return the result to the caller.
393397
return result
394398
})
@@ -487,7 +491,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
487491
process.environment = .init(env)
488492

489493
process.currentDirectoryURL = workingDirectory.asURL
490-
494+
491495
// Set up a pipe for sending structured messages to the plugin on its stdin.
492496
let stdinPipe = Pipe()
493497
let outputHandle = stdinPipe.fileHandleForWriting

Sources/swift-build-prebuilts/BuildPrebuilts.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ struct BuildPrebuilts: AsyncParsableCommand {
251251

252252
guard let swiftVersion = try computeSwiftVersion() else {
253253
print("Unable to determine swift compiler version")
254-
_exit(1)
254+
Foundation.exit(1)
255255
}
256256

257257
let id = "swift-syntax"
@@ -296,7 +296,7 @@ struct BuildPrebuilts: AsyncParsableCommand {
296296
let manifestURL = URL(string: prebuiltsUrl)?.appending(components: id, version, manifestFile)
297297
guard let manifestURL else {
298298
print("Invalid URL \(prebuiltsUrl)")
299-
_exit(1)
299+
Foundation.exit(1)
300300
}
301301

302302
var headers = HTTPClientHeaders()

0 commit comments

Comments
 (0)