Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
26 changes: 25 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ let package = Package(
"PackageModel",
]
),
.executable(
name: "package-parser",
targets: ["package-parser"]
),
],
targets: [
// The `PackageDescription` target provides the API that is available
Expand Down Expand Up @@ -152,6 +156,10 @@ let package = Package(
/** Package model conventions and loading support */
name: "PackageLoading",
dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageModel", "SourceControl"]),
.target(
name: "ScriptingCore",
/** Package models for scripting support */
dependencies: ["SwiftToolsSupport-auto", "Basics"]),

// MARK: Package Dependency Resolution

Expand Down Expand Up @@ -186,6 +194,12 @@ let package = Package(

// MARK: Package Manager Functionality

.target(
/** Parse `@package` marks */
name: "ScriptParse",
dependencies: ["SwiftToolsSupport-auto", "ArgumentParser", "SwiftSyntax"]
),

.target(
/** Builds Modules and Products */
name: "SPMBuildCore",
Expand Down Expand Up @@ -213,7 +227,7 @@ let package = Package(
.target(
/** High-level commands */
name: "Commands",
dependencies: ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]),
dependencies: ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections", "ScriptParse", "ScriptingCore"]),
.target(
/** The main executable provided by SwiftPM */
name: "swift-package",
Expand All @@ -230,6 +244,14 @@ let package = Package(
/** Runs an executable product */
name: "swift-run",
dependencies: ["Commands"]),
.target(
/** Manages and runs a script */
name: "swift-script",
dependencies: ["Commands"]),
.target(
/** Parse `@package` marks */
name: "package-parser",
dependencies: ["ScriptParse"]),
.target(
/** Interacts with package collections */
name: "swift-package-collection",
Expand Down Expand Up @@ -356,12 +378,14 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "1.1.4")),
.package(url: "https://github.com/apple/swift-syntax.git", .branch(relatedDependenciesBranch)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle this is correct, but SwiftSyntax is particularly tricky, because of its dependency on the corresponding linker library. In fact I wasn't able to get the main branch to work with Xcode 13 Betas at all. But as it happens we have two other intended uses of SwiftSyntax, and so I will be working with someone who knows it better than I do to add it as a dependency in a separate PR. So you can keep this as it is right now, and within not too long we should be able to have this dependency already added through a separate PR.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird because I'm building it with Xcode 13 Beta 4/5, on Big Sur.
I think the dependency could be dropped here some day for parsing, but it would help doing things like generating a package.

]
} else {
package.dependencies += [
.package(path: "../swift-tools-support-core"),
.package(path: "../swift-argument-parser"),
.package(path: "../swift-driver"),
.package(path: "../swift-crypto"),
.package(path: "../swift-syntax"),
]
}
30 changes: 29 additions & 1 deletion Sources/Basics/FileSystem+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2020 Apple Inc. and the Swift project authors
Copyright (c) 2020 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -110,3 +110,31 @@ extension FileSystem {
return idiomaticConfigDirectory
}
}

// MARK: - script cache

extension FileSystem {
/// SwiftPM cache directory under user's caches directory (if exists)
public var swiftScriptCacheDirectory: AbsolutePath {
return self.dotSwiftScriptCachesDirectory
}

fileprivate var dotSwiftScriptCachesDirectory: AbsolutePath {
return self.dotSwiftPM.appending(component: "scripts")
}
}

extension FileSystem {
public func getOrCreateSwiftScriptCacheDirectory() throws -> AbsolutePath {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this instead just call getOrCreateSwiftPMCacheDirectory() and then append the scripts subdirectory to it? Otherwise this function seems to duplicate some of the existing code.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ummm... In fact the scripts dir is supposed to be beside cache, which I'm afraid may "escape" if we simply append ../scripts to the cache dir (also, we need to create it if there's none, which needs a function to wrap up).
I thought it may be better to hardcode the path with ~/.swiftpm/scripts to make it more accessible.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense — I'm not 100% familiar with how the layout is supposed to look here, it just seemed as if there was some code overlap here.

let idiomaticCacheDirectory = self.swiftScriptCacheDirectory
// Create idiomatic if necessary
if !self.exists(idiomaticCacheDirectory) {
try self.createDirectory(idiomaticCacheDirectory, recursive: true)
}
// Create ~/.swiftpm if necessary
if !self.exists(self.dotSwiftPM) {
try self.createDirectory(self.dotSwiftPM, recursive: true)
}
return idiomaticCacheDirectory
}
}
3 changes: 3 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ add_subdirectory(PackagePlugin)
add_subdirectory(SPMBuildCore)
add_subdirectory(SPMLLBuild)
add_subdirectory(SourceControl)
#add_subdirectory(ScriptingCore)
#add_subdirectory(ScriptParse)
add_subdirectory(swift-build)
add_subdirectory(swift-package)
add_subdirectory(swift-run)
#add_subdirectory(swift-script)
add_subdirectory(swift-test)
add_subdirectory(Workspace)
add_subdirectory(XCBuildSupport)
Expand Down
5 changes: 4 additions & 1 deletion Sources/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
Expand All @@ -18,6 +18,7 @@ add_library(Commands
SwiftPackageCollectionsTool.swift
SwiftPackageTool.swift
SwiftRunTool.swift
# SwiftScriptTool.swift
SwiftTestTool.swift
SwiftTool.swift
SymbolGraphExtract.swift
Expand All @@ -28,6 +29,8 @@ target_link_libraries(Commands PUBLIC
Build
PackageCollections
PackageGraph
# ScriptingCore
# ScriptParse
SourceControl
TSCBasic
TSCUtility
Expand Down
Loading