Skip to content

Commit

Permalink
Add inline comments support to the xcconfig parser (#604)
Browse files Browse the repository at this point in the history
* Update xcconfig test data with comment examples

* Adjust unit-tests for xcconfig

* Update settingRegex regular expression with comments support

* Fix comment spelling

* Add an edge-case test when a comment has to space

* Add CHANGELOG.md entry for the PR
  • Loading branch information
dive committed Feb 18, 2021
1 parent 4b14bb1 commit f0b1d1b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- JSON decoder not properly decoding `defaultConfigurationIsVisible` in some projects [#593](https://github.com/tuist/XcodeProj/pull/593) by [@tjwio](https://github.com/tjwio)
- JSON decoder not properly decoding `proxyType` in some projects [#596](https://github.com/tuist/XcodeProj/issues/596) by [@tjwio](https://github.com/tjwio)
- BuildPhaseTests not handling failure cases properly [#597](https://github.com/tuist/XcodeProj/issues/597) by [@tjwio](https://github.com/tjwio)
- `xcconfig` parser does not support inline comments [#602](https://github.com/tuist/XcodeProj/issues/602) by [@dive](https://github.com/dive)

## 7.18.0 - Penguin

Expand Down
4 changes: 2 additions & 2 deletions Fixtures/XCConfigs/Children.xcconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Parent.xcconfig"

CONFIGURATION_BUILD_DIR = Test/
CONFIGURATION_BUILD_DIR = Test/ // NOTE: Test comment line to check several slashes
GCC_PREPROCESSOR_DEFINITIONS = $(inherited)
WARNING_CFLAGS = -Wall -Wno-direct-ivar-access -Wno-objc-missing-property-synthesis -Wno-readonly-iboutlet-property -Wno-switch-enum -Wno-padded
WARNING_CFLAGS = -Wall -Wno-direct-ivar-access -Wno-objc-missing-property-synthesis -Wno-readonly-iboutlet-property -Wno-switch-enum -Wno-padded
5 changes: 4 additions & 1 deletion Fixtures/XCConfigs/Parent.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// NOTE: Top level comment
OTHER_SWIFT_FLAGS_XCODE_0821 = $(inherited)
OTHER_SWIFT_FLAGS_XCODE_0830 = $(inherited) -enable-bridging-pch
OTHER_SWIFT_FLAGS_XCODE_0830 = $(inherited) -enable-bridging-pch
PRODUCT_NAME = $(TARGET_NAME) // NOTE: Test Comment
SWIFT_OPTIMIZATION_LEVEL = -Onone// Edge-case when a comment has no space
2 changes: 1 addition & 1 deletion Sources/XcodeProj/Utils/XCConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ final class XCConfigParser {
// swiftlint:disable:next force_try
private static var includeRegex = try! NSRegularExpression(pattern: "#include\\s+\"(.+\\.xcconfig)\"", options: .caseInsensitive)
// swiftlint:disable:next force_try
private static var settingRegex = try! NSRegularExpression(pattern: "^([a-zA-Z0-9_\\[\\]=\\*~]+)\\s*=\\s*(\"?.*?\"?)\\s*(?:;\\s*)?$", options: [])
private static var settingRegex = try! NSRegularExpression(pattern: "^([a-zA-Z0-9_\\[\\]=\\*~]+)\\s*=\\s*(\"?.*?\"?)\\s*(?:;\\s*)?(?=$|\\/\\/)", options: [])
}

// MARK: - XCConfig Extension (Equatable)
Expand Down
2 changes: 2 additions & 0 deletions Tests/XcodeProjTests/Utils/XCConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,7 @@ final class XCConfigIntegrationTests: XCTestCase {
XCTAssertEqual(config.includes.count, 1)
XCTAssertEqual(config.flattenedBuildSettings()["OTHER_SWIFT_FLAGS_XCODE_0821"] as? String, "$(inherited)")
XCTAssertEqual(config.flattenedBuildSettings()["OTHER_SWIFT_FLAGS_XCODE_0830"] as? String, "$(inherited) -enable-bridging-pch")
XCTAssertEqual(config.flattenedBuildSettings()["PRODUCT_NAME"] as? String, "$(TARGET_NAME)")
XCTAssertEqual(config.flattenedBuildSettings()["SWIFT_OPTIMIZATION_LEVEL"] as? String, "-Onone")
}
}

0 comments on commit f0b1d1b

Please sign in to comment.