@@ -998,23 +998,155 @@ class PackageBuilderTests: XCTestCase {
998
998
}
999
999
}
1000
1000
1001
- func testManifestTargetDeclErrors( ) throws {
1001
+ /// Starting with tools version 5.9, packages are permitted to place
1002
+ /// sources anywhere in ./Sources when a package has a single target.
1003
+ func testRelaxedSourceLocationSingleTarget( ) throws {
1002
1004
do {
1003
- // Reference a target which doesn't exist .
1005
+ // Single target: Sources are expected in ./Sources .
1004
1006
let fs = InMemoryFileSystem ( emptyFiles:
1005
- " /Foo.swift " )
1007
+ " /Sources/Foo.swift " )
1008
+
1009
+ let manifest = Manifest . createRootManifest (
1010
+ displayName: " pkg " ,
1011
+ toolsVersion: . v5_9,
1012
+ targets: [
1013
+ try TargetDescription ( name: " Random " ) ,
1014
+ ]
1015
+ )
1016
+ PackageBuilderTester ( manifest, in: fs) { package , diagnostics in
1017
+ package . checkModule ( " Random " ) { result in
1018
+ XCTAssertEqual ( " /Sources " , result. target. path)
1019
+ }
1020
+ }
1021
+ }
1022
+
1023
+ do {
1024
+ // Single target: Sources are expected in ./Sources.
1025
+ // In this case, there is a stray source file at the top-level, and no sources
1026
+ // under ./Sources, so the target Random has no sources.
1027
+ // This results in a *warning* that there are no sources for the target.
1028
+ let fs = InMemoryFileSystem ( emptyFiles:
1029
+ " /Stray.swift " )
1030
+
1031
+ let manifest = Manifest . createRootManifest (
1032
+ displayName: " pkg " ,
1033
+ toolsVersion: . v5_9,
1034
+ targets: [
1035
+ try TargetDescription ( name: " Random " ) ,
1036
+ ]
1037
+ )
1038
+ PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1039
+ diagnostics. check ( diagnostic: . contains( " Source files for target Random should be located under /Sources " ) , severity: . warning)
1040
+ }
1041
+ }
1042
+
1043
+ do {
1044
+ // Single target: Sources are expected in ./Sources. In this case,
1045
+ // there is a stray source file at the top-level which is ignored.
1046
+ let fs = InMemoryFileSystem ( emptyFiles:
1047
+ " /Stray.swift " ,
1048
+ " /Sources/Random.swift " )
1006
1049
1007
1050
let manifest = Manifest . createRootManifest (
1008
1051
displayName: " pkg " ,
1052
+ toolsVersion: . v5_9,
1009
1053
targets: [
1010
1054
try TargetDescription ( name: " Random " ) ,
1011
1055
]
1012
1056
)
1057
+ PackageBuilderTester ( manifest, in: fs) { package , diagnostics in
1058
+ package . checkModule ( " Random " )
1059
+ }
1060
+ }
1061
+
1062
+ do {
1063
+ // Single target: Sources can be expected in ./Sources/<target>.
1064
+ // If that directory exists, stray sources inside ./Sources will
1065
+ // not be included in the target.
1066
+ let fs = InMemoryFileSystem ( emptyFiles:
1067
+ " /Sources/Stray.swift " ,
1068
+ " /Sources/MyTarget/Foo.swift "
1069
+ )
1070
+ let manifest = Manifest . createRootManifest (
1071
+ displayName: " pkg " ,
1072
+ toolsVersion: . v5_9,
1073
+ targets: [
1074
+ try TargetDescription ( name: " MyTarget " ) ,
1075
+ ]
1076
+ )
1077
+ PackageBuilderTester ( manifest, in: fs) { package , diagnostics in
1078
+ package . checkModule ( " MyTarget " ) { result in
1079
+ result. checkSources ( paths: " Foo.swift " )
1080
+ }
1081
+ }
1082
+ }
1083
+
1084
+ do {
1085
+ // Multiple targets: Sources are expected in their respective subdirectories
1086
+ // under Sources
1087
+ let fs = InMemoryFileSystem ( emptyFiles:
1088
+ " /Foo.swift " )
1089
+
1090
+ let manifest = Manifest . createRootManifest (
1091
+ displayName: " pkg " ,
1092
+ toolsVersion: . v5_9,
1093
+ targets: [
1094
+ try TargetDescription ( name: " TargetA " ) ,
1095
+ try TargetDescription ( name: " TargetB " ) ,
1096
+ ]
1097
+ )
1098
+ PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1099
+ diagnostics. check ( diagnostic: . contains( " Source files for target TargetA should be located under 'Sources/TargetA' " ) , severity: . error)
1100
+ }
1101
+ }
1102
+ }
1103
+
1104
+ func testStrictSourceLocation( ) throws {
1105
+ do {
1106
+ for fs in [
1107
+ InMemoryFileSystem ( emptyFiles:
1108
+ " /Sources/Foo.swift " ) ,
1109
+ InMemoryFileSystem ( emptyFiles:
1110
+ " /Stray.swift " ) ,
1111
+ InMemoryFileSystem ( emptyFiles:
1112
+ " /Stray.swift " ,
1113
+ " /Sources/Random.swift " ) ,
1114
+ ] {
1115
+ let manifest = Manifest . createRootManifest (
1116
+ displayName: " pkg " ,
1117
+ targets: [
1118
+ try TargetDescription ( name: " Random " ) ,
1119
+ ]
1120
+ )
1121
+ PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1122
+ diagnostics. check ( diagnostic: . contains( " Source files for target Random should be located under 'Sources/Random' " ) , severity: . error)
1123
+ }
1124
+ }
1125
+ }
1126
+
1127
+ do {
1128
+ // Multiple targets: Sources are expected in their respective subdirectories
1129
+ // under Sources
1130
+ let fs = InMemoryFileSystem ( emptyFiles:
1131
+ " /Foo.swift " )
1132
+
1133
+ let manifest = Manifest . createRootManifest (
1134
+ displayName: " pkg " ,
1135
+ toolsVersion: . v5_9,
1136
+ targets: [
1137
+ try TargetDescription ( name: " TargetA " ) ,
1138
+ try TargetDescription ( name: " TargetB " ) ,
1139
+ ]
1140
+ )
1013
1141
PackageBuilderTester ( manifest, in: fs) { _, diagnostics in
1014
- diagnostics. check ( diagnostic: . contains( " Source files for target Random should be located under 'Sources/Random' " ) , severity: . error)
1142
+ diagnostics. check ( diagnostic: . contains( " Source files for target TargetA should be located under 'Sources/TargetA' " ) , severity: . error)
1015
1143
}
1016
1144
}
1017
1145
1146
+ }
1147
+
1148
+ func testManifestTargetDeclErrors( ) throws {
1149
+
1018
1150
do {
1019
1151
let fs = InMemoryFileSystem ( emptyFiles:
1020
1152
" /src/pkg/Foo.swift " )
@@ -1060,21 +1192,6 @@ class PackageBuilderTests: XCTestCase {
1060
1192
}
1061
1193
}
1062
1194
1063
- do {
1064
- let fs = InMemoryFileSystem ( emptyFiles:
1065
- " /Source/pkg/Foo.swift " )
1066
- // Reference invalid target.
1067
- let manifest = Manifest . createRootManifest (
1068
- displayName: " pkg " ,
1069
- targets: [
1070
- try TargetDescription ( name: " foo " ) ,
1071
- ]
1072
- )
1073
- PackageBuilderTester ( manifest, in: fs) { _, diagnotics in
1074
- diagnotics. check ( diagnostic: . contains( " Source files for target foo should be located under 'Sources/foo' " ) , severity: . error)
1075
- }
1076
- }
1077
-
1078
1195
do {
1079
1196
let fs = InMemoryFileSystem ( )
1080
1197
// Binary target.
0 commit comments