Skip to content

Commit

Permalink
Merge pull request #97 from finestructure/issue-96-dependencies
Browse files Browse the repository at this point in the history
Change dependency package name to PlaygroundDependencies to avoid collision with PFC's swift-dependencies
  • Loading branch information
finestructure authored Nov 3, 2023
2 parents b5aac0c + c21b826 commit 731f54d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Make sure to properly quote the URL if you are using the `..<` range operator. O

## Adding another dependency

Arena does not currently support adding further depenencies to an existing playground. However, since its dependencies are managed via the `Dependencies` package, you can simply add further entries to its `Package.swift` file - just like you would when extending any other package manifest.
Arena does not currently support adding further dependencies to an existing playground. However, since its dependencies are managed via the `PlaygroundDependencies` package, you can simply add further entries to its `Package.swift` file - just like you would when extending any other package manifest.

Here's what this looks like:

Expand Down
28 changes: 14 additions & 14 deletions Sources/ArenaCore/ArenaCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension Arena {
extension Arena {
var dependencyPackagePath: Path { outputPath/depdencyPackageName }

var depdencyPackageName: String { "Dependencies" }
var depdencyPackageName: String { "PlaygroundDependencies" }

var xcworkspacePath: Path { outputPath/"Playground.xcworkspace" }

Expand Down Expand Up @@ -116,19 +116,19 @@ extension Arena {
try shellOut(to: .createSwiftPackage(withType: .library), at: dependencyPackagePath)
}

// update Package.swift dependencies
// we need to keep the original description around, because we're going to re-write
// the manifest a second time, after we've resolved the packages. This is because we
// Update Package.swift dependencies
// We need to keep the original description around, because we're going to re-write
// the manifest a second time, after we've resolved the packages. This is because we need
// the manifest to resolve the packages and we need package resolution to be able to
// get PackageInfo, which we'll need to write out the proper dependency incl `name:`
// See https://github.com/finestructure/Arena/issues/33
// and https://github.com/finestructure/Arena/issues/38
let packagePath = dependencyPackagePath/"Package.swift"
let originalPackageDescription = try String(contentsOf: packagePath)
let manifestPath = dependencyPackagePath/"Package.swift"
let originalPackageDescription = try String(contentsOf: manifestPath)
do {
let depsClause = dependencies.map { " " + $0.packageClause() }.joined(separator: ",\n")
let updatedDeps = "package.dependencies = [\n\(depsClause)\n]"
try [originalPackageDescription, updatedDeps].joined(separator: "\n").write(to: packagePath)
try [originalPackageDescription, updatedDeps].joined(separator: "\n").write(to: manifestPath)
}

do {
Expand Down Expand Up @@ -157,13 +157,13 @@ extension Arena {
" " + dep.packageClause(name: pkg.name)
}.joined(separator: ",\n")
let updatedDeps = "package.dependencies = [\n\(depsClause)\n]"
try [originalPackageDescription, updatedDeps].joined(separator: "\n").write(to: packagePath)
try [originalPackageDescription, updatedDeps].joined(separator: "\n").write(to: manifestPath)
}

// update Package.swift targets
do {
let packagePath = dependencyPackagePath/"Package.swift"
let packageDescription = try String(contentsOf: packagePath)
let manifestPath = dependencyPackagePath/"Package.swift"
let packageDescription = try String(contentsOf: manifestPath)
let updatedTgts = """
package.targets = [
.target(name: "\(depdencyPackageName)",
Expand All @@ -173,20 +173,20 @@ extension Arena {
)
]
"""
try [packageDescription, updatedTgts].joined(separator: "\n").write(to: packagePath)
try [packageDescription, updatedTgts].joined(separator: "\n").write(to: manifestPath)
}

// update Package.swift platforms
do {
let packagePath = dependencyPackagePath/"Package.swift"
let packageDescription = try String(contentsOf: packagePath)
let manifestPath = dependencyPackagePath/"Package.swift"
let packageDescription = try String(contentsOf: manifestPath)
let platforms = packageInfo.compactMap {
$0.1.platforms
.map(PackageGenerator.Platforms.init(platforms:))
}
try [packageDescription,
PackageGenerator.platformsClause(platforms)]
.joined(separator: "\n").write(to: packagePath)
.joined(separator: "\n").write(to: manifestPath)
}

// create workspace
Expand Down

0 comments on commit 731f54d

Please sign in to comment.