Skip to content

plutil: Add a specific rpath for plutil and use it when linking. #2307

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 1 commit into from
Jun 25, 2019
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
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ if(FOUNDATION_ENABLE_LIBDISPATCH)
endif()
endif()

set(plutil_rpath)
if(CMAKE_SYSTEM_NAME STREQUAL Android OR CMAKE_SYSTEM_NAME STREQUAL Linux OR
CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(Foundation_RPATH -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN")
set(XDG_TEST_HELPER_RPATH -Xlinker;-rpath;-Xlinker;${CMAKE_CURRENT_BINARY_DIR})
set(plutil_rpath -Xlinker;-rpath;-Xlinker;"\\\$\$ORIGIN/../lib/swift/${swift_os}")
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
# FIXME(SR9138) Silence "locally defined symbol '…' imported in function '…'
set(WORKAROUND_SR9138 -Xlinker;-ignore:4049;-Xlinker;-ignore:4217)
Expand Down Expand Up @@ -389,11 +391,11 @@ add_swift_executable(plutil
CFLAGS
-F${CMAKE_CURRENT_BINARY_DIR}
LINK_FLAGS
${libdispatch_ldflags}
-L${CMAKE_CURRENT_BINARY_DIR}
-L;${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may add an empty /src to the library search path. @millenomi - is building Foundation with Dispatch something which is desired?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src was in the libdispatch_ldflags as a RUNPATH, so this is still needed for the link to succeed, but the RUNPATH itself isnt.

-lFoundation
${Foundation_INTERFACE_LIBRARIES}
${Foundation_RPATH}
${plutil_rpath}
SWIFT_FLAGS
-DDEPLOYMENT_RUNTIME_SWIFT
-I;${CMAKE_CURRENT_BINARY_DIR}/swift
Expand Down Expand Up @@ -601,7 +603,17 @@ if(ENABLE_TESTING)
ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:${FOUNDATION_PATH_TO_XCTEST_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}:${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD}/src
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX})
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/xdgTestHelper${CMAKE_EXECUTABLE_SUFFIX})

add_custom_command(TARGET TestFoundation
POST_BUILD
BYPRODUCTS
${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/plutil${CMAKE_EXECUTABLE_SUFFIX}
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/plutil${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR}/TestFoundation/plutil${CMAKE_EXECUTABLE_SUFFIX}
DEPENDS
TestFoundation
plutil)
endif()

if(BUILD_SHARED_LIBS)
Expand Down
28 changes: 27 additions & 1 deletion Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,20 @@
remoteGlobalIDString = 5B5D885C1BBC938800234F36;
remoteInfo = SwiftFoundation;
};
B98F173F229AF5AF00F2B002 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
proxyType = 1;
remoteGlobalIDString = EA66F66E1BF56CCB00136161;
remoteInfo = plutil;
};
B98F1741229AF5F900F2B002 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 5B5D885C1BBC938800234F36;
remoteInfo = SwiftFoundation;
};
EA993CE21BEACD8E000969A2 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 5B5D88541BBC938800234F36 /* Project object */;
Expand Down Expand Up @@ -2336,6 +2350,7 @@
buildRules = (
);
dependencies = (
B98F1740229AF5AF00F2B002 /* PBXTargetDependency */,
B90FD23020C2FF420087EF44 /* PBXTargetDependency */,
AE2FC5951CFEFC70008F7981 /* PBXTargetDependency */,
);
Expand Down Expand Up @@ -2374,6 +2389,7 @@
buildRules = (
);
dependencies = (
B98F1742229AF5F900F2B002 /* PBXTargetDependency */,
);
name = plutil;
productName = plutil;
Expand Down Expand Up @@ -2509,7 +2525,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cp ${BUILT_PRODUCTS_DIR}/xdgTestHelper.app/Contents/MacOS/xdgTestHelper ${BUILT_PRODUCTS_DIR}/TestFoundation.app/Contents/MacOS/\n";
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";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -2964,6 +2980,16 @@
target = 5B5D885C1BBC938800234F36 /* SwiftFoundation */;
targetProxy = B90FD23120C2FF840087EF44 /* PBXContainerItemProxy */;
};
B98F1740229AF5AF00F2B002 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = EA66F66E1BF56CCB00136161 /* plutil */;
targetProxy = B98F173F229AF5AF00F2B002 /* PBXContainerItemProxy */;
};
B98F1742229AF5F900F2B002 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 5B5D885C1BBC938800234F36 /* SwiftFoundation */;
targetProxy = B98F1741229AF5F900F2B002 /* PBXContainerItemProxy */;
};
EA993CE31BEACD8E000969A2 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 5B7C8A6D1BEA7F8F00C5B690 /* CoreFoundation */;
Expand Down
29 changes: 29 additions & 0 deletions TestFoundation/TestProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,33 @@ class TestProcess : XCTestCase {
task.waitUntilExit()
}


func test_plutil() throws {
let task = Process()

guard let url = testBundle().url(forAuxiliaryExecutable: "plutil") else {
throw Error.ExternalBinaryNotFound("plutil")
}

task.executableURL = url
task.arguments = []
let stdoutPipe = Pipe()
task.standardOutput = stdoutPipe

var stdoutData = Data()
stdoutPipe.fileHandleForReading.readabilityHandler = { fh in
stdoutData.append(fh.availableData)
}
try task.run()
task.waitUntilExit()
stdoutPipe.fileHandleForReading.readabilityHandler = nil
if let d = try stdoutPipe.fileHandleForReading.readToEnd() {
stdoutData.append(d)
}
XCTAssertEqual(String(data: stdoutData, encoding: .utf8), "No files specified.\n")
}


static var allTests: [(String, (TestProcess) -> () throws -> Void)] {
return [
("test_exit0" , test_exit0),
Expand Down Expand Up @@ -541,6 +568,7 @@ class TestProcess : XCTestCase {
("test_redirect_stderr_using_null", test_redirect_stderr_using_null),
("test_redirect_all_using_null", test_redirect_all_using_null),
("test_redirect_all_using_nil", test_redirect_all_using_nil),
("test_plutil", test_plutil),
]
}
}
Expand All @@ -549,6 +577,7 @@ private enum Error: Swift.Error {
case TerminationStatus(Int32)
case UnicodeDecodingError(Data)
case InvalidEnvironmentVariable(String)
case ExternalBinaryNotFound(String)
}

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