Skip to content

Commit

Permalink
Adding the SWIFTSHIELDED proprty in the build settings in a more resi…
Browse files Browse the repository at this point in the history
…lient way.
  • Loading branch information
Michele Simone authored and rockbruno committed Jun 8, 2021
1 parent 024fc1e commit 224259a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/SwiftShieldCore/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ struct Project: Hashable {

func markAsSwiftShielded() throws -> String {
var data = try pbxProj.read()
let matches = data.match(regex: "PRODUCT_NAME = \".*\";")
let matches = data.match(regex: "buildSettings = \\{")
for match in matches.reversed() {
let value = match.captureGroup(0, originalString: data)
let range = match.captureGroupRange(0, originalString: data)
let newValue = value + "SWIFTSHIELDED = true;"
let newValue = value + "\n" + "SWIFTSHIELDED = true;"
data = data.replacingCharacters(in: range, with: newValue)
}
return data
Expand Down
7 changes: 6 additions & 1 deletion Tests/SwiftShieldTests/ProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ final class ProjectTests: XCTestCase {

func test_projectTagging() throws {
let projectContent = """
buildSettings = {
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-D\" \"TESTS\"";
PRODUCT_BUNDLE_IDENTIFIER = com.rockbruno.MarketplaceTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
}
"""
let projTemp = temporaryFilePath(forFile: "foo.xcodeproj")
try? FileManager.default.createDirectory(
Expand All @@ -59,11 +61,14 @@ final class ProjectTests: XCTestCase {
let result = try projectFile.markAsSwiftShielded()

XCTAssertEqual(result, """
buildSettings = {
SWIFTSHIELDED = true;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-D\" \"TESTS\"";
PRODUCT_BUNDLE_IDENTIFIER = com.rockbruno.MarketplaceTests;
PRODUCT_NAME = "$(TARGET_NAME)";SWIFTSHIELDED = true;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
}
""")
}
}

0 comments on commit 224259a

Please sign in to comment.