From d44464128f1929c04bccf253e943132755811742 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 19 Feb 2024 01:06:05 +0800 Subject: [PATCH] Update warning as errors config --- Package.resolved | 2 +- Package.swift | 53 +++++++++++++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Package.resolved b/Package.resolved index 8118bb69..b0380e41 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,7 +6,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenGraph", "state" : { "branch" : "main", - "revision" : "8f0376278186b6e24e8d7a07a560f3efaa2fef1d" + "revision" : "8cc89abc1fff74b387a083eab8ffa91f1b9fdca7" } }, { diff --git a/Package.swift b/Package.swift index 920b7317..6ba620d1 100644 --- a/Package.swift +++ b/Package.swift @@ -4,10 +4,34 @@ import Foundation import PackageDescription -let isXcodeEnv = ProcessInfo.processInfo.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode" +func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { + guard let value = Context.environment[key] else { + return defaultValue + } + if value == "1" { + return true + } else if value == "0" { + return false + } else { + return defaultValue + } +} + +let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode" + // Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem" let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem" +var sharedSwiftSettings: [SwiftSetting] = [ + .enableExperimentalFeature("AccessLevelOnImport"), + .define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"), +] + +let warningsAsErrorsCondition = envEnable("OPENSWIFTUI_WERROR", default: isXcodeEnv) +if warningsAsErrorsCondition { + sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"])) +} + let openSwiftUITarget = Target.target( name: "OpenSwiftUI", dependencies: [ @@ -15,28 +39,28 @@ let openSwiftUITarget = Target.target( .target(name: "CoreServices", condition: .when(platforms: [.iOS])), .product(name: "OpenGraphShims", package: "OpenGraph"), ], - swiftSettings: [ - .enableExperimentalFeature("AccessLevelOnImport"), - .define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"), - ] + swiftSettings: sharedSwiftSettings ) let openSwiftUITestTarget = Target.testTarget( name: "OpenSwiftUITests", dependencies: [ "OpenSwiftUI", ], - exclude: ["README.md"] + exclude: ["README.md"], + swiftSettings: sharedSwiftSettings ) let openSwiftUITempTestTarget = Target.testTarget( name: "OpenSwiftUITempTests", dependencies: [ "OpenSwiftUI", ], - exclude: ["README.md"] + exclude: ["README.md"], + swiftSettings: sharedSwiftSettings ) let openSwiftUICompatibilityTestTarget = Target.testTarget( name: "OpenSwiftUICompatibilityTests", - exclude: ["README.md"] + exclude: ["README.md"], + swiftSettings: sharedSwiftSettings ) let package = Package( @@ -71,19 +95,6 @@ let package = Package( ] ) -func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { - guard let value = ProcessInfo.processInfo.environment[key] else { - return defaultValue - } - if value == "1" { - return true - } else if value == "0" { - return false - } else { - return defaultValue - } -} - #if os(macOS) let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true) #else