From 4a46d57f36d7acb25e123e37b5a2bb28dbdb9462 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Sun, 28 May 2023 18:40:51 -0700 Subject: [PATCH] Add -supplementary-output-file-map --- .../SwiftFrontend/SwiftFrontendArgInput.swift | 32 ++++++---- .../Commands/Swiftc/SwiftcContext.swift | 2 + .../Swiftc/SwiftcFilemapInputEditor.swift | 26 +++++++-- .../Commands/Swiftc/XCSwiftc.swift | 4 +- .../XCSwiftcFrontendMain.swift | 6 +- .../SwiftcFilemapInputEditorTests.swift | 58 ++++++++++++++++--- 6 files changed, 101 insertions(+), 27 deletions(-) diff --git a/Sources/XCRemoteCache/Commands/SwiftFrontend/SwiftFrontendArgInput.swift b/Sources/XCRemoteCache/Commands/SwiftFrontend/SwiftFrontendArgInput.swift index 26cc2d8c..dda0b23d 100644 --- a/Sources/XCRemoteCache/Commands/SwiftFrontend/SwiftFrontendArgInput.swift +++ b/Sources/XCRemoteCache/Commands/SwiftFrontend/SwiftFrontendArgInput.swift @@ -63,6 +63,7 @@ public struct SwiftFrontendArgInput { // .swiftsourceinfo and .swiftdoc will be placed next to the .swiftmodule let sourceInfoPath: String? let docPath: String? + let supplementaryOutputFileMap: String? /// Manual initializer implementation required to be public public init( @@ -77,7 +78,8 @@ public struct SwiftFrontendArgInput { dependenciesPaths: [String], diagnosticsPaths: [String], sourceInfoPath: String?, - docPath: String? + docPath: String?, + supplementaryOutputFileMap: String? ) { self.compile = compile self.emitModule = emitModule @@ -91,6 +93,7 @@ public struct SwiftFrontendArgInput { self.diagnosticsPaths = diagnosticsPaths self.sourceInfoPath = sourceInfoPath self.docPath = docPath + self.supplementaryOutputFileMap = supplementaryOutputFileMap } // swiftlint:disable:next cyclomatic_complexity function_body_length @@ -139,23 +142,28 @@ public struct SwiftFrontendArgInput { emitModule: nil ) - let compilationFileMap = (0.. [String: Any]? { + switch fileFormat { + case .json: + return try JSONSerialization.jsonObject(with: content, options: []) as? [String: Any] + case .yaml: + return try Yams.load(yaml: String(data: content, encoding: .utf8)!) as? [String: Any] + } + } } extension SwiftCompilationInfo { init(from object: [String: Any]) throws { - info = try SwiftModuleCompilationInfo(from: object[""]) + info = try SwiftModuleCompilationInfo(from: object["", default: [:]]) files = try object.reduce([]) { prev, new in let (key, value) = new if key.isEmpty { diff --git a/Sources/XCRemoteCache/Commands/Swiftc/XCSwiftc.swift b/Sources/XCRemoteCache/Commands/Swiftc/XCSwiftc.swift index ec2a54b0..a071f93c 100644 --- a/Sources/XCRemoteCache/Commands/Swiftc/XCSwiftc.swift +++ b/Sources/XCRemoteCache/Commands/Swiftc/XCSwiftc.swift @@ -83,7 +83,9 @@ public class XCSwiftAbstract { // and the file/list is named "output" switch context.outputs { case .fileMap(let path): - inputReader = SwiftcFilemapInputEditor(URL(fileURLWithPath: path), fileManager: fileManager) + inputReader = SwiftcFilemapInputEditor(URL(fileURLWithPath: path), fileFormat: .json, fileManager: fileManager) + case .supplementaryFileMap(let path): + inputReader = SwiftcFilemapInputEditor(URL(fileURLWithPath: path), fileFormat: .yaml, fileManager: fileManager) case .map(let map): // static - passed via the arguments list // TODO: check if first 2 ars can always be `nil` diff --git a/Sources/xcswift-frontend/XCSwiftcFrontendMain.swift b/Sources/xcswift-frontend/XCSwiftcFrontendMain.swift index 2e730fdb..05141f49 100644 --- a/Sources/xcswift-frontend/XCSwiftcFrontendMain.swift +++ b/Sources/xcswift-frontend/XCSwiftcFrontendMain.swift @@ -42,6 +42,7 @@ public class XCSwiftcFrontendMain { var diagnosticsPaths: [String] = [] var sourceInfoPath: String? var docPath: String? + var supplementaryOutputFileMap: String? for i in 0..