-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from polac24/20220606-publish-swifth-md5
Support exposing enums from ObjC via Bridging headers
- Loading branch information
Showing
39 changed files
with
795 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2022 Spotify AB. | ||
// | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import Foundation | ||
|
||
|
||
/// Performs a pre/postprocessing on an artifact package | ||
/// Could be a place for file reorganization (to support legacy package formats) and/or | ||
/// remapp absolute paths in some package files | ||
protocol ArtifactProcessor { | ||
/// Processes a raw artifact in a directory. Raw artifact is a format of an artifact | ||
/// that is stored in a remote cache server (generic) | ||
/// - Parameter rawArtifact: directory that contains raw artifact content | ||
func process(rawArtifact: URL) throws | ||
|
||
/// Processes a local artifact in a directory | ||
/// - Parameter localArtifact: directory that contains local (machine-specific) artifact content | ||
func process(localArtifact: URL) throws | ||
} | ||
|
||
/// Processes downloaded artifact by replacing generic paths in generated ObjC headers placed in ./include | ||
class UnzippedArtifactProcessor: ArtifactProcessor { | ||
/// All directories in an artifact that should be processed by path remapping | ||
private static let remappingDirs = ["include"] | ||
private let fileRemapper: FileDependenciesRemapper | ||
private let dirScanner: DirScanner | ||
|
||
init(fileRemapper: FileDependenciesRemapper, dirScanner: DirScanner) { | ||
self.fileRemapper = fileRemapper | ||
self.dirScanner = dirScanner | ||
} | ||
|
||
private func findProcessingEligableFiles(path: String) throws -> [URL] { | ||
let remappingURL = URL(fileURLWithPath: path) | ||
let allFiles = try dirScanner.recursiveItems(at: remappingURL) | ||
return allFiles.filter({ !$0.isHidden }) | ||
} | ||
|
||
/// Replaces all generic paths in a raw artifact's `include` dir with | ||
/// absolute paths, specific for a given machine and configuration | ||
/// - Parameter rawArtifact: raw artifact location | ||
func process(rawArtifact url: URL) throws { | ||
for remappingDir in Self.remappingDirs { | ||
let remappingPath = url.appendingPathComponent(remappingDir).path | ||
let allFiles = try findProcessingEligableFiles(path: remappingPath) | ||
try allFiles.forEach(fileRemapper.remap(fromGeneric:)) | ||
} | ||
} | ||
|
||
func process(localArtifact url: URL) throws { | ||
for remappingDir in Self.remappingDirs { | ||
let remappingPath = url.appendingPathComponent(remappingDir).path | ||
let allFiles = try findProcessingEligableFiles(path: remappingPath) | ||
try allFiles.forEach(fileRemapper.remap(fromLocal:)) | ||
} | ||
} | ||
} | ||
|
||
fileprivate extension URL { | ||
// Recognize hidden files starting with a dot | ||
var isHidden: Bool { | ||
lastPathComponent.hasPrefix(".") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Sources/XCRemoteCache/Artifacts/FileDependenciesRemapper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2022 Spotify AB. | ||
// | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import Foundation | ||
|
||
|
||
enum FileDependenciesRemapperError: Error { | ||
/// Thrown when the file to remap is invalid (e.g. doesn't exist or has unexpected format) | ||
case invalidRemappingFile(URL) | ||
} | ||
|
||
/// Replaces paths in a file content between generic (placeholder-based) | ||
/// and local formats | ||
protocol FileDependenciesRemapper { | ||
/// Replaces all generic paths (with placeholders) to a local, machine | ||
/// specific absolute paths | ||
/// - Parameter url: location of a file that should be remapped in-place | ||
func remap(fromGeneric url: URL) throws | ||
/// Replaces all local, machine specific absolute paths to | ||
/// generic ones | ||
/// - Parameter url: location of a file that should be remapped in-place | ||
func remap(fromLocal url: URL) throws | ||
} | ||
|
||
/// Remaps absolute paths in a text files stored on a disk | ||
/// Note: That class can be used only for text-based files, not binaries | ||
class TextFileDependenciesRemapper: FileDependenciesRemapper { | ||
private static let linesSeparator = "\n" | ||
private let remapper: DependenciesRemapper | ||
private let fileAccessor: FileAccessor | ||
|
||
init(remapper: DependenciesRemapper, fileAccessor: FileAccessor) { | ||
self.remapper = remapper | ||
self.fileAccessor = fileAccessor | ||
} | ||
|
||
private func readFileLines(_ url: URL) throws -> [String] { | ||
guard let content = try fileAccessor.contents(atPath: url.path) else { | ||
// the file is empty | ||
return [] | ||
} | ||
guard let contentString = String(data: content, encoding: .utf8) else { | ||
throw FileDependenciesRemapperError.invalidRemappingFile(url) | ||
} | ||
return contentString.components(separatedBy: .newlines) | ||
} | ||
|
||
private func storeFileLines(lines: [String], url: URL) throws { | ||
let contentString = lines.joined(separator: "\n") | ||
let contentData = contentString.data(using: String.Encoding.utf8) | ||
try fileAccessor.write(toPath: url.path, contents: contentData) | ||
} | ||
|
||
func remap(fromGeneric url: URL) throws { | ||
let contentLines = try readFileLines(url) | ||
let remappedContent = try remapper.replace(genericPaths: contentLines) | ||
try storeFileLines(lines: remappedContent, url: url) | ||
} | ||
|
||
func remap(fromLocal url: URL) throws { | ||
let contentLines = try readFileLines(url) | ||
let remappedContent = try remapper.replace(localPaths: contentLines) | ||
try storeFileLines(lines: remappedContent, url: url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.