Skip to content

Commit 1ec900e

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 4590aa1 commit 1ec900e

File tree

8 files changed

+97
-5
lines changed

8 files changed

+97
-5
lines changed

include/swift/Driver/ToolChain.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ class ToolChain {
143143
const llvm::opt::ArgList &inputArgs,
144144
llvm::opt::ArgStringList &arguments) const;
145145

146+
virtual void addPlatformSpecificPluginFrontendArgs(
147+
const OutputInfo &OI,
148+
const CommandOutput &output,
149+
const llvm::opt::ArgList &inputArgs,
150+
llvm::opt::ArgStringList &arguments) const;
146151
virtual InvocationInfo constructInvocation(const CompileJobAction &job,
147152
const JobContext &context) const;
148153
virtual InvocationInfo constructInvocation(const InterpretJobAction &job,

lib/Driver/DarwinToolChains.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,51 @@ 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+
646+
void toolchains::Darwin::addPlatformSpecificPluginFrontendArgs(
647+
const OutputInfo &OI,
648+
const CommandOutput &output,
649+
const llvm::opt::ArgList &inputArgs,
650+
llvm::opt::ArgStringList &arguments) const {
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+
}
666+
}
667+
623668
ToolChain::InvocationInfo
624669
toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
625670
const JobContext &context) const {

lib/Driver/ToolChains.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
375375
// Specify default plugin search path options after explicitly specified
376376
// options.
377377
inputArgs.AddAllArgs(arguments, options::OPT_plugin_search_Group);
378+
addPlatformSpecificPluginFrontendArgs(OI, output, inputArgs, arguments);
379+
380+
// Toolchain-relative plugin paths
378381
{
379382
SmallString<64> pluginPath;
380383
auto programPath = getDriver().getSwiftProgramPath();
@@ -403,6 +406,14 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
403406
inputArgs.AddAllArgs(arguments, options::OPT_Xcc);
404407
}
405408

409+
void ToolChain::addPlatformSpecificPluginFrontendArgs(
410+
const OutputInfo &OI,
411+
const CommandOutput &output,
412+
const llvm::opt::ArgList &inputArgs,
413+
llvm::opt::ArgStringList &arguments) const {
414+
// Overridden where necessary.
415+
}
416+
406417
static void addRuntimeLibraryFlags(const OutputInfo &OI,
407418
ArgStringList &Arguments) {
408419
if (!OI.RuntimeVariant)

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)