Skip to content

Commit 3d6c85b

Browse files
committed
lots of fixing around how we deal with config and library loading
1 parent e148e58 commit 3d6c85b

File tree

24 files changed

+127
-99
lines changed

24 files changed

+127
-99
lines changed

.github/scripts/validate_samples.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# shellcheck disable=SC2034
4-
declare -r GREEN='\033[0;31m'
4+
declare -r GREEN='\033[0;32m'
55
declare -r BOLD='\033[1m'
66
declare -r RESET='\033[0m'
77

@@ -15,22 +15,23 @@ for samplePackage in ${SAMPLE_PACKAGES} ; do
1515
echo ""
1616
echo ""
1717
echo "========================================================================"
18-
printf "Validate sample: '${BOLD}%s${RESET}' using: " "$sampleDir"
18+
printf "Validate sample '${BOLD}%s${RESET}' using: " "$sampleDir"
1919
cd "$sampleDir" || exit
2020
if [[ $(find . -name ${CI_VALIDATE_SCRIPT} -maxdepth 1) ]]; then
2121
echo -e "Custom ${BOLD}${CI_VALIDATE_SCRIPT}${RESET} script..."
2222
./${CI_VALIDATE_SCRIPT} || exit
2323
elif [[ $(find . -name 'build.gradle*' -maxdepth 1) ]]; then
2424
echo -e "${BOLD}Gradle${RESET} build..."
25-
./gradlew build --info || exit
25+
./gradlew build || ./gradlew build --info # re-run to get better failure output
2626
else
2727
echo -e "${BOLD}SwiftPM${RESET} build..."
2828
swift build || exit
2929
fi
3030

31+
echo -e "Validated sample '${BOLD}${sampleDir}${RESET}': ${BOLD}passed${RESET}."
3132
cd - || exit
3233
done
3334

34-
35+
echo
3536
printf "Done validating samples: "
36-
echo "${GREEN}done${RESET}."
37+
echo -e "${GREEN}done${RESET}."

BuildLogic/src/main/kotlin/build-logic.java-common-conventions.gradle.kts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import java.util.*
16+
import java.io.*
1617

1718
plugins {
1819
java
@@ -44,23 +45,23 @@ tasks.withType(JavaCompile::class).forEach {
4445

4546

4647
// FIXME: cannot share definition with 'buildSrc' so we duplicated the impl here
47-
fun javaLibraryPaths(): List<String> {
48+
fun javaLibraryPaths(dir: File): List<String> {
4849
val osName = System.getProperty("os.name")
4950
val osArch = System.getProperty("os.arch")
5051
val isLinux = osName.lowercase(Locale.getDefault()).contains("linux")
5152

5253
return listOf(
5354
if (isLinux) {
5455
if (osArch.equals("x86_64") || osArch.equals("amd64")) {
55-
"$rootDir/.build/x86_64-unknown-linux-gnu/debug/"
56+
"$dir/.build/x86_64-unknown-linux-gnu/debug/"
5657
} else {
57-
"$rootDir/.build/$osArch-unknown-linux-gnu/debug/"
58+
"$dir/.build/$osArch-unknown-linux-gnu/debug/"
5859
}
5960
} else {
6061
if (osArch.equals("aarch64")) {
61-
"$rootDir/.build/arm64-apple-macosx/debug/"
62+
"$dir/.build/arm64-apple-macosx/debug/"
6263
} else {
63-
"$rootDir/.build/$osArch-apple-macosx/debug/"
64+
"$dir/.build/$osArch-apple-macosx/debug/"
6465
}
6566
},
6667
if (isLinux) {
@@ -79,7 +80,9 @@ tasks.test {
7980
"--enable-native-access=ALL-UNNAMED",
8081

8182
// Include the library paths where our dylibs are that we want to load and call
82-
"-Djava.library.path=" + javaLibraryPaths().joinToString(File.pathSeparator)
83+
"-Djava.library.path=" +
84+
(javaLibraryPaths(rootDir) + javaLibraryPaths(project.projectDir))
85+
.joinToString(File.pathSeparator)
8386
)
8487
}
8588

Plugins/JExtractSwiftCommandPlugin/JExtractSwiftCommandPlugin.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ final class JExtractSwiftCommandPlugin: BuildToolPlugin, CommandPlugin {
5757
}
5858

5959
do {
60-
print("[swift-java] Extracting Java wrappers from target: '\(target.name)'...")
60+
print("[swift-java-command] Extracting Java wrappers from target: '\(target.name)'...")
6161
try performCommand(context: context, target: target, arguments: arguments)
6262
} catch {
63-
print("[swift-java] error: Failed to extract from target '\(target.name)': \(error)")
63+
print("[swift-java-command] error: Failed to extract from target '\(target.name)': \(error)")
6464
}
65+
66+
print("[swift-java-command] Done.")
6567
}
6668
}
6769

@@ -105,7 +107,7 @@ final class JExtractSwiftCommandPlugin: BuildToolPlugin, CommandPlugin {
105107
arguments.append(sourceDir)
106108

107109
try runExtract(context: context, target: target, arguments: arguments)
108-
110+
109111
if self.buildOutputs {
110112
// Building the *products* since we need to build the dylib that contains our newly generated sources,
111113
// so just building the target again would not be enough. We build all products which we affected using

Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ struct JExtractSwiftBuildToolPlugin: BuildToolPlugin {
3434
.appending(path: "generated")
3535
.appending(path: "java")
3636
let outputDirectorySwift = context.pluginWorkDirectoryURL
37-
.appending(path: "src")
38-
.appending(path: "generated")
3937
.appending(path: "Sources")
4038

4139
var arguments: [String] = [
Binary file not shown.
Binary file not shown.

Samples/JExtractPluginSampleApp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ application {
113113
// Include the library paths where our dylibs are that we want to load and call
114114
"-Djava.library.path=" +
115115
(BuildUtils.javaLibraryPaths(rootDir) +
116-
BuildUtils.javaLibraryPaths(layout.projectDirectory.asFile)).join(":"),
116+
BuildUtils.javaLibraryPaths(project.projectDir)).join(":"),
117117

118118
// Enable tracing downcalls (to Swift)
119119
"-Djextract.trace.downcalls=true"

Samples/JExtractPluginSampleApp/ci-validate.sh

100644100755
File mode changed.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
swift run JavaProbablyPrime 1337

Samples/SwiftKitSampleApp/Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ let package = Package(
6262
dependencies: [
6363
.product(name: "SwiftKitSwift", package: "swift-java"),
6464
],
65+
exclude: [
66+
"swift-java.config",
67+
],
6568
swiftSettings: [
6669
.swiftLanguageMode(.v5),
6770
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])

0 commit comments

Comments
 (0)