Skip to content

Commit 60b0515

Browse files
committed
[Macros] Add default plugin paths for Darwin SDKs and platforms.
Corresponding to swiftlang/swift-driver#1377, this adds some default plugin paths for Darwin SDKs and platforms. Fixes rdar://110819604.
1 parent 0998847 commit 60b0515

File tree

6 files changed

+75
-7
lines changed

6 files changed

+75
-7
lines changed

lib/Driver/DarwinToolChains.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,49 @@ void toolchains::Darwin::addCommonFrontendArgs(
620620
}
621621
}
622622

623+
/// Add the frontend arguments needed to find external plugins in standard
624+
/// locations based on the base path.
625+
static void addExternalPluginFrontendArgs(
626+
StringRef basePath, const llvm::opt::ArgList &inputArgs,
627+
llvm::opt::ArgStringList &arguments) {
628+
// Plugin server: $BASE/usr/bin/swift-plugin-server
629+
SmallString<128> pluginServer;
630+
llvm::sys::path::append(
631+
pluginServer, basePath, "usr", "bin", "swift-plugin-server");
632+
633+
SmallString<128> pluginDir;
634+
llvm::sys::path::append(pluginDir, basePath, "usr", "lib");
635+
llvm::sys::path::append(pluginDir, "swift", "host", "plugins");
636+
arguments.push_back("-external-plugin-path");
637+
arguments.push_back(inputArgs.MakeArgString(pluginDir + "#" + pluginServer));
638+
639+
pluginDir.clear();
640+
llvm::sys::path::append(pluginDir, basePath, "usr", "local", "lib");
641+
llvm::sys::path::append(pluginDir, "swift", "host", "plugins");
642+
arguments.push_back("-external-plugin-path");
643+
arguments.push_back(inputArgs.MakeArgString(pluginDir + "#" + pluginServer));
644+
}
645+
623646
void toolchains::Darwin::addPlatformSpecificPluginFrontendArgs(
624647
const OutputInfo &OI,
625648
const CommandOutput &output,
626649
const llvm::opt::ArgList &inputArgs,
627650
llvm::opt::ArgStringList &arguments) const {
628-
651+
// Add SDK-relative directories for plugins.
652+
if (!OI.SDKPath.empty()) {
653+
addExternalPluginFrontendArgs(OI.SDKPath, inputArgs, arguments);
654+
}
655+
656+
// Add platform-relative directories for plugins.
657+
if (!OI.SDKPath.empty()) {
658+
SmallString<128> platformPath;
659+
llvm::sys::path::append(platformPath, OI.SDKPath);
660+
llvm::sys::path::remove_filename(platformPath); // specific SDK
661+
llvm::sys::path::remove_filename(platformPath); // SDKs
662+
llvm::sys::path::remove_filename(platformPath); // Developer
663+
llvm::sys::path::append(platformPath, "Developer");
664+
addExternalPluginFrontendArgs(platformPath, inputArgs, arguments);
665+
}
629666
}
630667

631668
ToolChain::InvocationInfo
@@ -702,7 +739,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
702739
}
703740

704741
if (context.Args.hasArg(options::OPT_enable_app_extension)) {
705-
// Keep this string fixed in case the option used by the
742+
// Keep this string fixed in case the option used by thez
706743
// compiler itself changes.
707744
Arguments.push_back("-application_extension");
708745
}

lib/Driver/ToolChains.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
5353
const llvm::opt::ArgList &inputArgs,
5454
llvm::opt::ArgStringList &arguments) const override;
5555

56+
void addPlatformSpecificPluginFrontendArgs(
57+
const OutputInfo &OI,
58+
const CommandOutput &output,
59+
const llvm::opt::ArgList &inputArgs,
60+
llvm::opt::ArgStringList &arguments) const override;
61+
5662
InvocationInfo constructInvocation(const InterpretJobAction &job,
5763
const JobContext &context) const override;
5864
InvocationInfo constructInvocation(const DynamicLinkJobAction &job,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s 2>^1 | %FileCheck %s
2+
// REQUIRES: OS=macosx
3+
4+
// CHECK: -external-plugin-path
5+
// CHECK-SAME: .sdk/usr/lib/swift/host/plugins#
6+
// CHECK-SAME: .sdk/usr/bin/swift-plugin-server
7+
8+
// CHECK-SAME: -external-plugin-path
9+
// CHECK-SAME: .sdk/usr/local/lib/swift/host/plugins#
10+
// CHECK-SAME: .sdk/usr/bin/swift-plugin-server
11+
12+
// CHECK-SAME: -external-plugin-path
13+
// CHECK-SAME: MacOSX.platform/Developer/usr/lib/swift/host/plugins#
14+
// CHECK-SAME: MacOSX.platform/Developer/usr/bin/swift-plugin-server
15+
16+
// CHECK-SAME: -external-plugin-path
17+
// CHECK-SAME: MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#
18+
// CHECK-SAME: MacOSX.platform/Developer/usr/bin/swift-plugin-server
19+
20+
// CHECK-SAME: -plugin-path
21+
// CHECK-SAME: {{(/|\\\\)}}lib{{(/|\\\\)}}swift{{(/|\\\\)}}host{{(/|\\\\)}}plugins
22+
23+
// CHECK-SAME: -plugin-path
24+
// CHECK-SAME: {{(/|\\\\)}}local{{(/|\\\\)}}lib{{(/|\\\\)}}swift{{(/|\\\\)}}host{{(/|\\\\)}}plugins

test/Driver/driver-compile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
// COMPLEX: bin{{/|\\\\}}swift
7676
// COMPLEX: -c
7777
// COMPLEX: Driver{{/|\\\\}}driver-compile.swift
78-
// COMPLEX-DAG: -sdk {{.*}}/Inputs/clang-importer-sdk
78+
// COMPLEX-DAG: -sdk
7979
// COMPLEX-DAG: -foo -bar
8080
// COMPLEX-DAG: -Xllvm -baz
8181
// COMPLEX-DAG: -Xcc -garply

test/Driver/merge-module.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@
3636
// SIMPLE: -o main.swiftmodule
3737

3838

39-
// COMPLEX: {{bin(/|\\\\)swift(-frontend|c)?(\.exe)?"?}} -frontend
39+
// COMPLEX: -frontend
4040
// COMPLEX: -emit-module
4141
// COMPLEX-DAG: -emit-module-doc-path {{[^ ]*[/\\]}}merge-module-{{[^ ]*}}.swiftdoc
42-
// COMPLEX-DAG: -sdk {{.*}}/Inputs/clang-importer-sdk
42+
// COMPLEX-DAG: -sdk
43+
// COMPLEX-DAG /Inputs/clang-importer-sdk
4344
// COMPLEX-DAG: -foo -bar
4445
// COMPLEX-DAG: -F /path/to/frameworks -F /path/to/more/frameworks
4546
// COMPLEX-DAG: -I /path/to/headers -I path/to/more/headers
4647
// COMPLEX-DAG: -module-cache-path /tmp/modules
47-
// COMPLEX: {{bin(/|\\\\)swift(-frontend|c)?(\.exe)?"?}} -frontend
48+
// COMPLEX-DAG: -frontend
4849
// COMPLEX: -emit-module
4950
// COMPLEX-DAG: -F /path/to/frameworks -F /path/to/more/frameworks
5051
// COMPLEX-DAG: -I /path/to/headers -I path/to/more/headers

test/Driver/sdk.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// OSX: bin{{/|\\\\}}swift
1313
// OSX: Driver{{/|\\\\}}sdk.swift
1414
// OSX: -sdk {{.*}}/Inputs/clang-importer-sdk
15-
// OSX-NEXT: bin{{/|\\\\}}swift
15+
// OSX: bin{{/|\\\\}}swift
1616
// OSX: -sdk {{.*}}/Inputs/clang-importer-sdk
1717
// OSX: {{.*}}.o{{[ "]}}
1818
// OSX: {{-syslibroot|--sysroot}} {{[^ ]*}}/Inputs/clang-importer-sdk

0 commit comments

Comments
 (0)