6
6
7
7
See http://swift.org/LICENSE.txt for license information
8
8
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9
- */
9
+ */
10
10
11
11
import Basics
12
- import Foundation
13
- import PackageModel
14
12
import TSCBasic
13
+ import PackageModel
15
14
import TSCUtility
15
+ import Foundation
16
16
public typealias FileSystem = TSCBasic . FileSystem
17
17
18
18
public enum ManifestParseError : Swift . Error {
@@ -51,6 +51,7 @@ public protocol ManifestResourceProvider {
51
51
52
52
/// Default implemention for the resource provider.
53
53
public extension ManifestResourceProvider {
54
+
54
55
var sdkRoot : AbsolutePath ? {
55
56
return nil
56
57
}
@@ -324,8 +325,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
324
325
// Validate that the file exists.
325
326
guard fileSystem. isFile ( path) else {
326
327
throw PackageModel . Package. Error. noManifest (
327
- at: path, version: version? . description
328
- )
328
+ at: path, version: version? . description)
329
329
}
330
330
331
331
// Get the JSON string for the manifest.
@@ -353,11 +353,10 @@ public final class ManifestLoader: ManifestLoaderProtocol {
353
353
var targets = parsedManifest. targets
354
354
if products. isEmpty, targets. isEmpty,
355
355
fileSystem. isFile ( path. parentDirectory. appending ( component: moduleMapFilename) ) {
356
- products. append ( ProductDescription (
356
+ products. append ( ProductDescription (
357
357
name: parsedManifest. name,
358
358
type: . library( . automatic) ,
359
- targets: [ parsedManifest. name]
360
- )
359
+ targets: [ parsedManifest. name] )
361
360
)
362
361
targets. append ( try TargetDescription (
363
362
name: parsedManifest. name,
@@ -419,7 +418,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
419
418
}
420
419
421
420
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 ( )
423
422
for name in duplicateTargetNames {
424
423
try diagnostics. emit ( . duplicateTargetName( targetName: name) )
425
424
}
@@ -442,7 +441,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
442
441
443
442
// Check that products that reference only binary targets don't define a type.
444
443
let areTargetsBinary = product. targets. allSatisfy { manifest. targetMap [ $0] ? . type == . binary }
445
- if areTargetsBinary, product. type != . library( . automatic) {
444
+ if areTargetsBinary && product. type != . library( . automatic) {
446
445
try diagnostics. emit ( . invalidBinaryProductType( productName: product. name) )
447
446
}
448
447
}
@@ -459,24 +458,24 @@ public final class ManifestLoader: ManifestLoaderProtocol {
459
458
460
459
let duplicateDependencyIdentities = dependenciesByIdentity
461
460
. lazy
462
- . filter { $0. value. count > 1 }
463
- . map { $0. key }
461
+ . filter ( { $0. value. count > 1 } )
462
+ . map ( { $0. key } )
464
463
465
464
for identity in duplicateDependencyIdentities {
466
465
try diagnostics. emit ( . duplicateDependency( dependencyIdentity: identity) )
467
466
}
468
467
469
468
if toolsVersion >= . v5_2 {
470
- let duplicateDependencies = try duplicateDependencyIdentities. flatMap { identifier -> [ PackageDependencyDescription ] in
469
+ let duplicateDependencies = try duplicateDependencyIdentities. flatMap { identifier -> [ PackageDependencyDescription ] in
471
470
guard let dependency = dependenciesByIdentity [ identifier] else {
472
471
throw InternalError ( " unknown dependency \( identifier) " )
473
472
}
474
473
return dependency
475
474
}
476
475
let duplicateDependencyNames = manifest. dependencies
477
476
. lazy
478
- . filter { !duplicateDependencies. contains ( $0) }
479
- . map { $0. nameForTargetDependencyResolutionOnly }
477
+ . filter ( { !duplicateDependencies. contains ( $0) } )
478
+ . map ( { $0. nameForTargetDependencyResolutionOnly } )
480
479
. spm_findDuplicates ( )
481
480
482
481
for name in duplicateDependencyNames {
@@ -495,14 +494,14 @@ public final class ManifestLoader: ManifestLoaderProtocol {
495
494
496
495
let isRemote = target. url != nil
497
496
let validSchemes = [ " https " ]
498
- if isRemote, location. scheme. map ( { !validSchemes. contains ( $0) } ) ?? true {
497
+ if isRemote && ( location. scheme. map ( { !validSchemes. contains ( $0) } ) ?? true ) {
499
498
try diagnostics. emit ( . invalidBinaryURLScheme(
500
499
targetName: target. name,
501
500
validSchemes: validSchemes
502
501
) )
503
502
}
504
503
505
- let validExtensions = isRemote ? [ " zip " ] : BinaryTarget . Kind. allCases. map { $0. fileExtension }
504
+ let validExtensions = isRemote ? [ " zip " ] : BinaryTarget . Kind. allCases. map{ $0. fileExtension }
506
505
if !validExtensions. contains ( location. pathExtension) {
507
506
try diagnostics. emit ( . unsupportedBinaryLocationExtension(
508
507
targetName: target. name,
@@ -530,9 +529,10 @@ public final class ManifestLoader: ManifestLoaderProtocol {
530
529
}
531
530
case . byName( let name, _) :
532
531
// 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
+ {
536
536
try diagnostics. emit ( . unknownTargetDependency(
537
537
dependency: name,
538
538
targetName: target. name,
@@ -552,6 +552,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
552
552
fileSystem: FileSystem ,
553
553
diagnostics: DiagnosticsEngine ?
554
554
) throws -> String {
555
+
555
556
let cacheKey = try ManifestCacheKey (
556
557
packageIdentity: packageIdentity,
557
558
manifestPath: path,
@@ -631,12 +632,13 @@ public final class ManifestLoader: ManifestLoaderProtocol {
631
632
let swiftpmVersion : String
632
633
let sha256Checksum : String
633
634
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 {
640
642
let manifestContents = try fileSystem. readFileContents ( manifestPath) . contents
641
643
let sha256Checksum = try Self . computeSHA256Checksum ( packageIdentity: packageIdentity, manifestContents: manifestContents, toolsVersion: toolsVersion, env: env, swiftpmVersion: swiftpmVersion)
642
644
@@ -674,7 +676,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
674
676
675
677
internal struct ManifestParseResult : Codable {
676
678
var hasErrors : Bool {
677
- return self . parsedManifest == nil
679
+ return parsedManifest == nil
678
680
}
679
681
680
682
/// The path to the diagnostics file (.dia).
@@ -695,7 +697,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
695
697
/// For e.g., we could have failed to spawn the process or create temporary file.
696
698
var errorOutput : String ? {
697
699
didSet {
698
- assert ( self . parsedManifest == nil )
700
+ assert ( parsedManifest == nil )
699
701
}
700
702
}
701
703
}
@@ -730,7 +732,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
730
732
731
733
// FIXME: Workaround for the module cache bug that's been haunting Swift CI
732
734
// <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) }
734
736
735
737
var cmd : [ String ] = [ ]
736
738
cmd += [ resources. swiftCompiler. pathString]
@@ -740,7 +742,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
740
742
// If we got the binDir that means we could be developing SwiftPM in Xcode
741
743
// which produces a framework for dynamic package products.
742
744
let packageFrameworkPath = runtimePath. appending ( component: " PackageFrameworks " )
743
- if self . resources. binDir != nil , localFileSystem. exists ( packageFrameworkPath) {
745
+ if resources. binDir != nil , localFileSystem. exists ( packageFrameworkPath) {
744
746
cmd += [
745
747
" -F " , packageFrameworkPath. pathString,
746
748
" -framework " , " PackageDescription " ,
@@ -753,11 +755,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
753
755
" -L " , runtimePath. pathString,
754
756
" -lPackageDescription " ,
755
757
]
756
- #if !os(Windows)
758
+ #if !os(Windows)
757
759
// -rpath argument is not supported on Windows,
758
760
// so we add runtimePath to PATH when executing the manifest instead
759
761
cmd += [ " -Xlinker " , " -rpath " , " -Xlinker " , runtimePath. pathString]
760
- #endif
762
+ #endif
761
763
762
764
// note: this is not correct for all platforms, but we only actually use it on macOS.
763
765
macOSPackageDescriptionPath = runtimePath. appending ( RelativePath ( " libPackageDescription.dylib " ) )
@@ -776,7 +778,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
776
778
#endif
777
779
778
780
// Add any extra flags required as indicated by the ManifestLoader.
779
- cmd += self . resources. swiftCompilerFlags
781
+ cmd += resources. swiftCompilerFlags
780
782
781
783
cmd += self . interpreterFlags ( for: toolsVersion)
782
784
if let moduleCachePath = moduleCachePath {
@@ -798,11 +800,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
798
800
799
801
try withTemporaryDirectory ( removeTreeOnDeinit: true ) { tmpDir in
800
802
// Set path to compiled manifest executable.
801
- #if os(Windows)
803
+ #if os(Windows)
802
804
let executableSuffix = " .exe "
803
- #else
805
+ #else
804
806
let executableSuffix = " "
805
- #endif
807
+ #endif
806
808
let compiledManifestFile = tmpDir. appending ( component: " \( packageIdentity) -manifest \( executableSuffix) " )
807
809
cmd += [ " -o " , compiledManifestFile. pathString]
808
810
@@ -823,29 +825,29 @@ public final class ManifestLoader: ManifestLoaderProtocol {
823
825
}
824
826
825
827
cmd = [ compiledManifestFile. pathString]
826
- #if os(Windows)
828
+ #if os(Windows)
827
829
// NOTE: `_get_osfhandle` returns a non-owning, unsafe,
828
830
// unretained HANDLE. DO NOT invoke `CloseHandle` on `hFile`.
829
831
let hFile : Int = _get_osfhandle ( _fileno ( jsonOutputFileDesc) )
830
832
cmd += [ " -handle " , " \( String ( hFile, radix: 16 ) ) " ]
831
- #else
833
+ #else
832
834
cmd += [ " -fileno " , " \( fileno ( jsonOutputFileDesc) ) " ]
833
- #endif
835
+ #endif
834
836
// If enabled, run command in a sandbox.
835
837
// This provides some safety against arbitrary code execution when parsing manifest files.
836
838
// We only allow the permissions which are absolutely necessary.
837
839
if isManifestSandboxEnabled {
838
- let cacheDirectories = [ self . databaseCacheDir, moduleCachePath] . compactMap { $0 }
840
+ let cacheDirectories = [ self . databaseCacheDir, moduleCachePath] . compactMap { $0 }
839
841
let strictness : Sandbox . Strictness = toolsVersion < . v5_3 ? . manifest_pre_53 : . default
840
842
cmd = Sandbox . apply ( command: cmd, writableDirectories: cacheDirectories, strictness: strictness)
841
843
}
842
844
843
845
// Run the compiled manifest.
844
846
var environment = ProcessEnv . vars
845
- #if os(Windows)
847
+ #if os(Windows)
846
848
let windowsPathComponent = runtimePath. pathString. replacingOccurrences ( of: " / " , with: " \\ " )
847
849
environment [ " Path " ] = " \( windowsPathComponent) ; \( environment [ " Path " ] ?? " " ) "
848
- #endif
850
+ #endif
849
851
let runResult = try Process . popen ( arguments: cmd, environment: environment)
850
852
fclose ( jsonOutputFileDesc)
851
853
let runOutput = try ( runResult. utf8Output ( ) + runResult. utf8stderrOutput ( ) ) . spm_chuzzle ( )
@@ -900,12 +902,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
900
902
return sdkRoot
901
903
}
902
904
903
- var sdkRootPath : AbsolutePath ?
905
+ var sdkRootPath : AbsolutePath ? = nil
904
906
// Find SDKROOT on macOS using xcrun.
905
907
#if os(macOS)
906
908
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 " )
909
910
guard let sdkRoot = foundPath? . spm_chomp ( ) , !sdkRoot. isEmpty else {
910
911
return nil
911
912
}
@@ -925,19 +926,19 @@ public final class ManifestLoader: ManifestLoaderProtocol {
925
926
let runtimePath = self . runtimePath ( for: toolsVersion)
926
927
cmd += [ " -swift-version " , toolsVersion. swiftLanguageVersion. rawValue]
927
928
cmd += [ " -I " , runtimePath. pathString]
928
- #if os(macOS)
929
+ #if os(macOS)
929
930
if let sdkRoot = resources. sdkRoot ?? self . sdkRoot ( ) {
930
931
cmd += [ " -sdk " , sdkRoot. pathString]
931
932
}
932
- #endif
933
+ #endif
933
934
cmd += [ " -package-description-version " , toolsVersion. description]
934
935
return cmd
935
936
}
936
937
937
938
/// Returns the runtime path given the manifest version and path to libDir.
938
939
private func runtimePath( for version: ToolsVersion ) -> AbsolutePath {
939
940
// 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)
941
942
}
942
943
943
944
/// Returns path to the manifest database inside the given cache directory.
@@ -1006,8 +1007,8 @@ extension TSCBasic.Diagnostic.Message {
1006
1007
1007
1008
static func invalidLanguageTag( _ languageTag: String ) -> Self {
1008
1009
. 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
+ """ )
1012
1013
}
1013
1014
}
0 commit comments