Merge pull request #154 from yonaskolb/deterministic_references

Make references more deterministic
This commit is contained in:
Yonas Kolb authored and GitHub committed 2017-11-15 11:47:28 +01:00
commit 992c12c6c9
6 files changed
+456 -453

No files matched your search

+2 -1
View File
@@ -98,7 +98,7 @@ public class PBXProjGenerator {
if !carthageFrameworksByPlatform.isEmpty {
var platforms: [PBXGroup] = []
for (platform, fileReferences) in carthageFrameworksByPlatform {
let platformGroup = PBXGroup(reference: referenceGenerator.generate(PBXGroup.self, platform), children: fileReferences.sorted(), sourceTree: .group, name: platform, path: platform)
let platformGroup = PBXGroup(reference: referenceGenerator.generate(PBXGroup.self, "Carthage" + platform), children: fileReferences.sorted(), sourceTree: .group, name: platform, path: platform)
addObject(platformGroup)
platforms.append(platformGroup)
}
@@ -159,6 +159,7 @@ public class PBXProjGenerator {
func generateTarget(_ target: Target) throws -> PBXNativeTarget {
sourceGenerator.targetName = target.name
let carthageDependencies = getAllCarthageDependencies(target: target)
let sourceFiles = try sourceGenerator.getAllSourceFiles(sources: target.sources)
+3 -2
View File
@@ -18,14 +18,15 @@ public class ReferenceGenerator {
public func generate<T: PBXObject>(_ element: T.Type, _ id: String) -> String {
var uuid: String = ""
var counter: UInt = 0
let characterCount = 16
let className: String = String(describing: T.self)
.replacingOccurrences(of: "PBX", with: "")
.replacingOccurrences(of: "XC", with: "")
let classAcronym = String(className.filter { String($0).lowercased() != String($0) })
let stringID = String(abs(id.hashValue).description.prefix(10 - classAcronym.count))
let stringID = String(abs(id.hashValue).description.prefix(characterCount - classAcronym.count - 2))
repeat {
uuid = "\(classAcronym)_\(stringID)\(counter > 0 ? "-\(counter)" : "")"
counter += 1
uuid = "\(classAcronym)\(stringID)\(String(format: "%02d", counter))"
} while (references.contains(uuid))
references.insert(uuid)
return uuid
+8 -6
View File
@@ -29,6 +29,8 @@ class SourceGenerator {
private let proj: PBXProj
var addObject: (PBXObject) -> Void
var targetName: String = ""
init(spec: ProjectSpec, proj: PBXProj, referenceGenerator: ReferenceGenerator, addObject: @escaping (PBXObject) -> Void) {
self.spec = spec
self.proj = proj
@@ -59,7 +61,7 @@ class SourceGenerator {
}
//TODO: add the target name to the reference generator string so shared files don't have same reference (that will be escaped by appending a number)
let buildFile = PBXBuildFile(reference: referenceGenerator.generate(PBXBuildFile.self, fileReference), fileRef: fileReference, settings: settings.isEmpty ? nil : settings)
let buildFile = PBXBuildFile(reference: referenceGenerator.generate(PBXBuildFile.self, fileReference + targetName), fileRef: fileReference, settings: settings.isEmpty ? nil : settings)
return SourceFile(path: path, fileReference: fileReference, buildFile: buildFile, buildPhase: buildPhase)
}
@@ -67,7 +69,7 @@ class SourceGenerator {
if let fileReference = fileReferencesByPath[path] {
return fileReference
} else {
let fileReference = PBXFileReference(reference: referenceGenerator.generate(PBXFileReference.self, path.lastComponent), sourceTree: sourceTree, name: name, path: path.byRemovingBase(path: inPath).string)
let fileReference = PBXFileReference(reference: referenceGenerator.generate(PBXFileReference.self, path.byRemovingBase(path: spec.basePath).string), sourceTree: sourceTree, name: name, path: path.byRemovingBase(path: inPath).string)
addObject(fileReference)
fileReferencesByPath[path] = fileReference.reference
return fileReference.reference
@@ -109,7 +111,7 @@ class SourceGenerator {
let isTopLevelGroup = (isBaseGroup && !createIntermediateGroups) || isRootPath
group = PBXGroup(
reference: referenceGenerator.generate(PBXGroup.self, path.lastComponent),
reference: referenceGenerator.generate(PBXGroup.self, path.byRemovingBase(path: spec.basePath).string),
children: children,
sourceTree: .group,
name: name ?? path.lastComponent,
@@ -132,7 +134,7 @@ class SourceGenerator {
if let cachedGroup = variantGroupsByPath[path] {
variantGroup = cachedGroup
} else {
variantGroup = PBXVariantGroup(reference: referenceGenerator.generate(PBXVariantGroup.self, path.byRemovingBase(path: inPath).string),
variantGroup = PBXVariantGroup(reference: referenceGenerator.generate(PBXVariantGroup.self, path.byRemovingBase(path: spec.basePath).string),
children: [],
name: path.lastComponent,
sourceTree: .group)
@@ -236,7 +238,7 @@ class SourceGenerator {
groupChildren.append(variantGroup.reference)
baseLocalisationVariantGroups.append(variantGroup)
let buildFile = PBXBuildFile(reference: referenceGenerator.generate(PBXBuildFile.self, variantGroup.reference), fileRef: variantGroup.reference, settings: nil)
let buildFile = PBXBuildFile(reference: referenceGenerator.generate(PBXBuildFile.self, variantGroup.reference + targetName), fileRef: variantGroup.reference, settings: nil)
allSourceFiles.append(SourceFile(path: filePath, fileReference: variantGroup.reference, buildFile: buildFile, buildPhase: .resources))
}
}
@@ -258,7 +260,7 @@ class SourceGenerator {
}
} else {
// add SourceFile to group if there is no Base.lproj directory
let buildFile = PBXBuildFile(reference: referenceGenerator.generate(PBXBuildFile.self, fileReference),
let buildFile = PBXBuildFile(reference: referenceGenerator.generate(PBXBuildFile.self, fileReference + targetName),
fileRef: fileReference,
settings: nil)
allSourceFiles.append(SourceFile(path: filePath, fileReference: fileReference, buildFile: buildFile, buildPhase: .resources))
File diff suppressed because it is too large. Load diff
@@ -5,31 +5,31 @@
<TestAction selectedDebuggerIdentifier="Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier="Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv="YES" buildConfiguration="Production Debug">
<Testables>
<TestableReference skipped="NO">
<BuildableReference BlueprintIdentifier="NT7831228901" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
<BuildableReference BlueprintIdentifier="NT_783122899910" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
</MacroExpansion>
</TestAction>
<ProfileAction savedToolIdentifier="" useCustomWorkingDirectory="NO" shouldUseLaunchSchemeArgsEnv="YES" buildConfiguration="Production Release" debugDocumentVersioning="YES">
<BuildableProductRunnable runnableDebuggingMode="0">
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
</BuildableProductRunnable>
</ProfileAction>
<BuildAction parallelizeBuildables="YES" buildImplicitDependencies="YES">
<BuildActionEntries>
<BuildActionEntry buildForArchiving="YES" buildForTesting="YES" buildForRunning="YES" buildForProfiling="YES" buildForAnalyzing="YES">
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
</BuildActionEntry>
<BuildActionEntry buildForArchiving="NO" buildForTesting="YES" buildForRunning="NO" buildForProfiling="NO" buildForAnalyzing="YES">
<BuildableReference BlueprintIdentifier="NT7831228901" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
<BuildableReference BlueprintIdentifier="NT_783122899910" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS_Tests.xctest" BlueprintName="App_iOS" BuildableIdentifier="primary" />
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<LaunchAction selectedDebuggerIdentifier="Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier="Xcode.DebuggerFoundation.Launcher.LLDB" launchStyle="0" buildConfiguration="Production Debug" debugServiceExtension="internal" ignoresPersistentStateOnLaunch="NO" useCustomWorkingDirectory="NO" allowLocationSimulation="YES" debugDocumentVersioning="YES">
<BuildableProductRunnable runnableDebuggingMode="0">
<BuildableReference BlueprintIdentifier="NT8252321101" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
<BuildableReference BlueprintIdentifier="NT_825232110500" ReferencedContainer="container:Project.xcodeproj" BuildableName="App_iOS.app" BlueprintName="App_iOS" BuildableIdentifier="primary" />
</BuildableProductRunnable>
</LaunchAction>
</Scheme>
@@ -242,6 +242,33 @@ func projectGeneratorTests() {
}
}
$0.describe("Reference Generator") {
let referenceGenerator = ReferenceGenerator()
$0.before {
referenceGenerator.clear()
}
$0.it("generates prefixes") {
let references = [
referenceGenerator.generate(PBXGroup.self, "a"),
referenceGenerator.generate(PBXFileReference.self, "a"),
referenceGenerator.generate(XCConfigurationList.self, "a"),
]
try expect(references[0].hasPrefix("G")).to.beTrue()
try expect(references[1].hasPrefix("FR")).to.beTrue()
try expect(references[2].hasPrefix("CL")).to.beTrue()
}
$0.it("handles duplicates") {
let first = referenceGenerator.generate(PBXGroup.self, "a")
let second = referenceGenerator.generate(PBXGroup.self, "a")
try expect(first) != second
try expect(second.hasSuffix("-1")).to.beTrue()
}
}
$0.describe("Sources") {
let directoryPath = Path("TestDirectory")
@@ -494,34 +521,6 @@ func projectGeneratorTests() {
try project.expectFileMissing(paths: ["Sources", "A", "a.swift"])
}
}
$0.describe("Reference Generator") {
let referenceGenerator = ReferenceGenerator()
$0.before {
referenceGenerator.clear()
}
$0.it("generates prefixes") {
let references = [
referenceGenerator.generate(PBXGroup.self, "a"),
referenceGenerator.generate(PBXFileReference.self, "a"),
referenceGenerator.generate(XCConfigurationList.self, "a"),
]
try expect(references[0].hasPrefix("G")).to.beTrue()
try expect(references[1].hasPrefix("FR")).to.beTrue()
try expect(references[2].hasPrefix("CL")).to.beTrue()
}
$0.it("handles duplicates") {
let first = referenceGenerator.generate(PBXGroup.self, "a")
let second = referenceGenerator.generate(PBXGroup.self, "a")
try expect(first) != second
try expect(first.hasSuffix("01")).to.beTrue()
try expect(second.hasSuffix("02")).to.beTrue()
}
}
}
}