Skip to content

Commit 6d18f95

Browse files
authored
Merge pull request #9 from toshi0383/target-common
Trim Duplicated Lines between targets' configs
2 parents d672b9a + c5f788f commit 6d18f95

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## master
2+
* Trim Targets' Duplicated Lines
3+
[Toshihiro Suzuki](https://github.com/toshi0383)
4+
[#9](https://github.com/toshi0383/xcconfig-extractor/pull/9)
5+
16
## 0.3.0
27
* Introduce `--include-existing` (`--no-include-existing`) option
38
[Toshihiro Suzuki](https://github.com/toshi0383)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Options:
2828
```
2929
3030
# Build Setting Validation
31-
⚠️***Waring***⚠️
31+
⚠️ ***Waring*** ⚠️
3232
3333
You should check app's Build Settings hasn't been affected by applying this tool.
3434
xcconfig does not allow any `$(inherited)` from `#include`ing xcconfigs. (See: https://github.com/toshi0383/xcconfig-extractor/pull/8#issuecomment-298234943) So if you have any existing xcconfig configured on your project, it might cause problems.

Sources/xcconfig-extractor/main.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,26 @@ let main = command(
118118
baseResults[idx].settings = distinctArray(common + baseResults[idx].settings)
119119
// Write Upper Layer Configs (e.g. App-Debug.xcconfig, AppTests-Debug.xcconfig)
120120
for r in filtered {
121-
r.settings = r.settings - common
122-
try write(to: r.path, lines: formatter.format(result: r)) // not including any other xcconfigs for targets'
121+
let idx = targetResults.index(of: r)!
122+
targetResults[idx].settings = r.settings - common
123123
}
124124
}
125+
// Trim Duplicates in target configs (e.g. App-Debug.xcconfig and App-Release.xcconfig)
126+
for target in pbxproj.rootObject.targets {
127+
let filtered = targetResults
128+
.filter { $0.path.components.last!.characters.starts(with: "\(target.name)-".characters) }
129+
let common: [String] = commonElements(filtered.map { $0.settings })
130+
let targetConfigPath = Path("\(dirPath.string)/\(target.name).xcconfig")
131+
let r = ResultObject(path: targetConfigPath, settings: common)
132+
try write(to: r.path, lines: formatter.format(result: r))
133+
for r in filtered {
134+
let idx = targetResults.index(of: r)!
135+
targetResults[idx].settings = r.settings - common
136+
targetResults[idx].includes += [targetConfigPath.lastComponent]
137+
try write(to: r.path, lines: formatter.format(result: targetResults[idx]))
138+
}
139+
}
140+
125141
// Trim Duplicates in configurationName configs (e.g. Debug.xcconfig and Release.xcconfig)
126142
let common = commonElements(baseResults.map { $0.settings })
127143
// Write Configuration Base Configs (e.g. Debug.xcconfig, Release.xcconfig)

0 commit comments

Comments
 (0)