From c98dd8a8865f32043a281019117765dc96e7919f Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Thu, 20 Nov 2025 16:50:26 +0900 Subject: [PATCH 1/3] config: log-level should encode as string --- .../SwiftTypeInSubDirectory.swift | 0 .../Sources/MySwiftLibrary/swift-java.config | 3 +- .../swift/SwiftTypeInSubDirectoryTest.java | 71 +++++++++++++++++++ .../Sources/MySwiftLibrary/swift-java.config | 2 +- .../Configuration.swift | 17 +++-- 5 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/LibrarySubDirectory/SwiftTypeInSubDirectory.swift create mode 100644 Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java diff --git a/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/LibrarySubDirectory/SwiftTypeInSubDirectory.swift b/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/LibrarySubDirectory/SwiftTypeInSubDirectory.swift new file mode 100644 index 00000000..e69de29b diff --git a/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/swift-java.config b/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/swift-java.config index 6e5bc2af..3a76a8d8 100644 --- a/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/swift-java.config +++ b/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/swift-java.config @@ -1,3 +1,4 @@ { - "javaPackage": "com.example.swift" + "javaPackage": "com.example.swift", + "logLevel": "trace" } diff --git a/Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java b/Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java new file mode 100644 index 00000000..1f0464eb --- /dev/null +++ b/Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift.org project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of Swift.org project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +package com.example.swift; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.swift.swiftkit.core.SwiftLibraries; +import org.swift.swiftkit.ffm.AllocatingSwiftArena; + +import java.io.File; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.*; + +public class MySwiftClassTest { + + void checkPaths(Throwable throwable) { + var paths = SwiftLibraries.getJavaLibraryPath().split(":"); + for (var path : paths) { + Stream.of(new File(path).listFiles()) + .filter(file -> !file.isDirectory()) + .forEach((file) -> { + System.out.println(" - " + file.getPath()); + }); + } + + throw new RuntimeException(throwable); + } + + @Test + void test_MySwiftClass_voidMethod() { + try(var arena = AllocatingSwiftArena.ofConfined()) { + MySwiftClass o = MySwiftClass.init(12, 42, arena); + o.voidMethod(); + } catch (Throwable throwable) { + checkPaths(throwable); + } + } + + @Test + void test_MySwiftClass_makeIntMethod() { + try(var arena = AllocatingSwiftArena.ofConfined()) { + MySwiftClass o = MySwiftClass.init(12, 42, arena); + var got = o.makeIntMethod(); + assertEquals(12, got); + } + } + + @Test + @Disabled // TODO: Need var mangled names in interfaces + void test_MySwiftClass_property_len() { + try(var arena = AllocatingSwiftArena.ofConfined()) { + MySwiftClass o = MySwiftClass.init(12, 42, arena); + var got = o.getLen(); + assertEquals(12, got); + } + } + +} diff --git a/Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/swift-java.config b/Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/swift-java.config index be44c2fd..3d6a1201 100644 --- a/Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/swift-java.config +++ b/Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/swift-java.config @@ -1,5 +1,5 @@ { "javaPackage": "com.example.swift", "mode": "jni", - "logLevel": ["debug"] + "logLevel": "debug" } diff --git a/Sources/SwiftJavaConfigurationShared/Configuration.swift b/Sources/SwiftJavaConfigurationShared/Configuration.swift index 493ee4bc..661cf963 100644 --- a/Sources/SwiftJavaConfigurationShared/Configuration.swift +++ b/Sources/SwiftJavaConfigurationShared/Configuration.swift @@ -183,7 +183,10 @@ public func readConfiguration(string: String, configPath: URL?, file: String = # decoder.allowsJSON5 = true return try decoder.decode(Configuration.self, from: configData) } catch { - throw ConfigurationError(message: "Failed to parse SwiftJava configuration at '\(configPath.map({ $0.absoluteURL.description }) ?? "")'! \(#fileID):\(#line)", error: error, + throw ConfigurationError( + message: "Failed to parse SwiftJava configuration at '\(configPath.map({ $0.absoluteURL.description }) ?? "")'! \(#fileID):\(#line)", + error: error, + text: string, file: file, line: line) } } @@ -276,19 +279,21 @@ extension Configuration { public struct ConfigurationError: Error { let message: String let error: any Error + let text: String? let file: String let line: UInt - init(message: String, error: any Error, file: String = #fileID, line: UInt = #line) { + init(message: String, error: any Error, text: String?, file: String = #fileID, line: UInt = #line) { self.message = message self.error = error + self.text = text self.file = file self.line = line } } -public enum LogLevel: String, Codable, Hashable { +public enum LogLevel: String, ExpressibleByStringLiteral, Codable, Hashable { case trace = "trace" case debug = "debug" case info = "info" @@ -296,11 +301,15 @@ public enum LogLevel: String, Codable, Hashable { case warning = "warning" case error = "error" case critical = "critical" + + public init(stringLiteral value: String) { + self = LogLevel(rawValue: value) ?? .info + } } extension LogLevel { public init(from decoder: any Decoder) throws { - var container = try decoder.unkeyedContainer() + var container = try decoder.singleValueContainer() let string = try container.decode(String.self) switch string { case "trace": self = .trace From a0ad5153fc7b47f4bbaf20f6fd9e9b85bb2082f0 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Thu, 20 Nov 2025 16:53:29 +0900 Subject: [PATCH 2/3] Delete Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/LibrarySubDirectory/SwiftTypeInSubDirectory.swift --- .../LibrarySubDirectory/SwiftTypeInSubDirectory.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/LibrarySubDirectory/SwiftTypeInSubDirectory.swift diff --git a/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/LibrarySubDirectory/SwiftTypeInSubDirectory.swift b/Samples/SwiftJavaExtractFFMSampleApp/Sources/MySwiftLibrary/LibrarySubDirectory/SwiftTypeInSubDirectory.swift deleted file mode 100644 index e69de29b..00000000 From c8f46d45599c9bcf06cb67f1e73070a0e016ff63 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Thu, 20 Nov 2025 19:33:47 +0900 Subject: [PATCH 3/3] Delete Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java --- .../swift/SwiftTypeInSubDirectoryTest.java | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java diff --git a/Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java b/Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java deleted file mode 100644 index 1f0464eb..00000000 --- a/Samples/SwiftJavaExtractFFMSampleApp/src/test/java/com/example/swift/SwiftTypeInSubDirectoryTest.java +++ /dev/null @@ -1,71 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2024 Apple Inc. and the Swift.org project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of Swift.org project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -package com.example.swift; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.swift.swiftkit.core.SwiftLibraries; -import org.swift.swiftkit.ffm.AllocatingSwiftArena; - -import java.io.File; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; - -public class MySwiftClassTest { - - void checkPaths(Throwable throwable) { - var paths = SwiftLibraries.getJavaLibraryPath().split(":"); - for (var path : paths) { - Stream.of(new File(path).listFiles()) - .filter(file -> !file.isDirectory()) - .forEach((file) -> { - System.out.println(" - " + file.getPath()); - }); - } - - throw new RuntimeException(throwable); - } - - @Test - void test_MySwiftClass_voidMethod() { - try(var arena = AllocatingSwiftArena.ofConfined()) { - MySwiftClass o = MySwiftClass.init(12, 42, arena); - o.voidMethod(); - } catch (Throwable throwable) { - checkPaths(throwable); - } - } - - @Test - void test_MySwiftClass_makeIntMethod() { - try(var arena = AllocatingSwiftArena.ofConfined()) { - MySwiftClass o = MySwiftClass.init(12, 42, arena); - var got = o.makeIntMethod(); - assertEquals(12, got); - } - } - - @Test - @Disabled // TODO: Need var mangled names in interfaces - void test_MySwiftClass_property_len() { - try(var arena = AllocatingSwiftArena.ofConfined()) { - MySwiftClass o = MySwiftClass.init(12, 42, arena); - var got = o.getLen(); - assertEquals(12, got); - } - } - -}