Skip to content

Commit 63aafd2

Browse files
committed
Get version and date as function for late execution. Provide default version
and date to be used while fetching the submodule isn't complete.
1 parent 95fa3a1 commit 63aafd2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Package.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import PackageDescription
66

77

88
// Get the values we need to populate the LIBTIDY_VERSION and RELEASE_DATE macros later.
9-
let PWD = (#filePath as NSString).deletingLastPathComponent
10-
let VERSION_FILE = NSString.path(withComponents: [PWD, "Sources", "CLibTidy", "version.txt"])
11-
var CONTENTS:[String]
12-
do {
13-
CONTENTS = try String(contentsOfFile: VERSION_FILE).components(separatedBy: "\n")
9+
func tidyVersion() -> [String] {
10+
let PWD = (#filePath as NSString).deletingLastPathComponent
11+
let VERSION_FILE = NSString.path(withComponents: [PWD, "Sources", "CLibTidy", "version.txt"])
12+
if let CONTENTS = try? String(contentsOfFile: VERSION_FILE).components(separatedBy: "\n") {
13+
return CONTENTS
14+
}
15+
16+
return ["5.0.0", "2021/01/01"]
1417
}
1518

19+
1620
let package = Package(
1721
name: "SwLibTidy",
1822
products: [
@@ -52,8 +56,8 @@ let package = Package(
5256
, sources: ["src"]
5357
, publicHeadersPath: "include"
5458
, cSettings: [
55-
.define("LIBTIDY_VERSION", to: "\"\(CONTENTS[0])\"", nil),
56-
.define("RELEASE_DATE", to: "\"\(CONTENTS[1])\"", nil)
59+
.define("LIBTIDY_VERSION", to: "\"\(tidyVersion()[0])\"", nil),
60+
.define("RELEASE_DATE", to: "\"\(tidyVersion()[1])\"", nil)
5761
]
5862
),
5963

0 commit comments

Comments
 (0)