Skip to content

Commit 6701a33

Browse files
committed
[sourcekit] Enable installing both sourcekitdInProc and sourcekitd
Makes it possible to build and install both sourcekitdInProc and the XPC service on Darwin.
1 parent 472d88d commit 6701a33

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

tools/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
include(CheckIncludeFiles)
22
check_include_files("xpc/xpc.h" HAVE_XPC_H)
33

4-
swift_is_installing_component(sourcekit-inproc SOURCEKIT_INSTALLING_INPROC)
5-
6-
if(HAVE_XPC_H AND SWIFT_BUILD_SOURCEKIT AND NOT SOURCEKIT_INSTALLING_INPROC)
4+
if(HAVE_XPC_H AND SWIFT_BUILD_SOURCEKIT)
75
set(BUILD_SOURCEKIT_XPC_SERVICE TRUE)
86
else()
97
set(BUILD_SOURCEKIT_XPC_SERVICE FALSE)

tools/SourceKit/tools/sourcekitd/bin/InProc/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ set(EXPORTED_SYMBOL_FILE "${SOURCEKITD_SOURCE_DIR}/bin/sourcekitd.exports")
33
option(SOURCEKITD_BUILD_STATIC_INPROC
44
"Build sourcekitdInProc as a static library (in addition to a shared one)" OFF)
55

6+
swift_is_installing_component(sourcekit-inproc SOURCEKIT_INSTALLING_INPROC)
7+
68
set(sourcekitdInProc_args
79
sourcekitdInProc.cpp
810
LLVM_LINK_COMPONENTS support coverage
@@ -17,6 +19,11 @@ if (SOURCEKIT_INSTALLING_INPROC)
1719
INSTALL_IN_COMPONENT sourcekit-inproc
1820
)
1921
set_property(TARGET sourcekitdInProc APPEND_STRING PROPERTY LINK_FLAGS " -fapplication-extension")
22+
if (SOURCEKIT_DEPLOYMENT_OS MATCHES "^macosx")
23+
add_definitions(-DSOURCEKIT_VERSIONED_FRAMEWORK_BUNDLE)
24+
else()
25+
add_definitions(-DSOURCEKIT_UNVERSIONED_FRAMEWORK_BUNDLE)
26+
endif()
2027
else()
2128
add_sourcekit_library(sourcekitdInProc
2229
${sourcekitdInProc_args}

tools/SourceKit/tools/sourcekitd/bin/InProc/sourcekitdInProc.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,32 @@ static void getToolchainPrefixPath(llvm::SmallVectorImpl<char> &Path) {
4545
if (!GetModuleFileNameA(static_cast<HINSTANCE>(mbi.AllocationBase), path,
4646
MAX_PATH))
4747
llvm_unreachable("call to GetModuleFileNameA failed");
48-
auto parent =
49-
llvm::sys::path::parent_path(llvm::sys::path::parent_path(path));
48+
auto parent = llvm::sys::path::parent_path(path);
5049
Path.append(parent.begin(), parent.end());
5150
#else
5251
// This silly cast below avoids a C++ warning.
5352
Dl_info info;
5453
if (dladdr((void *)(uintptr_t)sourcekitd_initialize, &info) == 0)
5554
llvm_unreachable("Call to dladdr() failed");
56-
5755
// We now have the path to the shared lib, move to the parent prefix path.
58-
auto parent = llvm::sys::path::parent_path(
59-
llvm::sys::path::parent_path(info.dli_fname));
56+
auto parent = llvm::sys::path::parent_path(info.dli_fname);
6057
Path.append(parent.begin(), parent.end());
6158
#endif
59+
60+
#if defined(SOURCEKIT_UNVERSIONED_FRAMEWORK_BUNDLE)
61+
// Path points to e.g. "usr/lib/sourcekitdInProc.framework/"
62+
const unsigned NestingLevel = 2;
63+
#elif defined(SOURCEKIT_VERSIONED_FRAMEWORK_BUNDLE)
64+
// Path points to e.g. "usr/lib/sourcekitdInProc.framework/Versions/Current/"
65+
const unsigned NestingLevel = 4;
66+
#else
67+
// Path points to e.g. "usr/lib/"
68+
const unsigned NestingLevel = 1;
69+
#endif
70+
71+
// Get it to "usr"
72+
for (unsigned i = 0; i < NestingLevel; ++i)
73+
llvm::sys::path::remove_filename(Path);
6274
}
6375

6476
static std::string getRuntimeLibPath() {

tools/SourceKit/tools/sourcekitd/bin/XPC/Service/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if (NOT SOURCEKIT_INSTALLING_INPROC)
1+
if (BUILD_SOURCEKIT_XPC_SERVICE)
22
add_sourcekit_xpc_service(SourceKitService sourcekitd
33
XPCService.cpp
44
LLVM_LINK_COMPONENTS support coverage

0 commit comments

Comments
 (0)