mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-20 20:23:25 +01:00
spm App target builds and links!
This commit is contained in:
@@ -54,7 +54,7 @@ struct CargoPlugin: BuildToolPlugin {
|
||||
#if canImport(XcodeProjectPlugin)
|
||||
import XcodeProjectPlugin
|
||||
|
||||
extension SwiftLintPlugin: XcodeBuildToolPlugin {
|
||||
extension CargoPlugin: XcodeBuildToolPlugin {
|
||||
func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] {
|
||||
let inputFilePaths = target.inputFiles
|
||||
.filter { $0.type == .source && $0.path.extension == "swift" }
|
||||
@@ -68,3 +68,43 @@ extension SwiftLintPlugin: XcodeBuildToolPlugin {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if os(Linux)
|
||||
import Glibc
|
||||
#else
|
||||
import Darwin
|
||||
#endif
|
||||
|
||||
extension Path {
|
||||
/// Scans the receiver, then all of its parents looking for a configuration file with the name ".swiftlint.yml".
|
||||
///
|
||||
/// - returns: Path to the configuration file, or nil if one cannot be found.
|
||||
func firstConfigurationFileInParentDirectories() -> Path? {
|
||||
let defaultConfigurationFileName = ".swiftlint.yml"
|
||||
let proposedDirectory = sequence(
|
||||
first: self,
|
||||
next: { path in
|
||||
guard path.stem.count > 1 else {
|
||||
// Check we're not at the root of this filesystem, as `removingLastComponent()`
|
||||
// will continually return the root from itself.
|
||||
return nil
|
||||
}
|
||||
|
||||
return path.removingLastComponent()
|
||||
}
|
||||
).first { path in
|
||||
let potentialConfigurationFile = path.appending(subpath: defaultConfigurationFileName)
|
||||
return potentialConfigurationFile.isAccessible()
|
||||
}
|
||||
return proposedDirectory?.appending(subpath: defaultConfigurationFileName)
|
||||
}
|
||||
|
||||
/// Safe way to check if the file is accessible from within the current process sandbox.
|
||||
private func isAccessible() -> Bool {
|
||||
let result = string.withCString { pointer in
|
||||
access(pointer, R_OK)
|
||||
}
|
||||
|
||||
return result == 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright 2022 The Brave Authors. All rights reserved.
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import PackagePlugin
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
struct IntentBuilderPlugin: BuildToolPlugin {
|
||||
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
|
||||
let outputDirectory = context.pluginWorkDirectory.appending("GeneratedSources")
|
||||
guard let target = target as? SourceModuleTarget else {
|
||||
Diagnostics.error("Attempted to use `IntentBuilderPlugin` on an unsupported module target")
|
||||
return []
|
||||
}
|
||||
return target.sourceFiles(withSuffix: "intentdefinition")
|
||||
.map { file in
|
||||
.prebuildCommand(
|
||||
displayName: "Generate intents sources",
|
||||
executable: Path("/usr/bin/xcrun"),
|
||||
arguments: [
|
||||
"intentbuilderc", "generate",
|
||||
"-input", file.path.string,
|
||||
"-output", outputDirectory,
|
||||
"-language", "Swift",
|
||||
"-swiftVersion", "5.6",
|
||||
"-classPrefix", ""
|
||||
],
|
||||
outputFilesDirectory: outputDirectory
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 2022 The Brave Authors. All rights reserved.
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
import PackagePlugin
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
struct LoggerPlugin: BuildToolPlugin {
|
||||
func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
|
||||
let outputDirectory = context.pluginWorkDirectory.appending("GeneratedSources")
|
||||
guard let target = target as? SourceModuleTarget else {
|
||||
Diagnostics.error("Attempted to use `LoggerPlugin` on an unsupported module target")
|
||||
return []
|
||||
}
|
||||
|
||||
try FileManager.default.createDirectory(atPath: outputDirectory.string, withIntermediateDirectories: true)
|
||||
let source = """
|
||||
import Foundation
|
||||
import os.log
|
||||
|
||||
extension Logger {
|
||||
static var module: Logger {
|
||||
.init(subsystem: "\\(Bundle.main.bundleIdentifier ?? "com.sidestore.ios")", category: "\(target.moduleName)")
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let filePath = outputDirectory.appending("logger.swift")
|
||||
if !FileManager.default.fileExists(atPath: filePath.string) {
|
||||
try source.write(
|
||||
toFile: filePath.string,
|
||||
atomically: true,
|
||||
encoding: .utf8
|
||||
)
|
||||
}
|
||||
// TODO: Generate the above file in an `executableTarget` when SPM supports building Mac tools while targetting iOS
|
||||
return [
|
||||
.buildCommand(
|
||||
displayName: "Generate logger",
|
||||
executable: Path("/bin/zsh"),
|
||||
arguments: [],
|
||||
outputFiles: [outputDirectory.appending("logger.swift")]
|
||||
)
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user