Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ let package = Package(
.plugin(
name: "MetalCompilerPlugin",
targets: ["MetalCompilerPlugin"]
)
),
.library(name: "MetalCompilerPluginSupport", targets: ["MetalCompilerPluginSupport"]),
],
targets: [
.plugin(
name: "MetalCompilerPlugin",
capability: .buildTool()
),
.target(
name: "MetalCompilerPluginSupport"
),

// The following targets are for testing the plugin and are examples of its usage.
.target(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Foundation

public extension Bundle {
var parentBundle: Bundle? {
let components = bundlePath.split(separator: "/")
guard let index = components.dropLast().firstIndex(where: { $0.hasSuffix(".bundle") || $0.hasSuffix(".xctest") || $0.hasSuffix(".app") }) else {
return nil
}
let path = "/" + components[...index].joined(separator: "/")
return Bundle(path: path)
}

var childBundles: [Bundle] {
guard let resourcePath else {
return []
}
let fileManager = FileManager()
guard let paths = try? fileManager.contentsOfDirectory(atPath: resourcePath) else {
return []
}

return paths.filter {
$0.hasSuffix(".bundle")
}
.map {
Bundle(path: resourcePath.appending("/").appending($0))!
}
}

/// Looks for a child bundle with a name of the form: `"*_<suffix>.bundle"`. Use like `Bundle.module.parentBundle?.childBundle(withSuffix: "<target name>")` to help find a bundle with shaders
func childBundle(withSuffix suffix: String) -> Bundle? {
childBundles.first {
$0.bundleURL.lastPathComponent.hasSuffix(("_\(suffix).bundle"))
}
}
}