Rename swift-gtk-gen to gobject-generator with generator binary
This commit is contained in:
parent
d6fabd56ed
commit
f305df0eff
44 changed files with 67 additions and 69 deletions
|
|
@ -13,31 +13,31 @@ let pluginSettings: [SwiftSetting] = [
|
|||
]
|
||||
|
||||
let package = Package(
|
||||
name: "gir-generator",
|
||||
name: "gobject-generator",
|
||||
platforms: [.macOS(.v14)],
|
||||
products: [
|
||||
.executable(name: "swift-gtk-gen", targets: ["swift-gtk-gen"]),
|
||||
.plugin(name: "SwiftGtkGenCommandPlugin", targets: ["SwiftGtkGenCommandPlugin"]),
|
||||
.executable(name: "generator", targets: ["generator"]),
|
||||
.plugin(name: "GObjectGeneratorCommandPlugin", targets: ["GObjectGeneratorCommandPlugin"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/swiftlang/swift-format.git", branch: "release/6.3")
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "SwiftGtkGenCore",
|
||||
name: "GObjectGeneratorCore",
|
||||
dependencies: [],
|
||||
swiftSettings: concurrencySettings
|
||||
),
|
||||
.executableTarget(
|
||||
name: "swift-gtk-gen",
|
||||
name: "generator",
|
||||
dependencies: [
|
||||
"SwiftGtkGenCore",
|
||||
"GObjectGeneratorCore",
|
||||
.product(name: "SwiftFormat", package: "swift-format"),
|
||||
],
|
||||
swiftSettings: concurrencySettings
|
||||
),
|
||||
.plugin(
|
||||
name: "SwiftGtkGenCommandPlugin",
|
||||
name: "GObjectGeneratorCommandPlugin",
|
||||
capability: .command(
|
||||
intent: .custom(
|
||||
verb: "generate-gir-bindings",
|
||||
|
|
@ -45,22 +45,22 @@ let package = Package(
|
|||
),
|
||||
permissions: [.writeToPackageDirectory(reason: "Write generated Swift files to source directory.")]
|
||||
),
|
||||
dependencies: ["swift-gtk-gen"],
|
||||
path: "Sources/SwiftGtkGenCommandPlugin"
|
||||
dependencies: ["generator"],
|
||||
path: "Sources/GObjectGeneratorCommandPlugin"
|
||||
),
|
||||
.testTarget(
|
||||
name: "SwiftGtkGenCoreTests",
|
||||
dependencies: ["SwiftGtkGenCore"],
|
||||
name: "GObjectGeneratorCoreTests",
|
||||
dependencies: ["GObjectGeneratorCore"],
|
||||
swiftSettings: concurrencySettings
|
||||
),
|
||||
.testTarget(
|
||||
name: "SwiftGtkGenCLITests",
|
||||
dependencies: ["SwiftGtkGenCore"],
|
||||
name: "GObjectGeneratorCLITests",
|
||||
dependencies: ["GObjectGeneratorCore"],
|
||||
swiftSettings: concurrencySettings
|
||||
),
|
||||
.testTarget(
|
||||
name: "IntegrationTests",
|
||||
dependencies: ["SwiftGtkGenCore"],
|
||||
dependencies: ["GObjectGeneratorCore"],
|
||||
swiftSettings: concurrencySettings
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ Reads GObject Introspection (`.gir`) XML files and produces low-level Swift wrap
|
|||
## Usage
|
||||
|
||||
```bash
|
||||
swift-gtk-gen --gir-file /usr/share/gir-1.0/Gtk-4.0.gir --output ./Gtk
|
||||
generator --gir-file /usr/share/gir-1.0/Gtk-4.0.gir --output ./Gtk
|
||||
```
|
||||
|
||||
Library name and version are derived automatically from the GIR file's `<namespace>` element. Override via `config.toml` (see below).
|
||||
|
|
@ -54,15 +54,14 @@ rename = "Alignment"
|
|||
### Generate all types
|
||||
|
||||
```bash
|
||||
swift-gtk-gen --gir-file Gtk-4.0.gir --output ./Gtk --generate-all
|
||||
generator --gir-file Gtk-4.0.gir --output ./Gtk --generate-all
|
||||
```
|
||||
|
||||
### Generate specific types
|
||||
|
||||
```bash
|
||||
swift-gtk-gen --gir-file Gtk-4.0.gir --output ./Gtk \
|
||||
generator --gir-file Gtk-4.0.gir --output ./Gtk \
|
||||
--generate Gtk.Widget,Gtk.Window,Gtk.Button,Gtk.Align
|
||||
```
|
||||
|
||||
## Output Structure
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import Foundation
|
|||
/// SwiftPM command plugin for manual GIR binding regeneration.
|
||||
///
|
||||
/// Invoked via `swift package generate-gir-bindings`. Forwards all
|
||||
/// user-provided arguments directly to the `swift-gtk-gen` monorepo CLI,
|
||||
/// user-provided arguments directly to the `generator` monorepo CLI,
|
||||
/// defaulting `--output` to the package directory when the caller omits it.
|
||||
/// The generator itself decides what to plan, render, and write from the
|
||||
/// monorepo TOML config passed via `--monorepo-config`.
|
||||
@main
|
||||
struct SwiftGtkGenCommandPlugin: CommandPlugin {
|
||||
/// Runs `swift-gtk-gen` as a subprocess with the caller's arguments.
|
||||
struct GObjectGeneratorCommandPlugin: CommandPlugin {
|
||||
/// Runs `generator` as a subprocess with the caller's arguments.
|
||||
///
|
||||
/// Stdout and stderr are piped through to the caller. Throws if the
|
||||
/// subprocess exits non-zero.
|
||||
|
|
@ -25,7 +25,7 @@ struct SwiftGtkGenCommandPlugin: CommandPlugin {
|
|||
return
|
||||
}
|
||||
|
||||
let executable = try context.tool(named: "swift-gtk-gen")
|
||||
let executable = try context.tool(named: "generator")
|
||||
|
||||
var procArgs = arguments
|
||||
if !procArgs.contains("--output") {
|
||||
|
|
@ -54,23 +54,23 @@ struct SwiftGtkGenCommandPlugin: CommandPlugin {
|
|||
}
|
||||
|
||||
guard process.terminationStatus == 0 else {
|
||||
throw SwiftGtkGenPluginError.generationFailed
|
||||
throw GObjectGeneratorPluginError.generationFailed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors that can occur during command-plugin GIR generation.
|
||||
enum SwiftGtkGenPluginError: Error {
|
||||
/// The `swift-gtk-gen` subprocess exited non-zero.
|
||||
enum GObjectGeneratorPluginError: Error {
|
||||
/// The `generator` subprocess exited non-zero.
|
||||
case generationFailed
|
||||
}
|
||||
|
||||
extension SwiftGtkGenPluginError: CustomStringConvertible {
|
||||
extension GObjectGeneratorPluginError: CustomStringConvertible {
|
||||
/// A human-readable description of the error.
|
||||
var description: String {
|
||||
switch self {
|
||||
case .generationFailed:
|
||||
return "swift-gtk-gen generation failed; see output above for details."
|
||||
return "gobject-generator generation failed; see output above for details."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public struct CodeGenerator {
|
|||
/// available through a single import of this module.
|
||||
static func generateReexportUmbrellas(analysis: MultiPackageAnalysis) -> [String: String] {
|
||||
var files: [String: String] = [:]
|
||||
let header = "// Generated by SwiftGtkGen. DO NOT EDIT.\n\n"
|
||||
let header = "// Generated by gobject-generator. DO NOT EDIT.\n\n"
|
||||
for (moduleName, transitive) in analysis.transitiveDependencies {
|
||||
guard !transitive.isEmpty else { continue }
|
||||
var content = header
|
||||
|
|
@ -35,7 +35,7 @@ public func renderModule(_ plan: ModulePlan) -> [String: String] {
|
|||
|
||||
let depImports = plan.dependencyModules.map { "@_spi(SGTKInternal) import \($0)\n" }.joined()
|
||||
let header = """
|
||||
// Generated by SwiftGtkGen. DO NOT EDIT.
|
||||
// Generated by gobject-generator. DO NOT EDIT.
|
||||
|
||||
import C\(plan.module)
|
||||
\(depImports)
|
||||
|
|
@ -305,7 +305,7 @@ private func renderSupport(moduleName: String, dependencyModules: [String] = [],
|
|||
|
||||
let depImports = dependencyModules.map { "@_spi(SGTKInternal) import \($0)\n" }.joined()
|
||||
return """
|
||||
// Generated by SwiftGtkGen. DO NOT EDIT.
|
||||
// Generated by gobject-generator. DO NOT EDIT.
|
||||
|
||||
import C\(moduleName)
|
||||
\(depImports)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
import SwiftFormat
|
||||
import SwiftGtkGenCore
|
||||
import GObjectGeneratorCore
|
||||
|
||||
/// Command-line interface for the GIR-to-Swift binding generator.
|
||||
///
|
||||
|
|
@ -9,7 +9,7 @@ import SwiftGtkGenCore
|
|||
/// to the output directory. This is the subprocess entry point invoked by
|
||||
/// both the build tool plugin and the command plugin.
|
||||
@main
|
||||
struct SwiftGtkGenCLI {
|
||||
struct GeneratorCLI {
|
||||
/// Program entry point. Parses arguments, generates code, and writes output.
|
||||
static func main() {
|
||||
let args = parseArguments()
|
||||
|
|
@ -20,7 +20,7 @@ struct SwiftGtkGenCLI {
|
|||
|
||||
guard !args.monorepoConfigTOML.isEmpty else {
|
||||
print("Error: --monorepo-config is required")
|
||||
print(" swift-gtk-gen --monorepo-config configs/tier1.toml --output /tmp/out")
|
||||
print(" generator --monorepo-config configs/tier1.toml --output /tmp/out")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ struct SwiftGtkGenCLI {
|
|||
|
||||
/// Prints usage information to stdout.
|
||||
static func printHelp() {
|
||||
print("Usage: swift-gtk-gen --monorepo-config PATH [options]")
|
||||
print("Usage: generator --monorepo-config PATH [options]")
|
||||
print(" --monorepo-config PATH Monorepo TOML config (required)")
|
||||
print(" --output DIR Output directory (default: .)")
|
||||
print(" --skip-report Write skip-reports/<Module>.json and coverage-summary.json")
|
||||
|
|
@ -16,16 +16,15 @@ func testCLIHelp() throws {
|
|||
|
||||
private func findBinary() -> URL? {
|
||||
let candidates = [
|
||||
URL(fileURLWithPath: ".build/debug/swift-gtk-gen"),
|
||||
URL(fileURLWithPath: "generator/.build/debug/swift-gtk-gen"),
|
||||
URL(fileURLWithPath: ".build/release/swift-gtk-gen"),
|
||||
URL(fileURLWithPath: "generator/.build/release/swift-gtk-gen"),
|
||||
URL(fileURLWithPath: ".build/debug/generator"),
|
||||
URL(fileURLWithPath: ".build/release/generator"),
|
||||
]
|
||||
return candidates.first { FileManager.default.fileExists(atPath: $0.path) }
|
||||
}
|
||||
|
||||
|
||||
private func failBinaryNotFound() -> URL {
|
||||
Issue.record("swift-gtk-gen binary not found at any expected path")
|
||||
Issue.record("generator binary not found at any expected path")
|
||||
return URL(fileURLWithPath: "/nonexistent")
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Test("Analysis resolves class hierarchy")
|
||||
func testClassHierarchy() {
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Callback generation")
|
||||
struct CallbackGenerationTests {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Test("GenerationConfig can be built from TOML dictionary and GIR namespace")
|
||||
func testConfigFromTOML() throws {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Test("Config builder creates valid configuration")
|
||||
func testConfigBuilder() {
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Function generation")
|
||||
struct FunctionGenerationTests {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Testing
|
||||
import SwiftGtkGenCore
|
||||
import GObjectGeneratorCore
|
||||
|
||||
@Test("Namespace can hold types")
|
||||
func testNamespaceHoldsTypes() {
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Cross-module inherited-member dedup")
|
||||
struct InheritedMemberTests {
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Interface conformance")
|
||||
struct InterfaceConformanceTests {
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Interface generation")
|
||||
struct InterfaceGenerationTests {
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Interface signal generation")
|
||||
struct InterfaceSignalGenerationTests {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("MonorepoConfig")
|
||||
struct MonorepoConfigTests {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("MultiPackageAnalyzer")
|
||||
struct MultiPackageAnalysisTests {
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Naming conventions")
|
||||
struct NamingTests {
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
/// Wraps GIR element markup in a minimal well-formed repository document.
|
||||
///
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import Testing
|
||||
import Foundation
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Test("Parser reads namespace from minimal GIR XML")
|
||||
func testParsesNamespace() throws {
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Property generation")
|
||||
struct PropertyGenerationTests {
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Record generation")
|
||||
struct RecordGenerationTests {
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Renderer callables")
|
||||
struct RendererCallableTests {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Test("generatePackageScaffolding produces Package.swift")
|
||||
func testPackageScaffolding() {
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Signal generation")
|
||||
struct SignalGenerationTests {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Testing
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Test("TOML reader parses simple key-value pairs")
|
||||
func testSimpleKeyValue() throws {
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("TypeMapper")
|
||||
struct TypeMapperTests {
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("TypeRegistry")
|
||||
struct TypeRegistryTests {
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
import Foundation
|
||||
import Testing
|
||||
|
||||
@testable import SwiftGtkGenCore
|
||||
@testable import GObjectGeneratorCore
|
||||
|
||||
@Suite("Real GIR parsing")
|
||||
struct RealGIRParsingTests {
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@
|
|||
# --fresh remove the tier's output directory before generating (use when
|
||||
# the generated file set shrinks and stale files would linger)
|
||||
#
|
||||
# Output goes to ${TMPDIR:-/tmp}/swift-gtk-gen-gate/tier-N; a stable path so
|
||||
# Output goes to ${TMPDIR:-/tmp}/gobject-generator-gate/tier-N; a stable path so
|
||||
# incremental swift builds stay fast between runs.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
GATE_ROOT="${TMPDIR:-/tmp}/swift-gtk-gen-gate"
|
||||
GATE_ROOT="${TMPDIR:-/tmp}/gobject-generator-gate"
|
||||
|
||||
TIER_ARG="${1:-}"
|
||||
FRESH=0
|
||||
|
|
@ -39,7 +39,7 @@ fi
|
|||
|
||||
echo "==> Building generator"
|
||||
swift build --package-path "$ROOT"
|
||||
BIN="$(swift build --package-path "$ROOT" --show-bin-path)/swift-gtk-gen"
|
||||
BIN="$(swift build --package-path "$ROOT" --show-bin-path)/generator"
|
||||
|
||||
FAILED=0
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
# tier 1..6 (default 1). tier1 = GLib+GObject, tier2 = +GModule+Gio, …
|
||||
# --fresh wipe the tier's output directory before generating
|
||||
#
|
||||
# Output goes to ${TMPDIR:-/tmp}/swift-gtk-gen-smoke/tier-<N> (a stable path so
|
||||
# Output goes to ${TMPDIR:-/tmp}/gobject-generator-smoke/tier-<N> (a stable path so
|
||||
# incremental swift builds stay fast between runs).
|
||||
|
||||
set -euo pipefail
|
||||
|
|
@ -30,7 +30,7 @@ for arg in "$@"; do
|
|||
done
|
||||
|
||||
CONFIG="$ROOT/configs/tier${TIER}.toml"
|
||||
OUT="${TMPDIR:-/tmp}/swift-gtk-gen-smoke/tier-${TIER}"
|
||||
OUT="${TMPDIR:-/tmp}/gobject-generator-smoke/tier-${TIER}"
|
||||
|
||||
if [[ ! -f "$CONFIG" ]]; then
|
||||
echo "!! missing $CONFIG" >&2
|
||||
|
|
@ -42,7 +42,7 @@ mkdir -p "$OUT"
|
|||
|
||||
echo "==> Building generator"
|
||||
swift build --package-path "$ROOT"
|
||||
BIN="$(swift build --package-path "$ROOT" --show-bin-path)/swift-gtk-gen"
|
||||
BIN="$(swift build --package-path "$ROOT" --show-bin-path)/generator"
|
||||
|
||||
echo "==> Generating tier $TIER bindings (with SmokeTests target) into $OUT"
|
||||
"$BIN" --monorepo-config "$CONFIG" --output "$OUT" --smoke-target >"$OUT/generate.log" 2>&1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue