Skip to content

Commit b0a8f8d

Browse files
committed
Undo swiftformat changes
1 parent f7b51e2 commit b0a8f8d

File tree

1 file changed

+52
-51
lines changed

1 file changed

+52
-51
lines changed

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9-
*/
9+
*/
1010

1111
import Basics
12-
import Foundation
13-
import PackageModel
1412
import TSCBasic
13+
import PackageModel
1514
import TSCUtility
15+
import Foundation
1616
public typealias FileSystem = TSCBasic.FileSystem
1717

1818
public enum ManifestParseError: Swift.Error {
@@ -51,6 +51,7 @@ public protocol ManifestResourceProvider {
5151

5252
/// Default implemention for the resource provider.
5353
public extension ManifestResourceProvider {
54+
5455
var sdkRoot: AbsolutePath? {
5556
return nil
5657
}
@@ -324,8 +325,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
324325
// Validate that the file exists.
325326
guard fileSystem.isFile(path) else {
326327
throw PackageModel.Package.Error.noManifest(
327-
at: path, version: version?.description
328-
)
328+
at: path, version: version?.description)
329329
}
330330

331331
// Get the JSON string for the manifest.
@@ -353,11 +353,10 @@ public final class ManifestLoader: ManifestLoaderProtocol {
353353
var targets = parsedManifest.targets
354354
if products.isEmpty, targets.isEmpty,
355355
fileSystem.isFile(path.parentDirectory.appending(component: moduleMapFilename)) {
356-
products.append(ProductDescription(
356+
products.append(ProductDescription(
357357
name: parsedManifest.name,
358358
type: .library(.automatic),
359-
targets: [parsedManifest.name]
360-
)
359+
targets: [parsedManifest.name])
361360
)
362361
targets.append(try TargetDescription(
363362
name: parsedManifest.name,
@@ -419,7 +418,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
419418
}
420419

421420
private func validateTargets(_ manifest: Manifest, diagnostics: DiagnosticsEngine?) throws {
422-
let duplicateTargetNames = manifest.targets.map { $0.name }.spm_findDuplicates()
421+
let duplicateTargetNames = manifest.targets.map({ $0.name }).spm_findDuplicates()
423422
for name in duplicateTargetNames {
424423
try diagnostics.emit(.duplicateTargetName(targetName: name))
425424
}
@@ -442,7 +441,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
442441

443442
// Check that products that reference only binary targets don't define a type.
444443
let areTargetsBinary = product.targets.allSatisfy { manifest.targetMap[$0]?.type == .binary }
445-
if areTargetsBinary, product.type != .library(.automatic) {
444+
if areTargetsBinary && product.type != .library(.automatic) {
446445
try diagnostics.emit(.invalidBinaryProductType(productName: product.name))
447446
}
448447
}
@@ -459,24 +458,24 @@ public final class ManifestLoader: ManifestLoaderProtocol {
459458

460459
let duplicateDependencyIdentities = dependenciesByIdentity
461460
.lazy
462-
.filter { $0.value.count > 1 }
463-
.map { $0.key }
461+
.filter({ $0.value.count > 1 })
462+
.map({ $0.key })
464463

465464
for identity in duplicateDependencyIdentities {
466465
try diagnostics.emit(.duplicateDependency(dependencyIdentity: identity))
467466
}
468467

469468
if toolsVersion >= .v5_2 {
470-
let duplicateDependencies = try duplicateDependencyIdentities.flatMap { identifier -> [PackageDependencyDescription] in
469+
let duplicateDependencies = try duplicateDependencyIdentities.flatMap{ identifier -> [PackageDependencyDescription] in
471470
guard let dependency = dependenciesByIdentity[identifier] else {
472471
throw InternalError("unknown dependency \(identifier)")
473472
}
474473
return dependency
475474
}
476475
let duplicateDependencyNames = manifest.dependencies
477476
.lazy
478-
.filter { !duplicateDependencies.contains($0) }
479-
.map { $0.nameForTargetDependencyResolutionOnly }
477+
.filter({ !duplicateDependencies.contains($0) })
478+
.map({ $0.nameForTargetDependencyResolutionOnly })
480479
.spm_findDuplicates()
481480

482481
for name in duplicateDependencyNames {
@@ -495,14 +494,14 @@ public final class ManifestLoader: ManifestLoaderProtocol {
495494

496495
let isRemote = target.url != nil
497496
let validSchemes = ["https"]
498-
if isRemote, location.scheme.map({ !validSchemes.contains($0) }) ?? true {
497+
if isRemote && (location.scheme.map({ !validSchemes.contains($0) }) ?? true) {
499498
try diagnostics.emit(.invalidBinaryURLScheme(
500499
targetName: target.name,
501500
validSchemes: validSchemes
502501
))
503502
}
504503

505-
let validExtensions = isRemote ? ["zip"] : BinaryTarget.Kind.allCases.map { $0.fileExtension }
504+
let validExtensions = isRemote ? ["zip"] : BinaryTarget.Kind.allCases.map{ $0.fileExtension }
506505
if !validExtensions.contains(location.pathExtension) {
507506
try diagnostics.emit(.unsupportedBinaryLocationExtension(
508507
targetName: target.name,
@@ -530,9 +529,10 @@ public final class ManifestLoader: ManifestLoaderProtocol {
530529
}
531530
case .byName(let name, _):
532531
// Don't diagnose root manifests so we can emit a better diagnostic during package loading.
533-
if manifest.packageKind != .root,
534-
!manifest.targetMap.keys.contains(name),
535-
manifest.packageDependency(referencedBy: targetDependency) == nil {
532+
if manifest.packageKind != .root &&
533+
!manifest.targetMap.keys.contains(name) &&
534+
manifest.packageDependency(referencedBy: targetDependency) == nil
535+
{
536536
try diagnostics.emit(.unknownTargetDependency(
537537
dependency: name,
538538
targetName: target.name,
@@ -552,6 +552,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
552552
fileSystem: FileSystem,
553553
diagnostics: DiagnosticsEngine?
554554
) throws -> String {
555+
555556
let cacheKey = try ManifestCacheKey(
556557
packageIdentity: packageIdentity,
557558
manifestPath: path,
@@ -631,12 +632,13 @@ public final class ManifestLoader: ManifestLoaderProtocol {
631632
let swiftpmVersion: String
632633
let sha256Checksum: String
633634

634-
init(packageIdentity: PackageIdentity,
635-
manifestPath: AbsolutePath,
636-
toolsVersion: ToolsVersion,
637-
env: [String: String],
638-
swiftpmVersion: String,
639-
fileSystem: FileSystem) throws {
635+
init (packageIdentity: PackageIdentity,
636+
manifestPath: AbsolutePath,
637+
toolsVersion: ToolsVersion,
638+
env: [String: String],
639+
swiftpmVersion: String,
640+
fileSystem: FileSystem
641+
) throws {
640642
let manifestContents = try fileSystem.readFileContents(manifestPath).contents
641643
let sha256Checksum = try Self.computeSHA256Checksum(packageIdentity: packageIdentity, manifestContents: manifestContents, toolsVersion: toolsVersion, env: env, swiftpmVersion: swiftpmVersion)
642644

@@ -674,7 +676,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
674676

675677
internal struct ManifestParseResult: Codable {
676678
var hasErrors: Bool {
677-
return self.parsedManifest == nil
679+
return parsedManifest == nil
678680
}
679681

680682
/// The path to the diagnostics file (.dia).
@@ -695,7 +697,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
695697
/// For e.g., we could have failed to spawn the process or create temporary file.
696698
var errorOutput: String? {
697699
didSet {
698-
assert(self.parsedManifest == nil)
700+
assert(parsedManifest == nil)
699701
}
700702
}
701703
}
@@ -730,7 +732,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
730732

731733
// FIXME: Workaround for the module cache bug that's been haunting Swift CI
732734
// <rdar://problem/48443680>
733-
let moduleCachePath = (ProcessEnv.vars["SWIFTPM_MODULECACHE_OVERRIDE"] ?? ProcessEnv.vars["SWIFTPM_TESTS_MODULECACHE"]).flatMap { AbsolutePath($0) }
735+
let moduleCachePath = (ProcessEnv.vars["SWIFTPM_MODULECACHE_OVERRIDE"] ?? ProcessEnv.vars["SWIFTPM_TESTS_MODULECACHE"]).flatMap{ AbsolutePath.init($0) }
734736

735737
var cmd: [String] = []
736738
cmd += [resources.swiftCompiler.pathString]
@@ -740,7 +742,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
740742
// If we got the binDir that means we could be developing SwiftPM in Xcode
741743
// which produces a framework for dynamic package products.
742744
let packageFrameworkPath = runtimePath.appending(component: "PackageFrameworks")
743-
if self.resources.binDir != nil, localFileSystem.exists(packageFrameworkPath) {
745+
if resources.binDir != nil, localFileSystem.exists(packageFrameworkPath) {
744746
cmd += [
745747
"-F", packageFrameworkPath.pathString,
746748
"-framework", "PackageDescription",
@@ -753,11 +755,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
753755
"-L", runtimePath.pathString,
754756
"-lPackageDescription",
755757
]
756-
#if !os(Windows)
758+
#if !os(Windows)
757759
// -rpath argument is not supported on Windows,
758760
// so we add runtimePath to PATH when executing the manifest instead
759761
cmd += ["-Xlinker", "-rpath", "-Xlinker", runtimePath.pathString]
760-
#endif
762+
#endif
761763

762764
// note: this is not correct for all platforms, but we only actually use it on macOS.
763765
macOSPackageDescriptionPath = runtimePath.appending(RelativePath("libPackageDescription.dylib"))
@@ -776,7 +778,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
776778
#endif
777779

778780
// Add any extra flags required as indicated by the ManifestLoader.
779-
cmd += self.resources.swiftCompilerFlags
781+
cmd += resources.swiftCompilerFlags
780782

781783
cmd += self.interpreterFlags(for: toolsVersion)
782784
if let moduleCachePath = moduleCachePath {
@@ -798,11 +800,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
798800

799801
try withTemporaryDirectory(removeTreeOnDeinit: true) { tmpDir in
800802
// Set path to compiled manifest executable.
801-
#if os(Windows)
803+
#if os(Windows)
802804
let executableSuffix = ".exe"
803-
#else
805+
#else
804806
let executableSuffix = ""
805-
#endif
807+
#endif
806808
let compiledManifestFile = tmpDir.appending(component: "\(packageIdentity)-manifest\(executableSuffix)")
807809
cmd += ["-o", compiledManifestFile.pathString]
808810

@@ -823,29 +825,29 @@ public final class ManifestLoader: ManifestLoaderProtocol {
823825
}
824826

825827
cmd = [compiledManifestFile.pathString]
826-
#if os(Windows)
828+
#if os(Windows)
827829
// NOTE: `_get_osfhandle` returns a non-owning, unsafe,
828830
// unretained HANDLE. DO NOT invoke `CloseHandle` on `hFile`.
829831
let hFile: Int = _get_osfhandle(_fileno(jsonOutputFileDesc))
830832
cmd += ["-handle", "\(String(hFile, radix: 16))"]
831-
#else
833+
#else
832834
cmd += ["-fileno", "\(fileno(jsonOutputFileDesc))"]
833-
#endif
835+
#endif
834836
// If enabled, run command in a sandbox.
835837
// This provides some safety against arbitrary code execution when parsing manifest files.
836838
// We only allow the permissions which are absolutely necessary.
837839
if isManifestSandboxEnabled {
838-
let cacheDirectories = [self.databaseCacheDir, moduleCachePath].compactMap { $0 }
840+
let cacheDirectories = [self.databaseCacheDir, moduleCachePath].compactMap{ $0 }
839841
let strictness: Sandbox.Strictness = toolsVersion < .v5_3 ? .manifest_pre_53 : .default
840842
cmd = Sandbox.apply(command: cmd, writableDirectories: cacheDirectories, strictness: strictness)
841843
}
842844

843845
// Run the compiled manifest.
844846
var environment = ProcessEnv.vars
845-
#if os(Windows)
847+
#if os(Windows)
846848
let windowsPathComponent = runtimePath.pathString.replacingOccurrences(of: "/", with: "\\")
847849
environment["Path"] = "\(windowsPathComponent);\(environment["Path"] ?? "")"
848-
#endif
850+
#endif
849851
let runResult = try Process.popen(arguments: cmd, environment: environment)
850852
fclose(jsonOutputFileDesc)
851853
let runOutput = try (runResult.utf8Output() + runResult.utf8stderrOutput()).spm_chuzzle()
@@ -900,12 +902,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
900902
return sdkRoot
901903
}
902904

903-
var sdkRootPath: AbsolutePath?
905+
var sdkRootPath: AbsolutePath? = nil
904906
// Find SDKROOT on macOS using xcrun.
905907
#if os(macOS)
906908
let foundPath = try? Process.checkNonZeroExit(
907-
args: "/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-path"
908-
)
909+
args: "/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-path")
909910
guard let sdkRoot = foundPath?.spm_chomp(), !sdkRoot.isEmpty else {
910911
return nil
911912
}
@@ -925,19 +926,19 @@ public final class ManifestLoader: ManifestLoaderProtocol {
925926
let runtimePath = self.runtimePath(for: toolsVersion)
926927
cmd += ["-swift-version", toolsVersion.swiftLanguageVersion.rawValue]
927928
cmd += ["-I", runtimePath.pathString]
928-
#if os(macOS)
929+
#if os(macOS)
929930
if let sdkRoot = resources.sdkRoot ?? self.sdkRoot() {
930931
cmd += ["-sdk", sdkRoot.pathString]
931932
}
932-
#endif
933+
#endif
933934
cmd += ["-package-description-version", toolsVersion.description]
934935
return cmd
935936
}
936937

937938
/// Returns the runtime path given the manifest version and path to libDir.
938939
private func runtimePath(for version: ToolsVersion) -> AbsolutePath {
939940
// Bin dir will be set when developing swiftpm without building all of the runtimes.
940-
return self.resources.binDir ?? self.resources.libDir.appending(version.runtimeSubpath)
941+
return resources.binDir ?? resources.libDir.appending(version.runtimeSubpath)
941942
}
942943

943944
/// Returns path to the manifest database inside the given cache directory.
@@ -1006,8 +1007,8 @@ extension TSCBasic.Diagnostic.Message {
10061007

10071008
static func invalidLanguageTag(_ languageTag: String) -> Self {
10081009
.error("""
1009-
invalid language tag '\(languageTag)'; the pattern for language tags is groups of latin characters and \
1010-
digits separated by hyphens
1011-
""")
1010+
invalid language tag '\(languageTag)'; the pattern for language tags is groups of latin characters and \
1011+
digits separated by hyphens
1012+
""")
10121013
}
10131014
}

0 commit comments

Comments
 (0)