fix: auto-find Package.swift for SPM commands, fix VS Code git scanning
- XcodeTools: swift_package commands now search workspace root and immediate subdirs for Package.swift instead of blindly running from workspaceRoot (fixes 'Could not find Package.swift' error) - VS Code: set git.autoRepositoryDetection=openEditors and git.scanRepositories=[] to prevent path-doubling on CxSwiftAgent
This commit is contained in:
@@ -26,7 +26,10 @@ enum XcodeTools {
|
||||
] as [String: Any]
|
||||
) { args in
|
||||
if args["swift_package"] as? Bool == true {
|
||||
return runCommand("swift", ["build"], in: config.workspaceRoot)
|
||||
guard let spmDir = findPackageSwift(from: config.workspaceRoot) else {
|
||||
return err("Could not find Package.swift in workspace. Specify a project path or use xcode_build without swift_package.")
|
||||
}
|
||||
return runCommand("swift", ["build"], in: spmDir)
|
||||
}
|
||||
let xcArgs = buildXcodebuildCmd(args, action: "build", config: config)
|
||||
return runCommand(config.xcodePath, xcArgs, in: config.workspaceRoot)
|
||||
@@ -48,7 +51,10 @@ enum XcodeTools {
|
||||
] as [String: Any]
|
||||
) { args in
|
||||
if args["swift_package"] as? Bool == true {
|
||||
return runCommand("swift", ["test"], in: config.workspaceRoot)
|
||||
guard let spmDir = findPackageSwift(from: config.workspaceRoot) else {
|
||||
return err("Could not find Package.swift in workspace. Specify a project path or use xcode_test without swift_package.")
|
||||
}
|
||||
return runCommand("swift", ["test"], in: spmDir)
|
||||
}
|
||||
var xcArgs = buildXcodebuildCmd(args, action: "test", config: config)
|
||||
if let plan = args["test_plan"] as? String {
|
||||
@@ -141,7 +147,10 @@ enum XcodeTools {
|
||||
annotations: ToolAnnotations(destructiveHint: true)
|
||||
) { args in
|
||||
if args["swift_package"] as? Bool == true {
|
||||
return runCommand("swift", ["package", "clean"], in: config.workspaceRoot)
|
||||
guard let spmDir = findPackageSwift(from: config.workspaceRoot) else {
|
||||
return err("Could not find Package.swift in workspace.")
|
||||
}
|
||||
return runCommand("swift", ["package", "clean"], in: spmDir)
|
||||
}
|
||||
let xcArgs = buildXcodebuildCmd(args, action: "clean", config: config)
|
||||
return runCommand(config.xcodePath, xcArgs, in: config.workspaceRoot)
|
||||
@@ -215,6 +224,29 @@ enum XcodeTools {
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
/// Search for Package.swift in the root and one level of subdirectories.
|
||||
private static func findPackageSwift(from root: String) -> String? {
|
||||
let fm = FileManager.default
|
||||
// Check root first
|
||||
if fm.fileExists(atPath: (root as NSString).appendingPathComponent("Package.swift")) {
|
||||
return root
|
||||
}
|
||||
// Check immediate subdirectories
|
||||
if let children = try? fm.contentsOfDirectory(atPath: root) {
|
||||
for child in children {
|
||||
let childPath = (root as NSString).appendingPathComponent(child)
|
||||
var isDir: ObjCBool = false
|
||||
if fm.fileExists(atPath: childPath, isDirectory: &isDir), isDir.boolValue {
|
||||
let pkg = (childPath as NSString).appendingPathComponent("Package.swift")
|
||||
if fm.fileExists(atPath: pkg) {
|
||||
return childPath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private static func buildXcodebuildCmd(_ args: [String: Any], action: String, config: AgentConfig) -> [String] {
|
||||
var xcArgs = [action]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user