make generation work on macOS
This commit is contained in:
parent
24fc372849
commit
414cb95432
@ -12,7 +12,7 @@ import PackageDescription
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
name: "Adwaita",
|
name: "Adwaita",
|
||||||
platforms: [
|
platforms: [
|
||||||
.macOS(.v10_15)
|
.macOS(.v13)
|
||||||
],
|
],
|
||||||
products: [
|
products: [
|
||||||
.library(
|
.library(
|
||||||
|
|||||||
@ -23,8 +23,13 @@ struct Generation {
|
|||||||
/// The main function.
|
/// The main function.
|
||||||
func run() throws {
|
func run() throws {
|
||||||
removeOldFiles()
|
removeOldFiles()
|
||||||
guard let gtkDefinitions = getDefinitions(path: configuration.gtkGirFilePath),
|
guard let gtkDefinitions = getGtkDefinitions(path: configuration.gtkGirFilePath) else {
|
||||||
let adwDefinitions = getDefinitions(path: configuration.adwGirFilePath) else {
|
print("failed to get Gtk definitions")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let adwDefinitions = getAdwDefinitions(path: configuration.adwGirFilePath) else {
|
||||||
|
print("failed to get Adw definitions")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for `class` in gtkDefinitions.namespace.classes {
|
for `class` in gtkDefinitions.namespace.classes {
|
||||||
@ -66,17 +71,28 @@ struct Generation {
|
|||||||
/// Get the definitions of a GIR file at a specified path.
|
/// Get the definitions of a GIR file at a specified path.
|
||||||
/// - Parameter path: The path.
|
/// - Parameter path: The path.
|
||||||
/// - Returns: The GIR data.
|
/// - Returns: The GIR data.
|
||||||
func getDefinitions(path: String) -> GIR? {
|
func getGtkDefinitions(path: String) -> GIR? {
|
||||||
var path = path
|
var path = path
|
||||||
let girDir = getGirDir()
|
let girDir = getGtkGirDir()
|
||||||
path.replace(GenerationConfiguration.includeDir, with: girDir)
|
path.replace(GenerationConfiguration.gtkIncludeDir, with: girDir)
|
||||||
|
let data = (try? Data(contentsOf: .init(fileURLWithPath: path))) ?? .init()
|
||||||
|
return try? GIR.decodeGIR(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the definitions of a GIR file at a specified path.
|
||||||
|
/// - Parameter path: The path.
|
||||||
|
/// - Returns: The GIR data.
|
||||||
|
func getAdwDefinitions(path: String) -> GIR? {
|
||||||
|
var path = path
|
||||||
|
let girDir = getAdwGirDir()
|
||||||
|
path.replace(GenerationConfiguration.adwIncludeDir, with: girDir)
|
||||||
let data = (try? Data(contentsOf: .init(fileURLWithPath: path))) ?? .init()
|
let data = (try? Data(contentsOf: .init(fileURLWithPath: path))) ?? .init()
|
||||||
return try? GIR.decodeGIR(data)
|
return try? GIR.decodeGIR(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the directory of the gir files.
|
/// Get the directory of the gir files.
|
||||||
/// - Returns: The path.
|
/// - Returns: The path.
|
||||||
func getGirDir() -> String {
|
func getGtkGirDir() -> String {
|
||||||
let process = Process()
|
let process = Process()
|
||||||
process.executableURL = .init(fileURLWithPath: "/bin/bash")
|
process.executableURL = .init(fileURLWithPath: "/bin/bash")
|
||||||
process.arguments = ["-c", "pkg-config --variable=includedir gtk4"]
|
process.arguments = ["-c", "pkg-config --variable=includedir gtk4"]
|
||||||
@ -87,6 +103,19 @@ struct Generation {
|
|||||||
return .init(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
return .init(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the directory of the gir files.
|
||||||
|
/// - Returns: The path.
|
||||||
|
func getAdwGirDir() -> String {
|
||||||
|
let process = Process()
|
||||||
|
process.executableURL = .init(fileURLWithPath: "/bin/bash")
|
||||||
|
process.arguments = ["-c", "pkg-config --variable=includedir libadwaita-1"]
|
||||||
|
let pipe = Pipe()
|
||||||
|
process.standardOutput = pipe
|
||||||
|
try? process.run()
|
||||||
|
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
return .init(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a file containing a class.
|
/// Create a file containing a class.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - class: The class.
|
/// - class: The class.
|
||||||
|
|||||||
@ -13,9 +13,16 @@ import Foundation
|
|||||||
struct GenerationConfiguration {
|
struct GenerationConfiguration {
|
||||||
|
|
||||||
/// The include directory.
|
/// The include directory.
|
||||||
static let includeDir = "$(pkg-config --variable=includedir gtk4)"
|
static let gtkIncludeDir = "$(pkg-config --variable=includedir gtk4)"
|
||||||
|
|
||||||
|
/// The include directory.
|
||||||
|
static let adwIncludeDir = "$(pkg-config --variable=includedir libadwaita-1)"
|
||||||
|
|
||||||
/// The directory containing the GIR files.
|
/// The directory containing the GIR files.
|
||||||
static let girFilePath = "\(includeDir)/../share/gir-1.0/"
|
static let gtkGirFilePath = "\(gtkIncludeDir)/../share/gir-1.0/"
|
||||||
|
|
||||||
|
/// The directory containing the GIR files.
|
||||||
|
static let adwGirFilePath = "\(adwIncludeDir)/../share/gir-1.0/"
|
||||||
|
|
||||||
/// Exclude properties of buttons.
|
/// Exclude properties of buttons.
|
||||||
static var excludeButtons: [String] {
|
static var excludeButtons: [String] {
|
||||||
@ -23,9 +30,9 @@ struct GenerationConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The Gtk GIR file.
|
/// The Gtk GIR file.
|
||||||
var gtkGirFilePath = girFilePath + "Gtk-4.0.gir"
|
var gtkGirFilePath = gtkGirFilePath + "Gtk-4.0.gir"
|
||||||
/// The Adw GIR file.
|
/// The Adw GIR file.
|
||||||
var adwGirFilePath = girFilePath + "Adw-1.gir"
|
var adwGirFilePath = adwGirFilePath + "Adw-1.gir"
|
||||||
|
|
||||||
/// The folder containing the generated Swift files.
|
/// The folder containing the generated Swift files.
|
||||||
var folder = "Sources/Adwaita/View/Generated/"
|
var folder = "Sources/Adwaita/View/Generated/"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user