Skip to content

Fixed bug with expandedSearchPaths when dealing with windows paths #254

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

Merged
merged 5 commits into from
Mar 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -912,15 +912,16 @@ package final class GlobalProductPlan: GlobalTargetInfoProvider
func expandedSearchPaths(for items: [String], relativeTo sourcePath: Path, scope: MacroEvaluationScope) -> [String] {
var result = [String]()
for item in items {
let item = Path(item)
// Expand recursive header search paths, if present.
if item.hasSuffix("/**") {
if item.basename == "**" {
// Drop the recursive search marker and make absolute.
let item = Path(item).dirname
let item = item.dirname
let searchPath = sourcePath.join(item)

// Ignore any attempts to do a recursive search of root.
if searchPath.isRoot {
result.append("/")
result.append(Path.root.str)
} else {
let excludedPatterns = scope.evaluate(BuiltinMacros.EXCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES)
let includedPatterns = scope.evaluate(BuiltinMacros.INCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES)
Expand All @@ -941,7 +942,7 @@ package final class GlobalProductPlan: GlobalTargetInfoProvider
}
}
} else {
result.append(item)
result.append(item.str)
}
}
return result
Expand Down
2 changes: 1 addition & 1 deletion Sources/SWBTestSupport/BuildDescriptionBasedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension CoreBasedTests {
workspaceContext.updateUserPreferences(.defaultForTesting)

// Configure fake user and system info.
workspaceContext.updateUserInfo(UserInfo(user: "exampleUser", group: "exampleGroup", uid: 1234, gid:12345, home: Path("/Users/exampleUser"), environment: [:]))
workspaceContext.updateUserInfo(UserInfo(user: "exampleUser", group: "exampleGroup", uid: 1234, gid:12345, home: Path.root.join("Users/exampleUser"), environment: [:]))
workspaceContext.updateSystemInfo(SystemInfo(operatingSystemVersion: Version(99, 98, 97), productBuildVersion: "99A98", nativeArchitecture: "x86_64"))

let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
Expand Down
15 changes: 6 additions & 9 deletions Tests/SWBCoreTests/SettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1904,15 +1904,14 @@ import SWBMacro
}

/// Check the behavior of user defined settings, especially w.r.t. quoting rules.
@Test(.requireSDKs(.macOS))
@Test(.requireSDKs(.host))
func userDefinedSettings() async throws {
// Set up a trivial iOS project.
let testWorkspace = try await TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: []),
targets: [
TestStandardTarget("Target1",
type: .application,
TestStandardTarget("Target1", type: .commandLineTool,
buildConfigurations: [
TestBuildConfiguration("Debug",
buildSettings: [
Expand All @@ -1939,16 +1938,14 @@ import SWBMacro
}

// Test that we correctly normalize path of some special macros.
@Test(.requireSDKs(.macOS))
@Test(.requireSDKs(.host))
func macroPathNormalization() async throws {
let testWorkspace = try await TestWorkspace("Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: []),
targets: [
TestStandardTarget("Target1",
type: .application,
buildConfigurations: [
TestStandardTarget("Target1", type: .commandLineTool, buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: [
"SYMROOT": "./build",
"DSTROOT": "build/foo/bar/something/../dst",
Expand All @@ -1970,8 +1967,8 @@ import SWBMacro
}

let scope = settings.globalScope
#expect(scope.evaluate(BuiltinMacros.SYMROOT) == Path("/tmp/Workspace/aProject/build"))
#expect(scope.evaluate(BuiltinMacros.DSTROOT) == Path("/tmp/Workspace/aProject/build/foo/bar/dst"))
#expect(scope.evaluate(BuiltinMacros.SYMROOT) == Path.root.join("tmp/Workspace/aProject/build"))
#expect(scope.evaluate(BuiltinMacros.DSTROOT) == Path.root.join("tmp/Workspace/aProject/build/foo/bar/dst"))
}

@Test(.requireSDKs(.tvOS))
Expand Down
27 changes: 15 additions & 12 deletions Tests/SWBTaskConstructionTests/TaskConstructionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4771,7 +4771,7 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
}

/// Check recursive header search paths.
@Test(.requireSDKs(.macOS))
@Test(.requireSDKs(.host))
func recursiveHeaderSearchPaths() async throws {
let testProject = TestProject(
"aProject",
Expand Down Expand Up @@ -4812,26 +4812,29 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
try fs.createDirectory(Path(SRCROOT).join("Framework/FooFramework/Bar"), recursive: true)

// Check the build.
await tester.checkBuild(runDestination: .macOS, fs: fs) { results in
await tester.checkBuild(runDestination: .host, fs: fs) { results in
results.checkTarget("Tool") { target in
results.checkTask(.matchTarget(target), .matchRuleType("CompileC")) { task in
let buildProductsDirSuffix = RunDestinationInfo.host.builtProductsDirSuffix
let iQuoteArgs = task.commandLine.enumerated().filter { (i, arg) in
(task.commandLine[safe: i - 1]?.asString ?? "") == "-iquote"
}.map{ $0.1.asString }
let capIArgs = task.commandLine.filter{ $0.asString.hasPrefix("-I") }.map{ $0.asString }
let capFArgs = task.commandLine.filter{ $0.asString.hasPrefix("-F") }.map{ $0.asString }
#expect(iQuoteArgs == [
"User", "User/FooUser", "User/FooUser/Bar",
"/MissingPath", "OtherMissingPath"])
"User", Path("User/FooUser").str, Path("User/FooUser/Bar").str,
Path("/MissingPath").str, "OtherMissingPath"])
#expect(capIArgs == [
"-I\(SRCROOT)/build/Debug/include",
"-ISystem", "-ISystem/FooSystem", "-ISystem/FooSystem/Bar",
"-I\(SRCROOT)/build/aProject.build/Debug/Tool.build/DerivedSources-normal/x86_64",
"-I\(SRCROOT)/build/aProject.build/Debug/Tool.build/DerivedSources/x86_64",
"-I\(SRCROOT)/build/aProject.build/Debug/Tool.build/DerivedSources"])
#expect(capFArgs == [
"-F\(SRCROOT)/build/Debug",
"-FFramework", "-FFramework/FooFramework", "-FFramework/FooFramework/Bar"])
"-I\(Path(SRCROOT).join("build/Debug\(buildProductsDirSuffix)/include").str)",
"-ISystem", "-I\(Path("System/FooSystem").str)", "-I\(Path("System/FooSystem/Bar").str)",
"-I\(Path(SRCROOT).join("build/aProject.build/Debug\(buildProductsDirSuffix)/Tool.build/DerivedSources-normal/\(results.runDestinationTargetArchitecture)").str)",
"-I\(Path(SRCROOT).join("build/aProject.build/Debug\(buildProductsDirSuffix)/Tool.build/DerivedSources/\(results.runDestinationTargetArchitecture)").str)",
"-I\(Path(SRCROOT).join("build/aProject.build/Debug\(buildProductsDirSuffix)/Tool.build/DerivedSources").str)"])
if RunDestinationInfo.host == .macOS {
#expect(capFArgs == [
"-F\(SRCROOT)/build/Debug",
"-FFramework", "-FFramework/FooFramework", "-FFramework/FooFramework/Bar"])
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions Tests/SWBTaskExecutionTests/BuildDescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fileprivate struct BuildDescriptionTests: CoreBasedTests {
}

/// Check that build descriptions recompute based on recursive search path changes.
@Test(.skipHostOS(.windows, "Path handling needs work for windows"))
@Test(.requireSDKs(.host))
func recursiveSearchPathValidation() async throws {
try await withTemporaryDirectory { tmpDirPath in
try await withAsyncDeferrable { deferrable in
Expand All @@ -348,7 +348,7 @@ fileprivate struct BuildDescriptionTests: CoreBasedTests {
buildSettings: [
"USE_HEADERMAP": "NO",
"ALWAYS_SEARCH_USER_PATHS": "NO",
"USER_HEADER_SEARCH_PATHS": "/User/**",
"USER_HEADER_SEARCH_PATHS": Path.root.join("User/**").strWithPosixSlashes,
"CLANG_USE_RESPONSE_FILE": "NO"])],
targets: [
TestStandardTarget(
Expand Down Expand Up @@ -390,16 +390,16 @@ fileprivate struct BuildDescriptionTests: CoreBasedTests {
do {
let fs = PseudoFS()
try fs.createDirectory(Path.root.join("User/Foo"), recursive: true)
try await check(fs: fs, expected: ["/User", "/User/Foo"], expectedSource: .new)
try await check(fs: fs, expected: ["/User", "/User/Foo"], expectedSource: .inMemoryCache)
try await check(fs: fs, expected: [Path.root.join("User").str, Path.root.join("User/Foo").str], expectedSource: .new)
try await check(fs: fs, expected: [Path.root.join("User").str, Path.root.join("User/Foo").str], expectedSource: .inMemoryCache)
}

// Check after adding a path.
do {
let fs = PseudoFS()
try fs.createDirectory(Path.root.join("User/Foo/Bar"), recursive: true)
try await check(fs: fs, expected: ["/User", "/User/Foo", "/User/Foo/Bar"], expectedSource: .new)
try await check(fs: fs, expected: ["/User", "/User/Foo", "/User/Foo/Bar"], expectedSource: .inMemoryCache)
try await check(fs: fs, expected: [Path.root.join("User").str, Path.root.join("User/Foo").str, Path.root.join("User/Foo/Bar").str], expectedSource: .new)
try await check(fs: fs, expected: [Path.root.join("User").str, Path.root.join("User/Foo").str, Path.root.join("User/Foo/Bar").str], expectedSource: .inMemoryCache)
}
}
}
Expand Down