[Macros] Add default plugin paths for Darwin SDKs and platforms.

Corresponding to https://github.com/apple/swift-driver/pull/1377, this
adds some default plugin paths for Darwin SDKs and platforms.
Fixes rdar://110819604.
This commit is contained in:
Doug Gregor
2023-06-15 17:45:48 -07:00
parent 4590aa1ede
commit 1ec900e2a0
8 changed files with 97 additions and 5 deletions

View File

@@ -143,6 +143,11 @@ protected:
const llvm::opt::ArgList &inputArgs,
llvm::opt::ArgStringList &arguments) const;
virtual void addPlatformSpecificPluginFrontendArgs(
const OutputInfo &OI,
const CommandOutput &output,
const llvm::opt::ArgList &inputArgs,
llvm::opt::ArgStringList &arguments) const;
virtual InvocationInfo constructInvocation(const CompileJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const InterpretJobAction &job,

View File

@@ -620,6 +620,51 @@ void toolchains::Darwin::addCommonFrontendArgs(
}
}
/// Add the frontend arguments needed to find external plugins in standard
/// locations based on the base path.
static void addExternalPluginFrontendArgs(
StringRef basePath, const llvm::opt::ArgList &inputArgs,
llvm::opt::ArgStringList &arguments) {
// Plugin server: $BASE/usr/bin/swift-plugin-server
SmallString<128> pluginServer;
llvm::sys::path::append(
pluginServer, basePath, "usr", "bin", "swift-plugin-server");
SmallString<128> pluginDir;
llvm::sys::path::append(pluginDir, basePath, "usr", "lib");
llvm::sys::path::append(pluginDir, "swift", "host", "plugins");
arguments.push_back("-external-plugin-path");
arguments.push_back(inputArgs.MakeArgString(pluginDir + "#" + pluginServer));
pluginDir.clear();
llvm::sys::path::append(pluginDir, basePath, "usr", "local", "lib");
llvm::sys::path::append(pluginDir, "swift", "host", "plugins");
arguments.push_back("-external-plugin-path");
arguments.push_back(inputArgs.MakeArgString(pluginDir + "#" + pluginServer));
}
void toolchains::Darwin::addPlatformSpecificPluginFrontendArgs(
const OutputInfo &OI,
const CommandOutput &output,
const llvm::opt::ArgList &inputArgs,
llvm::opt::ArgStringList &arguments) const {
// Add SDK-relative directories for plugins.
if (!OI.SDKPath.empty()) {
addExternalPluginFrontendArgs(OI.SDKPath, inputArgs, arguments);
}
// Add platform-relative directories for plugins.
if (!OI.SDKPath.empty()) {
SmallString<128> platformPath;
llvm::sys::path::append(platformPath, OI.SDKPath);
llvm::sys::path::remove_filename(platformPath); // specific SDK
llvm::sys::path::remove_filename(platformPath); // SDKs
llvm::sys::path::remove_filename(platformPath); // Developer
llvm::sys::path::append(platformPath, "Developer");
addExternalPluginFrontendArgs(platformPath, inputArgs, arguments);
}
}
ToolChain::InvocationInfo
toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
const JobContext &context) const {

View File

@@ -375,6 +375,9 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
// Specify default plugin search path options after explicitly specified
// options.
inputArgs.AddAllArgs(arguments, options::OPT_plugin_search_Group);
addPlatformSpecificPluginFrontendArgs(OI, output, inputArgs, arguments);
// Toolchain-relative plugin paths
{
SmallString<64> pluginPath;
auto programPath = getDriver().getSwiftProgramPath();
@@ -403,6 +406,14 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
inputArgs.AddAllArgs(arguments, options::OPT_Xcc);
}
void ToolChain::addPlatformSpecificPluginFrontendArgs(
const OutputInfo &OI,
const CommandOutput &output,
const llvm::opt::ArgList &inputArgs,
llvm::opt::ArgStringList &arguments) const {
// Overridden where necessary.
}
static void addRuntimeLibraryFlags(const OutputInfo &OI,
ArgStringList &Arguments) {
if (!OI.RuntimeVariant)

View File

@@ -53,6 +53,12 @@ protected:
const llvm::opt::ArgList &inputArgs,
llvm::opt::ArgStringList &arguments) const override;
void addPlatformSpecificPluginFrontendArgs(
const OutputInfo &OI,
const CommandOutput &output,
const llvm::opt::ArgList &inputArgs,
llvm::opt::ArgStringList &arguments) const override;
InvocationInfo constructInvocation(const InterpretJobAction &job,
const JobContext &context) const override;
InvocationInfo constructInvocation(const DynamicLinkJobAction &job,

View File

@@ -0,0 +1,24 @@
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s 2>^1 | %FileCheck %s
// REQUIRES: OS=macosx
// CHECK: -external-plugin-path
// CHECK-SAME: .sdk/usr/lib/swift/host/plugins#
// CHECK-SAME: .sdk/usr/bin/swift-plugin-server
// CHECK-SAME: -external-plugin-path
// CHECK-SAME: .sdk/usr/local/lib/swift/host/plugins#
// CHECK-SAME: .sdk/usr/bin/swift-plugin-server
// CHECK-SAME: -external-plugin-path
// CHECK-SAME: MacOSX.platform/Developer/usr/lib/swift/host/plugins#
// CHECK-SAME: MacOSX.platform/Developer/usr/bin/swift-plugin-server
// CHECK-SAME: -external-plugin-path
// CHECK-SAME: MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#
// CHECK-SAME: MacOSX.platform/Developer/usr/bin/swift-plugin-server
// CHECK-SAME: -plugin-path
// CHECK-SAME: {{(/|\\\\)}}lib{{(/|\\\\)}}swift{{(/|\\\\)}}host{{(/|\\\\)}}plugins
// CHECK-SAME: -plugin-path
// CHECK-SAME: {{(/|\\\\)}}local{{(/|\\\\)}}lib{{(/|\\\\)}}swift{{(/|\\\\)}}host{{(/|\\\\)}}plugins

View File

@@ -75,7 +75,7 @@
// COMPLEX: bin{{/|\\\\}}swift
// COMPLEX: -c
// COMPLEX: Driver{{/|\\\\}}driver-compile.swift
// COMPLEX-DAG: -sdk {{.*}}/Inputs/clang-importer-sdk
// COMPLEX-DAG: -sdk
// COMPLEX-DAG: -foo -bar
// COMPLEX-DAG: -Xllvm -baz
// COMPLEX-DAG: -Xcc -garply

View File

@@ -36,15 +36,16 @@
// SIMPLE: -o main.swiftmodule
// COMPLEX: {{bin(/|\\\\)swift(-frontend|c)?(\.exe)?"?}} -frontend
// COMPLEX: -frontend
// COMPLEX: -emit-module
// COMPLEX-DAG: -emit-module-doc-path {{[^ ]*[/\\]}}merge-module-{{[^ ]*}}.swiftdoc
// COMPLEX-DAG: -sdk {{.*}}/Inputs/clang-importer-sdk
// COMPLEX-DAG: -sdk
// COMPLEX-DAG /Inputs/clang-importer-sdk
// COMPLEX-DAG: -foo -bar
// COMPLEX-DAG: -F /path/to/frameworks -F /path/to/more/frameworks
// COMPLEX-DAG: -I /path/to/headers -I path/to/more/headers
// COMPLEX-DAG: -module-cache-path /tmp/modules
// COMPLEX: {{bin(/|\\\\)swift(-frontend|c)?(\.exe)?"?}} -frontend
// COMPLEX-DAG: -frontend
// COMPLEX: -emit-module
// COMPLEX-DAG: -F /path/to/frameworks -F /path/to/more/frameworks
// COMPLEX-DAG: -I /path/to/headers -I path/to/more/headers

View File

@@ -12,7 +12,7 @@
// OSX: bin{{/|\\\\}}swift
// OSX: Driver{{/|\\\\}}sdk.swift
// OSX: -sdk {{.*}}/Inputs/clang-importer-sdk
// OSX-NEXT: bin{{/|\\\\}}swift
// OSX: bin{{/|\\\\}}swift
// OSX: -sdk {{.*}}/Inputs/clang-importer-sdk
// OSX: {{.*}}.o{{[ "]}}
// OSX: {{-syslibroot|--sysroot}} {{[^ ]*}}/Inputs/clang-importer-sdk