Skip to content

Commit

Permalink
added logging for DEBUG build
Browse files Browse the repository at this point in the history
  • Loading branch information
art-divin committed Dec 23, 2020
1 parent e1c2968 commit 1d32cc2
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 59 deletions.
75 changes: 75 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Xcode
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/
*.framework*
*.DS_Store*

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate
*.xcbkptlist

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output

# jazzy
docs/*
*docs/*
*/docs/*



Binary file modified XcodeUpdatesInternal/XcodeUpdatesInternal/External/xcodes
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class XcodeUpdatesRequest : Identifiable {

func popFirst() -> Input? {
guard !self.input.isEmpty else { return nil }
log("XXX sending next input: \(self.input.first!)")
return self.input.remove(at: 0)
}

Expand Down
122 changes: 63 additions & 59 deletions XcodeUpdatesInternal/XcodeUpdatesInternal/Wrapper/XcodesWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class XcodesWrapper {
private var writeHandle : FileHandle?
private var readHandle : FileHandle?
private var errorHandle : FileHandle?

private var cancellables : [AnyCancellable] = []
private var process : Process = Process()
private var outputData : Data?
Expand Down Expand Up @@ -97,8 +97,10 @@ class XcodesWrapper {
switch formattedOutput.first?.type {
case .error?:
output.send(.failure(.generalError(formattedOutput)))
log("XXX sending output error: \(formattedOutput)")
default:
output.send(.success(formattedOutput))
log("XXX sending output success: \(formattedOutput)")
}
} else {
self.output.send(formattedOutput)
Expand All @@ -114,71 +116,73 @@ class XcodesWrapper {
return retVal
}()
func run() {
self.log("XXX: started process 1")
let readPipe = Pipe()
let writePipe = Pipe()
let errorPipe = Pipe()
self.writeHandle = writePipe.fileHandleForWriting
self.readHandle = readPipe.fileHandleForReading
log("XXX: started process 1")
let readPipe = Pipe()
let writePipe = Pipe()
let errorPipe = Pipe()
self.writeHandle = writePipe.fileHandleForWriting
self.readHandle = readPipe.fileHandleForReading

self.errorHandle = errorPipe.fileHandleForReading
self.process.standardInput = writePipe
self.process.standardOutput = readPipe
self.errorHandle = errorPipe.fileHandleForReading
self.process.standardInput = writePipe
self.process.standardOutput = readPipe

self.process.standardError = errorPipe
self.process.executableURL = self.url
self.process.arguments = self.processArgs
self.readPipe = readPipe
self.writePipe = writePipe
self.errorPipe = errorPipe
do {
self.log("XXX: started process 2")
self.process.terminationHandler = { _ in
self.outputData = (self.outputData ?? Data()) + (self.readHandle?.availableData ?? Data())
self.log("XXX: ended process")
self.log("XXX: output: \(self.formattedOutput)")
self.sendOutput()
self.close()
}
self.readHandle?.readabilityHandler = {
let data = $0.availableData
self.log("XXX readHandle: " + (String(data: data, encoding: .utf8) ?? ""))
if data.isEmpty {
return
}
self.outputData = (self.outputData ?? Data()) + data
self.sendOutput()
self.process.standardError = errorPipe
self.process.executableURL = self.url
self.process.arguments = self.processArgs
self.readPipe = readPipe
self.writePipe = writePipe
self.errorPipe = errorPipe
do {
log("XXX: started process 2")
self.process.terminationHandler = { _ in
self.outputData = (self.outputData ?? Data()) + (self.readHandle?.availableData ?? Data())
log("XXX: ended process")
log("XXX: output: \(self.formattedOutput)")
self.sendOutput()
self.close()
}
self.readHandle?.readabilityHandler = {
let data = $0.availableData
log("XXX readHandle: " + (String(data: data, encoding: .utf8) ?? ""))
if data.isEmpty {
return
}
self.errorHandle?.readabilityHandler = {
let data = $0.availableData
self.log("XXX error " + (String(data: data, encoding: .utf8) ?? ""))
if data.isEmpty {
return
}
let error = String(data: data, encoding: .utf8)
if error?.contains("[logging]") ?? true {
return
}
self.outputData = (self.outputData ?? Data()) + data
self.sendOutput()
self.outputData = (self.outputData ?? Data()) + data
self.sendOutput()
}
self.errorHandle?.readabilityHandler = {
let data = $0.availableData
log("XXX error " + (String(data: data, encoding: .utf8) ?? ""))
if data.isEmpty {
return
}
try self.process.run()
self.queue.async {
self.process.waitUntilExit()
self.log("YYY: ended process")
let error = String(data: data, encoding: .utf8)
if error?.contains("[logging]") ?? true {
return
}
} catch {
self.log("XXX Very error: \(error.localizedDescription)")
self.outputData = (self.outputData ?? Data()) + data
self.sendOutput()
}
try self.process.run()
self.queue.async {
self.process.waitUntilExit()
log("YYY: ended process")
}
} catch {
log("XXX Very error: \(error.localizedDescription)")
}
}

private func log(_ string: String) {
let log = OSLog(subsystem: "com.xcodeupdates.xcodeupdatesinternal", category: .dynamicTracing)
#if DEBUG
os_log("XXX: %{public}@", log: log, type: .fault, string)
#else
// no-op
#endif
}


}

internal func log(_ string: String) {
let log = OSLog(subsystem: "com.xcodeupdates.xcodeupdatesinternal", category: .dynamicTracing)
#if DEBUG
os_log("XXX: %{public}@", log: log, type: .fault, string)
#else
// no-op
#endif
}

0 comments on commit 1d32cc2

Please sign in to comment.