Skip to content

Commit

Permalink
Added SPM support (#283)
Browse files Browse the repository at this point in the history
* added SPM support

* use SPM generated macro SWIFTPM_MODULE_BUNDLE

* updated gitignore

* Add GitHub to the SSH known hosts file

* Use https insted of ssh for dependency URL

* use make for CI.

* use PINOperation from - 1.2.0.

Co-authored-by: Garrett Moon <[email protected]>
  • Loading branch information
3a4oT and garrettmoon authored Oct 1, 2020
1 parent 33bede0 commit 4c3389b
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 22 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ jobs:
name: CocoaPods
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Lint
run: make cocoapods
carthage:
name: Carthage
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: carthage
run: make carthage
swift-package-manager:
runs-on: macos-latest
env:
DEVELOPER_DIR: /Applications/Xcode_12.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Verify that PINCache can be build by SPM
run: make spm
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ xcuserdata
/.buckd

Carthage/Build

# SPM
.swiftpm/
.build/
Package.resolved
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PLATFORM="platform=iOS Simulator,name=iPhone 8"
SDK="iphonesimulator"
SHELL=/bin/bash -o pipefail

.PHONY: all cocoapods test carthage analyze
.PHONY: all cocoapods test carthage analyze spm

cocoapods:
pod lib lint
Expand All @@ -25,4 +25,10 @@ carthage:
carthage update --no-use-binaries --no-build
carthage build --no-skip-current

all: carthage cocoapods test analyze
spm:
# For now just check whether we can assemble it
# TODO: replace it with "swift test --enable-test-discovery --sanitize=thread" when swiftPM resource-related bug would be fixed.
# https://bugs.swift.org/browse/SR-13560
swift build

all: carthage cocoapods test analyze spm
47 changes: 47 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "PINCache",
platforms: [
.macOS(.v10_10),
.iOS(.v9),
.watchOS(.v2),
.tvOS(.v9)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "PINCache",
targets: ["PINCache"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/pinterest/PINOperation.git", from: "1.2.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "PINCache",
dependencies: ["PINOperation"],
path: "Source",
exclude: ["Carthage", "docs",
"build_docs.sh", "Cartfile",
"Cartfile.resolved", "Makefile",
"PINCache.podspec", "Info.plist"],
publicHeadersPath: "."),
.testTarget(
name: "PINCacheTests",
dependencies: ["PINCache"],
path: "Tests",
exclude: ["Info.plist"],
resources: [.process("[email protected]")],
cSettings: [
.define("TEST_AS_SPM"),
]),
]
)
8 changes: 4 additions & 4 deletions Source/PINCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#import <Foundation/Foundation.h>

#import <PINCache/PINCacheMacros.h>
#import <PINCache/PINCaching.h>
#import <PINCache/PINDiskCache.h>
#import <PINCache/PINMemoryCache.h>
#import "PINCacheMacros.h"
#import "PINCaching.h"
#import "PINDiskCache.h"
#import "PINMemoryCache.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
2 changes: 1 addition & 1 deletion Source/PINCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#import "PINCache.h"

#import <PINOperation/PINOperation.h>
@import PINOperation;

static NSString * const PINCachePrefix = @"com.pinterest.PINCache";
static NSString * const PINCacheSharedName = @"PINCacheShared";
Expand Down
6 changes: 3 additions & 3 deletions Source/PINDiskCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#import <Foundation/Foundation.h>

#import <PINCache/PINCacheMacros.h>
#import <PINCache/PINCaching.h>
#import <PINCache/PINCacheObjectSubscripting.h>
#import "PINCacheMacros.h"
#import "PINCaching.h"
#import "PINCacheObjectSubscripting.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
2 changes: 1 addition & 1 deletion Source/PINDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#import <pthread.h>
#import <sys/xattr.h>

#import <PINOperation/PINOperation.h>
@import PINOperation;

#define PINDiskCacheError(error) if (error) { NSLog(@"%@ (%d) ERROR: %@", \
[[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
Expand Down
6 changes: 3 additions & 3 deletions Source/PINMemoryCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#import <Foundation/Foundation.h>

#import <PINCache/PINCacheMacros.h>
#import <PINCache/PINCaching.h>
#import <PINCache/PINCacheObjectSubscripting.h>
#import "PINCacheMacros.h"
#import "PINCaching.h"
#import "PINCacheObjectSubscripting.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
2 changes: 1 addition & 1 deletion Source/PINMemoryCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import "PINMemoryCache.h"

#import <pthread.h>
#import <PINOperation/PINOperation.h>
@import PINOperation;

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
#import <UIKit/UIKit.h>
Expand Down
13 changes: 10 additions & 3 deletions Tests/PINCacheTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// Modifications by Garrett Moon
// Copyright (c) 2015 Pinterest. All rights reserved.

@import PINCache;
@import PINOperation;

#import "PINCacheTests.h"
#import "NSDate+PINCacheTests.h"
#import "PINDiskCache+PINCacheTests.h"
#import <PINCache/PINCache.h>
#import <PINOperation/PINOperation.h>


#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
Expand Down Expand Up @@ -79,8 +80,14 @@ - (PINImage *)image
static PINImage *image = nil;

if (!image) {
#ifdef TEST_AS_SPM
NSBundle *bun = SWIFTPM_MODULE_BUNDLE;
#else
NSBundle *bun = [NSBundle bundleForClass:self.class];

#endif
NSURL *imageURL = [bun URLForResource:@"Default-568h@2x" withExtension:@"png"];
NSError *error = nil;
NSURL *imageURL = [[NSBundle bundleForClass:self.class] URLForResource:@"Default-568h@2x" withExtension:@"png"];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL
options:NSDataReadingUncached
error:&error];
Expand Down
2 changes: 1 addition & 1 deletion Tests/PINDiskCache+PINCacheTests.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import <PINCache/PINCache.h>
#import "PINCache.h"

@interface PINDiskCache (PINCacheTests)

Expand Down
2 changes: 1 addition & 1 deletion Tests/PINDiskCache+PINCacheTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @implementation PINDiskCache (PINCacheTests)
- (void)setTtlCacheSync:(BOOL)ttlCache
{
[self lock];
self->_ttlCache = ttlCache;
[self setValue:@(ttlCache) forKey:@"_ttlCache"];
[self unlock];
}

Expand Down

0 comments on commit 4c3389b

Please sign in to comment.