-
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 #215 from polac24/xcode-15-lightweight-support
Add support for Xcode 15
- Loading branch information
Showing
10 changed files
with
362 additions
and
31 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
38 changes: 38 additions & 0 deletions
38
Sources/XCRemoteCache/Commands/Swiftc/FilenameBasedAllowedInputDeterminer.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,38 @@ | ||
// Copyright (c) 2023 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 | ||
|
||
/// Decides if an input to the compilation step should allow reusing the cached artifact | ||
protocol AllowedInputDeterminer { | ||
/// Decides if the input file is allowed to be compiled, even not specified in the dependency list | ||
func allowedNonDependencyInput(file: URL) -> Bool | ||
} | ||
|
||
class FilenameBasedAllowedInputDeterminer: AllowedInputDeterminer { | ||
private let filenames: [String] | ||
|
||
init(_ filenames: [String]) { | ||
self.filenames = filenames | ||
} | ||
|
||
func allowedNonDependencyInput(file: URL) -> Bool { | ||
return filenames.contains(file.lastPathComponent) | ||
} | ||
} |
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
77 changes: 77 additions & 0 deletions
77
Sources/XCRemoteCache/Dependencies/AssetsFileDependenciesReader.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,77 @@ | ||
// Copyright (c) 2023 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 | ||
|
||
/// Parser for `assetcatalog_dependencies` file: an output of the `actool` | ||
/// that lists all dependencies of this command | ||
class AssetsFileDependenciesReader: DependenciesReader { | ||
private let file: URL | ||
private let dirAccessor: DirAccessor | ||
|
||
public init(_ file: URL, dirAccessor: DirAccessor) { | ||
self.file = file | ||
self.dirAccessor = dirAccessor | ||
} | ||
|
||
public func findDependencies() throws -> [String] { | ||
return try Array(findAllDependencies()) | ||
} | ||
|
||
public func findInputs() throws -> [String] { | ||
// XCRemoteCache doesn't use it yet | ||
exit(1, "TODO: implement") | ||
} | ||
|
||
public func readFilesAndDependencies() throws -> [String: [String]] { | ||
return try ["": findAllDependencies()] | ||
} | ||
|
||
private func findAllDependencies() throws -> [String] { | ||
let fileData = try getFileData() | ||
// all dependency files are separated by the \0 byte | ||
// each path has a file type prefix: | ||
// 0x10 - directory | ||
// 0x40 - file | ||
// We only care about dirs, as *.xcassets is a folder | ||
let pathDatas = fileData.split(separator: 0x0) | ||
let paths = pathDatas | ||
.filter { !$0.isEmpty && $0.first == 0x10 } | ||
.map { String(data: $0.dropFirst(), encoding: .utf8)! } | ||
.map(URL.init(fileURLWithPath:)) | ||
let xcassetsPaths = paths.filter { path in | ||
path.pathExtension == "xcassets" | ||
} | ||
return try xcassetsPaths.flatMap { try findAssetsContentJsons(xcasset: $0) } | ||
} | ||
|
||
private func findAssetsContentJsons(xcasset: URL) throws -> [String] { | ||
return try dirAccessor.recursiveItems(at: xcasset).filter { url in | ||
url.lastPathComponent == "Contents.json" | ||
}.map(\.path) | ||
} | ||
|
||
private func getFileData() throws -> Data { | ||
guard let fileData = try dirAccessor.contents(atPath: file.path) else { | ||
throw DependenciesReaderError.readingError | ||
} | ||
return fileData | ||
} | ||
|
||
} |
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.