Skip to content

Commit 25eac35

Browse files
committed
fixing subprocess build on linux
1 parent 1224e41 commit 25eac35

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

Package.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ let package = Package(
369369
"JavaKitShared",
370370
"JavaKitConfigurationShared",
371371
// .product(name: "Subprocess", package: "swift-subprocess")
372-
"_Subprocess", // using process spawning
372+
"_Subprocess",
373373
],
374374
swiftSettings: [
375375
.swiftLanguageMode(.v5),
@@ -394,11 +394,14 @@ let package = Package(
394394
"JavaKitShared",
395395
"JavaKitConfigurationShared",
396396
],
397-
398397
swiftSettings: [
399398
.swiftLanguageMode(.v5),
400399
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
401400
.enableUpcomingFeature("BareSlashRegexLiterals"),
401+
.define(
402+
"SYSTEM_PACKAGE_DARWIN",
403+
.when(platforms: [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .visionOS])),
404+
.define("SYSTEM_PACKAGE"),
402405
]
403406
),
404407

@@ -508,7 +511,11 @@ let package = Package(
508511
.product(name: "SystemPackage", package: "swift-system"),
509512
],
510513
swiftSettings: [
511-
.swiftLanguageMode(.v5)
514+
.swiftLanguageMode(.v5),
515+
.define(
516+
"SYSTEM_PACKAGE_DARWIN",
517+
.when(platforms: [.macOS, .macCatalyst, .iOS, .watchOS, .tvOS, .visionOS])),
518+
.define("SYSTEM_PACKAGE"),
512519
]
513520
),
514521
]

Sources/SwiftJavaTool/Commands/ResolveCommand.swift

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import SwiftJavaLib
2222
import JavaKitConfigurationShared
2323
import JavaKitShared
2424
import _Subprocess
25+
#if canImport(System)
2526
import System
27+
#else
28+
@preconcurrency import SystemPackage
29+
#endif
2630

2731
typealias Configuration = JavaKitConfigurationShared.Configuration
2832

@@ -58,31 +62,10 @@ extension SwiftJava.ResolveCommand {
5862
var printRuntimeClasspathTaskName: String { "printRuntimeClasspath" }
5963

6064
mutating func runSwiftJavaCommand(config: inout Configuration) async throws {
61-
// Form a class path from all of our input sources:
62-
let classpathOptionEntries: [String] = self.classpathEntries
63-
let classpathFromEnv = self.classpathEnvEntries
64-
let classpathFromConfig: [String] = config.classpath?.split(separator: ":").map(String.init) ?? []
65-
print("[debug][swift-java] Base classpath from config: \(classpathFromConfig)")
66-
67-
var classpathEntries: [String] = classpathFromConfig
68-
69-
let classPathFilesSearchDirectory = self.effectiveSwiftModuleURL.absoluteString
70-
print("[debug][swift-java] Search *.swift-java.classpath in: \(classPathFilesSearchDirectory)")
71-
let swiftJavaCachedModuleClasspath = findSwiftJavaClasspaths(in: classPathFilesSearchDirectory)
72-
73-
print("[debug][swift-java] Classpath from *.swift-java.classpath files: \(swiftJavaCachedModuleClasspath)")
74-
classpathEntries += swiftJavaCachedModuleClasspath
75-
76-
if logLevel >= .debug {
77-
let classpathString = classpathEntries.joined(separator: ":")
78-
print("[debug][swift-java] Initialize JVM with classpath: \(classpathString)")
79-
}
80-
let jvm = try JavaVirtualMachine.shared(classpath: classpathEntries)
81-
8265
var dependenciesToResolve: [JavaDependencyDescriptor] = []
8366
if let input, let inputDependencies = parseDependencyDescriptor(input) {
8467
dependenciesToResolve.append(inputDependencies)
85-
}
68+
}
8669
if let dependencies = config.dependencies {
8770
dependenciesToResolve += dependencies
8871
}
@@ -148,7 +131,7 @@ extension SwiftJava.ResolveCommand {
148131
"--rerun-tasks",
149132
"\(printRuntimeClasspathTaskName)",
150133
],
151-
workingDirectory: FilePath(resolverDir.path),
134+
workingDirectory: Optional(FilePath(resolverDir.path)),
152135
// TODO: we could move to stream processing the outputs
153136
output: .string(limit: Int.max, encoding: UTF8.self), // Don't limit output, we know it will be reasonable size
154137
error: .string(limit: Int.max, encoding: UTF8.self) // Don't limit output, we know it will be reasonable size

0 commit comments

Comments
 (0)