Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Sources/DependencyCalculator/DependencyGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,33 @@ extension PBXNativeTarget {
}

extension WorkspaceInfo {
/// Checks if the root Package.swift should be evaluated. It depends if there is a project file already. Project file is considered a higher level definition and should be parsed first.
private static func shouldIncludeRootPackage(at path: Path) throws -> Bool {
switch path.extension {
case "xcodeproj":
return false
case "xcworkspace":
let workspace = try XCWorkspace(path: path)
let projects = try workspace.allProjects(basePath: path.parent())

if projects.contains(where: { (_, path) in
path.contains("xcodeproj")
}) {
return false
}
else {
return true
}
default:
return true
}
}

public static func parseWorkspace(at path: Path,
config: WorkspaceInfo.AdditionalConfig? = nil,
exclude: [String]) throws -> WorkspaceInfo
{
let includeRootPackage = !Set(["xcworkspace", "xcodeproj"]).contains(path.extension)

let includeRootPackage = try shouldIncludeRootPackage(at: path)
var (packageWorkspaceInfo, packages) = try parsePackages(in: path, includeRootPackage: includeRootPackage, exclude: exclude)

var resultDependencies = packageWorkspaceInfo.dependencyStructure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "APackage",
platforms: [.iOS(.v15)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "APackage",
targets: ["APackage"]),
],
dependencies: [],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "APackage"),
.testTarget(
name: "APackageTests",
dependencies: ["APackage"]
),
]
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Tests/DependencyCalculatorTests/PackageMetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,36 @@ final class PackageMetadataTests: XCTestCase {
basePath + "Sources" + "SelectiveTestingCore"
]))
}

func testPackageAndWorkspace() async throws {
// given
guard let exampleInBundle = Bundle.module.path(forResource: "ExamplePackages", ofType: "") else {
fatalError("Missing ExamplePackages in TestBundle")
}
// when
let basePath = Path(exampleInBundle) + "PackageAndWorkspace"
let metadata = try PackageTargetMetadata.parse(at: basePath)

// then
XCTAssertEqual(metadata.count, 2)
let first = metadata[0]
XCTAssertEqual(first.name, "APackage")
XCTAssertEqual(first.path, basePath)
XCTAssertEqual(first.dependsOn, Set([]))
XCTAssertEqual(first.affectedBy, Set([
basePath + "Package.swift",
basePath + "Package.resolved",
basePath + "Sources" + "APackage"
]))

let second = metadata[1]
XCTAssertEqual(second.name, "APackageTests")
XCTAssertEqual(second.path, basePath)
XCTAssertEqual(second.dependsOn.count, 1)
XCTAssertEqual(second.affectedBy, Set([
basePath + "Package.swift",
basePath + "Package.resolved",
basePath + "Tests" + "APackageTests"
]))
}
}