func extraMetaKeys()

in Sources/XCRemoteCache/Commands/Plugins/Thinning/ThinningCreatorPlugin.swift [51:88]


    func extraMetaKeys(_ meta: MainArtifactMeta) throws -> [String: String] {
        // Navigate to the root targetTempDir of all build products (for a specific Configuration+architecture)
        let allTargetsTempDirRoot = targetTempDir.deletingLastPathComponent()

        // iterate all temp directories to find generated and uploaded artifacts. We assume that the DerivedData
        // was emptied before a build so all generated .zip files correspond to a current build
        let allURLs = try dirScanner.items(at: allTargetsTempDirRoot)
        struct TargetTuple {
            let targetName: String
            let fileKey: String
        }
        let uploadedTargetArtifacts = try allURLs.compactMap { tempDir -> TargetTuple? in
            let potentialArtifacts = try findTargetPackageZip(tempDir: tempDir)
            guard !potentialArtifacts.isEmpty else {
                // there is no generated *.zip file, so given target didn't create an artifact - it could be
                // just a helper target (like the target we integrate this plugin with)
                return nil
            }
            // Find {{fileKey}} based on the .zip file basename
            guard potentialArtifacts.count == 1 else {
                throw ThinningCreatorPluginError.noSingleTargetArtifactsGenerated(
                    rootDir: tempDir
                )
            }
            let fileKey = potentialArtifacts[0].deletingPathExtension().lastPathComponent
            // Taking target name from tempDir, which has a structures "*.build"
            let targetName = tempDir.deletingPathExtension().lastPathComponent
            return TargetTuple(targetName: targetName, fileKey: fileKey)
        }
        // Build a dictionary that will be appended to the meta with a format:
        // {
        //   "thinning_TargetName1": "ab2331a",
        //   "thinning_TargetName2": "23a2b1b"
        // }
        let extraKeysTuples = uploadedTargetArtifacts
            .map { ("\(ThinningPlugin.fileKeyPrefix)\($0.targetName)", $0.fileKey) }
        return Dictionary(uniqueKeysWithValues: extraKeysTuples)
    }