Skip to content
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Sources/GtkCodeGen/GirFiles"]
path = Sources/GtkCodeGen/GirFiles
url = https://github.com/moreSwift/gir-files
16 changes: 13 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,25 @@ Due to limitations of Swift Package Manager and the way this project is structur
2. Make sure that you haven't introduced any new warnings
3. Make sure that the code builds, and the example works correctly
4. If you are adding a new feature, consider adding an example usage of it to the example
5. Run `format_and_lint.sh` (requires installing `swift-format` and `swiftlint`)
5. Run `./Scripts/format_and_lint.sh` (requires installing `swift-format` and `swiftlint`)

## While coding

Here are a few things to keep in mind while working on the code.

1. Do not directly modify a file that has a corresponding `.gyb` template file (which will be in the
same directory). Instead, modify the template file and then run `./generate.sh` to build all of
the templates. To learn more about gyb [read this post](https://nshipster.com/swift-gyb/)
same directory). Instead, modify the template file and then run `./Scripts/generate_gyb.sh`
to build all of the templates. To learn more about gyb
[read this post](https://nshipster.com/swift-gyb/)
2. Do not directly modify files in `Sources/Gtk/Generated` or `Sources/Gtk3/Generated`. Update the
generator at `Sources/GtkCodeGen` instead and run `./Scripts/generate_gtk.sh` to regenerate the
Gtk 3 and Gtk 4 bindings. If the changes can not be made by updating the generator, pull the
target file out of `Sources/{Gtk,Gtk3}/Generated` and into `Sources/{Gtk,Gtk3}/Widgets` and
modify it however you want. Remember to remove the class from `allowListedClasses`,
`gtk3AllowListedClasses` or `gtk4AllowListedClasses` so that it doesn't get regenerated the
next time someone runs `./Scripts/generate_gtk.sh`. Alternatively, if possible, add
code to the generated classes via extensions outside of the Generated directories. I usually
name these extension files `ClassName+ManualAdditions.swift`.
3. Make sure to avoid massive monolithic commits where possible

## Codestyle
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ let package = Package(
name: "GtkCodeGen",
dependencies: [
"XMLCoder", .product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
]
],
exclude: ["GirFiles"]
),
.systemLibrary(
name: "CGtk3",
Expand Down
9 changes: 9 additions & 0 deletions Scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

cd "$(dirname "$0")"/../

if [ -z "$1" ]; then
swift format format --in-place --recursive --configuration .swift-format Sources Examples/Sources
else
swift format format --in-place --recursive --configuration .swift-format $1
fi
6 changes: 6 additions & 0 deletions Scripts/format_and_lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd "$(dirname "$0")"/../

./Scripts/format.sh
swiftlint lint --quiet
7 changes: 7 additions & 0 deletions Scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cd "$(dirname "$0")"

./generate_gyb.sh

./generate_gtk.sh
6 changes: 6 additions & 0 deletions Scripts/generate_gtk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd "$(dirname "$0")"

./generate_gtk4.sh
./generate_gtk3.sh
7 changes: 7 additions & 0 deletions Scripts/generate_gtk3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cd "$(dirname "$0")"/../

# Generate Gtk3 wrapper
swift run GtkCodeGen Sources/GtkCodeGen/GirFiles/Gtk-3.0.gir Sources/Gtk3/Generated CGtk3
./Scripts/format.sh Sources/Gtk3/Generated
7 changes: 7 additions & 0 deletions Scripts/generate_gtk4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

cd "$(dirname "$0")"/../

# Generate Gtk4 wrapper
swift run GtkCodeGen Sources/GtkCodeGen/GirFiles/Gtk-4.0.gir Sources/Gtk/Generated CGtk
./Scripts/format.sh Sources/Gtk/Generated
10 changes: 10 additions & 0 deletions Scripts/generate_gyb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

cd "$(dirname "$0")"/../

# Find and compile all *.gyb files in the Sources directory
find Sources -name '*.gyb' |
while read file; do
./gyb/gyb --line-directive '' -o "$PWD/${file%.gyb}" "$PWD/$file"
./Scripts/format.sh $PWD/${file%.gyb}
done
3 changes: 3 additions & 0 deletions test.sh → Scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/sh

cd "$(dirname "$0")"/../

# `swift test` builds all targets in the package (even those not depended upon
# by any test targets), which leads to `swift test` on its own being broken
# for SwiftCrossUI
Expand Down
2 changes: 1 addition & 1 deletion Sources/AppKitBackend/AppKitBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public final class AppKitBackend: AppBackend {
keyEquivalent: ""
)
renderedItem.isOn = value

let wrappedAction = Action {
onChange(!renderedItem.isOn)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/GtkCodeGen/GirFiles
Submodule GirFiles added at a9bfea
10 changes: 7 additions & 3 deletions Sources/SwiftCrossUI/Views/ForEach.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,13 @@ class ForEachViewChildren<
}
}


extension ForEach where ID == Int {
/// Creates a view that creates child views on demand based on a collection of data.
@available(*, deprecated, renamed: "init(_:id:_:)", message: "ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates")
@available(
*, deprecated, renamed: "init(_:id:_:)",
message:
"ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates"
)
@_disfavoredOverload
public init(
_ elements: Items,
Expand All @@ -457,7 +460,8 @@ extension ForEach where Child == [MenuItem], ID == Int {
@available(
*,
deprecated,
message: "ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates"
message:
"ForEach requires an explicit 'id' parameter for non-Identifiable elements to correctly persist state across view updates"
)
@_disfavoredOverload
public init(
Expand Down
2 changes: 0 additions & 2 deletions format_and_lint.sh

This file was deleted.

14 changes: 0 additions & 14 deletions generate.sh

This file was deleted.

Loading