Files
XcodeGen/Sources/XcodeGenKit/BreakpointGenerator.swift
T
Jierong Li d1dd93aac4 Rebase #177 - Shared breakpoints support (#693)
* Resolves #173 - Shared breakpoints support

* Added breakpoints full documentation

* Invalid breakpoint just throw JSONUtilities decoding error.

* Use enumeration types instead of String for extensionIDs

* Remove a necessary line

* Remove unnecessary custom Equatable implementation

* Update CHANGELOG.md

* Ignore empty breakpoints

* Update Docs/ProjectSpec.md

Fix a typo

Co-Authored-By: Yonas Kolb <yonaskolb@users.noreply.github.com>

* Change some properties that should be Int to Int

* Create 2 typealiases

* Use BreakpointType where it is missing

* Remove unused Location

* Change some names

* Add Breakpoint.Scope

* Add Breakpoint.StopOnStyle

* Change the type of the raw value to String

* Remove some properties that may cause confusing

* Require filePah and line when the type is .file

* Add tests about decoding breakpoints

* Add Breakpoint.Action.ConveyanceType

* Add default value for waitUntilDone

* Add Breakpoint.Action.SoundName

* Add tests about decoding breakpoint actions

* Fix some issues in ProjectSpec.md

* Improve ProjectSpec.md

* Add missing condition

* Add breakpoints to project.yml

* Use unwarp

* Remove the Breakpoint suffix

* Refactor BreakpointType

* Refactor Breakpoint.Action

* Remove unnecessary properties

* Adjust the line wrapping style for BreakpointGenerator

* Support column breakpoints

---------

Co-authored-by: Alex Rupérez <alejandro.ruperez@intelygenz.com>
Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>
2023-02-28 22:00:39 +11:00

125 lines
4.5 KiB
Swift

import Foundation
import ProjectSpec
import XcodeProj
public class BreakpointGenerator {
let project: Project
public init(project: Project) {
self.project = project
}
func generateBreakpointList() throws -> XCBreakpointList? {
let breakpoints = project.breakpoints
guard !breakpoints.isEmpty else {
return nil
}
return XCBreakpointList(type: "4", version: "2.0", breakpoints: try breakpoints.map({ try generateBreakpointProxy($0) }))
}
private func generateBreakpointProxy(_ breakpoint: Breakpoint) throws -> XCBreakpointList.BreakpointProxy {
let breakpointExtensionID: BreakpointExtensionID
var filePath: String?
var line: String?
var column: String?
var scope: String?
var stopOnStyle: String?
var symbol: String?
var module: String?
switch breakpoint.type {
case let .file(path, lineNumber, columnNumber):
breakpointExtensionID = .file
filePath = path
line = String(lineNumber)
column = columnNumber.map(String.init)
case let .exception(exception):
breakpointExtensionID = .exception
scope = exception.scope.rawValue
stopOnStyle = exception.stopOnStyle.rawValue
case .swiftError:
breakpointExtensionID = .swiftError
case .openGLError:
breakpointExtensionID = .openGLError
case let .symbolic(symbolName, moduleName):
breakpointExtensionID = .symbolic
symbol = symbolName
module = moduleName
case .ideConstraintError:
breakpointExtensionID = .ideConstraintError
case .ideTestFailure:
breakpointExtensionID = .ideTestFailure
}
let xcbreakpoint = XCBreakpointList.BreakpointProxy.BreakpointContent(
enabled: breakpoint.enabled,
ignoreCount: String(breakpoint.ignoreCount),
continueAfterRunningActions: breakpoint.continueAfterRunningActions,
filePath: filePath,
startingColumn: column,
endingColumn: column,
startingLine: line,
endingLine: line,
symbol: symbol,
module: module,
scope: scope,
stopOnStyle: stopOnStyle,
condition: breakpoint.condition,
actions: try breakpoint.actions.map { try generateBreakpointActionProxy($0) }
)
return XCBreakpointList.BreakpointProxy(
breakpointExtensionID: breakpointExtensionID,
breakpointContent: xcbreakpoint
)
}
private func generateBreakpointActionProxy(_ breakpointAction: Breakpoint.Action) throws -> XCBreakpointList.BreakpointProxy.BreakpointContent.BreakpointActionProxy {
let actionExtensionID: BreakpointActionExtensionID
var consoleCommand: String?
var message: String?
var conveyanceType: String?
var command: String?
var arguments: String?
var waitUntilDone: Bool?
var script: String?
var soundName: String?
switch breakpointAction {
case let .debuggerCommand(command):
actionExtensionID = .debuggerCommand
consoleCommand = command
case let .log(log):
actionExtensionID = .log
message = log.message
conveyanceType = log.conveyanceType.rawValue
case let .shellCommand(commandPath, commandArguments, waitUntilCommandDone):
actionExtensionID = .shellCommand
command = commandPath
arguments = commandArguments
waitUntilDone = waitUntilCommandDone
case .graphicsTrace:
actionExtensionID = .graphicsTrace
case let .appleScript(appleScript):
actionExtensionID = .appleScript
script = appleScript
case let .sound(sound):
actionExtensionID = .sound
soundName = sound.rawValue
}
let xcaction = XCBreakpointList.BreakpointProxy.BreakpointContent.BreakpointActionProxy.ActionContent(
consoleCommand: consoleCommand,
message: message,
conveyanceType: conveyanceType,
command: command,
arguments: arguments,
waitUntilDone: waitUntilDone,
script: script,
soundName: soundName
)
return XCBreakpointList.BreakpointProxy.BreakpointContent.BreakpointActionProxy(
actionExtensionID: actionExtensionID,
actionContent: xcaction
)
}
}