Skip to content

Commit d435d4f

Browse files
jaeoptthomaszurkan-optimizely
authored andcommitted
add SDK version control via xcode project config (#151)
* add SDK version control via xcode project config * set default version to 3.0.0-beta * fix bundle version error for CocoaPods * add test for SDK version
1 parent 51c2066 commit d435d4f

File tree

6 files changed

+65
-15
lines changed

6 files changed

+65
-15
lines changed

OptimizelySDK/Implementation/Events/BatchEventBuilder.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import Foundation
1010

1111
class BatchEventBuilder {
1212
static private let swiftSdkClientName = "swift-sdk"
13-
static private var swiftSdkClientVersion = {
14-
// TODO: fix this version controlled via xcode settings
15-
return "3.0.0"
16-
}()
1713

1814
static private var logger = HandlerRegistryService.shared.injectLogger()
1915

@@ -87,7 +83,7 @@ class BatchEventBuilder {
8783

8884
let batchEvent = BatchEvent(revision: config.project.revision,
8985
accountID: config.project.accountId,
90-
clientVersion: swiftSdkClientVersion,
86+
clientVersion: Utils.getSDKVersion(),
9187
visitors: [visitor],
9288
projectID: config.project.projectId,
9389
clientName: swiftSdkClientName,

OptimizelySDK/OptimizelySwiftSDK.xcodeproj/project.pbxproj

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
0BE644F5223821D3009A5D1D /* AtomicProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BE644EC223821D3009A5D1D /* AtomicProperty.swift */; };
137137
0BE644F6223821D3009A5D1D /* AtomicProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BE644EC223821D3009A5D1D /* AtomicProperty.swift */; };
138138
52E08AFF34D0A4A9ACB187EF /* libPods-OptimizelyTests-Common-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 307963A587A4D8DF0CFBF45E /* libPods-OptimizelyTests-Common-tvOS.a */; };
139+
6E06451C226FD6A000F8A693 /* OtherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E06451B226FD6A000F8A693 /* OtherTests.swift */; };
140+
6E06451D226FD6A000F8A693 /* OtherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E06451B226FD6A000F8A693 /* OtherTests.swift */; };
139141
6E0AFBBD2257C49800BC7665 /* BucketTests_ExpToVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0AFBB82257C49700BC7665 /* BucketTests_ExpToVariation.swift */; };
140142
6E0AFBBE2257C49800BC7665 /* BucketTests_ExpToVariation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0AFBB82257C49700BC7665 /* BucketTests_ExpToVariation.swift */; };
141143
6E0AFBBF2257C49800BC7665 /* BucketTests_Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E0AFBB92257C49800BC7665 /* BucketTests_Base.swift */; };
@@ -1237,6 +1239,7 @@
12371239
307963A587A4D8DF0CFBF45E /* libPods-OptimizelyTests-Common-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OptimizelyTests-Common-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
12381240
644A30DA4805286E7F8A1530 /* libPods-OptimizelyTests-Common-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OptimizelyTests-Common-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
12391241
6B36F1F60444A8511E8DCC10 /* Pods-OptimizelyTests-Common-tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OptimizelyTests-Common-tvOS.release.xcconfig"; path = "Target Support Files/Pods-OptimizelyTests-Common-tvOS/Pods-OptimizelyTests-Common-tvOS.release.xcconfig"; sourceTree = "<group>"; };
1242+
6E06451B226FD6A000F8A693 /* OtherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OtherTests.swift; sourceTree = "<group>"; };
12401243
6E0AFBB82257C49700BC7665 /* BucketTests_ExpToVariation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BucketTests_ExpToVariation.swift; sourceTree = "<group>"; };
12411244
6E0AFBB92257C49800BC7665 /* BucketTests_Base.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BucketTests_Base.swift; sourceTree = "<group>"; };
12421245
6E0AFBBA2257C49800BC7665 /* BucketTests_GroupToExp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BucketTests_GroupToExp.swift; sourceTree = "<group>"; };
@@ -1809,6 +1812,7 @@
18091812
isa = PBXGroup;
18101813
children = (
18111814
6EA426DF2219266600B074B5 /* ThrowableConditionListTest.swift */,
1815+
6E06451B226FD6A000F8A693 /* OtherTests.swift */,
18121816
);
18131817
path = "OptimizelyTests-Others";
18141818
sourceTree = "<group>";
@@ -3210,6 +3214,7 @@
32103214
6EA4268F221925B100B074B5 /* Variable.swift in Sources */,
32113215
6EA426CF221925DE00B074B5 /* DefaultLogger.swift in Sources */,
32123216
6EA42685221925B100B074B5 /* EventForDispatch.swift in Sources */,
3217+
6E06451C226FD6A000F8A693 /* OtherTests.swift in Sources */,
32133218
6EA4268C221925B100B074B5 /* ProjectConfig.swift in Sources */,
32143219
6EA426D0221925DE00B074B5 /* DefaultEventDispatcher.swift in Sources */,
32153220
6EA426CE221925DE00B074B5 /* OptimizelyLogLevel.swift in Sources */,
@@ -3278,6 +3283,7 @@
32783283
6EA426A2221925B300B074B5 /* Variable.swift in Sources */,
32793284
6EA426D9221925DF00B074B5 /* DefaultLogger.swift in Sources */,
32803285
6EA42698221925B300B074B5 /* EventForDispatch.swift in Sources */,
3286+
6E06451D226FD6A000F8A693 /* OtherTests.swift in Sources */,
32813287
6EA4269F221925B300B074B5 /* ProjectConfig.swift in Sources */,
32823288
6EA426DA221925DF00B074B5 /* DefaultEventDispatcher.swift in Sources */,
32833289
6EA426D8221925DF00B074B5 /* OptimizelyLogLevel.swift in Sources */,
@@ -3518,7 +3524,7 @@
35183524
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
35193525
CODE_SIGN_IDENTITY = "iPhone Developer";
35203526
COPY_PHASE_STRIP = NO;
3521-
CURRENT_PROJECT_VERSION = 1;
3527+
CURRENT_PROJECT_VERSION = "$(OPTIMIZELY_SDK_VERSION)";
35223528
DEBUG_INFORMATION_FORMAT = dwarf;
35233529
ENABLE_STRICT_OBJC_MSGSEND = YES;
35243530
ENABLE_TESTABILITY = YES;
@@ -3540,6 +3546,11 @@
35403546
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
35413547
MTL_FAST_MATH = YES;
35423548
ONLY_ACTIVE_ARCH = YES;
3549+
OPTIMIZELY_SDK_VERSION = "$(OPTIMIZELY_SDK_VERSION_MAJOR).$(OPTIMIZELY_SDK_VERSION_MINOR).$(OPTIMIZELY_SDK_VERSION_PATCH)$(OPTIMIZELY_SDK_VERSION_SUFFIX)";
3550+
OPTIMIZELY_SDK_VERSION_MAJOR = 3;
3551+
OPTIMIZELY_SDK_VERSION_MINOR = 0;
3552+
OPTIMIZELY_SDK_VERSION_PATCH = 0;
3553+
OPTIMIZELY_SDK_VERSION_SUFFIX = "-beta";
35433554
SDKROOT = iphoneos;
35443555
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
35453556
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -3582,12 +3593,13 @@
35823593
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
35833594
CODE_SIGN_IDENTITY = "iPhone Developer";
35843595
COPY_PHASE_STRIP = NO;
3585-
CURRENT_PROJECT_VERSION = 1;
3596+
CURRENT_PROJECT_VERSION = "$(OPTIMIZELY_SDK_VERSION)";
35863597
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
35873598
ENABLE_NS_ASSERTIONS = NO;
35883599
ENABLE_STRICT_OBJC_MSGSEND = YES;
35893600
GCC_C_LANGUAGE_STANDARD = gnu11;
35903601
GCC_NO_COMMON_BLOCKS = YES;
3602+
GCC_PREPROCESSOR_DEFINITIONS = "";
35913603
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
35923604
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
35933605
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -3597,6 +3609,11 @@
35973609
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
35983610
MTL_ENABLE_DEBUG_INFO = NO;
35993611
MTL_FAST_MATH = YES;
3612+
OPTIMIZELY_SDK_VERSION = "$(OPTIMIZELY_SDK_VERSION_MAJOR).$(OPTIMIZELY_SDK_VERSION_MINOR).$(OPTIMIZELY_SDK_VERSION_PATCH)$(OPTIMIZELY_SDK_VERSION_SUFFIX)";
3613+
OPTIMIZELY_SDK_VERSION_MAJOR = 3;
3614+
OPTIMIZELY_SDK_VERSION_MINOR = 0;
3615+
OPTIMIZELY_SDK_VERSION_PATCH = 0;
3616+
OPTIMIZELY_SDK_VERSION_SUFFIX = "-beta";
36003617
SDKROOT = iphoneos;
36013618
SWIFT_COMPILATION_MODE = wholemodule;
36023619
SWIFT_OPTIMIZATION_LEVEL = "-O";

OptimizelySDK/OptimizelyTests/OptimizelyTests-Common/BatchEventBuilderTests_Events.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import SwiftyJSON
1111

1212
class BatchEventBuilderTests_Events: XCTestCase {
1313

14-
let swiftSdkClientVersion = {
15-
// TODO: fix this version controlled via xcode settings
16-
return "3.0.0"
17-
}()
18-
1914
let experimentKey = "ab_running_exp_audience_combo_exact_foo_or_true__and__42_or_4_2"
2015
let userId = "test_user_1"
2116

@@ -54,7 +49,7 @@ class BatchEventBuilderTests_Events: XCTestCase {
5449

5550
XCTAssertEqual(event["revision"]!.stringValue, project.revision)
5651
XCTAssertEqual(event["account_id"]!.stringValue, project.accountId)
57-
XCTAssertEqual(event["client_version"]!.stringValue, swiftSdkClientVersion)
52+
XCTAssertEqual(event["client_version"]!.stringValue, Utils.getSDKVersion())
5853
XCTAssertEqual(event["project_id"]!.stringValue, project.projectId)
5954
XCTAssertEqual(event["client_name"]!.stringValue, "swift-sdk")
6055
XCTAssertEqual(event["anonymize_ip"]!.boolValue, project.anonymizeIP)
@@ -109,7 +104,7 @@ class BatchEventBuilderTests_Events: XCTestCase {
109104

110105
XCTAssertEqual(event["revision"]!.stringValue, project.revision)
111106
XCTAssertEqual(event["account_id"]!.stringValue, project.accountId)
112-
XCTAssertEqual(event["client_version"]!.stringValue, swiftSdkClientVersion)
107+
XCTAssertEqual(event["client_version"]!.stringValue, Utils.getSDKVersion())
113108
XCTAssertEqual(event["project_id"]!.stringValue, project.projectId)
114109
XCTAssertEqual(event["client_name"]!.stringValue, "swift-sdk")
115110
XCTAssertEqual(event["anonymize_ip"]!.boolValue, project.anonymizeIP)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
/****************************************************************************
3+
* Copyright 2019, Optimizely, Inc. and contributors *
4+
* *
5+
* Licensed under the Apache License, Version 2.0 (the "License"); *
6+
* you may not use this file except in compliance with the License. *
7+
* You may obtain a copy of the License at *
8+
* *
9+
* http://www.apache.org/licenses/LICENSE-2.0 *
10+
* *
11+
* Unless required by applicable law or agreed to in writing, software *
12+
* distributed under the License is distributed on an "AS IS" BASIS, *
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14+
* See the License for the specific language governing permissions and *
15+
* limitations under the License. *
16+
***************************************************************************/
17+
18+
19+
import XCTest
20+
21+
class OtherTests: XCTestCase {
22+
23+
func testSDKVersionFormat() {
24+
let version = Utils.getSDKVersion()
25+
XCTAssert(version.split(separator: ".").count == 3)
26+
}
27+
}

OptimizelySDK/Supporting Files/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>$(CURRENT_PROJECT_VERSION)</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
</dict>

OptimizelySDK/Utils/Utils.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,20 @@ class Utils {
113113
guard isBoolType(value) else { return nil }
114114
return (value as! Bool)
115115
}
116+
117+
static func getSDKVersion() -> String {
118+
119+
// - Bundle(for: OptimizelyManager.self) not working properly to get SDK bundle within unit tests
120+
// - Bundle(identifier: bundleIdentifier) works ok consistently
121+
// - CocoaPods uses its own bundle identifier, so let it use Bundle(for:) as a fallback
122+
// CocoaPods copies "s.version" in podspec to "CFBundleShortVersionString" in its own Info.plist file
123+
124+
let bundle = Bundle(identifier: "com.optimizely.OptimizelySwiftSDK") ?? Bundle(for: OptimizelyManager.self)
125+
guard let version = bundle.infoDictionary!["CFBundleShortVersionString"] as? String else {
126+
fatalError("Check if SDK framework identifier is correct")
127+
}
128+
129+
return version
130+
}
116131

117132
}

0 commit comments

Comments
 (0)