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
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ In the case of formatting issues, `git add` the formatting changes and attempt t

Some documentation is generated from source and checked in, so CI can catch it drifting out of date. If you changed `Configuration.swift` or a CLI command's flags/help text, run `scripts/generate-docs.sh` and commit the generated changes.

### Developing against local dependency checkouts

swift-java depends on [swift-java-jni-core](https://github.com/swiftlang/swift-java-jni-core) and [swift-binding-generator-core](https://github.com/swiftlang/swift-binding-generator-core) (home of the `SwiftExtract` library) from their `main` branches. To develop against local checkouts instead, clone the repositories next to your swift-java checkout and point the corresponding environment variables at them:

```bash
export PROJECT_ROOT= # the directory containing your checkouts
cd $PROJECT_ROOT
ls
> swift-java
> swift-java-jni-core
> swift-binding-generator-core
> # ...and all the others here

export SWIFT_JAVA_JNI_CORE_PATH=$PROJECT_ROOT/swift-java-jni-core
export SWIFT_BINDING_GENERATOR_CORE_PATH=$PROJECT_ROOT/swift-binding-generator-core
swift build
```

## How to contribute your work

Please open a pull request at https://github.com/swiftlang/swift-java. Make sure the CI passes, and then wait for code review.
Expand Down
80 changes: 12 additions & 68 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ if let localPath = Context.environment["SWIFT_JAVA_JNI_CORE_PATH"] {
swiftJavaJNICoreDep = .package(url: "https://github.com/swiftlang/swift-java-jni-core", branch: "main")
}

let swiftBindingGeneratorCoreDep: Package.Dependency
if let localPath = Context.environment["SWIFT_BINDING_GENERATOR_CORE_PATH"] {
swiftBindingGeneratorCoreDep = .package(path: localPath)
} else {
swiftBindingGeneratorCoreDep = .package(url: "https://github.com/swiftlang/swift-binding-generator-core", branch: "main")
}

// Set SWIFTJAVA_DOCC_PLUGIN_INSTALL=1 to install the docc-plugin automatically,
// or DOCC_PLUGIN_PATH=<path> to point at a local checkout.
// This is a workaround because swift-subprocess includes the plugin explicitly,
Expand Down Expand Up @@ -59,11 +66,6 @@ let package = Package(
targets: ["SwiftJavaConfigurationShared"]
),

.library(
name: "SwiftExtractConfigurationShared",
targets: ["SwiftExtractConfigurationShared"]
),

.library(
name: "JavaUtil",
targets: ["JavaUtil"]
Expand Down Expand Up @@ -129,11 +131,6 @@ let package = Package(
targets: ["SwiftRuntimeFunctions"]
),

.library(
name: "SwiftExtract",
targets: ["SwiftExtract"]
),

.library(
name: "CodePrinting",
targets: ["CodePrinting"]
Expand Down Expand Up @@ -166,6 +163,7 @@ let package = Package(
],
dependencies: [
swiftJavaJNICoreDep,
swiftBindingGeneratorCoreDep,
.package(url: "https://github.com/swiftlang/swift-syntax", from: "603.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.8.0"),
.package(url: "https://github.com/apple/swift-system", from: "1.4.0"),
Expand Down Expand Up @@ -304,14 +302,10 @@ let package = Package(
.target(
name: "SwiftJavaConfigurationShared",
dependencies: [
"SwiftExtractConfigurationShared"
.product(name: "SwiftExtractConfigurationShared", package: "swift-binding-generator-core")
]
),

.target(
name: "SwiftExtractConfigurationShared"
),

.target(
name: "SwiftJavaShared"
),
Expand Down Expand Up @@ -352,6 +346,7 @@ let package = Package(
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SystemPackage", package: "swift-system"),
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
"SwiftJava",
"JavaUtilJar",
"JavaNet",
Expand All @@ -375,32 +370,6 @@ let package = Package(
]
),

.target(
name: "SwiftExtract",
dependencies: [
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
.product(name: "SwiftIfConfig", package: "swift-syntax"),
.product(name: "SwiftLexicalLookup", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
"SwiftExtractConfigurationShared",
],
path: "Sources/SwiftExtract",
resources: [
// Holds the `dummy.json` placeholder so SwiftPM emits a `Bundle.module`
// for this target. The real `static-build-config.json` is generated at
// build time by the `_StaticBuildConfigPlugin` build tool below.
.process("Resources")
],
swiftSettings: [
.swiftLanguageMode(.v5)
],
plugins: [
.plugin(name: "_StaticBuildConfigPlugin")
]
),

.target(
name: "JExtractSwiftLib",
dependencies: [
Expand All @@ -412,7 +381,7 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "OrderedCollections", package: "swift-collections"),
.product(name: "SwiftJavaJNICore", package: "swift-java-jni-core"),
"SwiftExtract",
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
"SwiftJavaShared",
"SwiftJavaConfigurationShared",
"CodePrinting",
Expand All @@ -423,14 +392,6 @@ let package = Package(
]
),

.executableTarget(
name: "StaticBuildConfigPluginExecutable",
dependencies: [
.product(name: "Subprocess", package: "swift-subprocess"),
.product(name: "SwiftIfConfig", package: "swift-syntax"),
]
),

// Dev-time tool: regenerates the "Supported configuration options" table in
// `Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaConfigFile.md`
// straight from the doc comments on `Configuration.swift` and the enums it
Expand All @@ -448,14 +409,6 @@ let package = Package(
path: "Sources/GenerateConfigDocs"
),

.plugin(
name: "_StaticBuildConfigPlugin",
capability: .buildTool(),
dependencies: [
"StaticBuildConfigPluginExecutable"
]
),

.plugin(
name: "JExtractSwiftPlugin",
capability: .buildTool(),
Expand Down Expand Up @@ -512,23 +465,14 @@ let package = Package(
name: "JExtractSwiftTests",
dependencies: [
"JExtractSwiftLib",
"SwiftExtract",
.product(name: "SwiftExtract", package: "swift-binding-generator-core"),
"CodePrinting",
],
swiftSettings: [
.swiftLanguageMode(.v5)
]
),

.testTarget(
name: "SwiftExtractTests",
dependencies: [
"SwiftExtract",
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
]
),

.testTarget(
name: "CodePrintingTests",
dependencies: [
Expand Down
1 change: 0 additions & 1 deletion Plugins/PluginsShared/SwiftExtractConfigurationShared

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DO NOT EDIT THESE FILES IN THIS REPOSITORY.

The files in this directory are vendored, byte-identical copies of:

https://github.com/swiftlang/swift-binding-generator-core
Sources/SwiftExtractConfigurationShared/

They exist because SwiftPM package plugins cannot take sources from a package
dependency, so the plugins in this repository compile these files directly.

Make any changes in swift-binding-generator-core instead, and then copy the
updated files here. The swift-java compatibility CI job in
swift-binding-generator-core diffs these copies against its own sources and
will flag any drift.
34 changes: 0 additions & 34 deletions Plugins/_StaticBuildConfigPlugin/_StaticBuildConfigPlugin.swift

This file was deleted.

16 changes: 16 additions & 0 deletions Sources/GenerateConfigDocs/GenerateConfigDocs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,29 @@ struct GenerateConfigDocs: ParsableCommand {
.appendingPathComponent("Documentation.docc", isDirectory: true)
.appendingPathComponent("SwiftJavaConfigFile.md", isDirectory: false)

// `SwiftExtractConfigurationShared` lives in the swift-binding-generator-core
// package since `SwiftExtract` was split out of this repo. Scan every location
// it may be found in.
let scanDirs: [URL] = [
repoRoot
.appendingPathComponent("Sources", isDirectory: true)
.appendingPathComponent("SwiftJavaConfigurationShared", isDirectory: true),
// Legacy in-repo location (pre-split layout).
repoRoot
.appendingPathComponent("Sources", isDirectory: true)
.appendingPathComponent("SwiftExtractConfigurationShared", isDirectory: true),
// Resolved swift-binding-generator-core checkout.
repoRoot
.appendingPathComponent(".build", isDirectory: true)
.appendingPathComponent("checkouts", isDirectory: true)
.appendingPathComponent("swift-binding-generator-core", isDirectory: true)
.appendingPathComponent("Sources", isDirectory: true)
.appendingPathComponent("SwiftExtractConfigurationShared", isDirectory: true),
// Vendored copy shared with the build plugins.
repoRoot
.appendingPathComponent("Plugins", isDirectory: true)
.appendingPathComponent("PluginsShared", isDirectory: true)
.appendingPathComponent("SwiftExtractConfigurationShared", isDirectory: true),
]

// Parse enums and structs referenced by Configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@
//
//===----------------------------------------------------------------------===//

extension Dictionary {
/// Same values, corresponding to mapped keys.
public func mapKeys<Transformed>(
_ transform: (Key) throws -> Transformed
) rethrows -> [Transformed: Value] {
.init(
uniqueKeysWithValues: try map {
(try transform($0.key), $0.value)
}
)
}

}

extension Collection {
package typealias IsLastElement = Bool
package var withIsLast: any Collection<(Element, IsLastElement)> {
Expand All @@ -39,13 +25,3 @@ extension Collection {
}
}
}

extension Collection where Element == Int {
var sum: Int {
var s = 0
for i in self {
s += i
}
return s
}
}
Loading
Loading