mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Frontend: Only print the -project-name flag in private and package interfaces.
Resolves rdar://130992944.
This commit is contained in:
@@ -55,6 +55,10 @@ struct ModuleInterfaceOptions {
|
||||
/// Flags which appear in all .swiftinterface files.
|
||||
InterfaceFlags PublicFlags = {};
|
||||
|
||||
/// Flags which appear in both the private and package .swiftinterface files,
|
||||
/// but not the public interface.
|
||||
InterfaceFlags PrivateFlags = {};
|
||||
|
||||
/// Flags which appear only in the .package.swiftinterface.
|
||||
InterfaceFlags PackageFlags = {};
|
||||
|
||||
|
||||
@@ -489,13 +489,16 @@ static bool ShouldIncludeModuleInterfaceArg(const Arg *A) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ShouldIncludeArgInPackageInterfaceOnly(const Arg *A,
|
||||
ArgList &Args) {
|
||||
static bool IsPackageInterfaceFlag(const Arg *A, ArgList &Args) {
|
||||
return A->getOption().matches(options::OPT_package_name) &&
|
||||
Args.hasArg(
|
||||
options::OPT_disable_print_package_name_for_non_package_interface);
|
||||
}
|
||||
|
||||
static bool IsPrivateInterfaceFlag(const Arg *A, ArgList &Args) {
|
||||
return A->getOption().matches(options::OPT_project_name);
|
||||
}
|
||||
|
||||
/// Save a copy of any flags marked as ModuleInterfaceOption, if running
|
||||
/// in a mode that is going to emit a .swiftinterface file.
|
||||
static void SaveModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
|
||||
@@ -510,14 +513,18 @@ static void SaveModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
|
||||
};
|
||||
|
||||
RenderedInterfaceArgs PublicArgs{};
|
||||
RenderedInterfaceArgs PrivateArgs{};
|
||||
RenderedInterfaceArgs PackageArgs{};
|
||||
|
||||
auto interfaceArgListForArg = [&](Arg *A) -> ArgStringList & {
|
||||
bool ignorable =
|
||||
A->getOption().hasFlag(options::ModuleInterfaceOptionIgnorable);
|
||||
if (ShouldIncludeArgInPackageInterfaceOnly(A, Args))
|
||||
if (IsPackageInterfaceFlag(A, Args))
|
||||
return ignorable ? PackageArgs.Ignorable : PackageArgs.Standard;
|
||||
|
||||
if (IsPrivateInterfaceFlag(A, Args))
|
||||
return ignorable ? PrivateArgs.Ignorable : PrivateArgs.Standard;
|
||||
|
||||
return ignorable ? PublicArgs.Ignorable : PublicArgs.Standard;
|
||||
};
|
||||
|
||||
@@ -543,6 +550,7 @@ static void SaveModuleInterfaceArgs(ModuleInterfaceOptions &Opts,
|
||||
};
|
||||
|
||||
updateInterfaceOpts(Opts.PublicFlags, PublicArgs);
|
||||
updateInterfaceOpts(Opts.PrivateFlags, PrivateArgs);
|
||||
updateInterfaceOpts(Opts.PackageFlags, PackageArgs);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,12 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
|
||||
<< ToolsVersion << "\n";
|
||||
out << "// " SWIFT_MODULE_FLAGS_KEY ": " << Opts.PublicFlags.Flags;
|
||||
|
||||
// Append flags that are for the package interface only (e.g. -package-name
|
||||
// when -disable-print-package-name-for-non-package-interface is specified).
|
||||
if (Opts.printPackageInterface() && !Opts.PackageFlags.Flags.empty())
|
||||
if (Opts.InterfaceContentMode >= PrintOptions::InterfaceMode::Private &&
|
||||
!Opts.PrivateFlags.Flags.empty())
|
||||
out << " " << Opts.PrivateFlags.Flags;
|
||||
|
||||
if (Opts.InterfaceContentMode >= PrintOptions::InterfaceMode::Package &&
|
||||
!Opts.PackageFlags.Flags.empty())
|
||||
out << " " << Opts.PackageFlags.Flags;
|
||||
|
||||
// Insert additional -module-alias flags
|
||||
@@ -101,14 +104,29 @@ static void printToolVersionAndFlagsComment(raw_ostream &out,
|
||||
}
|
||||
out << "\n";
|
||||
|
||||
if (!Opts.PublicFlags.IgnorableFlags.empty()) {
|
||||
out << "// " SWIFT_MODULE_FLAGS_IGNORABLE_KEY ": "
|
||||
<< Opts.PublicFlags.IgnorableFlags << "\n";
|
||||
}
|
||||
// Add swift-module-flags-ignorable: if non-empty.
|
||||
{
|
||||
llvm::SmallVector<StringRef, 4> ignorableFlags;
|
||||
|
||||
// Append ignorable flags that are for the package interface only.
|
||||
if (Opts.printPackageInterface() && !Opts.PackageFlags.IgnorableFlags.empty())
|
||||
out << " " << Opts.PackageFlags.IgnorableFlags;
|
||||
if (!Opts.PublicFlags.IgnorableFlags.empty())
|
||||
ignorableFlags.push_back(Opts.PublicFlags.IgnorableFlags);
|
||||
|
||||
if (Opts.InterfaceContentMode >= PrintOptions::InterfaceMode::Private &&
|
||||
!Opts.PrivateFlags.IgnorableFlags.empty())
|
||||
ignorableFlags.push_back(Opts.PrivateFlags.IgnorableFlags);
|
||||
|
||||
if (Opts.InterfaceContentMode >= PrintOptions::InterfaceMode::Package &&
|
||||
!Opts.PackageFlags.IgnorableFlags.empty())
|
||||
ignorableFlags.push_back(Opts.PackageFlags.IgnorableFlags);
|
||||
|
||||
if (!ignorableFlags.empty()) {
|
||||
out << "// " SWIFT_MODULE_FLAGS_IGNORABLE_KEY ": ";
|
||||
llvm::interleave(
|
||||
ignorableFlags, [&out](StringRef str) { out << str; },
|
||||
[&out] { out << " "; });
|
||||
out << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
|
||||
23
test/ModuleInterface/project-name.swift
Normal file
23
test/ModuleInterface/project-name.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// RUN: %target-swift-frontend -emit-module %s -I %t \
|
||||
// RUN: -module-name Library -project-name ProjectName \
|
||||
// RUN: -enable-library-evolution -swift-version 5 \
|
||||
// RUN: -emit-module-interface-path %t/Library.swiftinterface \
|
||||
// RUN: -emit-private-module-interface-path %t/Library.private.swiftinterface \
|
||||
// RUN: -emit-package-module-interface-path %t/Library.package.swiftinterface
|
||||
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.private.swiftinterface) -module-name Library
|
||||
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.package.swiftinterface) -module-name Library
|
||||
|
||||
// RUN: %FileCheck %s < %t/Library.swiftinterface --check-prefix CHECK-PUBLIC
|
||||
// RUN: %FileCheck %s < %t/Library.private.swiftinterface --check-prefix CHECK-NONPUBLIC
|
||||
// RUN: %FileCheck %s < %t/Library.package.swiftinterface --check-prefix CHECK-NONPUBLIC
|
||||
|
||||
// CHECK-PUBLIC-NOT: -project-name
|
||||
|
||||
// CHECK-NONPUBLIC: swift-module-flags-ignorable:
|
||||
// CHECK-NONPUBLIC-SAME: -project-name ProjectName
|
||||
|
||||
public func foo() {}
|
||||
Reference in New Issue
Block a user