Skip to content

Commit bd445ee

Browse files
committed
plutil: Add a specific rpath for plutil and use it when linking.
- plutil requires an rpath of '$ORIGIN/../lib/swift/${swift_os}' so set this specificaly for plutil. - Add a test for running plutil, which relies on LD_LIBRARY_PATH being set when the tests are run to point to the build directories.
1 parent c5357f3 commit bd445ee

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ if(FOUNDATION_ENABLE_LIBDISPATCH)
100100
endif()
101101
endif()
102102

103+
set(plutil_rpath)
103104
if(CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL Linux)
104105
set(Foundation_RPATH -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
105106
set(XDG_TEST_HELPER_RPATH -Xlinker;-rpath;-Xlinker;${CMAKE_CURRENT_BINARY_DIR})
107+
set(plutil_rpath -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}")
106108
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
107109
set(Foundation_RPATH -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
108110
set(XDG_TEST_HELPER_RPATH -Xlinker;-rpath;-Xlinker;${CMAKE_CURRENT_BINARY_DIR})
111+
set(plutil_rpath -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}")
109112
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
110113
# FIXME(SR9138) Silence "locally defined symbol '…' imported in function '…'
111114
set(WORKAROUND_SR9138 -Xlinker;-ignore:4049;-Xlinker;-ignore:4217)
@@ -392,11 +395,11 @@ add_swift_executable(plutil
392395
CFLAGS
393396
-F${CMAKE_CURRENT_BINARY_DIR}
394397
LINK_FLAGS
395-
${libdispatch_ldflags}
396398
-L${CMAKE_CURRENT_BINARY_DIR}
399+
-L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src
397400
-lFoundation
398401
${Foundation_INTERFACE_LIBRARIES}
399-
${Foundation_RPATH}
402+
${plutil_rpath}
400403
SWIFT_FLAGS
401404
-DDEPLOYMENT_RUNTIME_SWIFT
402405
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
@@ -597,7 +600,17 @@ if(ENABLE_TESTING)
597600
ENVIRONMENT
598601
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src
599602
DEPENDS
600-
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX})
603+
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX})
604+
605+
add_custom_command(TARGET TestFoundation
606+
POST_BUILD
607+
BYPRODUCTS
608+
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/plutil${CMAKE_EXECUTABLE_SUFFIX}
609+
COMMAND
610+
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/plutil${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/plutil${CMAKE_EXECUTABLE_SUFFIX}
611+
DEPENDS
612+
TestFoundation
613+
plutil)
601614
endif()
602615

603616
# TODO(compnerd) honour lib vs lib64

Foundation.xcodeproj/project.pbxproj

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,20 @@
559559
remoteGlobalIDString = 5B5D885C1BBC938800234F36;
560560
remoteInfo = SwiftFoundation;
561561
};
562+
B98F173F229AF5AF00F2B002 /* PBXContainerItemProxy */ = {
563+
isa = PBXContainerItemProxy;
564+
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
565+
proxyType = 1;
566+
remoteGlobalIDString = EA66F66E1BF56CCB00136161;
567+
remoteInfo = plutil;
568+
};
569+
B98F1741229AF5F900F2B002 /* PBXContainerItemProxy */ = {
570+
isa = PBXContainerItemProxy;
571+
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
572+
proxyType = 1;
573+
remoteGlobalIDString = 5B5D885C1BBC938800234F36;
574+
remoteInfo = SwiftFoundation;
575+
};
562576
EA993CE21BEACD8E000969A2 /* PBXContainerItemProxy */ = {
563577
isa = PBXContainerItemProxy;
564578
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
@@ -2333,6 +2347,7 @@
23332347
buildRules = (
23342348
);
23352349
dependencies = (
2350+
B98F1740229AF5AF00F2B002 /* PBXTargetDependency */,
23362351
B90FD23020C2FF420087EF44 /* PBXTargetDependency */,
23372352
AE2FC5951CFEFC70008F7981 /* PBXTargetDependency */,
23382353
);
@@ -2371,6 +2386,7 @@
23712386
buildRules = (
23722387
);
23732388
dependencies = (
2389+
B98F1742229AF5F900F2B002 /* PBXTargetDependency */,
23742390
);
23752391
name = plutil;
23762392
productName = plutil;
@@ -2506,7 +2522,7 @@
25062522
);
25072523
runOnlyForDeploymentPostprocessing = 0;
25082524
shellPath = /bin/sh;
2509-
shellScript = "cp ${BUILT_PRODUCTS_DIR}/xdgTestHelper.app/Contents/MacOS/xdgTestHelper ${BUILT_PRODUCTS_DIR}/TestFoundation.app/Contents/MacOS/\n";
2525+
shellScript = "cp ${BUILT_PRODUCTS_DIR}/xdgTestHelper.app/Contents/MacOS/xdgTestHelper ${BUILT_PRODUCTS_DIR}/TestFoundation.app/Contents/MacOS/\ncp ${BUILT_PRODUCTS_DIR}/plutil ${BUILT_PRODUCTS_DIR}/TestFoundation.app/Contents/MacOS/\n";
25102526
};
25112527
/* End PBXShellScriptBuildPhase section */
25122528

@@ -2960,6 +2976,16 @@
29602976
target = 5B5D885C1BBC938800234F36 /* SwiftFoundation */;
29612977
targetProxy = B90FD23120C2FF840087EF44 /* PBXContainerItemProxy */;
29622978
};
2979+
B98F1740229AF5AF00F2B002 /* PBXTargetDependency */ = {
2980+
isa = PBXTargetDependency;
2981+
target = EA66F66E1BF56CCB00136161 /* plutil */;
2982+
targetProxy = B98F173F229AF5AF00F2B002 /* PBXContainerItemProxy */;
2983+
};
2984+
B98F1742229AF5F900F2B002 /* PBXTargetDependency */ = {
2985+
isa = PBXTargetDependency;
2986+
target = 5B5D885C1BBC938800234F36 /* SwiftFoundation */;
2987+
targetProxy = B98F1741229AF5F900F2B002 /* PBXContainerItemProxy */;
2988+
};
29632989
EA993CE31BEACD8E000969A2 /* PBXTargetDependency */ = {
29642990
isa = PBXTargetDependency;
29652991
target = 5B7C8A6D1BEA7F8F00C5B690 /* CoreFoundation */;

TestFoundation/TestProcess.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,33 @@ class TestProcess : XCTestCase {
514514
task.waitUntilExit()
515515
}
516516

517+
518+
func test_plutil() throws {
519+
let task = Process()
520+
521+
guard let url = testBundle().url(forAuxiliaryExecutable: "plutil") else {
522+
throw Error.ExternalBinaryNotFound("plutil")
523+
}
524+
525+
task.executableURL = url
526+
task.arguments = []
527+
let stdoutPipe = Pipe()
528+
task.standardOutput = stdoutPipe
529+
530+
var stdoutData = Data()
531+
stdoutPipe.fileHandleForReading.readabilityHandler = { fh in
532+
stdoutData.append(fh.availableData)
533+
}
534+
try task.run()
535+
task.waitUntilExit()
536+
stdoutPipe.fileHandleForReading.readabilityHandler = nil
537+
if let d = try stdoutPipe.fileHandleForReading.readToEnd() {
538+
stdoutData.append(d)
539+
}
540+
XCTAssertEqual(String(data: stdoutData, encoding: .utf8), "No files specified.\n")
541+
}
542+
543+
517544
static var allTests: [(String, (TestProcess) -> () throws -> Void)] {
518545
return [
519546
("test_exit0" , test_exit0),
@@ -541,6 +568,7 @@ class TestProcess : XCTestCase {
541568
("test_redirect_stderr_using_null", test_redirect_stderr_using_null),
542569
("test_redirect_all_using_null", test_redirect_all_using_null),
543570
("test_redirect_all_using_nil", test_redirect_all_using_nil),
571+
("test_plutil", test_plutil),
544572
]
545573
}
546574
}
@@ -549,6 +577,7 @@ private enum Error: Swift.Error {
549577
case TerminationStatus(Int32)
550578
case UnicodeDecodingError(Data)
551579
case InvalidEnvironmentVariable(String)
580+
case ExternalBinaryNotFound(String)
552581
}
553582

554583
// Run xdgTestHelper, wait for 'Ready' from the sub-process, then signal a semaphore.

0 commit comments

Comments
 (0)