Skip to content

Commit

Permalink
Merge branch 'master' into add-file-helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyapuchka authored Jan 13, 2018
2 parents 283d075 + e7bda02 commit 2cdec26
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
- Fix Xcode 9.2 warning https://github.com/xcodeswift/xcproj/pull/209 by @keith
- macOS CLI targets now have a nil extension, instead of an empty string https://github.com/xcodeswift/xcproj/pull/208 by @keith
- Fix unnecessary quotations in CommentedString https://github.com/xcodeswift/xcproj/pull/211 by @allu22
- Fixed xml files format not matching Xcode format, added some missing actions attributes. https://github.com/xcodeswift/xcproj/pull/216 by @ilyapuchka

### Changed
- **Breaking:** `XCWorkspace.Data` renamed to `XCWorkspaceData` and removed `references`.
- Improved README examples. https://github.com/xcodeswift/xcproj/pull/212 by @ilyapuchka
- Added methods to get paths to workspace, project and breakpoints and shemes files, added public methods to write them separatery. https://github.com/xcodeswift/xcproj/pull/215 by @ilyapuchka
- Added helper methods for adding source file to the project. https://github.com/xcodeswift/xcproj/pull/213 by @ilyapuchka

## 2.0.0
Expand Down
6 changes: 6 additions & 0 deletions Carthage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
BF1286225402 /* KeyedDecodingContainer+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR6357036901 /* KeyedDecodingContainer+Additions.swift */; };
BF1398928001 /* PBXProject.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR2458458701 /* PBXProject.swift */; };
BF1398928002 /* PBXProject.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR2458458701 /* PBXProject.swift */; };
BF1456930601 /* AEXML+XcodeFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR3463446801 /* AEXML+XcodeFormat.swift */; };
BF1456930602 /* AEXML+XcodeFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR3463446801 /* AEXML+XcodeFormat.swift */; };
BF1618407401 /* PBXRezBuildPhase.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR8785334801 /* PBXRezBuildPhase.swift */; };
BF1618407402 /* PBXRezBuildPhase.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR8785334801 /* PBXRezBuildPhase.swift */; };
BF1641641601 /* AEXML.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR6447358001 /* AEXML.framework */; };
Expand Down Expand Up @@ -145,6 +147,7 @@
FR3255351901 /* Bool+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bool+Extras.swift"; sourceTree = "<group>"; };
FR3300528101 /* Referenceable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Referenceable.swift; sourceTree = "<group>"; };
FR3402716401 /* BuildSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildSettings.swift; sourceTree = "<group>"; };
FR3463446801 /* AEXML+XcodeFormat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AEXML+XcodeFormat.swift"; sourceTree = "<group>"; };
FR3546471301 /* PBXGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PBXGroup.swift; sourceTree = "<group>"; };
FR3952162601 /* PBXAggregateTarget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PBXAggregateTarget.swift; sourceTree = "<group>"; };
FR4128075701 /* PBXBuildPhase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PBXBuildPhase.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -255,6 +258,7 @@
G48093636701 /* xcproj */ = {
isa = PBXGroup;
children = (
FR3463446801 /* AEXML+XcodeFormat.swift */,
FR3255351901 /* Bool+Extras.swift */,
FR4602369901 /* BuildPhase.swift */,
FR3402716401 /* BuildSettings.swift */,
Expand Down Expand Up @@ -433,6 +437,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BF1456930601 /* AEXML+XcodeFormat.swift in Sources */,
BF2311546501 /* Bool+Extras.swift in Sources */,
BF9042303701 /* BuildPhase.swift in Sources */,
BF6966109201 /* BuildSettings.swift in Sources */,
Expand Down Expand Up @@ -496,6 +501,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BF1456930602 /* AEXML+XcodeFormat.swift in Sources */,
BF2311546502 /* Bool+Extras.swift in Sources */,
BF9042303702 /* BuildPhase.swift in Sources */,
BF6966109202 /* BuildSettings.swift in Sources */,
Expand Down
137 changes: 137 additions & 0 deletions Sources/xcproj/AEXML+XcodeFormat.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import Foundation
import AEXML

extension AEXMLDocument {

var xmlXcodeFormat: String {
var xml = "<?xml version=\"\(options.documentHeader.version)\" encoding=\"\(options.documentHeader.encoding.uppercased())\"?>\n"
xml += root._xmlXcodeFormat + "\n"
return xml
}

}

let attributesOrder: [String: [String]] = [
"BuildActionEntry": [
"buildForTesting",
"buildForRunning",
"buildForProfiling",
"buildForArchiving",
"buildForAnalyzing"
],
"BuildableReference": [
"BuildableIdentifier",
"BlueprintIdentifier",
"BuildableName",
"BlueprintName",
"ReferencedContainer"
],
"TestAction": [
"buildConfiguration",
"selectedDebuggerIdentifier",
"selectedLauncherIdentifier",
"language",
"region",
"shouldUseLaunchSchemeArgsEnv",
"codeCoverageEnabled"
],
"LaunchAction": [
"buildConfiguration",
"selectedDebuggerIdentifier",
"selectedLauncherIdentifier",
"language",
"region",
"launchStyle",
"useCustomWorkingDirectory",
"ignoresPersistentStateOnLaunch",
"debugDocumentVersioning",
"debugServiceExtension",
"allowLocationSimulation"
],
"ProfileAction": [
"buildConfiguration",
"shouldUseLaunchSchemeArgsEnv",
"savedToolIdentifier",
"useCustomWorkingDirectory",
"ignoresPersistentStateOnLaunch",
"debugDocumentVersioning",
"enableTestabilityWhenProfilingTests"
]
]

extension AEXMLElement {

fileprivate var _xmlXcodeFormat: String {
var xml = String()

// open element
xml += indent(withDepth: parentsCount - 1)
xml += "<\(name)"

if attributes.count > 0 {
// insert attributes
var attributes = self.attributes
for key in attributesOrder[self.name] ?? [] {
if let value = attributes.removeValue(forKey: key) {
xml += "\n"
xml += indent(withDepth: parentsCount)
xml += "\(key) = \"\(value.xmlEscaped)\""
}
}

for (key, value) in attributes {
xml += "\n"
xml += indent(withDepth: parentsCount)
xml += "\(key) = \"\(value.xmlEscaped)\""
}
}

if value == nil && children.count == 0 {
// close element
xml += ">\n"
} else {
if children.count > 0 {
// add children
xml += ">\n"
for child in children {
xml += "\(child._xmlXcodeFormat)\n"
}
} else {
// insert string value and close element
xml += ">\n"
xml += indent(withDepth: parentsCount - 1)
xml += ">\n\(string.xmlEscaped)"
}
}

xml += indent(withDepth: parentsCount - 1)
xml += "</\(name)>"

return xml
}

private var parentsCount: Int {
var count = 0
var element = self

while let parent = element.parent {
count += 1
element = parent
}

return count
}

private func indent(withDepth depth: Int) -> String {
var count = depth
var indent = String()

while count > 0 {
indent += " "
count -= 1
}

return indent
}

}
2 changes: 1 addition & 1 deletion Sources/xcproj/XCBreakpointList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ extension XCBreakpointList: Writable {
if override && path.exists {
try path.delete()
}
try path.write(document.xml)
try path.write(document.xmlXcodeFormat)
}

}
Expand Down
Loading

0 comments on commit 2cdec26

Please sign in to comment.