Skip to content

Commit

Permalink
Swift 4.2 is the current GM, so our min is 3.2.
Browse files Browse the repository at this point in the history
- Update docs.
- Remove all `#if swift(>=3.2)` checks dropping the `else` clause.
  • Loading branch information
thomasvl committed Jan 4, 2019
1 parent 575c0c4 commit 3088a28
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Documentation/CONFORMANCE_TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ these tests regularly.

## Preparation

The conformance test suite requires Swift 3.1, standard command-line
The conformance test suite requires Swift 3.2, standard command-line
tools such as make and awk, and a full source checkout of
[Google's protobuf project](https://github.com/protocolbuffers/protobuf).

Expand Down
4 changes: 2 additions & 2 deletions Documentation/INTERNALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ behavior are always appreciated.

The goal is to always support "one full major version”, which basically
means if the current official release of Swift is `X.Y`, the library will
support back to `X-1.Y`. That is, when Swift 4.1 gets released, the minimum
for support gets moved up to 3.1.
support back to `X-1.Y`. That is, when Swift 4.2 was released, the minimum
for support got moved up to 3.2.

When the minimum Swift version gets updated, update:
- The `README.md` in the root of the project
Expand Down
2 changes: 1 addition & 1 deletion Documentation/PLUGIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Swift runtime library to your project.

To use Swift with Protocol buffers, you'll need:

* A recent Swift 3.1 compiler that includes the Swift Package Manager.
* A recent Swift 3.2 compiler that includes the Swift Package Manager.
We recommend using the latest release build from
[Swift.org](https://swift.org) or the command-line tools included
with the latest version of Xcode.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ your project as explained below.

To use Swift with Protocol buffers, you'll need:

* A Swift 3.1 or later compiler (Xcode 8.3.3 or later). Support is included
* A Swift 3.2 or later compiler (Xcode 9.0 or later). Support is included
for the Swift Package Manager; or using the included Xcode project. The Swift
protobuf project is being developed and tested against the latest release
version of Swift available from [Swift.org](https://swift.org)
Expand Down
4 changes: 0 additions & 4 deletions Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import Dispatch

internal func buildTypeURL(forMessage message: Message, typePrefix: String) -> String {
var url = typePrefix
#if swift(>=3.2)
let needsSlash = typePrefix.isEmpty || typePrefix.last != "/"
#else
let needsSlash = typePrefix.isEmpty || typePrefix.characters.last != "/"
#endif
if needsSlash {
url += "/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ private func parseDuration(text: String) throws -> (Int64, Int32) {
var digits = [Character]()
var digitCount = 0
var total = 0
#if swift(>=3.2)
var chars = text.makeIterator()
#else
var chars = text.characters.makeIterator()
#endif
var seconds: Int64?
var nanos: Int32 = 0
while let c = chars.next() {
Expand Down
18 changes: 2 additions & 16 deletions Sources/SwiftProtobuf/Google_Protobuf_FieldMask+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@

private func ProtoToJSON(name: String) -> String? {
var jsonPath = String()
#if swift(>=3.2)
var chars = name.makeIterator()
#else
var chars = name.characters.makeIterator()
#endif
while let c = chars.next() {
switch c {
case "_":
Expand All @@ -47,12 +43,7 @@ private func ProtoToJSON(name: String) -> String? {

private func JSONToProto(name: String) -> String? {
var path = String()
#if swift(>=3.2)
let chars = name
#else
let chars = name.characters
#endif
for c in chars {
for c in name {
switch c {
case "_":
return nil
Expand All @@ -70,12 +61,7 @@ private func parseJSONFieldNames(names: String) -> [String]? {
var fieldNameCount = 0
var fieldName = String()
var split = [String]()
#if swift(>=3.2)
let namesChars = names
#else
let namesChars = names.characters
#endif
for c: Character in namesChars {
for c in names {
switch c {
case ",":
if fieldNameCount == 0 {
Expand Down
7 changes: 1 addition & 6 deletions Sources/SwiftProtobuf/NameMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
private func toJsonFieldName(_ s: String) -> String {
var result = String()
var capitalizeNext = false
#if swift(>=3.2)
let chars = s
#else
let chars = s.characters
#endif
for c in chars {
for c in s {
if c == "_" {
capitalizeNext = true
} else if capitalizeNext {
Expand Down
16 changes: 3 additions & 13 deletions Sources/SwiftProtobufPluginLibrary/NamingUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,8 @@ fileprivate func sanitizeTypeName(_ s: String, disambiguator: String) -> String
// conflict. This can be resolved recursively by stripping
// the disambiguator, sanitizing the root, then re-adding the
// disambiguator:
#if swift(>=3.2)
let e = s.index(s.endIndex, offsetBy: -disambiguator.count)
let truncated = String(s[..<e])
#else
let e = s.index(s.endIndex, offsetBy: -disambiguator.characters.count)
let truncated = s.substring(to: e)
#endif
let e = s.index(s.endIndex, offsetBy: -disambiguator.count)
let truncated = String(s[..<e])
return sanitizeTypeName(truncated, disambiguator: disambiguator) + disambiguator
} else {
return s
Expand Down Expand Up @@ -302,12 +297,7 @@ public enum NamingUtils {
// "pacakge.some_name" -> "Package_SomeName"
var makeUpper = true
var prefix = ""
#if swift(>=3.2)
let protoPackageChars = protoPackage
#else
let protoPackageChars = protoPackage.characters
#endif
for c in protoPackageChars {
for c in protoPackage {
if c == "_" {
makeUpper = true
} else if c == "." {
Expand Down
11 changes: 1 addition & 10 deletions Sources/protoc-gen-swift/StringUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ func splitPath(pathname: String) -> (dir:String, base:String, suffix:String) {
var dir = ""
var base = ""
var suffix = ""
#if swift(>=3.2)
let pathnameChars = pathname
#else
let pathnameChars = pathname.characters
#endif
for c in pathnameChars {
for c in pathname {
if c == "/" {
dir += base + suffix + String(c)
base = ""
Expand All @@ -31,11 +26,7 @@ func splitPath(pathname: String) -> (dir:String, base:String, suffix:String) {
suffix += String(c)
}
}
#if swift(>=3.2)
let validSuffix = suffix.isEmpty || suffix.first == "."
#else
let validSuffix = suffix.isEmpty || suffix.characters.first == "."
#endif
if !validSuffix {
base += suffix
suffix = ""
Expand Down
7 changes: 1 addition & 6 deletions Tests/SwiftProtobufTests/Test_JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,8 @@ class Test_JSON: XCTestCase, PBTestHelpers {
var m = MessageTestType()
configureLargeObject(&m)
let s = try m.jsonString()
#if swift(>=3.2)
let chars = s
#else
let chars = s.characters
#endif
var truncated = ""
for c in chars {
for c in s {
truncated.append(c)
do {
_ = try MessageTestType(jsonString: truncated)
Expand Down

0 comments on commit 3088a28

Please sign in to comment.