diff --git a/.jazzy.yaml b/.jazzy.yaml index b7bac020..3c32f440 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -3,11 +3,11 @@ sourcekitten_sourcefile: docs.json clean: true author: Timofey Solomko module: SWCompression -module_version: 4.5.3 +module_version: 4.5.4 copyright: '© 2020 Timofey Solomko' readme: README.md github_url: https://github.com/tsolomko/SWCompression -github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.5.3 +github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.5.4 theme: fullwidth custom_categories: diff --git a/.travis.yml b/.travis.yml index 3bf75bab..79e81c0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,32 +1,62 @@ +# TODO: There is probably a way to simplify this very explicit build matrix. git: depth: 1 submodules: false jobs: include: + # We cannot test with Swift 4.2 on macOS since Carthage doesn't work with multiple Swift versions. - stage: test language: swift os: osx - osx_image: xcode10.3 + osx_image: xcode10.3 # Swift 5.0 + env: + - HOMEBREW_NO_INSTALL_CLEANUP=1 before_install: - brew update install: - - Utils/ci-install-macos.sh + - ./utils.py ci install-macos before_script: - - Utils/prepare-workspace-macos.sh + - ./utils.py prepare-workspace macos script: - - Utils/ci-script-macos.sh + - ./utils.py ci script-macos - stage: test language: swift os: osx - osx_image: xcode11.3 + osx_image: xcode11.3 # Swift 5.1 + env: + - HOMEBREW_NO_INSTALL_CLEANUP=1 before_install: - brew update install: - - Utils/ci-install-macos.sh + - ./utils.py ci install-macos before_script: - - Utils/prepare-workspace-macos.sh + - ./utils.py prepare-workspace macos script: - - Utils/ci-script-macos.sh + - ./utils.py ci script-macos + - stage: test + language: swift + os: osx + osx_image: xcode11.4 # Swift 5.2 + env: + - HOMEBREW_NO_INSTALL_CLEANUP=1 + before_install: + - brew update + install: + - ./utils.py ci install-macos + before_script: + - ./utils.py prepare-workspace macos + script: + - ./utils.py ci script-macos + - stage: test + language: generic + os: linux + dist: xenial + env: + - SWIFT_VERSION=4.2 + install: + - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" + script: + - ./utils.py ci script-linux - stage: test language: generic os: linux @@ -36,12 +66,34 @@ jobs: install: - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" script: - - Utils/ci-script-linux.sh + - ./utils.py ci script-linux + - stage: test + language: generic + os: linux + dist: xenial + env: + - SWIFT_VERSION=5.1 + install: + - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" + script: + - ./utils.py ci script-linux + - stage: test + language: generic + os: linux + dist: xenial + env: + - SWIFT_VERSION=5.2 + install: + - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" + script: + - ./utils.py ci script-linux - stage: deploy if: tag IS present language: generic os: osx osx_image: xcode11.3 + env: + - HOMEBREW_NO_INSTALL_CLEANUP=1 env: secure: iavIkrus2Xd3b086nz2srMGl52yqzLuCdhyEAhMODVqkzqMQ17s10y1TNb+vkepd0HgxI9j57d5X7tfChjWuWDwE2hZKjr/Kx2DfiUr1AKQD6ymuGrq/0Vv6yL9dfPU8goFArcrsBcyVKczLtTuLCKL498ZqokkQc/3kGvzW74lv+z410MfHS9/tvToO/yXJckL6qJ2XBAiElfOO0rEkllTeCo6N3bjcHZ2o7PE0K+CHYxwNKj0TmPmuNWZ3U4fzoWzkk01re1C1l5cpSb20g+2aGyi0yYX+PomX7fIIqNq9vmmyoeNdr35yqoQv/0zFeFnps83NKmZLAjSUhiUdhlbuBLBE+w8544LOaZnMDlFmpDjgyaVnRrOh0NrBB1FwU48aGfX5ljRQmk/07FTEUjvwvGGoOpz8lrLZi148FMHEospL3Sf7d8K+Q9WdtLTGk7HCnbOVcxS6oB/SWF/Cj6n5wu+EI1floBaZEsNPR40Gd4eM/Ik/E3lDrZThGDCWQsao981wm7IfEDBR1nuMME8gpZINFANNS1+5miFaGdTnDTp4Yd5MGEFZm+K8x+TG1891NwNH1ZmKXlypJXiUzvSjbh2ViNJGekdQj9q2gj2ZFlCfHJ05adwJ4w9qRuF00HpAOD6At6EnsjDXFJeTZS5dj8fi2YsU9or8KfTFoNY= addons: @@ -57,8 +109,8 @@ jobs: - > if ! [ "$BEFORE_DEPLOY_RUN" ]; then export BEFORE_DEPLOY_RUN=1; - Utils/prepare-workspace-macos.sh -T; - Utils/ci-before-deploy.sh; + ./utils.py prepare-workspace macos -T + ./utils.py ci before-deploy; fi deploy: - provider: releases diff --git a/CHANGELOG.md b/CHANGELOG.md index c464b966..79aeac08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.5.4 + +- Fixed issues when installing using SPM or Xcode in certain situations. +- Fixed incompatibility with Swift Package Manager from Swift 4.2. + ## 4.5.3 - Improved compatibility with the latest versions of Swift (5.x) and Xcode. diff --git a/Cartfile b/Cartfile index e879c41f..934643de 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "tsolomko/BitByteData" ~> 1.4.2 +github "tsolomko/BitByteData" ~> 1.4.3 diff --git a/Package.swift b/Package.swift index b831b146..d957f93e 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( // .package(url: "https://github.com/jakeheis/SwiftCLI", // from: "5.2.0"), .package(url: "https://github.com/tsolomko/BitByteData", - from: "1.4.2"), + from: "1.4.3"), ], targets: [ // SWCOMP: Uncomment the lines below to build swcomp example program. diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift new file mode 100644 index 00000000..33ca19c7 --- /dev/null +++ b/Package@swift-4.2.swift @@ -0,0 +1,32 @@ +// swift-tools-version:4.0 +import PackageDescription + +let package = Package( + name: "SWCompression", + products: [ + .library( + name: "SWCompression", + targets: ["SWCompression"]), + ], + dependencies: [ + // SWCOMP: Uncomment the line below to build swcomp example program. + // .package(url: "https://github.com/jakeheis/SwiftCLI", + // from: "5.2.0"), + .package(url: "https://github.com/tsolomko/BitByteData", + from: "1.4.3"), + ], + targets: [ + // SWCOMP: Uncomment the lines below to build swcomp example program. + // .target( + // name: "swcomp", + // dependencies: ["SWCompression", "SwiftCLI"], + // path: "Sources", + // sources: ["swcomp"]), + .target( + name: "SWCompression", + dependencies: ["BitByteData"], + path: "Sources", + sources: ["Common", "7-Zip", "BZip2", "Deflate", "GZip", "LZMA", "LZMA2", "TAR", "XZ", "ZIP", "Zlib"]), + ], + swiftLanguageVersions: [4] +) diff --git a/README.md b/README.md index cedf1722..f115dafd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # SWCompression [![Swift 4.2](https://img.shields.io/badge/Swift-4.2-blue.svg)](https://developer.apple.com/swift/) +[![Swift 5.X](https://img.shields.io/badge/Swift-5.X-blue.svg)](https://developer.apple.com/swift/) [![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/tsolomko/SWCompression/master/LICENSE) [![Build Status](https://travis-ci.com/tsolomko/SWCompression.svg?branch=develop)](https://travis-ci.com/tsolomko/SWCompression) -A framework with (de)compression algorithms and functions for processing various archives and containers. +A framework with (de)compression algorithms and functions for working with various archives and containers. ## What is this? @@ -16,8 +17,7 @@ SWCompression — is a framework with a collection of functions for: It also works both on Apple platforms and __Linux__. -All features are listed in the tables below. -"TBD" means that feature is planned but not implemented (yet). +All features are listed in the tables below. "TBD" means that feature is planned but not implemented (yet). | | Deflate | BZip2 | LZMA/LZMA2 | | ------------- | ------- | ----- | ---------- | @@ -37,7 +37,7 @@ SWCompression can be integrated into your project using Swift Package Manager, C ### Swift Package Manager -Add SWCompression to you package dependencies and specify it as a dependency for your target, e.g.: +To install using SPM, add SWCompression to you package dependencies and specify it as a dependency for your target, e.g.: ```swift import PackageDescription @@ -61,12 +61,11 @@ More details you can find in [Swift Package Manager's Documentation](https://git ### CocoaPods -Add `pod 'SWCompression', '~> 4.5'` and `use_frameworks!` to your Podfile. +Add `pod 'SWCompression', '~> 4.5'` and `use_frameworks!` lines to your Podfile. To complete installation, run `pod install`. -If you need only some parts of framework, you can install only them using sub-podspecs. -Available subspecs: +If you need only some parts of framework, you can install only them using sub-podspecs. Available subspecs: - SWCompression/BZip2 - SWCompression/Deflate @@ -81,15 +80,15 @@ Available subspecs: #### "Optional Dependencies" -For both ZIP and 7-Zip there is a most commonly used compression method. This is Deflate for ZIP and LZMA/LZMA2 for -7-Zip. Thus, SWCompression/ZIP subspec has SWCompression/Deflate subspec as a dependency and SWCompression/LZMA subspec -is a dependency for SWCompression/SevenZip. +For both ZIP and 7-Zip there is the most commonly used compression method: Deflate and LZMA/LZMA2 correspondingly. Thus, +SWCompression/ZIP subspec has SWCompression/Deflate subspec as a dependency and SWCompression/LZMA subspec is a +dependency for SWCompression/SevenZip. -But both of these formats support other compression methods as well, and some of them are implemented in SWCompression. +But both of these formats also support other compression methods, and some of them are implemented in SWCompression. For CocoaPods configurations there are some sort of 'optional dependencies' for such compression methods. -"Optional dependency" in this context means that SWCompression/ZIP or SWCompression/7-Zip will support particular -compression methods only if a corresponding subspec is expicitly specified in your Podfile and installed. +"Optional dependency" in this context means that SWCompression/ZIP or SWCompression/7-Zip will support a compression +method only if a corresponding subspec is expicitly specified in your Podfile and installed. List of "optional dependecies": @@ -105,29 +104,31 @@ BZip2 and LZMA/LZMA2 support). ### Carthage +__Important:__ Only Swift 5.x is supported when installing BitByteData via Carthage. + Add to your Cartfile `github "tsolomko/SWCompression" ~> 4.5`. Then run `carthage update`. -Finally, drag and drop `SWCompression.framework` from `Carthage/Build` folder -into the "Embedded Binaries" section on your targets' "General" tab in Xcode. +Finally, drag and drop `SWCompression.framework` from the `Carthage/Build` directory into the "Embedded Binaries" section +on your targets' "General" tab in Xcode. SWCompression uses [BitByteData](https://github.com/tsolomko/BitByteData) framework, so Carthage will also download it, -and you should drag and drop `BitByteData.framework` file into the "Embedded Binaries" as well. +and you should put the `BitByteData.framework` file into the "Embedded Binaries" as well. ## Usage ### Basic Example -If you'd like to decompress "deflated" data just use: +For example, if you want to decompress "deflated" data just use: ```swift // let data = let decompressedData = try? Deflate.decompress(data: data) ``` -However, it is unlikely that you will encounter deflated data outside of any archive. -So, in case of GZip archive you should use: +However, it is unlikely that you will encounter deflated data outside of any archive. So, in the case of GZip archive +you should use: ```swift let decompressedData = try? GzipArchive.unarchive(archive: data) @@ -135,9 +136,9 @@ let decompressedData = try? GzipArchive.unarchive(archive: data) ### Handling Errors -Most SWCompression functions can throw an error and you are responsible for handling them. -If you look at list of available error types and their cases, you may be frightened by their number. -However, most of these cases (such as `XZError.wrongMagic`) exist for diagnostic purposes. +Most SWCompression functions can throw errors and you are responsible for handling them. If you look at the list of +available error types and their cases, you may be frightened by their number. However, most of the cases (such as +`XZError.wrongMagic`) exist for diagnostic purposes. Thus, you only need to handle the most common type of error for your archive/algorithm. For example: @@ -146,73 +147,73 @@ do { // let data = let decompressedData = try XZArchive.unarchive(archive: data) } catch let error as XZError { - + // } catch let error { - + // } ``` -Or, if you don't care about errors at all, use `try?`. - ### Documentation -Every function or type of SWCompression's public API is documented. -This documentation can be found at its own [website](http://tsolomko.github.io/SWCompression). +Every function or type of SWCompression's public API is documented. This documentation can be found at its own +[website](http://tsolomko.github.io/SWCompression). ### Sophisticated example -There is a small command-line program, "swcomp", which is included in this repository in "Sources/swcomp". -To build it you need to uncomment several lines in "Package.swift" and run `swift build -c release`. +There is a small command-line program, "swcomp", which is included in this repository in "Sources/swcomp". To build it +you need to uncomment several lines in "Package.swift" and run `swift build -c release`. ## Contributing -Whether you find a bug, have a suggestion, idea or something else, -please [create an issue](https://github.com/tsolomko/SWCompression/issues) on GitHub. +Whether you find a bug, have a suggestion, idea, feedback or something else, please +[create an issue](https://github.com/tsolomko/SWCompression/issues) on GitHub. -In case you have encoutered a bug, it would be especially helpful if you attach a file (archive, etc.) -that caused the bug to happen. +In the case of a bug, it will be especially helpful if you attach a file (archive, etc.) that caused the bug to occur. -If you'd like to contribute code, please [create a pull request](https://github.com/tsolomko/SWCompression/pulls) on GitHub. +If you'd like to contribute, please [create a pull request](https://github.com/tsolomko/SWCompression/pulls) on GitHub. __Note:__ If you are considering working on SWCompression, please note that Xcode project (SWCompression.xcodeproj) was created manually and you shouldn't use `swift package generate-xcodeproj` command. ### Executing tests locally -If you'd like to run tests on your computer, you need to do an additional step after cloning this repository: +If you want to run tests on your computer, you need to do an additional step after cloning the repository: ```bash -git submodule update --init --recursive +./utils.py prepare-workspace {macos|other} ``` -This command downloads files which are used for testing. These files are stored in a -[separate repository](https://github.com/tsolomko/SWCompression-Test-Files). -Git LFS is used for storing them which is the reason for having them in the separate repository, -since Swift Package Manager have some problems with Git LFS-enabled repositories -(installing git-lfs _locally_ with `--skip-smudge` option is required to solve these problems). +The argument of this function is an operating system that you're using. This command will download files used in tests, +and on macOS it will also try to download BitByteData dependency, which requires having Carthage installed. -__Note:__ You can also use "Utils/prepare-workspace-macos.sh" script from the repository, -which not only downloads test files but also downloads dependencies. +Test files are stored in a [separate repository](https://github.com/tsolomko/SWCompression-Test-Files), using Git LFS. +There are two reasons for this complicated setup. Firstly, some of these files can be quite big, and it would be +unfortunate if the users of SWCompression had to download them every time during the installation. Secondly, Swift +Package Manager and contemporary versions of Xcode don't always work well with git-lfs-enabled repositories. To prevent +any potential problems test files were moved into another repository. Additionaly, the custom command line tool `utils.py` +is used to work around issues occuring on certain user systems (see, for example, #9). + +Please note, that if you want to add a new _type_ of test files, in addition to running `git lfs track`, you have to +also copy into the "Tests/Test Files/gitattributes-copy" file a line this command adds to the "Tests/Test Files/.gitattributes" +file. __Do not commit the ".gitattributes" file to the git history. It is git-ignored for a reason!__ ## Performance -Usage of whole module optimizations is recommended for best performance. -These optimizations are enabled by default for Release configurations. +Using whole module optimizations is recommended for the best performance. They are enabled by default in the Release build +configuration. [Tests Results](Tests/Results.md) document contains results of benchmarking of various functions. ## Why? -First of all, existing solutions for work with compression, archives and containers have certain disadvantages. -They might not support a particular compression algorithm or archive format and they all have different APIs, -which sometimes can be slightly confusing for users. -This project attempts to provide missing (and sometimes existing) functionality through unified API -which is easy to use and remember. +First of all, existing solutions for working with compression, archives and containers have certain disadvantages. They +might not support a particular compression algorithm or archive format and they all have different APIs, which sometimes +can be slightly confusing for users, especially when you mix different libraries in one project. This project attempts to +provide missing (and sometimes existing) functionality through the unified API which is easy to use and remember. -Secondly, it may be important to have a compression framework written completely in Swift, -without relying on either system libraries or solutions implemented in different languages. -Additionaly, since SWCompression is written fully in Swift without Objective-C, -it can also be used on __Linux__. +Secondly, in some cases it may be important to have a compression framework written entirely in Swift, without relying +on either system libraries or solutions implemented in other languages. Additionaly, since SWCompression is written +completely in Swift without Objective-C, it can also be used on __Linux__. ## Future plans @@ -223,11 +224,6 @@ new features. - Better Deflate compression. - Something else... -## Support Financially - -If you would like to support this project or me financially you can do so via PayPal using -[this link](https://paypal.me/tsolomko). - ## License [MIT licensed](LICENSE) diff --git a/SWCompression.podspec b/SWCompression.podspec index 1066f298..f8021c02 100644 --- a/SWCompression.podspec +++ b/SWCompression.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SWCompression" - s.version = "4.5.3" + s.version = "4.5.4" s.summary = "A framework with functions for working with compression, archives and containers." s.description = "A framework with (de)compression algorithms and functions for processing various archives and containers." @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.swift_versions = ["4", "5"] - s.dependency "BitByteData", "~> 1.4.2" + s.dependency "BitByteData", "~> 1.4.3" s.subspec "Deflate" do |sp| sp.source_files = "Sources/{Deflate/*,Common/*,Common/CodingTree/*}.swift" diff --git a/SWCompression.xcodeproj/SWCompression.plist b/SWCompression.xcodeproj/SWCompression.plist index cad806c9..1f365055 100644 --- a/SWCompression.xcodeproj/SWCompression.plist +++ b/SWCompression.xcodeproj/SWCompression.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.5.3 + 4.5.4 CFBundleVersion - 70 + 71 NSHumanReadableCopyright Copyright © 2020 Timofey Solomko. All rights reserved. diff --git a/SWCompression.xcodeproj/TestSWCompression.plist b/SWCompression.xcodeproj/TestSWCompression.plist index 5f17fa96..ab28948b 100644 --- a/SWCompression.xcodeproj/TestSWCompression.plist +++ b/SWCompression.xcodeproj/TestSWCompression.plist @@ -15,8 +15,8 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 4.5.3 + 4.5.4 CFBundleVersion - 70 + 71 diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index b9d3593d..5c533063 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -1236,7 +1236,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 70; + CURRENT_PROJECT_VERSION = 71; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1295,7 +1295,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 70; + CURRENT_PROJECT_VERSION = 71; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; @@ -1335,7 +1335,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 70; + DYLIB_CURRENT_VERSION = 71; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -1362,7 +1362,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 70; + DYLIB_CURRENT_VERSION = 71; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme b/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme index 6273a6a1..0f4b19d0 100644 --- a/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme +++ b/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme @@ -78,7 +78,7 @@ diff --git a/Sources/swcomp/main.swift b/Sources/swcomp/main.swift index 389facee..123f7971 100644 --- a/Sources/swcomp/main.swift +++ b/Sources/swcomp/main.swift @@ -7,7 +7,7 @@ import Foundation import SWCompression import SwiftCLI -let cli = CLI(name: "swcomp", version: "4.5.3", +let cli = CLI(name: "swcomp", version: "4.5.4", description: """ swcomp - small command-line client for SWCompression framework. Serves as an example of SWCompression usage. diff --git a/Tests/Test Files b/Tests/Test Files index 543e5bc9..dfcec032 160000 --- a/Tests/Test Files +++ b/Tests/Test Files @@ -1 +1 @@ -Subproject commit 543e5bc90d065c9cac22e501cff97d5c4489ce45 +Subproject commit dfcec032712aea0be1b42998d1a3837c21f75285 diff --git a/Utils/ci-before-deploy.sh b/Utils/ci-before-deploy.sh deleted file mode 100755 index 67977edd..00000000 --- a/Utils/ci-before-deploy.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -euxo pipefail - -(set +x; echo "=> Removing bcsymbolmap files for dependencies.") -rm -f Carthage/Build/Mac/*.bcsymbolmap -rm -f Carthage/Build/watchOS/*.bcsymbolmap -rm -f Carthage/Build/tvOS/*.bcsymbolmap -rm -f Carthage/Build/iOS/*.bcsymbolmap -(set +x; echo "=> Removing checkouts for dependencies.") -rm -rf Carthage/Checkouts -(set +x; echo "=> Preparing deployment files.") -carthage build --no-skip-current -carthage archive SWCompression -sourcekitten doc --spm-module SWCompression > docs.json -jazzy diff --git a/Utils/ci-install-macos.sh b/Utils/ci-install-macos.sh deleted file mode 100755 index e765a7c8..00000000 --- a/Utils/ci-install-macos.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -euxo pipefail - -brew install git-lfs -git lfs install -gem install -N xcpretty-travis-formatter diff --git a/Utils/ci-script-linux.sh b/Utils/ci-script-linux.sh deleted file mode 100755 index 9e78f922..00000000 --- a/Utils/ci-script-linux.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -euxo pipefail - -swift build -swift build -c release diff --git a/Utils/ci-script-macos.sh b/Utils/ci-script-macos.sh deleted file mode 100755 index cda1458a..00000000 --- a/Utils/ci-script-macos.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -set -euxo pipefail - -xcodebuild -project SWCompression.xcodeproj -scheme SWCompression -destination "platform=OS X" clean test | xcpretty -f `xcpretty-travis-formatter` -xcodebuild -project SWCompression.xcodeproj -scheme SWCompression -destination "platform=iOS Simulator,name=iPhone 8" clean test | xcpretty -f `xcpretty-travis-formatter` -xcodebuild -project SWCompression.xcodeproj -scheme SWCompression -destination "platform=watchOS Simulator,name=Apple Watch - 38mm" clean build | xcpretty -f `xcpretty-travis-formatter` -xcodebuild -project SWCompression.xcodeproj -scheme SWCompression -destination "platform=tvOS Simulator,name=Apple TV" clean test | xcpretty -f `xcpretty-travis-formatter` diff --git a/Utils/cleanup-workspace.sh b/Utils/cleanup-workspace.sh deleted file mode 100755 index f53029e1..00000000 --- a/Utils/cleanup-workspace.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -if [[ -d "build/" ]]; then - (set -x; rm -rf build/) -fi - -if [[ -d "Carthage/" ]]; then - (set -x; rm -rf Carthage/) -fi - -if [[ -d "docs/" ]]; then - (set -x; rm -rf docs/) -fi - -if [[ -d "Pods/" ]]; then - (set -x; rm -rf Pods/) -fi - -if [[ -d ".build/" ]]; then - (set -x; rm -rf .build/) -fi - -if [[ -f "Cartfile.resolved" ]]; then - (set -x; rm Cartfile.resolved) -fi - -if [[ -f "docs.json" ]]; then - (set -x; rm docs.json) -fi - -if [[ -f "Package.resolved" ]]; then - (set -x; rm Package.resolved) -fi - -if [[ -f "SWCompression.framework.zip" ]]; then - (set -x; rm SWCompression.framework.zip) -fi diff --git a/Utils/prepare-workspace-macos.sh b/Utils/prepare-workspace-macos.sh deleted file mode 100755 index 57289385..00000000 --- a/Utils/prepare-workspace-macos.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -if [[ $# -ne 1 || $1 != "-T" ]]; then - echo "=> Downloading files used for testing" - - (set -x ; git submodule update --init --recursive) - if [ $? -ne 0 ]; then - echo "ERROR: unable to update git submodule" - exit 1 - fi -fi - -echo "=> Downloading dependency (BitByteData) using Carthage" -(set -x; carthage bootstrap) diff --git a/utils.py b/utils.py new file mode 100755 index 00000000..173012ac --- /dev/null +++ b/utils.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess +import sys + +def _sprun(cmd, *args, **kwargs): + print("+ " + " ".join(cmd)) + subprocess.run(cmd, check=True, *args, **kwargs) + +def _ci_before_deploy(): + print("=> Removing bcsymbolmap files for dependencies.") + platforms = ["Mac", "watchOS", "tvOS", "iOS"] + for platform in platforms: + _sprun(["rm", "-f", "Carthage/Build/{0}/*.bcsymbolmap".format(platform)]) + print("=> Removing checkouts for dependencies.") + _sprun(["rm", "-rf", "Carthage/Checkouts"]) + print("=> Preparing deployment files.") + _sprun(["carthage", "build", "--no-skip-current"]) + _sprun(["carthage", "archive", "SWCompression"]) + docs_json_file = open("docs.json", "w") + _sprun(["sourcekitten", "doc", "--spm-module", "SWCompression"], stdout=docs_json_file) + docs_json_file.close() + _sprun(["jazzy"]) + +def _ci_install_macos(): + _sprun(["brew", "install", "git-lfs"]) + _sprun(["git", "lfs", "install"]) + _sprun(["gem", "install", "-N", "xcpretty-travis-formatter"]) + +def _ci_script_linux(): + _sprun(["swift", "build"]) + _sprun(["swift", "build", "-c", "release"]) + +def _ci_script_macos(): + xcodebuild_command_parts = ["xcodebuild", "-project", "SWCompression.xcodeproj", "-scheme", "SWCompression"] + destinations_actions = [(["-destination 'platform=OS X'"], ["clean", "test"]), + (["-destination 'platform=iOS Simulator,name=iPhone 8'"], ["clean", "test"]), + (["-destination 'platform=watchOS Simulator,name=Apple Watch - 38mm'"], ["clean", "build"]), + (["-destination 'platform=tvOS Simulator,name=Apple TV'"], ["clean", "test"])] + + for destination, action in destinations_actions: + xcodebuild_command = xcodebuild_command_parts + destination + action + print("+ {0} | xcpretty -f `xcpretty-travis-formatter`".format(" ".join(xcodebuild_command))) + xcodebuild_process = subprocess.Popen(xcodebuild_command, stdout=subprocess.PIPE) + xcpretty_command = ["xcpretty", "-f", "`xcpretty-travis-formatter`"] + subprocess.run(xcpretty_command, stdin=xcodebuild_process.stdout, shell=True, check=True) + +def action_ci(args): + if args.cmd == "before-deploy": + _ci_before_deploy() + elif args.cmd == "install-macos": + _ci_install_macos() + elif args.cmd == "script-linux": + _ci_script_linux() + elif args.cmd == "script-macos": + _ci_script_macos() + else: + raise Exception("Unknown CI command") + +def action_cw(args): + _sprun(["rm", "-rf", "build/"]) + _sprun(["rm", "-rf", "Carthage/"]) + _sprun(["rm", "-rf", "docs/"]) + _sprun(["rm", "-rf", "Pods/"]) + _sprun(["rm", "-rf", ".build/"]) + _sprun(["rm", "-f", "Cartfile.resolved"]) + _sprun(["rm", "-f", "docs.json"]) + _sprun(["rm", "-f", "Package.resolved"]) + _sprun(["rm", "-f", "SWCompression.framework.zip"]) + +def _pw_macos(): + print("=> Downloading dependency (BitByteData) using Carthage") + _sprun(["carthage", "bootstrap"]) + +def action_pw(args): + if args.os == "macos": + _pw_macos() + elif args.os == "other": + pass + else: + raise Exception("Unknown OS") + if not args.no_test_files: + print("=> Downloading files used for testing") + _sprun(["git", "submodule", "update", "--init", "--recursive"]) + _sprun(["cp", "-f", "Tests/Test Files/gitattributes-copy", "Tests/Test Files/.gitattributes"]) + _sprun(["git", "lfs", "pull"], cwd="Tests/Test Files/") + _sprun(["git", "lfs", "checkout"], cwd="Tests/Test Files/") + +parser = argparse.ArgumentParser(description="A tool with useful commands for developing SWCompression") +subparsers = parser.add_subparsers(title="commands", help="a command to perform", metavar="CMD") + +# Parser for 'ci' command. +parser_ci = subparsers.add_parser("ci", help="a subset of commands used by CI", + description="a subset of commands used by CI") +parser_ci.add_argument("cmd", choices=["before-deploy", "install-macos", "script-linux", "script-macos"], + help="a command to perform on CI", metavar="CI_CMD") +parser_ci.set_defaults(func=action_ci) + +# Parser for 'cleanup-workspace' command. +parser_cw = subparsers.add_parser("cleanup-workspace", help="cleanup workspace", + description="cleans workspace from files produced by various build systems") +parser_cw.set_defaults(func=action_cw) + +# Parser for 'prepare-workspace' command. +parser_pw = subparsers.add_parser("prepare-workspace", help="prepare workspace", + description="prepares workspace for developing SWCompression") +parser_pw.add_argument("os", choices=["macos", "other"], help="development operating system", metavar="OS") +parser_pw.add_argument("--no-test-files", "-T", action="store_true", dest="no_test_files", + help="don't download example files used for testing") +parser_pw.set_defaults(func=action_pw) + +args = parser.parse_args() +args.func(args)