Skip to content

Commit 4f7a2b8

Browse files
committed
Add tests for SwiftPM args and swiftc args that shouldn't cause a rebuild
1 parent 906e649 commit 4f7a2b8

File tree

1 file changed

+101
-1
lines changed

1 file changed

+101
-1
lines changed

Tests/CommandsTests/BuildCommandTests.swift

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,96 @@ struct BuildCommandTestCases {
11251125
}
11261126
}
11271127

1128-
1128+
private static func buildSystemAndOutputLocation() throws -> [(BuildSystemProvider.Kind, Basics.RelativePath)] {
1129+
return try SupportedBuildSystemOnPlatform.map { buildSystem in
1130+
switch buildSystem {
1131+
case .xcode:
1132+
return (
1133+
.xcode,
1134+
try RelativePath(validating: ".build")
1135+
.appending("apple")
1136+
.appending("Products")
1137+
.appending("Debug")
1138+
.appending("ExecutableNew")
1139+
)
1140+
case .swiftbuild:
1141+
let triple = try UserToolchain.default.targetTriple.withoutVersion().tripleString
1142+
return (
1143+
.swiftbuild,
1144+
try RelativePath(validating: ".build")
1145+
.appending(triple)
1146+
.appending("Products")
1147+
.appending("Debug")
1148+
.appending("ExecutableNew")
1149+
)
1150+
case .native:
1151+
return (
1152+
.native,
1153+
try RelativePath(validating: ".build")
1154+
.appending("debug")
1155+
.appending("ExecutableNew.build")
1156+
.appending("main.swift.o")
1157+
)
1158+
}
1159+
}
1160+
}
1161+
1162+
@Test(arguments: try buildSystemAndOutputLocation())
1163+
func doesNotRebuildWithVerboseFlag(
1164+
buildSystem: BuildSystemProvider.Kind,
1165+
outputFile: Basics.RelativePath
1166+
) async throws {
1167+
try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in
1168+
_ = try await self.build(
1169+
[],
1170+
packagePath: fixturePath,
1171+
cleanAfterward: false,
1172+
buildSystem: buildSystem,
1173+
)
1174+
1175+
let mainOFile = fixturePath.appending(outputFile)
1176+
let initialMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date
1177+
1178+
_ = try await self.build(
1179+
["--verbose"],
1180+
packagePath: fixturePath,
1181+
cleanAfterward: false,
1182+
buildSystem: buildSystem,
1183+
)
1184+
1185+
let subsequentMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date
1186+
#expect(initialMainOMtime == subsequentMainOMtime, "Expected no rebuild to occur when using the verbose flag, but the file was modified.")
1187+
}
1188+
}
1189+
1190+
@Test(arguments: try buildSystemAndOutputLocation())
1191+
func doesNotRebuildWithSwiftcArgsThatDontAffectIncrementalBuilds(
1192+
buildSystem: BuildSystemProvider.Kind,
1193+
outputFile: Basics.RelativePath
1194+
) async throws {
1195+
try await fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { fixturePath in
1196+
_ = try await self.build(
1197+
[],
1198+
packagePath: fixturePath,
1199+
cleanAfterward: false,
1200+
buildSystem: buildSystem,
1201+
)
1202+
1203+
let mainOFile = fixturePath.appending(outputFile)
1204+
let initialMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date
1205+
1206+
_ = try await self.build(
1207+
["-Xswiftc", "-diagnostic-style=llvm"],
1208+
packagePath: fixturePath,
1209+
cleanAfterward: false,
1210+
buildSystem: buildSystem,
1211+
)
1212+
1213+
let subsequentMainOMtime = try FileManager.default.attributesOfItem(atPath: mainOFile.pathString)[.modificationDate] as? Date
1214+
#expect(initialMainOMtime == subsequentMainOMtime, "Expected no rebuild to occur when supplying -diagnostic-style, but the file was modified.")
1215+
}
1216+
}
1217+
11291218
@Test(
11301219
.SWBINTTODO("Test failed because of missing plugin support in the PIF builder. This can be reinvestigated after the support is there."),
11311220
.tags(
@@ -1233,5 +1322,16 @@ struct BuildCommandTestCases {
12331322

12341323
}
12351324

1325+
extension Triple {
1326+
func withoutVersion() throws -> Triple {
1327+
if isDarwin() {
1328+
let stringWithoutVersion = tripleString(forPlatformVersion: "")
1329+
return try Triple(stringWithoutVersion)
1330+
} else {
1331+
return self
1332+
}
1333+
}
1334+
}
1335+
12361336

12371337

0 commit comments

Comments
 (0)