Skip to content

Commit 37ac5e3

Browse files
authored
Use llbuild's new content-exclusion-patterns node attribute to prevent it from descending into .build and .git directories (#5594) (#5599)
This requires the llbuild commit a1adaff2a405c3a74925e60356431050cb9a3a9d, but it does not cause problems if the llbuild being used doesn't yet support this property. Instead it will be ignored. This adds a dedicated unit test with a flat package. We should consider whether any customized scratch directory should also be included in the list. This is a little tricky since the exclusion patterns are applied to all subdirectory name, not just those at the top level. In testing, it doesn't actually seem to be required, which seems a little surprising. The fix in this commit is safe and good on its own, and we can consider adding customized scratch paths later once we've looked deeper into that issue. rdar://93982172 (cherry picked from commit fb032ac)
1 parent 757df3b commit 37ac5e3

File tree

7 files changed

+66
-0
lines changed

7 files changed

+66
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@main
2+
public struct MyExec {
3+
public private(set) var text = "Hello, World!"
4+
5+
public static func main() {
6+
print(MyExec().text)
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import XCTest
2+
@testable import MyExec
3+
4+
final class MyTest: XCTestCase {
5+
func testExample() throws {
6+
XCTAssertEqual(MyExec().text, "Hello, World!")
7+
}
8+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version: 5.5
2+
import PackageDescription
3+
4+
let execSrcFiles = ["MyExec.swift"]
5+
let testSrcFiles = ["MyTest.swift"]
6+
let variousFiles = ["README.md"]
7+
8+
let package = Package(
9+
name: "FlatPackage",
10+
dependencies: [
11+
],
12+
targets: [
13+
.executableTarget(
14+
name: "MyExec",
15+
dependencies: [],
16+
path: ".",
17+
exclude: testSrcFiles + variousFiles,
18+
sources: execSrcFiles
19+
),
20+
.testTarget(
21+
name: "MyTest",
22+
dependencies: ["MyExec"],
23+
path: ".",
24+
exclude: execSrcFiles + variousFiles,
25+
sources: testSrcFiles
26+
),
27+
]
28+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# FlatPackage
2+
3+
A description of this package.

Sources/LLBuildManifest/ManifestWriter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ public struct ManifestWriter {
4848
if !directoryStructureNodes.isEmpty {
4949
stream <<< "nodes:\n"
5050
}
51+
let namesToExclude = [".git", ".build"]
5152
for node in directoryStructureNodes.sorted(by: { $0.name < $1.name }) {
5253
stream <<< " " <<< Format.asJSON(node) <<< ":\n"
5354
stream <<< " is-directory-structure: true\n"
55+
stream <<< " content-exclusion-patterns: " <<< Format.asJSON(namesToExclude) <<< "\n"
5456
}
5557

5658
stream <<< "commands:\n"

Tests/BuildTests/LLBuildManifestTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class LLBuildManifestTests: XCTestCase {
4848
nodes:
4949
"/some/dir/structure/":
5050
is-directory-structure: true
51+
content-exclusion-patterns: [".git",".build"]
5152
commands:
5253
"C.Foo":
5354
tool: phony

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,20 @@ class MiscellaneousTestCase: XCTestCase {
811811
XCTAssertTrue(result.stderr.contains("Copying best.txt\n"), "build log is missing message about copying resource file")
812812
}
813813
}
814+
815+
func testNoJSONOutputWithFlatPackageStructure() throws {
816+
try fixture(name: "Miscellaneous/FlatPackage") { package in
817+
// First build, make sure we got the `.build` directory where we expect it, and that there is no JSON output (by looking for known output).
818+
let (stdout1, stderr1) = try SwiftPMProduct.SwiftBuild.execute([], packagePath: package)
819+
XCTAssertDirectoryExists(package.appending(component: ".build"))
820+
XCTAssertNoMatch(stdout1, .contains("command_arguments"))
821+
XCTAssertNoMatch(stderr1, .contains("command_arguments"))
822+
823+
// Now test, make sure we got the `.build` directory where we expect it, and that there is no JSON output (by looking for known output).
824+
let (stdout2, stderr2) = try SwiftPMProduct.SwiftTest.execute([], packagePath: package)
825+
XCTAssertDirectoryExists(package.appending(component: ".build"))
826+
XCTAssertNoMatch(stdout2, .contains("command_arguments"))
827+
XCTAssertNoMatch(stderr2, .contains("command_arguments"))
828+
}
829+
}
814830
}

0 commit comments

Comments
 (0)