Skip to content

Remove the dependency on libreadline #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let appleOS = false

let useLocalDependencies = Context.environment["SWIFTCI_USE_LOCAL_DEPS"] != nil
let useLLBuildFramework = Context.environment["SWIFTBUILD_LLBUILD_FWK"] != nil
let readlinePackage = !appleOS ? "readline" : nil

let swiftSettings: [SwiftSetting] = [
// Upcoming Swift 6.0 features
Expand Down Expand Up @@ -162,7 +161,6 @@ let package = Package(
dependencies: [
"SWBCSupport",
"SWBLibc",
.target(name: "readline", condition: .when(platforms: [.linux])),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux, .android])),
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .android, .windows])),
Expand Down Expand Up @@ -343,17 +341,6 @@ let package = Package(
dependencies: ["SwiftBuild", "SWBTestSupport", "SwiftBuildTestSupport"],
swiftSettings: swiftSettings),

// System libraries
.systemLibrary(
name: "readline",
path: "Packages/Sources/readline",
pkgConfig: readlinePackage,
providers: [
.apt(["libreadline-dev"]),
.yum(["readline-devel"]),
]
),

// Commands
.plugin(
name: "launch-xcode",
Expand Down
4 changes: 0 additions & 4 deletions Packages/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions Packages/Sources/readline/module.modulemap

This file was deleted.

14 changes: 0 additions & 14 deletions Packages/Sources/readline/sdk_readline.h

This file was deleted.

9 changes: 0 additions & 9 deletions Sources/SWBCSupport/SWBCSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
#include <TargetConditionals.h>
#endif

#ifndef __APPLE__
// Re-exported from readline
char *readline(const char *);
int add_history(const char *);
int read_history(const char *);
int write_history(const char *);
int history_truncate_file(const char *, int);
#endif

#include "CLibclang.h"
#include "CLibRemarksHelper.h"
#include "PluginAPI.h"
Expand Down
66 changes: 0 additions & 66 deletions Sources/SWBUtil/GNUReadLine.swift

This file was deleted.

20 changes: 4 additions & 16 deletions Sources/SwiftBuild/SWBTerminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,19 @@ import SWBUtil

import Foundation

let kHistoryFilePath = "~/.swbuild_history"
let kMaxHistoryLines = 100

func swbuild_handle_command_result(result: SWBServiceConsoleResult) {
print(result.output, terminator: "")
}

/// Process a command line.
///
/// - returns: True if the console should continue handling commands, otherwise the console should quit.
func swbuild_process_command(console: SWBBuildServiceConsole, command: String, historyPath: String) async -> (shouldContinue: Bool, success: Bool) {
func swbuild_process_command(console: SWBBuildServiceConsole, command: String) async -> (shouldContinue: Bool, success: Bool) {
// Ignore empty commands.
if command.isEmpty {
return (true, true)
}

// Add the line to the history.
swb_add_history(command)
swb_write_history(historyPath)
swb_history_truncate_file(historyPath, kMaxHistoryLines)

// Process the line.
let (result, success) = await console.sendCommandString(command)
swbuild_handle_command_result(result: result)
Expand Down Expand Up @@ -71,24 +63,20 @@ func swbuild_repl() async throws -> Bool {
// Save the terminal attributes (and restore them and exit).
return try await withTerminalAttributes { terminalAttributes in
return try await withServiceConsole { console in
let historyPath = (kHistoryFilePath as NSString).expandingTildeInPath

// Read in the command history.
swb_read_history(historyPath)

// Disable echo, after all readline initialization is done.
terminalAttributes.disableEcho()

var ok = true
var shouldContinue = true
while shouldContinue {
guard let line = swb_readline("swbuild> ") else {
print("swbuild> ", terminator: "")
guard let line = readLine() else {
// If we received the EOF then exit.
print()
break
}

(shouldContinue, ok) = await swbuild_process_command(console: console, command: line, historyPath: historyPath)
(shouldContinue, ok) = await swbuild_process_command(console: console, command: line)
}

return ok
Expand Down