diff --git a/CMakeLists.txt b/CMakeLists.txt index cd358d45ae..68772b0bec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 -lFoundation ${Foundation_INTERFACE_LIBRARIES} - ${Foundation_RPATH} + ${plutil_rpath} SWIFT_FLAGS -DDEPLOYMENT_RUNTIME_SWIFT -I;${CMAKE_CURRENT_BINARY_DIR}/swift @@ -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) diff --git a/Foundation.xcodeproj/project.pbxproj b/Foundation.xcodeproj/project.pbxproj index 79115b0aa8..6b061c03a8 100644 --- a/Foundation.xcodeproj/project.pbxproj +++ b/Foundation.xcodeproj/project.pbxproj @@ -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 */; @@ -2336,6 +2350,7 @@ buildRules = ( ); dependencies = ( + B98F1740229AF5AF00F2B002 /* PBXTargetDependency */, B90FD23020C2FF420087EF44 /* PBXTargetDependency */, AE2FC5951CFEFC70008F7981 /* PBXTargetDependency */, ); @@ -2374,6 +2389,7 @@ buildRules = ( ); dependencies = ( + B98F1742229AF5F900F2B002 /* PBXTargetDependency */, ); name = plutil; productName = plutil; @@ -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 */ @@ -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 */; diff --git a/TestFoundation/TestProcess.swift b/TestFoundation/TestProcess.swift index 9ab5b7604c..90d15fa258 100644 --- a/TestFoundation/TestProcess.swift +++ b/TestFoundation/TestProcess.swift @@ -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), @@ -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), ] } } @@ -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.