diff --git a/AssetResizer.xcodeproj/project.pbxproj b/AssetResizer.xcodeproj/project.pbxproj index dd79e53..06242c7 100644 --- a/AssetResizer.xcodeproj/project.pbxproj +++ b/AssetResizer.xcodeproj/project.pbxproj @@ -35,7 +35,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - F70398681EE6D347003F2AD6 /* update-version.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "update-version.sh"; sourceTree = ""; }; F70398691EE6D347003F2AD6 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; F703986A1EE6D347003F2AD6 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; F703986C1EE6D7A7003F2AD6 /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = ""; }; @@ -87,7 +86,6 @@ F70398691EE6D347003F2AD6 /* LICENSE */, F703986A1EE6D347003F2AD6 /* README.md */, F703986C1EE6D7A7003F2AD6 /* .travis.yml */, - F70398681EE6D347003F2AD6 /* update-version.sh */, ); sourceTree = ""; }; @@ -175,7 +173,6 @@ F79678DF1EDFD14600AC0948 /* Frameworks */, F79678E01EDFD14600AC0948 /* Headers */, F79678E11EDFD14600AC0948 /* Resources */, - F7F0E35C1EE2693400E09A9A /* Increment Build Number */, ); buildRules = ( ); @@ -211,19 +208,19 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1010; ORGANIZATIONNAME = "Jean-Étienne"; TargetAttributes = { F79678E21EDFD14600AC0948 = { CreatedOnToolsVersion = 8.3.2; DevelopmentTeam = N44EJ7YB22; - LastSwiftMigration = 0900; + LastSwiftMigration = 1010; ProvisioningStyle = Automatic; }; F79678EB1EDFD14600AC0948 = { CreatedOnToolsVersion = 8.3.2; DevelopmentTeam = N44EJ7YB22; - LastSwiftMigration = 0900; + LastSwiftMigration = 1010; ProvisioningStyle = Automatic; }; }; @@ -266,23 +263,6 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - F7F0E35C1EE2693400E09A9A /* Increment Build Number */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Increment Build Number"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "sh update-version.sh --xcodeproj=$PROJECT_FILE --plist=$INFOPLIST_FILE"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ F79678DE1EDFD14600AC0948 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -334,6 +314,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -341,6 +322,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -350,7 +332,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 9; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -393,6 +375,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -400,6 +383,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -409,7 +393,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 9; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -439,7 +423,7 @@ DEFINES_MODULE = YES; DEVELOPMENT_TEAM = N44EJ7YB22; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 2; + DYLIB_CURRENT_VERSION = 9; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; INFOPLIST_FILE = AssetResizer/Info.plist; @@ -449,7 +433,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -462,7 +447,7 @@ DEFINES_MODULE = YES; DEVELOPMENT_TEAM = N44EJ7YB22; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 2; + DYLIB_CURRENT_VERSION = 9; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; INFOPLIST_FILE = AssetResizer/Info.plist; @@ -471,7 +456,8 @@ PRODUCT_BUNDLE_IDENTIFIER = net.jeanetienne.AssetResizer; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -485,7 +471,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.jeanetienne.AssetResizerTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -499,7 +486,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.jeanetienne.AssetResizerTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/AssetResizer.xcodeproj/xcshareddata/xcschemes/AssetResizer.xcscheme b/AssetResizer.xcodeproj/xcshareddata/xcschemes/AssetResizer.xcscheme index f73adf4..1c0065f 100644 --- a/AssetResizer.xcodeproj/xcshareddata/xcschemes/AssetResizer.xcscheme +++ b/AssetResizer.xcodeproj/xcshareddata/xcschemes/AssetResizer.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> diff --git a/AssetResizer/AppIconSet.swift b/AssetResizer/AppIconSet.swift index a3892b5..e37ff60 100644 --- a/AssetResizer/AppIconSet.swift +++ b/AssetResizer/AppIconSet.swift @@ -1,9 +1,6 @@ // -// AppIconSet.swift // AssetResizer -// -// Created by Jean-Étienne on 2/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import Foundation @@ -48,7 +45,7 @@ public struct AppIconSet { if let jsonSizes = jsonContents["images"] as? [[String: String]] { return jsonSizes.map { jsonSize -> SizeDescription? in return SizeDescription(json: jsonSize) - }.flatMap { $0 } + }.compactMap { $0 } } else { return [] } @@ -118,7 +115,7 @@ public struct AppIconSet { return newJsonSize } - .flatMap { $0 } + .compactMap { $0 } do { try AppIconSet.write(jsonContents: jsonContents, atPath: jsonPath) diff --git a/AssetResizer/Info.plist b/AssetResizer/Info.plist index 6720d95..bac7b65 100644 --- a/AssetResizer/Info.plist +++ b/AssetResizer/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.0.2 + 0.1.0 CFBundleVersion - 8 + 9 NSHumanReadableCopyright - Copyright © 2017 Jean-Étienne. All rights reserved. + Copyright © 2019 Jean-Étienne. All rights reserved. NSPrincipalClass diff --git a/AssetResizer/NSImage+Resizing.swift b/AssetResizer/NSImage+Resizing.swift index f10fd84..9b3a7f5 100644 --- a/AssetResizer/NSImage+Resizing.swift +++ b/AssetResizer/NSImage+Resizing.swift @@ -1,9 +1,6 @@ // -// NSImage+Resizing.swift // AssetResizer -// -// Created by Jean-Étienne on 1/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import AppKit @@ -14,7 +11,7 @@ extension NSImage { let frame = CGRect(origin: CGPoint.zero, size: size) guard let bestRepresentation = self.bestRepresentation(for: frame, context: nil, - hints: [NSImageHintInterpolation: NSImageInterpolation.high]) + hints: [.interpolation: NSImageInterpolation.high]) else { return nil } diff --git a/AssetResizer/NSImage+Saving.swift b/AssetResizer/NSImage+Saving.swift index bd1c7d5..51b0dfe 100644 --- a/AssetResizer/NSImage+Saving.swift +++ b/AssetResizer/NSImage+Saving.swift @@ -1,9 +1,6 @@ // -// NSImage+Saving.swift // AssetResizer -// -// Created by Jean-Étienne on 1/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import AppKit @@ -14,7 +11,7 @@ extension NSImage { case WritingBitmapRepresentationFailed } - func save(to url: URL, type: NSBitmapImageFileType) throws { + func save(to url: URL, type: NSBitmapImageRep.FileType) throws { if let bitmapRepresentation = representation(forType: type) { try bitmapRepresentation.write(to: url, options: .atomicWrite) } else { @@ -22,7 +19,7 @@ extension NSImage { } } - private func representation(forType type: NSBitmapImageFileType) -> Data? { + private func representation(forType type: NSBitmapImageRep.FileType) -> Data? { if let tiff = self.tiffRepresentation, let tiffData = NSBitmapImageRep(data: tiff) { return tiffData.representation(using: type, properties: [:]) } diff --git a/AssetResizer/ResizedImage.swift b/AssetResizer/ResizedImage.swift index 984ea25..955483d 100644 --- a/AssetResizer/ResizedImage.swift +++ b/AssetResizer/ResizedImage.swift @@ -1,9 +1,6 @@ // -// ResizedImage.swift // AssetResizer -// -// Created by Jean-Étienne on 1/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import AppKit @@ -21,7 +18,7 @@ public struct ResizedImage { public let sizeDescription: SizeDescription /// The bitmap type to be used when saving this image to disk - public let bitmapType: NSBitmapImageFileType + public let bitmapType: NSBitmapImageRep.FileType /// The filename to be used when saving this image to disk public var filename: String { @@ -39,7 +36,7 @@ public struct ResizedImage { init?(original: NSImage, name aName: String, resizing aSizeDescription: SizeDescription, - bitmapType aBitmapType: NSBitmapImageFileType) { + bitmapType aBitmapType: NSBitmapImageRep.FileType) { guard let resizedOriginal = original.resize(to: aSizeDescription.pixelSize) else { return nil } @@ -140,21 +137,21 @@ private extension CGFloat { } -private extension NSBitmapImageFileType { +private extension NSBitmapImageRep.FileType { var fileExtension: String { switch self { - case .TIFF: + case .tiff: return "tiff" - case .BMP: + case .bmp: return "bmp" - case .GIF: + case .gif: return "gif" - case .JPEG: + case .jpeg: return "jpg" - case .PNG: + case .png: return "png" - case .JPEG2000: + case .jpeg2000: return "jpg" } } diff --git a/AssetResizerTests/AppIconSetTests.swift b/AssetResizerTests/AppIconSetTests.swift index 8108b74..ec68a40 100644 --- a/AssetResizerTests/AppIconSetTests.swift +++ b/AssetResizerTests/AppIconSetTests.swift @@ -1,9 +1,6 @@ // -// AppIconSetTests.swift // AssetResizer -// -// Created by Jean-Étienne on 2/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import XCTest @@ -64,8 +61,8 @@ class AppIconSetTests: XCTestCase { return ResizedImage(original: originalImage, name: sizeDescription.canonicalName, resizing: sizeDescription, - bitmapType: .PNG) - }.flatMap { $0 } + bitmapType: .png) + }.compactMap { $0 } do { try appIconSet.update(with: resizedImages) @@ -74,7 +71,7 @@ class AppIconSetTests: XCTestCase { } if let updatedSizes = AppIconSet(atPath: appIconSetPath)?.jsonRepresentation["images"] as? [[String: String]] { - let updatedFilenames = updatedSizes.map { $0["filename"] }.flatMap { $0 }.sorted() + let updatedFilenames = updatedSizes.map { $0["filename"] }.compactMap { $0 }.sorted() let expectedFilenames = [ "car-60@2x.png", "car-60@3x.png", diff --git a/AssetResizerTests/AssetResizerTests.swift b/AssetResizerTests/AssetResizerTests.swift index e722a08..765fa70 100644 --- a/AssetResizerTests/AssetResizerTests.swift +++ b/AssetResizerTests/AssetResizerTests.swift @@ -1,9 +1,6 @@ // -// AssetResizerTests.swift // AssetResizer -// -// Created by Jean-Étienne on 1/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import XCTest diff --git a/AssetResizerTests/Info.plist b/AssetResizerTests/Info.plist index b8bd8b7..a08e908 100644 --- a/AssetResizerTests/Info.plist +++ b/AssetResizerTests/Info.plist @@ -15,8 +15,8 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 0.0.2 + 0.1.0 CFBundleVersion - 8 + 9 diff --git a/AssetResizerTests/ResizedImageTests.swift b/AssetResizerTests/ResizedImageTests.swift index 19ce24f..4481af8 100644 --- a/AssetResizerTests/ResizedImageTests.swift +++ b/AssetResizerTests/ResizedImageTests.swift @@ -1,9 +1,6 @@ // -// ResizedImageTests.swift // AssetResizer -// -// Created by Jean-Étienne on 5/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import XCTest @@ -30,7 +27,7 @@ class ResizedImageTests: XCTestCase { let resizedImage = ResizedImage(original: image, name: "failed", resizing: sizeDescription, - bitmapType: .PNG) + bitmapType: .png) XCTAssertNil(resizedImage) } @@ -42,7 +39,7 @@ class ResizedImageTests: XCTestCase { if let resizedImage = ResizedImage(original: image!, name: "foo", resizing: sizeDescription, - bitmapType: .PNG) { + bitmapType: .png) { XCTAssertEqual(resizedImage.filename, "foo.png", "Resized image has wrong filename") } else { XCTAssertTrue(false, "Resized image could not be initialized") @@ -57,7 +54,7 @@ class ResizedImageTests: XCTestCase { if let resizedImage = ResizedImage(original: image!, name: "bar", resizing: sizeDescription, - bitmapType: .TIFF) { + bitmapType: .tiff) { XCTAssertEqual(resizedImage.filename, "bar.tiff", "Resized image has wrong filename") } else { XCTAssertTrue(false, "Resized image could not be initialized") @@ -72,7 +69,7 @@ class ResizedImageTests: XCTestCase { if let resizedImage = ResizedImage(original: image!, name: "baz", resizing: sizeDescription, - bitmapType: .JPEG2000) { + bitmapType: .jpeg2000) { XCTAssertEqual(resizedImage.filename, "baz.jpg", "Resized image has wrong filename") } else { XCTAssertTrue(false, "Resized image could not be initialized") @@ -87,7 +84,7 @@ class ResizedImageTests: XCTestCase { if let resizedImage = ResizedImage(original: image!, name: "baz", resizing: sizeDescription, - bitmapType: .BMP) { + bitmapType: .bmp) { XCTAssertEqual(resizedImage.filename, "baz.bmp", "Resized image has wrong filename") } else { XCTAssertTrue(false, "Resized image could not be initialized") @@ -102,7 +99,7 @@ class ResizedImageTests: XCTestCase { if let resizedImage = ResizedImage(original: image!, name: "baz", resizing: sizeDescription, - bitmapType: .GIF) { + bitmapType: .gif) { XCTAssertEqual(resizedImage.filename, "baz.gif", "Resized image has wrong filename") } else { XCTAssertTrue(false, "Resized image could not be initialized") @@ -117,7 +114,7 @@ class ResizedImageTests: XCTestCase { if let resizedImage = ResizedImage(original: image!, name: "baz", resizing: sizeDescription, - bitmapType: .JPEG) { + bitmapType: .jpeg) { XCTAssertEqual(resizedImage.filename, "baz.jpg", "Resized image has wrong filename") } else { XCTAssertTrue(false, "Resized image could not be initialized") @@ -132,7 +129,7 @@ class ResizedImageTests: XCTestCase { if let resizedImage = ResizedImage(original: image!, name: sizeDescription.canonicalName, resizing: sizeDescription, - bitmapType: .PNG) { + bitmapType: .png) { try? resizedImage.save(at: URL.cacheFolder) let resizedImageURL = URL.cacheFolder.appendingPathComponent(resizedImage.filename) XCTAssertNotNil(NSImage(contentsOf: resizedImageURL), diff --git a/AssetResizerTests/SizeDescriptionTests.swift b/AssetResizerTests/SizeDescriptionTests.swift index 7c01aa7..b0b827f 100644 --- a/AssetResizerTests/SizeDescriptionTests.swift +++ b/AssetResizerTests/SizeDescriptionTests.swift @@ -1,9 +1,6 @@ // -// SizeDescriptionTests.swift // AssetResizer -// -// Created by Jean-Étienne on 5/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import XCTest diff --git a/AssetResizerTests/Tools/Bundle+Tests.swift b/AssetResizerTests/Tools/Bundle+Tests.swift index 5c8d6fc..7c9586b 100644 --- a/AssetResizerTests/Tools/Bundle+Tests.swift +++ b/AssetResizerTests/Tools/Bundle+Tests.swift @@ -1,9 +1,6 @@ // -// Bundle+Tests.swift -// Speller -// -// Created by Jean-Étienne Parrot on 12/2/17. -// Copyright © 2017 Speller. All rights reserved. +// AssetResizer +// Copyright © 2019 Jean-Étienne. All rights reserved. // import Foundation diff --git a/AssetResizerTests/Tools/TestData.swift b/AssetResizerTests/Tools/TestData.swift index a9306d3..a63c7a9 100644 --- a/AssetResizerTests/Tools/TestData.swift +++ b/AssetResizerTests/Tools/TestData.swift @@ -1,9 +1,6 @@ // -// TestData.swift // AssetResizer -// -// Created by Jean-Étienne on 1/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import AppKit diff --git a/AssetResizerTests/Tools/URL+TempFolder.swift b/AssetResizerTests/Tools/URL+TempFolder.swift index 629820c..d9b2052 100644 --- a/AssetResizerTests/Tools/URL+TempFolder.swift +++ b/AssetResizerTests/Tools/URL+TempFolder.swift @@ -1,9 +1,6 @@ // -// URL+TempFolder.swift // AssetResizer -// -// Created by Jean-Étienne on 5/6/17. -// Copyright © 2017 Jean-Étienne. All rights reserved. +// Copyright © 2019 Jean-Étienne. All rights reserved. // import Foundation diff --git a/LICENSE b/LICENSE index b90e54a..a4dd973 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Jean-Étienne +Copyright (c) 2019 Jean-Étienne Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/update-version.sh b/update-version.sh deleted file mode 100755 index e9f858f..0000000 --- a/update-version.sh +++ /dev/null @@ -1,232 +0,0 @@ -#!/bin/bash -# Link: -# -# A command-line script for incrementing build numbers for all known targets in an Xcode project. -# -# This script has two main goals: firstly, to ensure that all the targets in a project have the -# same CFBundleVersion and CFBundleShortVersionString values. This is because mismatched values -# can cause a warning when submitting to the App Store. Secondly, to ensure that the build number -# is incremented appropriately when git has changes. -# -# If not using git, you are a braver soul than I. - -## -# The xcodeproj. This is usually found by the script, but you may need to specify its location -# if it's not in the same folder as the script is called from (the project root if called as a -# build phase run script). -# -# This value can also be provided (or overridden) using "--xcodeproj=" -# -#xcodeproj="Project.xcodeproj" - -## -# We have to define an Info.plist as the source of truth. This is typically the one for the main -# target. If not set, the script will try to guess the correct file from the list it gathers from -# the xcodeproj file, but this can be overriden by setting the path here. -# -# This value can also be provided (or overridden) using "--plist=" -# -#plist="Project/Info.plist" - -## -# By default, the script ensures that the build number is incremented when changes are declared -# based on git's records. Alternatively the number of commits on the current branch can be used -# by toggling the "reflect_commits" variable to true. If not on "master", the current branch name -# will be used to ensure no version collisions across branches, i.e. "497-develop". -# -# This setting can also be enabled using "--reflect-commits" -# -#reflect_commits=true - -## -# If you would like to iterate the build number only when a specific branch is checked out -# (i.e. "master"), you can specify the branch name. The current version will still be replicated -# across all Info.plist files (to ensure consistency) if they don't match the source of truth. -# -# This setting can be enabled for multiple branches can be enabled by using comma separated names -# (i.e. "master,develop"). No spacing is permitted. -# -# This setting can also be enabled using "--branch" -# -#enable_for_branch="master" - -## -# Released under the BSD License -# -# Copyright © 2017 Daniel Farrelly -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this list -# of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright notice, this -# list of conditions and the following disclaimer in the documentation and/or -# other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# We use PlistBuddy to handle the Info.plist values. Here we define where it lives. -plistBuddy="/usr/libexec/PlistBuddy" - -# Parse input variables and update settings. -for i in "$@"; do -case $i in - -h|--help) - echo "usage: sh version-update.sh [options...]\n" - echo "Options: (when provided via the CLI, these will override options set within the script itself)" - echo "-b, --branch= Only allow the script to run on the branch with the given name(s)." - echo " --build= Apply the given value to the build number (CFBundleVersion) for the project." - echo "-i, --ignore-changes Ignore git status when iterating build number (doesn't apply to manual values or --reflect-commits)." - echo "-p, --plist= Use the specified plist file as the source of truth for version details." - echo " --reflect-commits Reflect the number of commits in the current branch when preparing build numbers." - echo " --version= Apply the given value to the marketing version (CFBundleShortVersionString) for the project." - echo "-x, --xcodeproj= Use the specified Xcode project file to gather plist names." - echo "\nFor more detailed information on the use of these variables, see the script source." - exit 1 - ;; - --reflect-commits) - reflect_commits=true - shift - ;; - -x=*|--xcodeproj=*) - xcodeproj="${i#*=}" - shift - ;; - -p=*|--plist=*) - plist="${i#*=}" - shift - ;; - -b=*|--branch=*) - enable_for_branch="${i#*=}" - shift - ;; - --build=*) - specified_build="${i#*=}" - shift - ;; - --version=*) - specified_version="${i#*=}" - shift - ;; - -i|--ignore-changes) - ignore_git_status=true - shift - ;; - *) - ;; -esac -done - -# Locate the xcodeproj. -# If we've specified a xcodeproj above, we'll simply use that instead. -if [[ -z ${xcodeproj} ]]; then - xcodeproj=$(find . -depth 1 -name "*.xcodeproj" | sed -e 's/^\.\///g') -fi - -# Check that the xcodeproj file we've located is valid, and warn if it isn't. -# This could also indicate an issue with the code used to automatically locate the xcodeproj file. -# If you're encountering this and the file exists, ensure that ${xcodeproj} contains the correct -# path, or use the "--xcodeproj" variable to provide an accurate location. -if [[ ! -f "${xcodeproj}/project.pbxproj" ]]; then - echo "${BASH_SOURCE}:${LINENO}: error: Could not locate the xcodeproj file \"${xcodeproj}\"." - exit 1 -else - echo "Xcode Project: \"${xcodeproj}\"" -fi - -# Find unique references to Info.plist files in the project -projectFile="${xcodeproj}/project.pbxproj" -plists=$(grep "^\s*INFOPLIST_FILE.*$" "${projectFile}" | sed -Ee 's/^[[:space:]]+INFOPLIST_FILE[[:space:]*=[[:space:]]*["]?([^"]+)["]?;$/\1/g' | sort | uniq) - -# Attempt to guess the plist based on the list we have. -# If we've specified a plist above, we'll simply use that instead. -if [[ -z ${plist} ]]; then - read -r plist <<< "${plists}" -fi - -# Check that the plist file we've located is valid, and warn if it isn't. -# This could also indicate an issue with the code used to match plist files in the xcodeproj file. -# If you're encountering this and the file exists, ensure that ${plists} contains _ONLY_ filenames. -if [[ ! -f ${plist} ]]; then - echo "${BASH_SOURCE}:${LINENO}: error: Could not locate the plist file \"${plist}\"." - exit 1 -else - echo "Source Info.plist: \"${plist}\"" -fi - -# Find the current build number in the main Info.plist -mainBundleVersion=$("${plistBuddy}" -c "Print CFBundleVersion" "${plist}") -mainBundleShortVersionString=$("${plistBuddy}" -c "Print CFBundleShortVersionString" "${plist}") -echo "Current project version is ${mainBundleShortVersionString} (${mainBundleVersion})." - -# If the user specified a marketing version (via "--version"), we overwrite the version from the source of truth. -if [[ ! -z ${specified_version} ]]; then - mainBundleShortVersionString=${specified_version} - echo "Applying specified marketing version (${specified_version})..." -fi - -# Increment the build number if git says things have changed. Note that we also check the main -# Info.plist file, and if it has already been modified, we don't increment the build number. -# Alternatively, if the script has been called using "--reflect-commits", we just update to the -# current number of commits. We can also specify a build number to use with "--build". -git=$(sh /etc/profile; which git) -branchName=$("${git}" rev-parse --abbrev-ref HEAD) -if [[ -z ${enable_for_branch} ]] || [[ ",${enable_for_branch}," == *",${branchName},"* ]]; then - if [[ ! -z ${specified_build} ]]; then - mainBundleVersion=${specified_build} - echo "Applying specified build number (${specified_build})..." - elif [[ ! -z ${reflect_commits} ]] && [[ ${reflect_commits} ]]; then - currentBundleVersion=${mainBundleVersion} - mainBundleVersion=$("${git}" rev-list --count HEAD) - if [[ ${branchName} != "master" ]]; then - mainBundleVersion="${mainBundleVersion}-${branchName}" - fi - if [[ ${currentBundleVersion} != ${mainBundleVersion} ]]; then - echo "Branch \"${branchName}\" has ${mainBundleVersion} commit(s). Updating build number..." - else - echo "Branch \"${branchName}\" has ${mainBundleVersion} commit(s). Version is stable." - fi - elif [[ ! -z ${ignore_git_status} ]] && [[ ${ignore_git_status} ]]; then - echo "Iterating build number (forced)..." - mainBundleVersion=$((${mainBundleVersion} + 1)) - else - status=$("${git}" status --porcelain) - if [[ ${#status} == 0 ]]; then - echo "Repository does not have any changes. Version is stable." - elif [[ ${status} == *"M ${plist}"* ]] || [[ ${status} == *"M \"${plist}\""* ]]; then - echo "The source Info.plist has been modified. Version is assumed to be stable. Use --ignore-changes to override." - else - echo "Repository is dirty. Iterating build number..." - mainBundleVersion=$((${mainBundleVersion} + 1)) - fi - fi -else - echo "${xcodeproj}:0: warning: Version number updates are disabled for the current git branch (${branchName})." -fi - -# Update all of the Info.plist files we discovered -while read -r thisPlist; do - # Find out the current version - thisBundleVersion=$("${plistBuddy}" -c "Print CFBundleVersion" "${thisPlist}") - thisBundleShortVersionString=$("${plistBuddy}" -c "Print CFBundleShortVersionString" "${thisPlist}") - # Update the CFBundleVersion if needed - if [[ ${thisBundleVersion} != ${mainBundleVersion} ]]; then - echo "Updating \"${thisPlist}\" with build ${mainBundleVersion}..." - "${plistBuddy}" -c "Set :CFBundleVersion ${mainBundleVersion}" "${thisPlist}" - fi - # Update the CFBundleShortVersionString if needed - if [[ ${thisBundleShortVersionString} != ${mainBundleShortVersionString} ]]; then - echo "Updating \"${thisPlist}\" with marketing version ${mainBundleShortVersionString}..." - "${plistBuddy}" -c "Set :CFBundleShortVersionString ${mainBundleShortVersionString}" "${thisPlist}" - fi -done <<< "${plists}"