Skip to content

Commit ea8164b

Browse files
committed
debugging swiftpm plugin + subprocess hangs
1 parent 3e7ae28 commit ea8164b

File tree

3 files changed

+42
-44
lines changed

3 files changed

+42
-44
lines changed

Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ let package = Package(
187187
.swiftLanguageMode(.v5),
188188
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
189189
]
190-
// // FIXME: when the tool is run from plugin it hangs even if sandbox is disabled
191-
// ,
192-
// plugins: [
193-
// "SwiftJavaBootstrapJavaPlugin",
194-
// ]
190+
// FIXME: when the tool is run from plugin it hangs even if sandbox is disabled
191+
,
192+
plugins: [
193+
"SwiftJavaBootstrapJavaPlugin",
194+
]
195195
),
196196

197197
.target(

Samples/JavaDependencySampleApp/ci-validate.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@
33
set -e
44
set -x
55

6-
# TODO: this is a workaround for build plugins getting stuck running the bootstrap plugin
7-
cd ../../
8-
swift build --product SwiftJavaBootstrapJavaTool
9-
.build/debug/SwiftJavaBootstrapJavaTool --fetch Sources/JavaKitDependencyResolver/swift-java.config --module-name JavaKitDependencyResolver --output-directory .build/plugins/outputs/swift-java/JavaKitDependencyResolver/destination/SwiftJavaBootstrapJavaPlugin
10-
11-
cd -
126
swift run --disable-sandbox

Sources/SwiftJavaBootstrapJavaTool/SwiftJavaBootstrapJavaTool.swift

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Synchronization
1717
import JavaKitConfigurationShared
1818
import Dispatch
1919
import _Subprocess
20+
import System
2021

2122
@available(macOS 15.0, *)
2223
@main
@@ -67,45 +68,48 @@ final class SwiftJavaBootstrapJavaTool {
6768
"--rerun-tasks",
6869
// "--debug",
6970
// "\(localGradleProjectDependencyName):jar",
70-
"\(localGradleProjectDependencyName):\(printRuntimeClasspathTaskName)"
71-
]
71+
"\(localGradleProjectDependencyName):\(printRuntimeClasspathTaskName)",
72+
],
73+
output: .writeTo(.open("/tmp/out.txt", .writeOnly), closeAfterSpawningProcess: true),
74+
error: .writeTo(.open("/tmp/err.txt", .writeOnly), closeAfterSpawningProcess: true)
7275
)
7376

74-
let outString = String(
75-
data: process.standardOutput,
76-
encoding: .utf8
77-
)
78-
let errString = String(
79-
data: process.standardError,
80-
encoding: .utf8
81-
)
82-
83-
print("OUT ==== \(outString?.count) ::: \(outString ?? "")")
84-
print("ERR ==== \(errString?.count) ::: \(errString ?? "")")
85-
86-
let classpathOutput: String
87-
if let found = outString?.split(separator: "\n").first(where: { $0.hasPrefix(self.SwiftJavaClasspathPrefix) }) {
88-
classpathOutput = String(found)
89-
} else if let found = errString?.split(separator: "\n").first(where: { $0.hasPrefix(self.SwiftJavaClasspathPrefix) }) {
90-
classpathOutput = String(found)
91-
} else {
92-
let suggestDisablingSandbox = "It may be that the Sandbox has prevented dependency fetching, please re-run with '--disable-sandbox'."
93-
fatalError("Gradle output had no SWIFT_JAVA_CLASSPATH! \(suggestDisablingSandbox). \n" +
94-
"Output was:<<<\(outString ?? "<empty>")>>>; Err was:<<<\(errString ?? "<empty>")>>>")
95-
}
96-
97-
let classpathString = String(classpathOutput.dropFirst(self.SwiftJavaClasspathPrefix.count))
98-
99-
_ = try? FileManager.default.createDirectory(
100-
at: URL(fileURLWithPath: outputDirectoryPath),
101-
withIntermediateDirectories: true,
102-
attributes: nil
103-
)
104-
77+
// let outString = String(
78+
// data: process.standardOutput,
79+
// encoding: .utf8
80+
// )
81+
// let errString = String(
82+
// data: process.standardError,
83+
// encoding: .utf8
84+
// )
85+
//
86+
// print("OUT ==== \(outString?.count) ::: \(outString ?? "")")
87+
// print("ERR ==== \(errString?.count) ::: \(errString ?? "")")
88+
//
89+
// let classpathOutput: String
90+
// if let found = outString?.split(separator: "\n").first(where: { $0.hasPrefix(self.SwiftJavaClasspathPrefix) }) {
91+
// classpathOutput = String(found)
92+
// } else if let found = errString?.split(separator: "\n").first(where: { $0.hasPrefix(self.SwiftJavaClasspathPrefix) }) {
93+
// classpathOutput = String(found)
94+
// } else {
95+
// let suggestDisablingSandbox = "It may be that the Sandbox has prevented dependency fetching, please re-run with '--disable-sandbox'."
96+
// fatalError("Gradle output had no SWIFT_JAVA_CLASSPATH! \(suggestDisablingSandbox). \n" +
97+
// "Output was:<<<\(outString ?? "<empty>")>>>; Err was:<<<\(errString ?? "<empty>")>>>")
98+
// }
99+
//
100+
// let classpathString = String(classpathOutput.dropFirst(self.SwiftJavaClasspathPrefix.count))
101+
//
102+
// _ = try? FileManager.default.createDirectory(
103+
// at: URL(fileURLWithPath: outputDirectoryPath),
104+
// withIntermediateDirectories: true,
105+
// attributes: nil
106+
// )
107+
//
105108
let classpathOutputURL =
106109
URL(fileURLWithPath: outputDirectoryPath)
107110
.appendingPathComponent("\(moduleName).swift-java.classpath", isDirectory: false)
108111

112+
let classpathString = "MOCK"
109113
try! classpathString.write(to: classpathOutputURL, atomically: true, encoding: .utf8)
110114

111115
print("[swift-java-bootstrap] Done, written classpath to: \(classpathOutputURL)")

0 commit comments

Comments
 (0)