Skip to content

Commit 6750709

Browse files
committed
build dependency fixes in gradle: depend on SwiftKit as well
1 parent acf1716 commit 6750709

File tree

6 files changed

+77
-21
lines changed

6 files changed

+77
-21
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Prepare CI Environment
3434
uses: ./.github/actions/prepare_env
3535
- name: Gradle :SwiftKit:build
36-
run: ./gradlew build -x test # just build
36+
run: ./gradlew build -x test
3737
- name: Gradle :SwiftKit:check
3838
run: ./gradlew :SwiftKit:check --info
3939
- name: Gradle compile JMH benchmarks

Samples/JExtractPluginSampleApp/build.gradle

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ java {
3636

3737
// This is for development, when we edit the Swift swift-java project, the outputs of the generated sources may change.
3838
// Thus, we also need to watch and re-build the top level project.
39-
def buildJExtractPlugin = tasks.register("swiftBuildJExtractPlugin", Exec) {
39+
def compileSwiftJExtractPlugin = tasks.register("compileSwiftJExtractPlugin", Exec) {
4040
description = "Rebuild the swift-java root project"
4141

4242
inputs.file(new File(rootDir, "Package.swift"))
@@ -45,25 +45,41 @@ def buildJExtractPlugin = tasks.register("swiftBuildJExtractPlugin", Exec) {
4545

4646
workingDir = rootDir
4747
commandLine "swift"
48-
args "build"
48+
args("build",
49+
"--product", "SwiftKitSwift",
50+
"--product", "JExtractSwiftPlugin",
51+
"--product", "JExtractSwiftCommandPlugin")
52+
}
53+
def compileSwiftKitSwift = tasks.register("compileSwiftKitSwift", Exec) {
54+
description = "Rebuild the swift-java root project"
55+
56+
inputs.file(new File(rootDir, "Package.swift"))
57+
inputs.dir(new File(rootDir, "Sources"))
58+
outputs.dir(new File(rootDir, ".build"))
59+
60+
workingDir = rootDir
61+
commandLine "swift"
62+
args("build",
63+
"--product", "SwiftKitSwift")
4964
}
5065

51-
def swiftClean = tasks.register("swiftClean", Exec) {
66+
def cleanSwift = tasks.register("cleanSwift", Exec) {
5267
workingDir = layout.projectDirectory
5368
commandLine "swift"
5469
args("package", "clean")
5570
}
5671

5772
def jextract = tasks.register("jextract", Exec) {
5873
description = "Builds swift sources, including swift-java source generation"
59-
dependsOn buildJExtractPlugin
74+
dependsOn compileSwiftJExtractPlugin
75+
dependsOn compileSwiftKitSwift
6076

6177
// only because we depend on "live developing" the plugin while using this project to test it
6278
inputs.file(new File(rootDir, "Package.swift"))
6379
inputs.dir(new File(rootDir, "Sources"))
6480

65-
inputs.file(layout.projectDirectory.file("Package.swift"))
66-
inputs.dir(layout.projectDirectory.dir("Sources"))
81+
inputs.file(new File(projectDir, "Package.swift"))
82+
inputs.dir(new File(projectDir, "Sources"))
6783

6884
// TODO: we can use package describe --type json to figure out which targets depend on JExtractSwiftPlugin and will produce outputs
6985
// Avoid adding this directory, but create the expected one specifically for all targets
@@ -100,7 +116,7 @@ tasks.build {
100116
}
101117

102118
tasks.clean {
103-
dependsOn("swiftClean")
119+
dependsOn("cleanSwift")
104120
}
105121

106122
dependencies {

Samples/SwiftKitSampleApp/build.gradle

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ java {
3737

3838
// This is for development, when we edit the Swift swift-java project, the outputs of the generated sources may change.
3939
// Thus, we also need to watch and re-build the top level project.
40-
def buildJExtractPlugin = tasks.register("swiftBuildJExtractPlugin", Exec) {
40+
def compileSwiftJExtractPlugin = tasks.register("compileSwiftJExtractPlugin", Exec) {
4141
description = "Rebuild the swift-java root project"
4242

4343
inputs.file(new File(rootDir, "Package.swift"))
@@ -46,25 +46,22 @@ def buildJExtractPlugin = tasks.register("swiftBuildJExtractPlugin", Exec) {
4646

4747
workingDir = rootDir
4848
commandLine "swift"
49-
args "build"
50-
}
51-
52-
def swiftClean = tasks.register("swiftClean", Exec) {
53-
workingDir = layout.projectDirectory
54-
commandLine "swift"
55-
args("package", "clean")
49+
args("build",
50+
"--product", "SwiftKitSwift",
51+
"--product", "JExtractSwiftPlugin",
52+
"--product", "JExtractSwiftCommandPlugin")
5653
}
5754

5855
def jextract = tasks.register("jextract", Exec) {
5956
description = "Builds swift sources, including swift-java source generation"
60-
dependsOn buildJExtractPlugin
57+
dependsOn compileSwiftJExtractPlugin
6158

6259
// only because we depend on "live developing" the plugin while using this project to test it
6360
inputs.file(new File(rootDir, "Package.swift"))
6461
inputs.dir(new File(rootDir, "Sources"))
6562

66-
inputs.file(layout.projectDirectory.file("Package.swift"))
67-
inputs.dir(layout.projectDirectory.dir("Sources"))
63+
inputs.file(new File(projectDir, "Package.swift"))
64+
inputs.dir(new File(projectDir, "Sources"))
6865

6966
// TODO: we can use package describe --type json to figure out which targets depend on JExtractSwiftPlugin and will produce outputs
7067
// Avoid adding this directory, but create the expected one specifically for all targets
@@ -110,8 +107,14 @@ tasks.build {
110107
dependsOn("jextract")
111108
}
112109

110+
111+
def cleanSwift = tasks.register("cleanSwift", Exec) {
112+
workingDir = layout.projectDirectory
113+
commandLine "swift"
114+
args("package", "clean")
115+
}
113116
tasks.clean {
114-
dependsOn("swiftClean")
117+
dependsOn("cleanSwift")
115118
}
116119

117120
dependencies {

SwiftKit/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,32 @@ tasks.test {
4040
events("passed", "skipped", "failed")
4141
}
4242
}
43+
44+
// SwiftKit depends on SwiftKitSwift (Swift library that this Java library calls into)
45+
46+
def compileSwift = tasks.register("compileSwift", Exec) {
47+
description "Compile the swift-java SwiftKitSwift dynamic library that SwiftKit (Java) calls into"
48+
49+
inputs.file(new File(rootDir, "Package.swift"))
50+
inputs.dir(new File(rootDir, "Sources/")) // a bit generous, but better safe than sorry, and include all Swift source changes
51+
outputs.dir(new File(rootDir, ".build"))
52+
53+
workingDir = rootDir
54+
commandLine "swift"
55+
args("build", "--target", "SwiftKitSwift")
56+
}
57+
tasks.build {
58+
dependsOn("compileSwift")
59+
}
60+
61+
62+
63+
def cleanSwift = tasks.register("cleanSwift", Exec) {
64+
workingDir = rootDir
65+
commandLine "swift"
66+
args("package", "clean")
67+
}
68+
tasks.clean {
69+
dependsOn("cleanSwift")
70+
}
71+

buildSrc/build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@
1515
repositories {
1616
mavenCentral()
1717
}
18+
19+
def cleanSwift = tasks.register("cleanSwift", Exec) {
20+
workingDir = layout.projectDirectory
21+
commandLine "swift"
22+
args("package", "clean")
23+
}
24+
tasks.clean {
25+
dependsOn("cleanSwift")
26+
}

settings.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ new File(rootDir, "Samples").listFiles().each {
2626
include ":Samples:${it.name}"
2727
}
2828
}
29-

0 commit comments

Comments
 (0)