Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add excludes to fix SPM build warnings #266

Merged
merged 1 commit into from
Sep 4, 2024
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
3 changes: 2 additions & 1 deletion Generator/Sources/CodeWriters/IndentedTextOutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public class IndentedTextOutputStream: TextOutputStream {
grouping: VerticalGrouping? = nil,
header: String? = nil,
footer: String? = nil,
endFooterLine: Bool = true,
body: () throws -> Void) rethrows {

if let grouping {
Expand All @@ -164,7 +165,7 @@ public class IndentedTextOutputStream: TextOutputStream {
if let footer {
// Force the footer to be grouped with the line above
self.lineGrouping = nil
write(footer, endLine: true)
write(footer, endLine: endFooterLine)
}

self.lineGrouping = grouping
Expand Down
42 changes: 22 additions & 20 deletions Generator/Sources/CodeWriters/Swift/SwiftPackage+write.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,59 @@ extension SwiftPackage {
// products:
if !products.isEmpty {
writer.write(",", endLine: true)
writer.writeIndentedBlock(header: "products: [") {
writer.writeIndentedBlock(header: "products: [", footer: "]", endFooterLine: false) {
for (index, product) in products.enumerated() {
if index > 0 { writer.write(", ", endLine: true) }
product.write(to: writer)
}
}
writer.write("]")
}

// dependencies:
if !dependencies.isEmpty {
writer.write(",", endLine: true)
writer.writeIndentedBlock(header: "dependencies: [") {
writer.writeIndentedBlock(header: "dependencies: [", footer: "]", endFooterLine: false) {
for (index, dependency) in dependencies.enumerated() {
if index > 0 { writer.write(", ", endLine: true) }
dependency.write(to: writer)
}
}
writer.write("]")
}

// targets:
if !targets.isEmpty {
writer.write(",", endLine: true)
writer.writeIndentedBlock(header: "targets: [") {
writer.writeIndentedBlock(header: "targets: [", footer: "]", endFooterLine: false) {
for (index, target) in targets.enumerated() {
if index > 0 { writer.write(", ", endLine: true) }
target.write(to: writer)
}
}
writer.write("]")
}
}
}
}

extension SwiftPackage.Product {
fileprivate func write(to writer: IndentedTextOutputStream) {
writer.writeIndentedBlock(header: ".library(") {
writer.writeIndentedBlock(header: ".library(", footer: ")", endFooterLine: false) {
writer.write("name: \"\(escapeStringLiteral(name))\"")
if !targets.isEmpty {
writer.write(",", endLine: true)
writer.writeIndentedBlock(header: "targets: [") {
writer.writeIndentedBlock(header: "targets: [", footer: "]", endFooterLine: false) {
for (index, target) in targets.enumerated() {
if index > 0 { writer.write(", ", endLine: true) }
writer.write("\"\(escapeStringLiteral(target))\"")
}
}
writer.write("]")
}
}
writer.write(")")
}
}

extension SwiftPackage.Dependency {
fileprivate func write(to writer: IndentedTextOutputStream) {
writer.writeIndentedBlock(header: ".package(") {
writer.writeIndentedBlock(header: ".package(", footer: ")", endFooterLine: false) {
switch self {
case .fileSystem(let name, let path):
if let name { writer.write("name: \"\(name)\",", endLine: true) }
Expand All @@ -78,48 +73,55 @@ extension SwiftPackage.Dependency {
writer.write("branch: \"\(escapeStringLiteral(branch))\"")
}
}
writer.write(")")
}
}

extension SwiftPackage.Target {
fileprivate func write(to writer: IndentedTextOutputStream) {
writer.writeIndentedBlock(header: ".target(") {
writer.writeIndentedBlock(header: ".target(", footer: ")", endFooterLine: false) {
writer.write("name: \"\(escapeStringLiteral(name))\"")

if !dependencies.isEmpty {
writer.write(",", endLine: true)
writer.writeIndentedBlock(header: "dependencies: [") {
writer.writeIndentedBlock(header: "dependencies: [", footer: "]", endFooterLine: false) {
for (index, dependency) in dependencies.enumerated() {
if index > 0 { writer.write(", ", endLine: true) }
dependency.write(to: writer)
}
}
writer.write("]")
}

if let path {
writer.write(",", endLine: true)
writer.write("path: \"\(escapeStringLiteral(path))\"")
}

if !exclude.isEmpty {
writer.write(",", endLine: true)
writer.writeIndentedBlock(header: "exclude: [", footer: "]", endFooterLine: false) {
for (index, path) in exclude.enumerated() {
if index > 0 { writer.write(", ", endLine: true) }
writer.write("\"")
writer.write(path.replacingOccurrences(of: "\\", with: "\\\\"))
writer.write("\"")
}
}
}

if !cUnsafeFlags.isEmpty {
writer.write(",", endLine: true)
writer.writeIndentedBlock(header: "cSettings: [") {
writer.writeIndentedBlock(header: ".unsafeFlags([") {
writer.writeIndentedBlock(header: "cSettings: [", footer: "]", endFooterLine: false) {
writer.writeIndentedBlock(header: ".unsafeFlags([", footer: "]", endFooterLine: false) {
for (index, flag) in cUnsafeFlags.enumerated() {
if index > 0 { writer.write(", ", endLine: true) }
writer.write("\"")
writer.write(flag)
writer.write("\"")
}
}
writer.write("])")
}
writer.write("]")
}
}
writer.write(")")
}
}

Expand Down
8 changes: 5 additions & 3 deletions Generator/Sources/CodeWriters/Swift/SwiftPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ public struct SwiftPackage {
public var name: String
public var dependencies: [Dependency] = []
public var path: String?
public var exclude: [String] = []
public var cUnsafeFlags: [String]

public init(name: String, dependencies: [Dependency] = [], path: String? = nil, cUnsafeFlags: [String] = []) {
public init(name: String, dependencies: [Dependency] = [], path: String? = nil, exclude: [String] = [], cUnsafeFlags: [String] = []) {
self.name = name
self.dependencies = dependencies
self.path = path
self.exclude = exclude
self.cUnsafeFlags = cUnsafeFlags
}

public static func target(name: String, dependencies: [Dependency] = [], path: String? = nil, cUnsafeFlags: [String] = []) -> Target {
.init(name: name, dependencies: dependencies, path: path, cUnsafeFlags: cUnsafeFlags)
public static func target(name: String, dependencies: [Dependency] = [], path: String? = nil, exclude: [String] = [], cUnsafeFlags: [String] = []) -> Target {
.init(name: name, dependencies: dependencies, path: path, exclude: exclude, cUnsafeFlags: cUnsafeFlags)
}

public enum Dependency: ExpressibleByStringLiteral {
Expand Down
9 changes: 8 additions & 1 deletion Generator/Sources/SwiftWinRT/Writing/SwiftPackageFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DotNetMetadata
import ProjectionModel
import struct Foundation.URL

func writeSwiftPackageFile(_ projection: SwiftProjection, supportPackageLocation: String, toPath path: String) {
func writeSwiftPackageFile(_ projection: SwiftProjection, supportPackageLocation: String, excludeCMakeLists: Bool, toPath path: String) {
var package = SwiftPackage(name: "Projection")
package.dependencies.append(getSupportPackageDependency(location: supportPackageLocation))

Expand Down Expand Up @@ -55,6 +55,13 @@ func writeSwiftPackageFile(_ projection: SwiftProjection, supportPackageLocation
}
}

if excludeCMakeLists {
// Assume every target has a root CMakeLists.txt file
for targetIndex in package.targets.indices {
package.targets[targetIndex].exclude.append("CMakeLists.txt")
}
}

package.products.append(.library(name: "Projection", targets: productTargets))

package.write(version: "5.10", to: FileTextOutputStream(path: path, directoryCreation: .ancestors))
Expand Down
1 change: 1 addition & 0 deletions Generator/Sources/SwiftWinRT/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ do {
writeSwiftPackageFile(
projection,
supportPackageLocation: commandLineArguments.supportPackageLocation,
excludeCMakeLists: commandLineArguments.generateCMakeLists,
toPath: "\(commandLineArguments.outputDirectoryPath)\\Package.swift")
}

Expand Down
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ let package = Package(
name: "WindowsRuntime",
dependencies: ["COM", "WindowsRuntime_ABI", "InternalABI"],
path: "Support/Sources/WindowsRuntime",
exclude: ["CMakeLists.txt", "Readme.md"]),
exclude: [
"CMakeLists.txt",
"ProjectedTypes/Core/Readme.md",
"ProjectedTypes/WindowsFoundation/Readme.md",
]),
.testTarget(
name: "Tests",
dependencies: ["COM", "WindowsRuntime"],
Expand Down
Loading