Skip to content

Commit 71df99c

Browse files
authored
Fixed bug with expandedSearchPaths when dealing with windows paths (#254)
* Fixed bug with expandedSearchPaths when dealing with windows paths - enabled recursiveSearchPathValidation for all hosts - enabled some Path settings tests for all hosts - default some testing support methods to be .host instead of .macOS * update * update * fixed Path joins * fixed merge
1 parent 3ad06c0 commit 71df99c

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

Sources/SWBTaskConstruction/ProductPlanning/ProductPlan.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -912,15 +912,16 @@ package final class GlobalProductPlan: GlobalTargetInfoProvider
912912
func expandedSearchPaths(for items: [String], relativeTo sourcePath: Path, scope: MacroEvaluationScope) -> [String] {
913913
var result = [String]()
914914
for item in items {
915+
let item = Path(item)
915916
// Expand recursive header search paths, if present.
916-
if item.hasSuffix("/**") {
917+
if item.basename == "**" {
917918
// Drop the recursive search marker and make absolute.
918-
let item = Path(item).dirname
919+
let item = item.dirname
919920
let searchPath = sourcePath.join(item)
920921

921922
// Ignore any attempts to do a recursive search of root.
922923
if searchPath.isRoot {
923-
result.append("/")
924+
result.append(Path.root.str)
924925
} else {
925926
let excludedPatterns = scope.evaluate(BuiltinMacros.EXCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES)
926927
let includedPatterns = scope.evaluate(BuiltinMacros.INCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES)
@@ -941,7 +942,7 @@ package final class GlobalProductPlan: GlobalTargetInfoProvider
941942
}
942943
}
943944
} else {
944-
result.append(item)
945+
result.append(item.str)
945946
}
946947
}
947948
return result

Sources/SWBTestSupport/BuildDescriptionBasedTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extension CoreBasedTests {
5252
workspaceContext.updateUserPreferences(.defaultForTesting)
5353

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

5858
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)

Tests/SWBCoreTests/SettingsTests.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,15 +1904,14 @@ import SWBMacro
19041904
}
19051905

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

19411940
// Test that we correctly normalize path of some special macros.
1942-
@Test(.requireSDKs(.macOS))
1941+
@Test(.requireSDKs(.host))
19431942
func macroPathNormalization() async throws {
19441943
let testWorkspace = try await TestWorkspace("Workspace",
19451944
projects: [
19461945
TestProject("aProject",
19471946
groupTree: TestGroup("SomeFiles", children: []),
19481947
targets: [
1949-
TestStandardTarget("Target1",
1950-
type: .application,
1951-
buildConfigurations: [
1948+
TestStandardTarget("Target1", type: .commandLineTool, buildConfigurations: [
19521949
TestBuildConfiguration("Debug", buildSettings: [
19531950
"SYMROOT": "./build",
19541951
"DSTROOT": "build/foo/bar/something/../dst",
@@ -1970,8 +1967,8 @@ import SWBMacro
19701967
}
19711968

19721969
let scope = settings.globalScope
1973-
#expect(scope.evaluate(BuiltinMacros.SYMROOT) == Path("/tmp/Workspace/aProject/build"))
1974-
#expect(scope.evaluate(BuiltinMacros.DSTROOT) == Path("/tmp/Workspace/aProject/build/foo/bar/dst"))
1970+
#expect(scope.evaluate(BuiltinMacros.SYMROOT) == Path.root.join("tmp/Workspace/aProject/build"))
1971+
#expect(scope.evaluate(BuiltinMacros.DSTROOT) == Path.root.join("tmp/Workspace/aProject/build/foo/bar/dst"))
19751972
}
19761973

19771974
@Test(.requireSDKs(.tvOS))

Tests/SWBTaskConstructionTests/TaskConstructionTests.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4771,7 +4771,7 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
47714771
}
47724772

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

48144814
// Check the build.
4815-
await tester.checkBuild(runDestination: .macOS, fs: fs) { results in
4815+
await tester.checkBuild(runDestination: .host, fs: fs) { results in
48164816
results.checkTarget("Tool") { target in
48174817
results.checkTask(.matchTarget(target), .matchRuleType("CompileC")) { task in
4818+
let buildProductsDirSuffix = RunDestinationInfo.host.builtProductsDirSuffix
48184819
let iQuoteArgs = task.commandLine.enumerated().filter { (i, arg) in
48194820
(task.commandLine[safe: i - 1]?.asString ?? "") == "-iquote"
48204821
}.map{ $0.1.asString }
48214822
let capIArgs = task.commandLine.filter{ $0.asString.hasPrefix("-I") }.map{ $0.asString }
48224823
let capFArgs = task.commandLine.filter{ $0.asString.hasPrefix("-F") }.map{ $0.asString }
48234824
#expect(iQuoteArgs == [
4824-
"User", "User/FooUser", "User/FooUser/Bar",
4825-
"/MissingPath", "OtherMissingPath"])
4825+
"User", Path("User/FooUser").str, Path("User/FooUser/Bar").str,
4826+
Path("/MissingPath").str, "OtherMissingPath"])
48264827
#expect(capIArgs == [
4827-
"-I\(SRCROOT)/build/Debug/include",
4828-
"-ISystem", "-ISystem/FooSystem", "-ISystem/FooSystem/Bar",
4829-
"-I\(SRCROOT)/build/aProject.build/Debug/Tool.build/DerivedSources-normal/x86_64",
4830-
"-I\(SRCROOT)/build/aProject.build/Debug/Tool.build/DerivedSources/x86_64",
4831-
"-I\(SRCROOT)/build/aProject.build/Debug/Tool.build/DerivedSources"])
4832-
#expect(capFArgs == [
4833-
"-F\(SRCROOT)/build/Debug",
4834-
"-FFramework", "-FFramework/FooFramework", "-FFramework/FooFramework/Bar"])
4828+
"-I\(Path(SRCROOT).join("build/Debug\(buildProductsDirSuffix)/include").str)",
4829+
"-ISystem", "-I\(Path("System/FooSystem").str)", "-I\(Path("System/FooSystem/Bar").str)",
4830+
"-I\(Path(SRCROOT).join("build/aProject.build/Debug\(buildProductsDirSuffix)/Tool.build/DerivedSources-normal/\(results.runDestinationTargetArchitecture)").str)",
4831+
"-I\(Path(SRCROOT).join("build/aProject.build/Debug\(buildProductsDirSuffix)/Tool.build/DerivedSources/\(results.runDestinationTargetArchitecture)").str)",
4832+
"-I\(Path(SRCROOT).join("build/aProject.build/Debug\(buildProductsDirSuffix)/Tool.build/DerivedSources").str)"])
4833+
if RunDestinationInfo.host == .macOS {
4834+
#expect(capFArgs == [
4835+
"-F\(SRCROOT)/build/Debug",
4836+
"-FFramework", "-FFramework/FooFramework", "-FFramework/FooFramework/Bar"])
4837+
}
48354838
}
48364839
}
48374840

Tests/SWBTaskExecutionTests/BuildDescriptionTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ fileprivate struct BuildDescriptionTests: CoreBasedTests {
330330
}
331331

332332
/// Check that build descriptions recompute based on recursive search path changes.
333-
@Test(.skipHostOS(.windows, "Path handling needs work for windows"))
333+
@Test(.requireSDKs(.host))
334334
func recursiveSearchPathValidation() async throws {
335335
try await withTemporaryDirectory { tmpDirPath in
336336
try await withAsyncDeferrable { deferrable in
@@ -348,7 +348,7 @@ fileprivate struct BuildDescriptionTests: CoreBasedTests {
348348
buildSettings: [
349349
"USE_HEADERMAP": "NO",
350350
"ALWAYS_SEARCH_USER_PATHS": "NO",
351-
"USER_HEADER_SEARCH_PATHS": "/User/**",
351+
"USER_HEADER_SEARCH_PATHS": Path.root.join("User/**").strWithPosixSlashes,
352352
"CLANG_USE_RESPONSE_FILE": "NO"])],
353353
targets: [
354354
TestStandardTarget(
@@ -390,16 +390,16 @@ fileprivate struct BuildDescriptionTests: CoreBasedTests {
390390
do {
391391
let fs = PseudoFS()
392392
try fs.createDirectory(Path.root.join("User/Foo"), recursive: true)
393-
try await check(fs: fs, expected: ["/User", "/User/Foo"], expectedSource: .new)
394-
try await check(fs: fs, expected: ["/User", "/User/Foo"], expectedSource: .inMemoryCache)
393+
try await check(fs: fs, expected: [Path.root.join("User").str, Path.root.join("User/Foo").str], expectedSource: .new)
394+
try await check(fs: fs, expected: [Path.root.join("User").str, Path.root.join("User/Foo").str], expectedSource: .inMemoryCache)
395395
}
396396

397397
// Check after adding a path.
398398
do {
399399
let fs = PseudoFS()
400400
try fs.createDirectory(Path.root.join("User/Foo/Bar"), recursive: true)
401-
try await check(fs: fs, expected: ["/User", "/User/Foo", "/User/Foo/Bar"], expectedSource: .new)
402-
try await check(fs: fs, expected: ["/User", "/User/Foo", "/User/Foo/Bar"], expectedSource: .inMemoryCache)
401+
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)
402+
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)
403403
}
404404
}
405405
}

0 commit comments

Comments
 (0)