diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 65b5d4444..875033412 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -1927,10 +1927,11 @@ 849C645C1ED37A5D003D8FC0 /* Sources */, 849C645D1ED37A5D003D8FC0 /* Frameworks */, 849C645E1ED37A5D003D8FC0 /* Resources */, - 84C987A52000AC9E0066B150 /* ShellScript */, + 84C987A52000AC9E0066B150 /* Run Script: Automated build numbers */, 84B06F681ED37B9000F0B54B /* Embed Frameworks */, 6581C75720CED60100F4AD34 /* Embed App Extensions */, - 8423E3E3220158E700C3795B /* ShellScript */, + D519E77022EE5B4100923F27 /* Run Script: Verify No Build Settings */, + 8423E3E3220158E700C3795B /* Run Script: codesign release builds */, ); buildRules = ( ); @@ -2292,7 +2293,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 8423E3E3220158E700C3795B /* ShellScript */ = { + 8423E3E3220158E700C3795B /* Run Script: codesign release builds */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -2301,6 +2302,7 @@ ); inputPaths = ( ); + name = "Run Script: codesign release builds"; outputFileListPaths = ( ); outputPaths = ( @@ -2309,19 +2311,38 @@ shellPath = /bin/sh; shellScript = "# See https://github.com/Watson1978/kotori/commit/ffe320f2e058828f0af294b65ed88dfd7baaabff\n\nif [ \"${CONFIGURATION}\" = \"Release\" ]; then\n codesign --verbose --force --deep -o runtime --sign \"Developer ID Application: Brent Simmons\" \"${CODESIGNING_FOLDER_PATH}/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/AutoUpdate.app\"\nfi\n"; }; - 84C987A52000AC9E0066B150 /* ShellScript */ = { + 84C987A52000AC9E0066B150 /* Run Script: Automated build numbers */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); + name = "Run Script: Automated build numbers"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "# See https://blog.curtisherbert.com/automated-build-numbers/\n\ngit=`sh /etc/profile; which git`\nbranch_name=`$git symbolic-ref HEAD | sed -e 's,.*/\\\\(.*\\\\),\\\\1,'`\ngit_count=`$git rev-list $branch_name |wc -l | sed 's/^ *//;s/ *$//'`\nsimple_branch_name=`$git rev-parse --abbrev-ref HEAD`\n\nbuild_number=\"$git_count\"\nif [ $CONFIGURATION != \"Release\" ]; then\nbuild_number+=\"-$simple_branch_name\"\nfi\n\nplist=\"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}\"\ndsym_plist=\"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist\"\n\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $build_number\" \"$plist\"\nif [ -f \"$DSYM_INFO_PLIST\" ] ; then\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $build_number\" \"$dsym_plist\"\nfi\n"; }; + D519E77022EE5B4100923F27 /* Run Script: Verify No Build Settings */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Run Script: Verify No Build Settings"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "xcrun -sdk macosx swiftc -target x86_64-macosx10.11 buildscripts/VerifyNoBuildSettings.swift -o $CONFIGURATION_TEMP_DIR/VerifyNoBS\n$CONFIGURATION_TEMP_DIR/VerifyNoBS ${PROJECT_NAME}.xcodeproj/project.pbxproj\n"; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/buildscripts/VerifyNoBuildSettings.swift b/buildscripts/VerifyNoBuildSettings.swift new file mode 100755 index 000000000..885e660ef --- /dev/null +++ b/buildscripts/VerifyNoBuildSettings.swift @@ -0,0 +1,82 @@ +#!/usr/bin/swift + +// This script is originally from github.com/olofhellman/VerifyNoBS +// The idea is that all build settings should be kept in .xcconfig files, +// rather than in the xcode pbxproj file inside an Xcode project bundle +// Having the script run as part of a regular build ensures that the project file +// doesn't accidentally accumulate build settings + +import Darwin +import Foundation + +func reportError(message: String) { + print("error message was \(message)") + let stderr = FileHandle.standardError + if let data = message.data(using: String.Encoding.utf8, allowLossyConversion: false) { + stderr.write(data) + } else { + print("there was an error. script \"VerifyNoBuildSettings\" could not convert error message to printable string") + } +} + +public enum ProcessXcodeprojResult { + case FoundBuildSettings([String]) + case Error(String) + case OK(String) +} + +public func processXcodeprojAt(url: URL) -> ProcessXcodeprojResult { + let startTime = Date() + guard let xcodeproj = try? String(contentsOf: url, encoding: String.Encoding.utf8) else { + return .Error("script \"VerifyNoBuildSettings\" failed making xcodeproj from url") + } + let lines = xcodeproj.components(separatedBy: CharacterSet.newlines) + print ("found \(lines.count) lines") + + var badLines: [String] = [] + var inBuildSettingsBlock = false + for nthLine in lines { + if inBuildSettingsBlock { + if let _ = nthLine.range(of:"\\u007d[:space:]*;", options: .regularExpression) { + inBuildSettingsBlock = false + } else if let _ = nthLine.range(of:"CODE_SIGN_IDENTITY") { + + } else { + badLines.append(nthLine) + } + } else { + if let _ = nthLine.range(of:"buildSettings[:space:]*=", options: .regularExpression) { + inBuildSettingsBlock = true + } + } + } + + let timeInterval = Date().timeIntervalSince(startTime) + print ("process took \(timeInterval) seconds") + if (badLines.count > 0) { + return .FoundBuildSettings(badLines) + } + return .OK(":-)") +} +print("Verifying no buildSettings...") + +let commandLineArgs = CommandLine.arguments +print("processArgs were \(commandLineArgs)") +let xcodeprojfilepath = commandLineArgs[1] +let myUrl = URL(fileURLWithPath:xcodeprojfilepath) +let result = processXcodeprojAt(url: myUrl) + +switch result { + case .Error(let str): + reportError (message: "error script \"VerifyNoBuildSettings\" encountered an error: \(str)") + exit(EXIT_FAILURE) + case .FoundBuildSettings(let badLines): + reportError (message: "script \"VerifyNoBuildSettings\" found build settings in the project file:") + for badLine in badLines { + reportError (message: " \(badLine)\n") + } + exit(EXIT_FAILURE) + case .OK: + print ("script \"VerifyNoBuildSettings\" verified the project contained no buildSettings") + exit(EXIT_SUCCESS) +} diff --git a/xcconfig/NetNewsWire_project.xcconfig b/xcconfig/NetNewsWire_project.xcconfig index c91ef3a68..fbb95fcf1 100644 --- a/xcconfig/NetNewsWire_project.xcconfig +++ b/xcconfig/NetNewsWire_project.xcconfig @@ -1,9 +1,6 @@ -// If a warning is commented out in this list, it is a candidate for uncommenting -// that we just aven't gotten to yet - ALWAYS_SEARCH_USER_PATHS = NO CLANG_ANALYZER_NONNULL = YES -// CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; +CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = gnu++0x CLANG_CXX_LIBRARY = libc++ CLANG_ENABLE_MODULES = YES @@ -28,7 +25,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR CLANG_WARN_RANGE_LOOP_ANALYSIS = YES CLANG_WARN_STRICT_PROTOTYPES = YES CLANG_WARN_SUSPICIOUS_MOVE = YES -// CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CLANG_WARN_UNREACHABLE_CODE = YES COPY_PHASE_STRIP = NO ENABLE_STRICT_OBJC_MSGSEND = YES