Skip to content

Commit

Permalink
Use llbuild's new content-exclusion-patterns node attribute to prev…
Browse files Browse the repository at this point in the history
…ent it from descending into `.build` and `.git` directories (#5594)

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
  • Loading branch information
abertelrud authored Jun 17, 2022
1 parent 27694b5 commit fb032ac
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Fixtures/Miscellaneous/FlatPackage/MyExec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@main
public struct MyExec {
public private(set) var text = "Hello, World!"

public static func main() {
print(MyExec().text)
}
}
8 changes: 8 additions & 0 deletions Fixtures/Miscellaneous/FlatPackage/MyTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import XCTest
@testable import MyExec

final class MyTest: XCTestCase {
func testExample() throws {
XCTAssertEqual(MyExec().text, "Hello, World!")
}
}
28 changes: 28 additions & 0 deletions Fixtures/Miscellaneous/FlatPackage/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.5
import PackageDescription

let execSrcFiles = ["MyExec.swift"]
let testSrcFiles = ["MyTest.swift"]
let variousFiles = ["README.md"]

let package = Package(
name: "FlatPackage",
dependencies: [
],
targets: [
.executableTarget(
name: "MyExec",
dependencies: [],
path: ".",
exclude: testSrcFiles + variousFiles,
sources: execSrcFiles
),
.testTarget(
name: "MyTest",
dependencies: ["MyExec"],
path: ".",
exclude: execSrcFiles + variousFiles,
sources: testSrcFiles
),
]
)
3 changes: 3 additions & 0 deletions Fixtures/Miscellaneous/FlatPackage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# FlatPackage

A description of this package.
2 changes: 2 additions & 0 deletions Sources/LLBuildManifest/ManifestWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public struct ManifestWriter {
if !directoryStructureNodes.isEmpty {
stream <<< "nodes:\n"
}
let namesToExclude = [".git", ".build"]
for node in directoryStructureNodes.sorted(by: { $0.name < $1.name }) {
stream <<< " " <<< Format.asJSON(node) <<< ":\n"
stream <<< " is-directory-structure: true\n"
stream <<< " content-exclusion-patterns: " <<< Format.asJSON(namesToExclude) <<< "\n"
}

stream <<< "commands:\n"
Expand Down
1 change: 1 addition & 0 deletions Tests/BuildTests/LLBuildManifestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ final class LLBuildManifestTests: XCTestCase {
nodes:
"\(root.appending(components: "dir", "structure"))/":
is-directory-structure: true
content-exclusion-patterns: [".git",".build"]
commands:
"C.Foo":
tool: phony
Expand Down
16 changes: 16 additions & 0 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -817,4 +817,20 @@ class MiscellaneousTestCase: XCTestCase {
XCTAssertTrue(result.stderr.contains("Copying best.txt\n"), "build log is missing message about copying resource file")
}
}

func testNoJSONOutputWithFlatPackageStructure() throws {
try fixture(name: "Miscellaneous/FlatPackage") { package in
// 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).
let (stdout1, stderr1) = try SwiftPMProduct.SwiftBuild.execute([], packagePath: package)
XCTAssertDirectoryExists(package.appending(component: ".build"))
XCTAssertNoMatch(stdout1, .contains("command_arguments"))
XCTAssertNoMatch(stderr1, .contains("command_arguments"))

// 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).
let (stdout2, stderr2) = try SwiftPMProduct.SwiftTest.execute([], packagePath: package)
XCTAssertDirectoryExists(package.appending(component: ".build"))
XCTAssertNoMatch(stdout2, .contains("command_arguments"))
XCTAssertNoMatch(stderr2, .contains("command_arguments"))
}
}
}

0 comments on commit fb032ac

Please sign in to comment.