Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use llbuild's new content-exclusion-patterns node attribute to prevent it from descending into .build and .git directories #5594

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
}
}
}