Skip to content

Commit b13c3c6

Browse files
committed
Remove the dependency on libreadline
It was only active on macOS and Linux but not other platforms due to existing dependency complexities, and just isn't that useful overall. This will help unblock swiftlang/swift-package-manager#8271 without having to add new dependencies to the Swift Docker images.
1 parent b1dea33 commit b13c3c6

File tree

7 files changed

+4
-127
lines changed

7 files changed

+4
-127
lines changed

Package.swift

-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ let appleOS = false
2222

2323
let useLocalDependencies = Context.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil
2424
let useLLBuildFramework = Context.environment["SWIFTBUILD_LLBUILD_FWK"] != nil
25-
let readlinePackage = !appleOS ? "readline" : nil
2625

2726
let swiftSettings: [SwiftSetting] = [
2827
// Upcoming Swift 6.0 features
@@ -162,7 +161,6 @@ let package = Package(
162161
dependencies: [
163162
"SWBCSupport",
164163
"SWBLibc",
165-
.target(name: "readline", condition: .when(platforms: [.linux])),
166164
.product(name: "ArgumentParser", package: "swift-argument-parser"),
167165
.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux, .android])),
168166
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .android, .windows])),
@@ -343,17 +341,6 @@ let package = Package(
343341
dependencies: ["SwiftBuild", "SWBTestSupport", "SwiftBuildTestSupport"],
344342
swiftSettings: swiftSettings),
345343

346-
// System libraries
347-
.systemLibrary(
348-
name: "readline",
349-
path: "Packages/Sources/readline",
350-
pkgConfig: readlinePackage,
351-
providers: [
352-
.apt(["libreadline-dev"]),
353-
.yum(["readline-devel"]),
354-
]
355-
),
356-
357344
// Commands
358345
.plugin(
359346
name: "launch-xcode",

Packages/.gitignore

-4
This file was deleted.

Packages/Sources/readline/module.modulemap

-5
This file was deleted.

Packages/Sources/readline/sdk_readline.h

-14
This file was deleted.

Sources/SWBCSupport/SWBCSupport.h

-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
#include <TargetConditionals.h>
2020
#endif
2121

22-
#ifndef __APPLE__
23-
// Re-exported from readline
24-
char *readline(const char *);
25-
int add_history(const char *);
26-
int read_history(const char *);
27-
int write_history(const char *);
28-
int history_truncate_file(const char *, int);
29-
#endif
30-
3122
#include "CLibclang.h"
3223
#include "CLibRemarksHelper.h"
3324
#include "PluginAPI.h"

Sources/SWBUtil/GNUReadLine.swift

-66
This file was deleted.

Sources/SwiftBuild/SWBTerminal.swift

+4-16
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,19 @@ import SWBUtil
1515

1616
import Foundation
1717

18-
let kHistoryFilePath = "~/.swbuild_history"
19-
let kMaxHistoryLines = 100
20-
2118
func swbuild_handle_command_result(result: SWBServiceConsoleResult) {
2219
print(result.output, terminator: "")
2320
}
2421

2522
/// Process a command line.
2623
///
2724
/// - returns: True if the console should continue handling commands, otherwise the console should quit.
28-
func swbuild_process_command(console: SWBBuildServiceConsole, command: String, historyPath: String) async -> (shouldContinue: Bool, success: Bool) {
25+
func swbuild_process_command(console: SWBBuildServiceConsole, command: String) async -> (shouldContinue: Bool, success: Bool) {
2926
// Ignore empty commands.
3027
if command.isEmpty {
3128
return (true, true)
3229
}
3330

34-
// Add the line to the history.
35-
swb_add_history(command)
36-
swb_write_history(historyPath)
37-
swb_history_truncate_file(historyPath, kMaxHistoryLines)
38-
3931
// Process the line.
4032
let (result, success) = await console.sendCommandString(command)
4133
swbuild_handle_command_result(result: result)
@@ -71,24 +63,20 @@ func swbuild_repl() async throws -> Bool {
7163
// Save the terminal attributes (and restore them and exit).
7264
return try await withTerminalAttributes { terminalAttributes in
7365
return try await withServiceConsole { console in
74-
let historyPath = (kHistoryFilePath as NSString).expandingTildeInPath
75-
76-
// Read in the command history.
77-
swb_read_history(historyPath)
78-
7966
// Disable echo, after all readline initialization is done.
8067
terminalAttributes.disableEcho()
8168

8269
var ok = true
8370
var shouldContinue = true
8471
while shouldContinue {
85-
guard let line = swb_readline("swbuild> ") else {
72+
print("swbuild> ", terminator: "")
73+
guard let line = readLine() else {
8674
// If we received the EOF then exit.
8775
print()
8876
break
8977
}
9078

91-
(shouldContinue, ok) = await swbuild_process_command(console: console, command: line, historyPath: historyPath)
79+
(shouldContinue, ok) = await swbuild_process_command(console: console, command: line)
9280
}
9381

9482
return ok

0 commit comments

Comments
 (0)