Skip to content

Commit 8d99ac9

Browse files
authored
Merge pull request #2307 from spevans/pr_fix_plutil_rpath
plutil: Add a specific rpath for plutil and use it when linking.
2 parents 664c8a0 + c76eb37 commit 8d99ac9

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ if(FOUNDATION_ENABLE_LIBDISPATCH)
9797
endif()
9898
endif()
9999

100+
set(plutil_rpath)
100101
if(CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL Linux OR
101102
CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
102103
set(Foundation_RPATH -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
103104
set(XDG_TEST_HELPER_RPATH -Xlinker;-rpath;-Xlinker;${CMAKE_CURRENT_BINARY_DIR})
105+
set(plutil_rpath -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}")
104106
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
105107
# FIXME(SR9138) Silence "locally defined symbol '…' imported in function '…'
106108
set(WORKAROUND_SR9138 -Xlinker;-ignore:4049;-Xlinker;-ignore:4217)
@@ -389,11 +391,11 @@ add_swift_executable(plutil
389391
CFLAGS
390392
-F${CMAKE_CURRENT_BINARY_DIR}
391393
LINK_FLAGS
392-
${libdispatch_ldflags}
393394
-L${CMAKE_CURRENT_BINARY_DIR}
395+
-L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src
394396
-lFoundation
395397
${Foundation_INTERFACE_LIBRARIES}
396-
${Foundation_RPATH}
398+
${plutil_rpath}
397399
SWIFT_FLAGS
398400
-DDEPLOYMENT_RUNTIME_SWIFT
399401
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
@@ -601,7 +603,17 @@ if(ENABLE_TESTING)
601603
ENVIRONMENT
602604
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src
603605
DEPENDS
604-
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX})
606+
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX})
607+
608+
add_custom_command(TARGET TestFoundation
609+
POST_BUILD
610+
BYPRODUCTS
611+
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/plutil${CMAKE_EXECUTABLE_SUFFIX}
612+
COMMAND
613+
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/plutil${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/plutil${CMAKE_EXECUTABLE_SUFFIX}
614+
DEPENDS
615+
TestFoundation
616+
plutil)
605617
endif()
606618

607619
if(BUILD_SHARED_LIBS)

Foundation.xcodeproj/project.pbxproj

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,20 @@
560560
remoteGlobalIDString = 5B5D885C1BBC938800234F36;
561561
remoteInfo = SwiftFoundation;
562562
};
563+
B98F173F229AF5AF00F2B002 /* PBXContainerItemProxy */ = {
564+
isa = PBXContainerItemProxy;
565+
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
566+
proxyType = 1;
567+
remoteGlobalIDString = EA66F66E1BF56CCB00136161;
568+
remoteInfo = plutil;
569+
};
570+
B98F1741229AF5F900F2B002 /* PBXContainerItemProxy */ = {
571+
isa = PBXContainerItemProxy;
572+
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
573+
proxyType = 1;
574+
remoteGlobalIDString = 5B5D885C1BBC938800234F36;
575+
remoteInfo = SwiftFoundation;
576+
};
563577
EA993CE21BEACD8E000969A2 /* PBXContainerItemProxy */ = {
564578
isa = PBXContainerItemProxy;
565579
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
@@ -2336,6 +2350,7 @@
23362350
buildRules = (
23372351
);
23382352
dependencies = (
2353+
B98F1740229AF5AF00F2B002 /* PBXTargetDependency */,
23392354
B90FD23020C2FF420087EF44 /* PBXTargetDependency */,
23402355
AE2FC5951CFEFC70008F7981 /* PBXTargetDependency */,
23412356
);
@@ -2374,6 +2389,7 @@
23742389
buildRules = (
23752390
);
23762391
dependencies = (
2392+
B98F1742229AF5F900F2B002 /* PBXTargetDependency */,
23772393
);
23782394
name = plutil;
23792395
productName = plutil;
@@ -2509,7 +2525,7 @@
25092525
);
25102526
runOnlyForDeploymentPostprocessing = 0;
25112527
shellPath = /bin/sh;
2512-
shellScript = "cp ${BUILT_PRODUCTS_DIR}/xdgTestHelper.app/Contents/MacOS/xdgTestHelper ${BUILT_PRODUCTS_DIR}/TestFoundation.app/Contents/MacOS/\n";
2528+
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";
25132529
};
25142530
/* End PBXShellScriptBuildPhase section */
25152531

@@ -2964,6 +2980,16 @@
29642980
target = 5B5D885C1BBC938800234F36 /* SwiftFoundation */;
29652981
targetProxy = B90FD23120C2FF840087EF44 /* PBXContainerItemProxy */;
29662982
};
2983+
B98F1740229AF5AF00F2B002 /* PBXTargetDependency */ = {
2984+
isa = PBXTargetDependency;
2985+
target = EA66F66E1BF56CCB00136161 /* plutil */;
2986+
targetProxy = B98F173F229AF5AF00F2B002 /* PBXContainerItemProxy */;
2987+
};
2988+
B98F1742229AF5F900F2B002 /* PBXTargetDependency */ = {
2989+
isa = PBXTargetDependency;
2990+
target = 5B5D885C1BBC938800234F36 /* SwiftFoundation */;
2991+
targetProxy = B98F1741229AF5F900F2B002 /* PBXContainerItemProxy */;
2992+
};
29672993
EA993CE31BEACD8E000969A2 /* PBXTargetDependency */ = {
29682994
isa = PBXTargetDependency;
29692995
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)